mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Document a more robust implementation of performCustomLowering.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45326 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
52ec375438
commit
0adede059e
@ -1084,37 +1084,35 @@ href="WritingAnLLVMPass.html#doInitialization_mod"><tt>doInitialization(Module
|
||||
|
||||
<blockquote><pre
|
||||
>#include "llvm/Module.h"
|
||||
#include "llvm/Instructions.h"
|
||||
#include "llvm/IntrinsicInst.h"
|
||||
|
||||
bool MyCollector::initializeCustomLowering(Module &M) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MyCollector::performCustomLowering(Function &F) {
|
||||
const Module *M = F.getParent();
|
||||
|
||||
Function *GCReadInt = M->getFunction("llvm.gcread"),
|
||||
*GCWriteInt = M->getFunction("llvm.gcwrite"),
|
||||
*GCRootInt = M->getFunction("llvm.gcroot");
|
||||
|
||||
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<CallInst>(II++))
|
||||
if (Function *F = CI->getCalledFunction())
|
||||
if (F == GCWriteInt) {
|
||||
for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E; ++II)
|
||||
if (IntrinsicInst *CI = dyn_cast<IntrinsicInst>(II))
|
||||
if (Function *F = CI->getCalledFunction())
|
||||
switch (F->getIntrinsicID()) {
|
||||
case Intrinsic::gcwrite:
|
||||
// Handle llvm.gcwrite.
|
||||
CI->eraseFromParent();
|
||||
CI->eraseFromParent();
|
||||
MadeChange = true;
|
||||
} else if (F == GCReadInt) {
|
||||
break;
|
||||
case Intrinsic::gcread:
|
||||
// Handle llvm.gcread.
|
||||
CI->eraseFromParent();
|
||||
CI->eraseFromParent();
|
||||
MadeChange = true;
|
||||
} else if (F == GCRootInt) {
|
||||
break;
|
||||
case Intrinsic::gcroot:
|
||||
// Handle llvm.gcroot.
|
||||
CI->eraseFromParent();
|
||||
CI->eraseFromParent();
|
||||
MadeChange = true;
|
||||
break;
|
||||
}
|
||||
|
||||
return MadeChange;
|
||||
|
Loading…
Reference in New Issue
Block a user