From d87748c5dd49d9f681920a02d1767c4abcc29cfa Mon Sep 17 00:00:00 2001 From: Ilia Filippov Date: Wed, 15 Jan 2014 14:58:42 +0400 Subject: [PATCH 1/3] switching to 1d tasking in 'mandelbrot_tasks' benchmark --- examples/mandelbrot_tasks/mandelbrot_tasks.ispc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/mandelbrot_tasks/mandelbrot_tasks.ispc b/examples/mandelbrot_tasks/mandelbrot_tasks.ispc index c765b29b..eea65f55 100644 --- a/examples/mandelbrot_tasks/mandelbrot_tasks.ispc +++ b/examples/mandelbrot_tasks/mandelbrot_tasks.ispc @@ -31,7 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define _3D_TASKING +//#define _3D_TASKING //uncomment for using "3d tasking" model. This can influence performance. static inline int mandel(float c_re, float c_im, int count) { From aa31957d842d2be230afe658ce89427540fb1d73 Mon Sep 17 00:00:00 2001 From: Ilia Filippov Date: Tue, 21 Jan 2014 14:21:26 +0400 Subject: [PATCH 2/3] supporting LLVM trunk --- builtins.cpp | 10 +++++++++- cbackend.cpp | 21 ++++++++++++++++----- func.cpp | 8 ++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/builtins.cpp b/builtins.cpp index 6be41f13..d6eefde5 100644 --- a/builtins.cpp +++ b/builtins.cpp @@ -643,13 +643,21 @@ lSetInternalFunctions(llvm::Module *module) { void AddBitcodeToModule(const unsigned char *bitcode, int length, llvm::Module *module, SymbolTable *symbolTable) { - std::string bcErr; llvm::StringRef sb = llvm::StringRef((char *)bitcode, length); llvm::MemoryBuffer *bcBuf = llvm::MemoryBuffer::getMemBuffer(sb); +#if defined(LLVM_3_5) + llvm::ErrorOr ModuleOrErr = llvm::parseBitcodeFile(bcBuf, *g->ctx); + if (llvm::error_code EC = ModuleOrErr.getError()) + Error(SourcePos(), "Error parsing stdlib bitcode: %s", EC.message().c_str()); + else { + llvm::Module *bcModule = ModuleOrErr.get(); +#else + std::string bcErr; llvm::Module *bcModule = llvm::ParseBitcodeFile(bcBuf, *g->ctx, &bcErr); if (!bcModule) Error(SourcePos(), "Error parsing stdlib bitcode: %s", bcErr.c_str()); else { +#endif // FIXME: this feels like a bad idea, but the issue is that when we // set the llvm::Module's target triple in the ispc Module::Module // constructor, we start by calling llvm::sys::getHostTriple() (and diff --git a/cbackend.cpp b/cbackend.cpp index 2ac6cc0b..6465d466 100644 --- a/cbackend.cpp +++ b/cbackend.cpp @@ -2327,7 +2327,11 @@ bool CWriter::doInitialization(llvm::Module &M) { if (I->hasExternalLinkage() || I->hasExternalWeakLinkage() || I->hasCommonLinkage()) Out << "extern "; +#if defined (LLVM_3_5) + else if (I->hasDLLImportStorageClass()) +#else else if (I->hasDLLImportLinkage()) +#endif Out << "__declspec(dllimport) "; else continue; // Internal Global @@ -2499,11 +2503,13 @@ bool CWriter::doInitialization(llvm::Module &M) { if (I->hasLocalLinkage()) Out << "static "; - else if (I->hasDLLImportLinkage()) - Out << "__declspec(dllimport) "; - else if (I->hasDLLExportLinkage()) - Out << "__declspec(dllexport) "; - +#if defined(LLVM_3_5) + else if (I->hasDLLImportStorageClass()) Out << "__declspec(dllimport) "; + else if (I->hasDLLExportStorageClass()) Out << "__declspec(dllexport) "; +#else + else if (I->hasDLLImportLinkage()) Out << "__declspec(dllimport) "; + else if (I->hasDLLExportLinkage()) Out << "__declspec(dllexport) "; +#endif // Thread Local Storage if (I->isThreadLocal()) Out << "__thread "; @@ -2782,8 +2788,13 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) { bool isStructReturn = F->hasStructRetAttr(); if (F->hasLocalLinkage()) Out << "static "; +#if defined(LLVM_3_5) + if (F->hasDLLImportStorageClass()) Out << "__declspec(dllimport) "; + if (F->hasDLLExportStorageClass()) Out << "__declspec(dllexport) "; +#else if (F->hasDLLImportLinkage()) Out << "__declspec(dllimport) "; if (F->hasDLLExportLinkage()) Out << "__declspec(dllexport) "; +#endif switch (F->getCallingConv()) { case llvm::CallingConv::X86_StdCall: Out << "__attribute__((stdcall)) "; diff --git a/func.cpp b/func.cpp index 610a2bef..3d3a4112 100644 --- a/func.cpp +++ b/func.cpp @@ -477,7 +477,11 @@ Function::GenerateIR() { } if (m->errorCount == 0) { +#if defined (LLVM_3_5) + if (llvm::verifyFunction(*function) == true) { +#else if (llvm::verifyFunction(*function, llvm::ReturnStatusAction) == true) { +#endif if (g->debugPrint) function->dump(); FATAL("Function verificication failed"); @@ -523,8 +527,12 @@ Function::GenerateIR() { emitCode(&ec, appFunction, firstStmtPos); if (m->errorCount == 0) { sym->exportedFunction = appFunction; +#if defined(LLVM_3_5) + if (llvm::verifyFunction(*appFunction) == true) { +#else if (llvm::verifyFunction(*appFunction, llvm::ReturnStatusAction) == true) { +#endif if (g->debugPrint) appFunction->dump(); FATAL("Function verificication failed"); From 3b2fe1d8f651491ae9451ce04761c8b4a4c9b1bf Mon Sep 17 00:00:00 2001 From: Ilia Filippov Date: Tue, 21 Jan 2014 17:26:05 +0400 Subject: [PATCH 3/3] adding patch for LLVM. Fix for trunk(select) --- .../3_3_3_4_r198267_trunc_of_select.patch | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 llvm_patches/3_3_3_4_r198267_trunc_of_select.patch diff --git a/llvm_patches/3_3_3_4_r198267_trunc_of_select.patch b/llvm_patches/3_3_3_4_r198267_trunc_of_select.patch new file mode 100644 index 00000000..f6a43b3d --- /dev/null +++ b/llvm_patches/3_3_3_4_r198267_trunc_of_select.patch @@ -0,0 +1,34 @@ +Index: lib/IR/ConstantFold.cpp +=================================================================== +--- lib/IR/ConstantFold.cpp (revision 197981) ++++ lib/IR/ConstantFold.cpp (working copy) +@@ -705,12 +705,23 @@ + SmallVector Result; + Type *Ty = IntegerType::get(CondV->getContext(), 32); + for (unsigned i = 0, e = V1->getType()->getVectorNumElements(); i != e;++i){ +- ConstantInt *Cond = dyn_cast(CondV->getOperand(i)); +- if (Cond == 0) break; +- +- Constant *V = Cond->isNullValue() ? V2 : V1; +- Constant *Res = ConstantExpr::getExtractElement(V, ConstantInt::get(Ty, i)); +- Result.push_back(Res); ++ Constant *V; ++ Constant *V1Element = ConstantExpr::getExtractElement(V1, ++ ConstantInt::get(Ty, i)); ++ Constant *V2Element = ConstantExpr::getExtractElement(V2, ++ ConstantInt::get(Ty, i)); ++ Constant *Cond = dyn_cast(CondV->getOperand(i)); ++ if (V1Element == V2Element) { ++ V = V1Element; ++ } ++ else if (isa(Cond)) { ++ V = isa(V1Element) ? V1Element : V2Element; ++ } ++ else { ++ if (!isa(Cond)) break; ++ V = Cond->isNullValue() ? V2Element : V1Element; ++ } ++ Result.push_back(V); + } + + // If we were able to build the vector, return it.