From 3607f3e0458de9d87ed543fb868b0c18439af645 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Sat, 17 Sep 2011 13:18:59 -0700 Subject: [PATCH] Remove support for building with LLVM 2.8. Fixes issue #66. Both 2.9 and top-of-tree generate substantially better code than LLVM 2.8 did, so it's not worth fixing the 2.8 build. --- ctx.cpp | 32 ++------------------------------ expr.cpp | 2 +- ispc.cpp | 6 ------ ispc_test.cpp | 14 -------------- main.cpp | 6 +----- module.cpp | 19 ++----------------- module.h | 5 +---- opt.cpp | 23 +++++++---------------- type.cpp | 37 ------------------------------------- 9 files changed, 14 insertions(+), 130 deletions(-) diff --git a/ctx.cpp b/ctx.cpp index a407bf92..e6bbde3d 100644 --- a/ctx.cpp +++ b/ctx.cpp @@ -153,7 +153,6 @@ FunctionEmitContext::FunctionEmitContext(const Type *rt, llvm::Function *functio StoreInst(llvm::Constant::getNullValue(ftype), returnValuePtr); } -#ifndef LLVM_2_8 if (m->diBuilder) { /* If debugging is enabled, tell the debug information emission code about this new function */ @@ -174,7 +173,6 @@ FunctionEmitContext::FunctionEmitContext(const Type *rt, llvm::Function *functio /* And start a scope representing the initial function scope */ StartScope(); } -#endif // LLVM_2_8 launchedTasks = false; @@ -183,7 +181,6 @@ FunctionEmitContext::FunctionEmitContext(const Type *rt, llvm::Function *functio assert(maskSymbol != NULL); maskSymbol->storagePtr = maskPtr; -#ifndef LLVM_2_8 // add debugging info for __mask, programIndex, ... if (m->diBuilder) { maskSymbol->pos = funcStartPos; @@ -208,15 +205,12 @@ FunctionEmitContext::FunctionEmitContext(const Type *rt, llvm::Function *functio true /* static */, programCountSymbol->storagePtr); } -#endif } FunctionEmitContext::~FunctionEmitContext() { assert(controlFlowInfo.size() == 0); -#ifndef LLVM_2_8 assert(debugScopes.size() == (m->diBuilder ? 1 : 0)); -#endif } @@ -857,7 +851,6 @@ FunctionEmitContext::GetDebugPos() const { void FunctionEmitContext::AddDebugPos(llvm::Value *value, const SourcePos *pos, llvm::DIScope *scope) { -#ifndef LLVM_2_8 llvm::Instruction *inst = llvm::dyn_cast(value); if (inst != NULL && m->diBuilder) { SourcePos p = pos ? *pos : currentPos; @@ -868,13 +861,11 @@ FunctionEmitContext::AddDebugPos(llvm::Value *value, const SourcePos *pos, inst->setDebugLoc(llvm::DebugLoc::get(p.first_line, p.first_column, scope ? *scope : GetDIScope())); } -#endif } void FunctionEmitContext::StartScope() { -#ifndef LLVM_2_8 if (m->diBuilder != NULL) { llvm::DIScope parentScope; if (debugScopes.size() > 0) @@ -888,18 +879,15 @@ FunctionEmitContext::StartScope() { currentPos.first_column); debugScopes.push_back(lexicalBlock); } -#endif } void FunctionEmitContext::EndScope() { -#ifndef LLVM_2_8 if (m->diBuilder != NULL) { assert(debugScopes.size() > 0); debugScopes.pop_back(); } -#endif } @@ -912,7 +900,6 @@ FunctionEmitContext::GetDIScope() const { void FunctionEmitContext::EmitVariableDebugInfo(Symbol *sym) { -#ifndef LLVM_2_8 if (m->diBuilder == NULL) return; @@ -928,13 +915,11 @@ FunctionEmitContext::EmitVariableDebugInfo(Symbol *sym) { llvm::Instruction *declareInst = m->diBuilder->insertDeclare(sym->storagePtr, var, bblock); AddDebugPos(declareInst, &sym->pos, &scope); -#endif } void FunctionEmitContext::EmitFunctionParameterDebugInfo(Symbol *sym) { -#ifndef LLVM_2_8 if (m->diBuilder == NULL) return; @@ -950,7 +935,6 @@ FunctionEmitContext::EmitFunctionParameterDebugInfo(Symbol *sym) { llvm::Instruction *declareInst = m->diBuilder->insertDeclare(sym->storagePtr, var, bblock); AddDebugPos(declareInst, &sym->pos, &scope); -#endif } @@ -1508,27 +1492,15 @@ FunctionEmitContext::gather(llvm::Value *lvalue, const Type *type, void FunctionEmitContext::addGSMetadata(llvm::Instruction *inst, SourcePos pos) { llvm::Value *str = llvm::MDString::get(*g->ctx, pos.name); -#ifdef LLVM_2_8 - llvm::MDNode *md = llvm::MDNode::get(*g->ctx, &str, 1); -#else llvm::MDNode *md = llvm::MDNode::get(*g->ctx, str); -#endif inst->setMetadata("filename", md); llvm::Value *line = LLVMInt32(pos.first_line); -#ifdef LLVM_2_8 - md = llvm::MDNode::get(*g->ctx, &line, 1); -#else md = llvm::MDNode::get(*g->ctx, line); -#endif inst->setMetadata("line", md); llvm::Value *column = LLVMInt32(pos.first_column); -#ifdef LLVM_2_8 - md = llvm::MDNode::get(*g->ctx, &column, 1); -#else md = llvm::MDNode::get(*g->ctx, column); -#endif inst->setMetadata("column", md); } @@ -1845,9 +1817,9 @@ llvm::PHINode * FunctionEmitContext::PhiNode(LLVM_TYPE_CONST llvm::Type *type, int count, const char *name) { llvm::PHINode *pn = llvm::PHINode::Create(type, -#if !defined(LLVM_2_8) && !defined(LLVM_2_9) +#if defined(LLVM_3_0) || defined(LLVM_3_0svn) count, -#endif // !LLVM_2_8 && !LLVM_2_9 +#endif // LLVM_3_0 name ? name : "phi", bblock); AddDebugPos(pn); return pn; diff --git a/expr.cpp b/expr.cpp index 5a4bca85..0322ef27 100644 --- a/expr.cpp +++ b/expr.cpp @@ -2569,7 +2569,7 @@ ExprList::GetConstant(const Type *type) const { } if (dynamic_cast(type) != NULL) { -#if defined(LLVM_2_8) || defined(LLVM_2_9) +#if defined(LLVM_2_9) return llvm::ConstantStruct::get(*g->ctx, cv, false); #else LLVM_TYPE_CONST llvm::StructType *llvmStructType = diff --git a/ispc.cpp b/ispc.cpp index e77cbe5d..ec96d3b3 100644 --- a/ispc.cpp +++ b/ispc.cpp @@ -46,9 +46,7 @@ #endif #include #include -#ifndef LLVM_2_8 #include -#endif #include #include #include @@ -309,13 +307,9 @@ SourcePos::SourcePos(const char *n, int l, int c) { } llvm::DIFile SourcePos::GetDIFile() const { -#ifdef LLVM_2_8 - return llvm::DIFile(); -#else std::string directory, filename; GetDirectoryAndFileName(g->currentDirectory, name, &directory, &filename); return m->diBuilder->createFile(filename, directory); -#endif // LLVM_2_8 } diff --git a/ispc_test.cpp b/ispc_test.cpp index 79059fea..790f79f1 100644 --- a/ispc_test.cpp +++ b/ispc_test.cpp @@ -81,9 +81,7 @@ extern "C" { #include #include #include -#ifndef LLVM_2_8 #include -#endif bool shouldFail = false; @@ -145,17 +143,6 @@ double Log(double x) { return log(x); } static bool lRunTest(const char *fn) { llvm::LLVMContext *ctx = new llvm::LLVMContext; -#ifdef LLVM_2_8 - std::string err; - llvm::MemoryBuffer *buf = llvm::MemoryBuffer::getFileOrSTDIN(fn, &err); - if (!buf) { - fprintf(stderr, "Unable to open file \"%s\": %s\n", fn, err.c_str()); - delete ctx; - return false; - } - std::string bcErr; - llvm::Module *module = llvm::ParseBitcodeFile(buf, *ctx, &bcErr); -#else llvm::OwningPtr buf; llvm::error_code err = llvm::MemoryBuffer::getFileOrSTDIN(fn, buf); if (err) { @@ -165,7 +152,6 @@ static bool lRunTest(const char *fn) { } std::string bcErr; llvm::Module *module = llvm::ParseBitcodeFile(buf.get(), *ctx, &bcErr); -#endif if (!module) { fprintf(stderr, "Bitcode reader failed for \"%s\": %s\n", fn, bcErr.c_str()); diff --git a/main.cpp b/main.cpp index c969f267..b5c69aae 100644 --- a/main.cpp +++ b/main.cpp @@ -40,11 +40,7 @@ #include #include #include -#ifdef LLVM_2_8 - #include -#else - #include -#endif +#include #if defined(LLVM_3_0) || defined(LLVM_3_0svn) #include #include diff --git a/module.cpp b/module.cpp index dabda818..b01f25ac 100644 --- a/module.cpp +++ b/module.cpp @@ -80,12 +80,8 @@ #include #include #include -#ifndef LLVM_2_8 - #include - #include -#else // !LLVM_2_8 - #include -#endif // LLVM_2_8 +#include +#include #include #include #include @@ -106,14 +102,11 @@ Module::Module(const char *fn) { module->setTargetTriple(g->target.GetTripleString()); -#ifndef LLVM_2_8 if (g->generateDebuggingSymbols) diBuilder = new llvm::DIBuilder(*module); else diBuilder = NULL; -#endif // LLVM_2_8 -#ifndef LLVM_2_8 // If we're generating debugging symbols, let the DIBuilder know that // we're starting a new compilation unit. if (diBuilder != NULL) { @@ -139,7 +132,6 @@ Module::Module(const char *fn) { 0 /* run time version */); } } -#endif // LLVM_2_8 } @@ -564,7 +556,6 @@ Module::AddGlobal(DeclSpecs *ds, Declarator *decl) { decl->sym->name.c_str()); m->symbolTable->AddVariable(decl->sym); -#ifndef LLVM_2_8 if (diBuilder && (ds->storageClass != SC_EXTERN)) { llvm::DIFile file = decl->pos.GetDIFile(); diBuilder->createGlobalVariable(decl->sym->name, @@ -574,7 +565,6 @@ Module::AddGlobal(DeclSpecs *ds, Declarator *decl) { (ds->storageClass == SC_STATIC), decl->sym->storagePtr); } -#endif // LLVM_2_8 } } @@ -931,12 +921,7 @@ Module::WriteOutput(OutputType outputType, const char *outFileName) { return true; } else { -#ifdef LLVM_2_8 - fprintf(stderr, "Direct object file emission not supported in this build.\n"); - return false; -#else return writeObjectFileOrAssembly(outputType, outFileName); -#endif // LLVM_2_8 } } } diff --git a/module.h b/module.h index 85b74adb..1530a722 100644 --- a/module.h +++ b/module.h @@ -91,11 +91,8 @@ public: /** llvm Module object into which globals and functions are added. */ llvm::Module *module; -#ifndef LLVM_2_8 - /** The diBuilder manages generating debugging information (only - supported in LLVM 2.9 and beyond...) */ + /** The diBuilder manages generating debugging information */ llvm::DIBuilder *diBuilder; -#endif GatherBuffer *gatherBuffer; diff --git a/opt.cpp b/opt.cpp index d57fb434..1b5c4cb9 100644 --- a/opt.cpp +++ b/opt.cpp @@ -56,13 +56,11 @@ #include #include #include -#ifndef LLVM_2_8 - #include - #ifdef LLVM_2_9 - #include - #else - #include - #endif // LLVM_2_9 +#include +#ifdef LLVM_2_9 + #include +#else + #include #endif // LLVM_2_8 #include #include @@ -73,9 +71,7 @@ #include #include #include -#ifndef LLVM_2_8 #include -#endif #include #include #ifdef ISPC_IS_LINUX @@ -186,11 +182,9 @@ Optimize(llvm::Module *module, int optLevel) { llvm::PassManager optPM; llvm::FunctionPassManager funcPM(module); -#ifndef LLVM_2_8 llvm::TargetLibraryInfo *targetLibraryInfo = new llvm::TargetLibraryInfo(llvm::Triple(module->getTargetTriple())); optPM.add(targetLibraryInfo); -#endif optPM.add(new llvm::TargetData(module)); if (optLevel == 0) { @@ -220,7 +214,6 @@ Optimize(llvm::Module *module, int optLevel) { // only later in the optimization process as things like constant // propagation have done their thing, and then when they do kick // in, they can often open up new opportunities for optimization... -#ifndef LLVM_2_8 llvm::PassRegistry *registry = llvm::PassRegistry::getPassRegistry(); llvm::initializeCore(*registry); llvm::initializeScalarOpts(*registry); @@ -231,7 +224,7 @@ Optimize(llvm::Module *module, int optLevel) { llvm::initializeInstCombine(*registry); llvm::initializeInstrumentation(*registry); llvm::initializeTarget(*registry); -#endif + // Early optimizations to try to reduce the total amount of code to // work with if we can optPM.add(CreateGatherScatterFlattenPass()); @@ -288,9 +281,7 @@ Optimize(llvm::Module *module, int optLevel) { optPM.add(llvm::createConstantPropagationPass()); optPM.add(CreateIntrinsicsOptPass()); -#if defined(LLVM_2_8) - optPM.add(CreateIsCompileTimeConstantPass(true)); -#elif defined(LLVM_2_9) +#if defined(LLVM_2_9) llvm::createStandardModulePasses(&optPM, 3, false /* opt size */, true /* unit at a time */, diff --git a/type.cpp b/type.cpp index 053a37d3..4e61d156 100644 --- a/type.cpp +++ b/type.cpp @@ -45,9 +45,7 @@ #include #include #include -#ifndef LLVM_2_8 #include -#endif #include #include @@ -414,10 +412,6 @@ AtomicType::LLVMType(llvm::LLVMContext *ctx) const { llvm::DIType AtomicType::GetDIType(llvm::DIDescriptor scope) const { -#ifdef LLVM_2_8 - FATAL("debug info not supported in llvm 2.8"); - return llvm::DIType(); -#else if (isUniform) { switch (basicType) { case TYPE_VOID: @@ -484,7 +478,6 @@ AtomicType::GetDIType(llvm::DIDescriptor scope) const { uint64_t align = unifType.getAlignInBits() * g->target.vectorWidth; return m->diBuilder->createVectorType(size, align, unifType, subArray); } -#endif // LLVM_2_8 } @@ -645,10 +638,6 @@ EnumType::LLVMType(llvm::LLVMContext *ctx) const { llvm::DIType EnumType::GetDIType(llvm::DIDescriptor scope) const { -#ifdef LLVM_2_8 - FATAL("debug info not supported in llvm 2.8"); - return llvm::DIType(); -#else std::vector enumeratorDescriptors; for (unsigned int i = 0; i < enumerators.size(); ++i) { unsigned int enumeratorValue; @@ -688,7 +677,6 @@ EnumType::GetDIType(llvm::DIDescriptor scope) const { uint64_t size = diType.getSizeInBits() * g->target.vectorWidth; uint64_t align = diType.getAlignInBits() * g->target.vectorWidth; return m->diBuilder->createVectorType(size, align, diType, subArray); -#endif // !LLVM_2_8 } @@ -893,10 +881,6 @@ ArrayType::TotalElementCount() const { llvm::DIType ArrayType::GetDIType(llvm::DIDescriptor scope) const { -#ifdef LLVM_2_8 - FATAL("debug info not supported in llvm 2.8"); - return llvm::DIType(); -#else if (!child) return llvm::DIType(); @@ -923,7 +907,6 @@ ArrayType::GetDIType(llvm::DIDescriptor scope) const { uint64_t align = eltType.getAlignInBits(); return m->diBuilder->createArrayType(size, align, eltType, subArray); -#endif // LLVM_2_8 } @@ -1044,16 +1027,11 @@ SOAArrayType::LLVMType(llvm::LLVMContext *ctx) const { llvm::DIType SOAArrayType::GetDIType(llvm::DIDescriptor scope) const { -#ifdef LLVM_2_8 - FATAL("debug info not supported in llvm 2.8"); - return llvm::DIType(); -#else if (!child) return llvm::DIType(); const Type *t = soaType(); return t->GetDIType(scope); -#endif } @@ -1217,10 +1195,6 @@ VectorType::LLVMType(llvm::LLVMContext *ctx) const { llvm::DIType VectorType::GetDIType(llvm::DIDescriptor scope) const { -#ifdef LLVM_2_8 - FATAL("debug info not supported in llvm 2.8"); - return llvm::DIType(); -#else llvm::DIType eltType = base->GetDIType(scope); llvm::Value *sub = m->diBuilder->getOrCreateSubrange(0, numElements-1); #ifdef LLVM_2_9 @@ -1240,7 +1214,6 @@ VectorType::GetDIType(llvm::DIDescriptor scope) const { align = 4 * g->target.nativeVectorWidth; return m->diBuilder->createVectorType(sizeBits, align, eltType, subArray); -#endif // LLVM_2_8 } @@ -1443,10 +1416,6 @@ StructType::LLVMType(llvm::LLVMContext *ctx) const { llvm::DIType StructType::GetDIType(llvm::DIDescriptor scope) const { -#ifdef LLVM_2_8 - FATAL("debug info not supported in llvm 2.8"); - return llvm::DIType(); -#else uint64_t currentSize = 0, align = 0; std::vector elementLLVMTypes; @@ -1500,7 +1469,6 @@ StructType::GetDIType(llvm::DIDescriptor scope) const { llvm::DIFile diFile = pos.GetDIFile(); return m->diBuilder->createStructType(scope, name, diFile, pos.first_line, currentSize, align, 0, elements); -#endif // LLVM_2_8 } @@ -1698,13 +1666,8 @@ ReferenceType::LLVMType(llvm::LLVMContext *ctx) const { llvm::DIType ReferenceType::GetDIType(llvm::DIDescriptor scope) const { -#ifdef LLVM_2_8 - FATAL("debug info not supported in llvm 2.8"); - return llvm::DIType(); -#else llvm::DIType diTargetType = targetType->GetDIType(scope); return m->diBuilder->createReferenceType(diTargetType); -#endif // LLVM_2_8 }