Allowed LLVM optimisations to build against both LLVM 2.9 and LLVM 3.0.

main
theraven 15 years ago
parent f6697e5f86
commit 34aa9f9455

@ -38,7 +38,6 @@ namespace
if (F->isDeclaration()) { continue; } if (F->isDeclaration()) { continue; }
SmallVector<std::pair<CallSite, bool>, 16> Lookups; SmallVector<std::pair<CallSite, bool>, 16> Lookups;
BasicBlock *entry = &F->getEntryBlock();
for (Function::iterator i=F->begin(), end=F->end() ; for (Function::iterator i=F->begin(), end=F->end() ;
i != end ; ++i) { i != end ; ++i) {
@ -62,7 +61,6 @@ namespace
} }
} }
} }
IRBuilder<> B = IRBuilder<>(entry);
for (SmallVectorImpl<std::pair<CallSite, bool> >::iterator for (SmallVectorImpl<std::pair<CallSite, bool> >::iterator
i=Lookups.begin(), e=Lookups.end() ; e!=i ; i++) { i=Lookups.begin(), e=Lookups.end() ; e!=i ; i++) {
Instruction *call = i->first.getInstruction(); Instruction *call = i->first.getInstruction();

@ -11,6 +11,7 @@
#include <string> #include <string>
#include "IMPCacher.h" #include "IMPCacher.h"
#include "LLVMCompat.h"
using namespace llvm; using namespace llvm;
using namespace GNUstep; using namespace GNUstep;
@ -98,8 +99,7 @@ namespace
removeTerminator(beforeLookupBB); removeTerminator(beforeLookupBB);
removeTerminator(lookupBB); removeTerminator(lookupBB);
PHINode *phi = PHINode *phi = CreatePHI(clsTy, 2, cls, afterLookupBB->begin());
PHINode::Create(clsTy, 2, cls, afterLookupBB->begin());
// We replace all of the existing uses with the PHI node now, because // 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 // we're going to add some more uses later that we don't want
// replaced. // replaced.

@ -11,6 +11,8 @@
#include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Transforms/Utils/Cloning.h"
#include "LLVMCompat.h"
GNUstep::IMPCacher::IMPCacher(LLVMContext &C, Pass *owner) : Context(C), GNUstep::IMPCacher::IMPCacher(LLVMContext &C, Pass *owner) : Context(C),
Owner(owner) { Owner(owner) {
@ -19,7 +21,7 @@ GNUstep::IMPCacher::IMPCacher(LLVMContext &C, Pass *owner) : Context(C),
IntTy = Type::getInt32Ty(Context); IntTy = Type::getInt32Ty(Context);
IdTy = PointerType::getUnqual(PtrTy); IdTy = PointerType::getUnqual(PtrTy);
Value *AlreadyCachedFlagValue = MDString::get(C, "IMPCached"); Value *AlreadyCachedFlagValue = MDString::get(C, "IMPCached");
AlreadyCachedFlag = MDNode::get(C, &AlreadyCachedFlagValue, 1); AlreadyCachedFlag = CreateMDNode(C, AlreadyCachedFlagValue);
IMPCacheFlagKind = Context.getMDKindID("IMPCache"); IMPCacheFlagKind = Context.getMDKindID("IMPCache");
} }
@ -171,8 +173,7 @@ void GNUstep::IMPCacher::SpeculativelyInline(Instruction *call, Function
// Unify the return values // Unify the return values
if (call->getType() != Type::getVoidTy(Context)) { if (call->getType() != Type::getVoidTy(Context)) {
B.SetInsertPoint(afterCallBB, afterCallBB->begin()); PHINode *phi = CreatePHI(call->getType(), 2, 0, afterCallBB->begin());
PHINode *phi = B.CreatePHI(call->getType(), 2);
call->replaceAllUsesWith(phi); call->replaceAllUsesWith(phi);
phi->addIncoming(call, callBB); phi->addIncoming(call, callBB);
phi->addIncoming(inlineResult, inlineBB); phi->addIncoming(inlineResult, inlineBB);

@ -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<Value*> val(V);
return MDNode::get(C, val);
#endif
}

@ -2,6 +2,7 @@ LEVEL = ../../../
LIBRARYNAME = libGNUObjCRuntime LIBRARYNAME = libGNUObjCRuntime
LOADABLE_MODULE = 1 LOADABLE_MODULE = 1
USEDLIBS = USEDLIBS =
CPPFLAGS += `llvm-config --version | sed 's/\([0-9]*\).\([0-9]*\).*/-DLLVM_MAJOR=\1 -DLLVM_MINOR=\2/'`
include $(LEVEL)/Makefile.common include $(LEVEL)/Makefile.common

@ -65,7 +65,6 @@ namespace {
if (Entry->size() == 1) { if (Entry->size() == 1) {
TypeInfoProvider::CallSiteEntry::iterator iterator = Entry->begin();
Function *method = M.getFunction(Entry->begin()->getKey()); Function *method = M.getFunction(Entry->begin()->getKey());
if (0 == method || method->isDeclaration()) { continue; } if (0 == method || method->isDeclaration()) { continue; }

Loading…
Cancel
Save