aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGil Pitney <gil.pitney@linaro.org>2014-12-08 18:45:22 -0800
committerGil Pitney <gil.pitney@linaro.org>2014-12-08 18:52:06 -0800
commit9ec15177ee308a2f730d9dbb030352c7ad7fc227 (patch)
tree7371026c25e895905d59d1337babb8a0630aef82
parent76bd0a080cd23ea52bd88d0520b2f450ad33a6c5 (diff)
Added -ffake-address-space-map option to generate LLVM IR address spaces
Previously, shamrock was not able to get address space attributes from LLVM's getAddressSpace() API for function (kernel) arguments, as they didn't exist in the generated LLVM IR. Now, we use a clang option to force address space mapping, causing addrspace(<n>) attrs to be inserted. See the discussion here: https://www.mail-archive.com/cfe-commits@cs.uiuc.edu/msg76370.html This was a necessary step to get many of the Khronos basic tests involving local variables and parameters to not crash. Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
-rw-r--r--src/builtins/CMakeLists.txt2
-rw-r--r--src/core/compiler.cpp6
-rw-r--r--src/core/kernel.cpp3
-rw-r--r--src/core/kernel.h13
4 files changed, 15 insertions, 9 deletions
diff --git a/src/builtins/CMakeLists.txt b/src/builtins/CMakeLists.txt
index a83dfdf..d91c775 100644
--- a/src/builtins/CMakeLists.txt
+++ b/src/builtins/CMakeLists.txt
@@ -1,6 +1,6 @@
if (SHAMROCK_BUILD)
-set(CUSTOM_COMMAND ${CLANG_EXECUTABLE} -cc1 -emit-llvm-bc -x cl -O2 -fno-builtin -nobuiltininc -Fvisibility=protected -cl-std=CL1.2 -ffp-contract=off )
+set(CUSTOM_COMMAND ${CLANG_EXECUTABLE} -cc1 -emit-llvm-bc -x cl -O2 -fno-builtin -nobuiltininc -Fvisibility=protected -ffake-address-space-map -cl-std=CL1.2 -ffp-contract=off )
FILE(GLOB CL_SOURCES ${CLC_BUILTINS_DIR}/*.cl)
#MESSAGE(STATUS "CL_SOURCES: ${CL_SOURCES}" )
diff --git a/src/core/compiler.cpp b/src/core/compiler.cpp
index d4d5240..eb121cb 100644
--- a/src/core/compiler.cpp
+++ b/src/core/compiler.cpp
@@ -127,6 +127,10 @@ int Compiler::compile(const std::string &options,
if (devtype == CL_DEVICE_TYPE_CPU) {
// Originally: target_opts.Triple = llvm::sys::getHostTriple();
target_opts.Triple = llvm::sys::getDefaultTargetTriple();
+ // For CPU, we need OpenCL address space modifiers on our data types.
+ // This setting achieves that, and shamrock needs to know clang's address mapping.
+ // In the future, if we ever get a SPIR->ARM backend, this may be unnecessary.
+ lang_opts.FakeAddressSpaceMap = true;
}
else // devtype != CL_DEVICE_TYPE_CPU
{
@@ -286,7 +290,7 @@ int Compiler::compile(const std::string &options,
p_module = Act->takeModule();
// uncomment to debug the llvm IR
- // p_module->dump();
+ // p_module->dump();
return false;
}
diff --git a/src/core/kernel.cpp b/src/core/kernel.cpp
index 4c53576..76c7ab8 100644
--- a/src/core/kernel.cpp
+++ b/src/core/kernel.cpp
@@ -178,7 +178,8 @@ cl_int Kernel::addFunction(DeviceInterface *device, llvm::Function *function,
// It's a pointer, dereference it
llvm::PointerType *p_type = llvm::cast<llvm::PointerType>(arg_type);
- file = (Arg::File)p_type->getAddressSpace();
+ unsigned int space = p_type->getAddressSpace();
+ file = (Arg::File)space;
arg_type = p_type->getElementType();
// If it's a __local argument, we'll have to allocate memory at run time
diff --git a/src/core/kernel.h b/src/core/kernel.h
index 80672ea..d633aa2 100644
--- a/src/core/kernel.h
+++ b/src/core/kernel.h
@@ -90,15 +90,16 @@ class Kernel : public Object
enum File
{
Private = 0, /*!< \brief __private */
-#if 1
+#ifdef SHAMROCK_BUILD
+ /* clang -ffake-address-space-map mappings, LLVM IR */
+ Global = 1, /*!< \brief __global */
+ Local = 2, /*!< \brief __local */
+ Constant = 3 /*!< \brief __constant */
+#else
+ /* Mapping used by TI DSP (SPIR) */
Global = 1, /*!< \brief __global */
Constant = 2, /*!< \brief __constant */
Local = 3 /*!< \brief __local */
-#else
- /* using clang defaults */
- Global = 0xFFFF00, /*!< \brief __global */
- Local = 0xFFFF01, /*!< \brief __local */
- Constant = 0xFFFF02 /*!< \brief __constant */
#endif
};