llvm.org GIT mirror llvm / 0adede0
Document a more robust implementation of performCustomLowering. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45326 91177308-0d34-0410-b5e6-96231b3b80d8 Gordon Henriksen 11 years ago
1 changed file(s) with 14 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
10831083
10841084
                  
                
10851085 >#include "llvm/Module.h"
1086 #include "llvm/Instructions.h"
1086 #include "llvm/IntrinsicInst.h"
10871087
10881088 bool MyCollector::initializeCustomLowering(Module &M) {
10891089 return false;
10901090 }
10911091
10921092 bool MyCollector::performCustomLowering(Function &F) {
1093 const Module *M = F.getParent();
1094
1095 Function *GCReadInt = M->getFunction("llvm.gcread"),
1096 *GCWriteInt = M->getFunction("llvm.gcwrite"),
1097 *GCRootInt = M->getFunction("llvm.gcroot");
1098
10991093 bool MadeChange = false;
11001094
11011095 for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
1102 for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E;)
1103 if (CallInst *CI = dyn_cast<CallInst>(II++))
1104 if (Function *F = CI->getCalledFunction())
1105 if (F == GCWriteInt) {
1096 for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E; ++II)
1097 if (IntrinsicInst *CI = dyn_cast<IntrinsicInst>(II))
1098 if (Function *F = CI->getCalledFunction())
1099 switch (F->getIntrinsicID()) {
1100 case Intrinsic::gcwrite:
11061101 // Handle llvm.gcwrite.
1107 CI->eraseFromParent();
1102 CI->eraseFromParent();
11081103 MadeChange = true;
1109 } else if (F == GCReadInt) {
1104 break;
1105 case Intrinsic::gcread:
11101106 // Handle llvm.gcread.
1111 CI->eraseFromParent();
1107 CI->eraseFromParent();
11121108 MadeChange = true;
1113 } else if (F == GCRootInt) {
1109 break;
1110 case Intrinsic::gcroot:
11141111 // Handle llvm.gcroot.
1115 CI->eraseFromParent();
1112 CI->eraseFromParent();
11161113 MadeChange = true;
1114 break;
11171115 }
11181116
11191117 return MadeChange;