From: Gordon Henriksen Date: Sat, 22 Dec 2007 17:27:01 +0000 (+0000) Subject: Use getIntrinsicID instead of looking up intrinsic prototypes. Also X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=a6c99250877dad280fbd59480463bd9f91740187 Use getIntrinsicID instead of looking up intrinsic prototypes. Also fixes a bug with indirect calls. (Test case will be included with ocaml collector patch.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45316 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/Collector.cpp b/lib/CodeGen/Collector.cpp index 67b392889e1..bed0923b176 100644 --- a/lib/CodeGen/Collector.cpp +++ b/lib/CodeGen/Collector.cpp @@ -35,10 +35,6 @@ namespace { /// directed by the Collector. It also performs automatic root initialization /// and custom intrinsic lowering. class VISIBILITY_HIDDEN LowerIntrinsics : public FunctionPass { - /// GCRootInt, GCReadInt, GCWriteInt - The function prototypes for the - /// llvm.gc* intrinsics. - Function *GCRootInt, *GCReadInt, *GCWriteInt; - static bool NeedsDefaultLoweringPass(const Collector &C); static bool NeedsCustomLoweringPass(const Collector &C); static bool CouldBecomeSafePoint(Instruction *I); @@ -138,8 +134,7 @@ FunctionPass *llvm::createGCLoweringPass() { char LowerIntrinsics::ID = 0; LowerIntrinsics::LowerIntrinsics() - : FunctionPass((intptr_t)&ID), - GCRootInt(0), GCReadInt(0), GCWriteInt(0) {} + : FunctionPass((intptr_t)&ID) {} const char *LowerIntrinsics::getPassName() const { return "Lower Garbage Collection Instructions"; @@ -152,10 +147,6 @@ void LowerIntrinsics::getAnalysisUsage(AnalysisUsage &AU) const { /// doInitialization - If this module uses the GC intrinsics, find them now. bool LowerIntrinsics::doInitialization(Module &M) { - GCReadInt = M.getFunction("llvm.gcread"); - GCWriteInt = M.getFunction("llvm.gcwrite"); - GCRootInt = M.getFunction("llvm.gcroot"); - // FIXME: This is rather antisocial in the context of a JIT since it performs // work against the entire module. But this cannot be done at // runFunction time (initializeCustomLowering likely needs to change @@ -277,25 +268,35 @@ bool LowerIntrinsics::PerformDefaultLowering(Function &F, Collector &Coll) { bool MadeChange = false; for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E;) { - if (CallInst *CI = dyn_cast(II++)) { + if (IntrinsicInst *CI = dyn_cast(II++)) { Function *F = CI->getCalledFunction(); - if (F == GCWriteInt && LowerWr) { - // Replace a write barrier with a simple store. - Value *St = new StoreInst(CI->getOperand(1), CI->getOperand(3), CI); - CI->replaceAllUsesWith(St); - CI->eraseFromParent(); - } else if (F == GCReadInt && LowerRd) { - // Replace a read barrier with a simple load. - Value *Ld = new LoadInst(CI->getOperand(2), "", CI); - Ld->takeName(CI); - CI->replaceAllUsesWith(Ld); - CI->eraseFromParent(); - } else if (F == GCRootInt && InitRoots) { - // Initialize the GC root, but do not delete the intrinsic. The - // backend needs the intrinsic to flag the stack slot. - Roots.push_back(cast( - IntrinsicInst::StripPointerCasts(CI->getOperand(1)))); - } else { + switch (F->getIntrinsicID()) { + case Intrinsic::gcwrite: + if (LowerWr) { + // Replace a write barrier with a simple store. + Value *St = new StoreInst(CI->getOperand(1), CI->getOperand(3), CI); + CI->replaceAllUsesWith(St); + CI->eraseFromParent(); + } + break; + case Intrinsic::gcread: + if (LowerRd) { + // Replace a read barrier with a simple load. + Value *Ld = new LoadInst(CI->getOperand(2), "", CI); + Ld->takeName(CI); + CI->replaceAllUsesWith(Ld); + CI->eraseFromParent(); + } + break; + case Intrinsic::gcroot: + if (InitRoots) { + // Initialize the GC root, but do not delete the intrinsic. The + // backend needs the intrinsic to flag the stack slot. + Roots.push_back(cast( + IntrinsicInst::StripPointerCasts(CI->getOperand(1)))); + } + break; + default: continue; }