mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-07 14:33:15 +00:00
Refactor CloneFunction to expose the new CloneBasicBlock function
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5806 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
15faa8498c
commit
17d145d26f
@ -31,6 +31,25 @@ static inline void RemapInstruction(Instruction *I,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CloneBasicBlock - See comments in Cloning.h
|
||||||
|
BasicBlock *CloneBasicBlock(const BasicBlock *BB,
|
||||||
|
std::map<const Value*, Value*> &ValueMap,
|
||||||
|
const char *NameSuffix) {
|
||||||
|
BasicBlock *NewBB = new BasicBlock("");
|
||||||
|
if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix);
|
||||||
|
|
||||||
|
// Loop over all instructions copying them over...
|
||||||
|
for (BasicBlock::const_iterator II = BB->begin(), IE = BB->end();
|
||||||
|
II != IE; ++II) {
|
||||||
|
Instruction *NewInst = II->clone();
|
||||||
|
if (II->hasName())
|
||||||
|
NewInst->setName(II->getName()+NameSuffix);
|
||||||
|
NewBB->getInstList().push_back(NewInst);
|
||||||
|
ValueMap[II] = NewInst; // Add instruction map to value.
|
||||||
|
}
|
||||||
|
return NewBB;
|
||||||
|
}
|
||||||
|
|
||||||
// Clone OldFunc into NewFunc, transforming the old arguments into references to
|
// Clone OldFunc into NewFunc, transforming the old arguments into references to
|
||||||
// ArgMap values.
|
// ArgMap values.
|
||||||
//
|
//
|
||||||
@ -54,21 +73,11 @@ void CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
|
|||||||
BI != BE; ++BI) {
|
BI != BE; ++BI) {
|
||||||
const BasicBlock &BB = *BI;
|
const BasicBlock &BB = *BI;
|
||||||
|
|
||||||
// Create a new basic block to copy instructions into!
|
// Create a new basic block and copy instructions into it!
|
||||||
BasicBlock *CBB = new BasicBlock("", NewFunc);
|
BasicBlock *CBB = CloneBasicBlock(&BB, ValueMap, NameSuffix);
|
||||||
if (BB.hasName()) CBB->setName(BB.getName()+NameSuffix);
|
NewFunc->getBasicBlockList().push_back(CBB);
|
||||||
ValueMap[&BB] = CBB; // Add basic block mapping.
|
ValueMap[&BB] = CBB; // Add basic block mapping.
|
||||||
|
|
||||||
// Loop over all instructions copying them over...
|
|
||||||
for (BasicBlock::const_iterator II = BB.begin(), IE = BB.end();
|
|
||||||
II != IE; ++II) {
|
|
||||||
Instruction *NewInst = II->clone();
|
|
||||||
if (II->hasName())
|
|
||||||
NewInst->setName(II->getName()+NameSuffix); // Name is not cloned...
|
|
||||||
CBB->getInstList().push_back(NewInst);
|
|
||||||
ValueMap[II] = NewInst; // Add instruction map to value.
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ReturnInst *RI = dyn_cast<ReturnInst>(CBB->getTerminator()))
|
if (ReturnInst *RI = dyn_cast<ReturnInst>(CBB->getTerminator()))
|
||||||
Returns.push_back(RI);
|
Returns.push_back(RI);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user