summaryrefslogtreecommitdiff
path: root/backend/src/llvm
diff options
context:
space:
mode:
authorBenjamin Segovia <devnull@localhost>2012-06-12 18:34:25 +0000
committerKeith Packard <keithp@keithp.com>2012-08-10 16:18:28 -0700
commit8b40191eda9bc7de918daf01f54c6a08d0f3b543 (patch)
tree3c29695ea96aed6b16a242260fab54a7c8ec0355 /backend/src/llvm
parent645e55a0ac148344ee7e7c5e57f1b8d3b95b4eb5 (diff)
Cleaned up the code to enable the blob compilation path
Diffstat (limited to 'backend/src/llvm')
-rw-r--r--backend/src/llvm/llvm_gen_backend.cpp10
-rw-r--r--backend/src/llvm/llvm_passes.cpp8
-rw-r--r--backend/src/llvm/llvm_to_gen.cpp9
3 files changed, 18 insertions, 9 deletions
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
index cbda45cc..c52f348c 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -448,8 +448,10 @@ namespace gbe
GBE_ASSERTM(false, "Unsupported constant expression");
if (ConstantVector *CV = dyn_cast<ConstantVector>(CPV)) {
+#if GBE_DEBUG
const uint32_t elemNum = CV->getNumOperands();
GBE_ASSERTM(index < elemNum, "Out-of-bound constant vector access");
+#endif /* GBE_DEBUG */
CPV = cast<Constant>(CV->getOperand(index));
}
@@ -659,11 +661,11 @@ namespace gbe
// When returning a structure, first input register is the pointer to the
// structure
+#if GBE_DEBUG
const Type *type = F.getReturnType();
GBE_ASSERTM(type->isVoidTy() == true,
"Returned value for kernel functions is forbidden");
-#if GBE_DEBUG
// Variable number of arguments is not supported
FunctionType *FT = cast<FunctionType>(F.getFunctionType());
GBE_ASSERT(FT->isVarArg() == false);
@@ -901,9 +903,11 @@ namespace gbe
{
Constant *CPV = dyn_cast<Constant>(srcValue);
if (CPV == NULL) {
+#if GBE_DEBUG
Type *dstType = dstValue->getType();
Type *srcType = srcValue->getType();
GBE_ASSERT(getTypeByteSize(unit, dstType) == getTypeByteSize(unit, srcType));
+#endif /* GBE_DEBUG */
regTranslator.newValueProxy(srcValue, dstValue);
} else
this->newRegister(dstValue);
@@ -1072,10 +1076,12 @@ namespace gbe
"Invalid index type for InsertElement");
// Crash on overrun
+ const uint32_t extractedID = x.data.u32;
+#if GBE_DEBUG
VectorType *vectorType = cast<VectorType>(extracted->getType());
const uint32_t elemNum = vectorType->getNumElements();
- const uint32_t extractedID = x.data.u32;
GBE_ASSERTM(extractedID < elemNum, "Out-of-bound index for InsertElement");
+#endif /* GBE_DEBUG */
// Easy when the vector is not immediate
regTranslator.newValueProxy(extracted, &I, extractedID, 0);
diff --git a/backend/src/llvm/llvm_passes.cpp b/backend/src/llvm/llvm_passes.cpp
index 9d900e34..c6c33060 100644
--- a/backend/src/llvm/llvm_passes.cpp
+++ b/backend/src/llvm/llvm_passes.cpp
@@ -18,13 +18,15 @@
*/
/**
- * \file llvm_to_gen.cpp
+ * \file llvm_passes.cpp
* \author Benjamin Segovia <benjamin.segovia@intel.com>
+ * \author Heldge RHodin <alice.rhodin@alice-dsl.net>
*/
-/* THIS CODE IS DERIVED FROM LLVM PTX BACKEND. CODE IS HERE:
+/* THIS CODE IS DERIVED FROM GPL LLVM PTX BACKEND. CODE IS HERE:
* http://sourceforge.net/scm/?type=git&group_id=319085
- * Note that the LICENSE is GPL
+ * Note that however, the original author, Heldge Rhodin, granted me (Benjamin
+ * Segovia) the right to use another license for it (MIT here)
*/
#include "llvm/CallingConv.h"
diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp
index 0759f46f..a41f4a58 100644
--- a/backend/src/llvm/llvm_to_gen.cpp
+++ b/backend/src/llvm/llvm_to_gen.cpp
@@ -39,6 +39,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <memory>
namespace gbe
{
@@ -52,7 +53,7 @@ namespace gbe
// Get the global LLVM context
llvm::LLVMContext& c = llvm::getGlobalContext();
std::string errInfo;
- auto *o = new llvm::raw_fd_ostream("-", errInfo);
+ std::unique_ptr<llvm::raw_fd_ostream> o(new llvm::raw_fd_ostream("-", errInfo));
// Get the module from its file
SMDiagnostic Err;
@@ -65,7 +66,7 @@ namespace gbe
// Print the code before further optimizations
if (OCL_OUTPUT_LLVM_BEFORE_EXTRA_PASS)
- passes.add(createPrintModulePass(o));
+ passes.add(createPrintModulePass(&*o));
passes.add(createScalarReplAggregatesPass()); // Break up allocas
passes.add(createRemoveGEPPass(unit));
passes.add(createConstantPropagationPass());
@@ -77,11 +78,11 @@ namespace gbe
// Print the code extra optimization passes
if (OCL_OUTPUT_LLVM)
- passes.add(createPrintModulePass(o));
+ passes.add(createPrintModulePass(&*o));
passes.run(mod);
// raw_fd_ostream closes stdout. We must reopen it
- delete o;
+ o = NULL;
int fd;
fd = open("/dev/tty", O_WRONLY);
stdout = fdopen(fd, "w");