diff --git a/opts/ClassIMPCache.cpp b/opts/ClassIMPCache.cpp index f0beb45..493e969 100644 --- a/opts/ClassIMPCache.cpp +++ b/opts/ClassIMPCache.cpp @@ -38,7 +38,6 @@ namespace if (F->isDeclaration()) { continue; } SmallVector, 16> Lookups; - BasicBlock *entry = &F->getEntryBlock(); for (Function::iterator i=F->begin(), end=F->end() ; i != end ; ++i) { @@ -62,7 +61,6 @@ namespace } } } - IRBuilder<> B = IRBuilder<>(entry); for (SmallVectorImpl >::iterator i=Lookups.begin(), e=Lookups.end() ; e!=i ; i++) { Instruction *call = i->first.getInstruction(); diff --git a/opts/ClassLookupCache.cpp b/opts/ClassLookupCache.cpp index 7d34c11..6068357 100644 --- a/opts/ClassLookupCache.cpp +++ b/opts/ClassLookupCache.cpp @@ -11,6 +11,7 @@ #include #include "IMPCacher.h" +#include "LLVMCompat.h" using namespace llvm; using namespace GNUstep; @@ -98,8 +99,7 @@ namespace removeTerminator(beforeLookupBB); removeTerminator(lookupBB); - PHINode *phi = - PHINode::Create(clsTy, 2, cls, afterLookupBB->begin()); + PHINode *phi = CreatePHI(clsTy, 2, cls, afterLookupBB->begin()); // We replace all of the existing uses with the PHI node now, because // we're going to add some more uses later that we don't want // replaced. diff --git a/opts/IMPCacher.cpp b/opts/IMPCacher.cpp index bcc48a3..0638eb3 100644 --- a/opts/IMPCacher.cpp +++ b/opts/IMPCacher.cpp @@ -11,6 +11,8 @@ #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/Cloning.h" +#include "LLVMCompat.h" + GNUstep::IMPCacher::IMPCacher(LLVMContext &C, Pass *owner) : Context(C), Owner(owner) { @@ -19,7 +21,7 @@ GNUstep::IMPCacher::IMPCacher(LLVMContext &C, Pass *owner) : Context(C), IntTy = Type::getInt32Ty(Context); IdTy = PointerType::getUnqual(PtrTy); Value *AlreadyCachedFlagValue = MDString::get(C, "IMPCached"); - AlreadyCachedFlag = MDNode::get(C, &AlreadyCachedFlagValue, 1); + AlreadyCachedFlag = CreateMDNode(C, AlreadyCachedFlagValue); IMPCacheFlagKind = Context.getMDKindID("IMPCache"); } @@ -171,8 +173,7 @@ void GNUstep::IMPCacher::SpeculativelyInline(Instruction *call, Function // Unify the return values if (call->getType() != Type::getVoidTy(Context)) { - B.SetInsertPoint(afterCallBB, afterCallBB->begin()); - PHINode *phi = B.CreatePHI(call->getType(), 2); + PHINode *phi = CreatePHI(call->getType(), 2, 0, afterCallBB->begin()); call->replaceAllUsesWith(phi); phi->addIncoming(call, callBB); phi->addIncoming(inlineResult, inlineBB); diff --git a/opts/LLVMCompat.h b/opts/LLVMCompat.h new file mode 100644 index 0000000..d7df502 --- /dev/null +++ b/opts/LLVMCompat.h @@ -0,0 +1,29 @@ +/** + * Compatibility header that wraps LLVM API breakage and lets us compile with + * old and new versions of LLVM. + */ + +__attribute((unused)) static inline +PHINode* CreatePHI(const Type *Ty, + unsigned NumReservedValues, + const Twine &NameStr="", + Instruction *InsertBefore=0) { +#if LLVM_MAJOR < 3 + PHINode *phi = PHINode::Create(Ty, NameStr, InsertBefore); + phi->reserveOperandSpace(NumReservedValues); + return phi; +#else + return PHINode::Create(Ty, NumReservedValues, NameStr, InsertBefore); +#endif +} + +__attribute((unused)) static inline +MDNode* CreateMDNode(LLVMContext &C, + Value *V) { +#if LLVM_MAJOR < 3 + return MDNode::get(C, &V, 1); +#else + ArrayRef val(V); + return MDNode::get(C, val); +#endif +} diff --git a/opts/Makefile b/opts/Makefile index fcef1b5..46e15e0 100644 --- a/opts/Makefile +++ b/opts/Makefile @@ -2,6 +2,7 @@ LEVEL = ../../../ LIBRARYNAME = libGNUObjCRuntime LOADABLE_MODULE = 1 USEDLIBS = +CPPFLAGS += `llvm-config --version | sed 's/\([0-9]*\).\([0-9]*\).*/-DLLVM_MAJOR=\1 -DLLVM_MINOR=\2/'` include $(LEVEL)/Makefile.common diff --git a/opts/TypeFeedbackDrivenInliner.cpp b/opts/TypeFeedbackDrivenInliner.cpp index 77702b5..2658b65 100644 --- a/opts/TypeFeedbackDrivenInliner.cpp +++ b/opts/TypeFeedbackDrivenInliner.cpp @@ -65,7 +65,6 @@ namespace { if (Entry->size() == 1) { - TypeInfoProvider::CallSiteEntry::iterator iterator = Entry->begin(); Function *method = M.getFunction(Entry->begin()->getKey()); if (0 == method || method->isDeclaration()) { continue; }