forked from OSchip/llvm-project
Remove CloningDirector and associated code
With the removal of the old landing pad code in r249918, CloningDirector is not used anywhere else. NFCI. llvm-svn: 257185
This commit is contained in:
parent
bf5ccdccb2
commit
7f18729039
|
@ -147,42 +147,12 @@ void CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
|
|||
ValueMapTypeRemapper *TypeMapper = nullptr,
|
||||
ValueMaterializer *Materializer = nullptr);
|
||||
|
||||
/// A helper class used with CloneAndPruneIntoFromInst to change the default
|
||||
/// behavior while instructions are being cloned.
|
||||
class CloningDirector {
|
||||
public:
|
||||
/// This enumeration describes the way CloneAndPruneIntoFromInst should
|
||||
/// proceed after the CloningDirector has examined an instruction.
|
||||
enum CloningAction {
|
||||
///< Continue cloning the instruction (default behavior).
|
||||
CloneInstruction,
|
||||
///< Skip this instruction but continue cloning the current basic block.
|
||||
SkipInstruction,
|
||||
///< Skip this instruction and stop cloning the current basic block.
|
||||
StopCloningBB,
|
||||
///< Don't clone the terminator but clone the current block's successors.
|
||||
CloneSuccessors
|
||||
};
|
||||
|
||||
virtual ~CloningDirector() {}
|
||||
|
||||
/// Subclasses must override this function to customize cloning behavior.
|
||||
virtual CloningAction handleInstruction(ValueToValueMapTy &VMap,
|
||||
const Instruction *Inst,
|
||||
BasicBlock *NewBB) = 0;
|
||||
|
||||
virtual ValueMapTypeRemapper *getTypeRemapper() { return nullptr; }
|
||||
virtual ValueMaterializer *getValueMaterializer() { return nullptr; }
|
||||
};
|
||||
|
||||
void CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
|
||||
const Instruction *StartingInst,
|
||||
ValueToValueMapTy &VMap, bool ModuleLevelChanges,
|
||||
SmallVectorImpl<ReturnInst*> &Returns,
|
||||
const char *NameSuffix = "",
|
||||
ClonedCodeInfo *CodeInfo = nullptr,
|
||||
CloningDirector *Director = nullptr);
|
||||
|
||||
SmallVectorImpl<ReturnInst *> &Returns,
|
||||
const char *NameSuffix = "",
|
||||
ClonedCodeInfo *CodeInfo = nullptr);
|
||||
|
||||
/// CloneAndPruneFunctionInto - This works exactly like CloneFunctionInto,
|
||||
/// except that it does some simple constant prop and DCE on the fly. The
|
||||
|
|
|
@ -266,27 +266,14 @@ namespace {
|
|||
bool ModuleLevelChanges;
|
||||
const char *NameSuffix;
|
||||
ClonedCodeInfo *CodeInfo;
|
||||
CloningDirector *Director;
|
||||
ValueMapTypeRemapper *TypeMapper;
|
||||
ValueMaterializer *Materializer;
|
||||
|
||||
public:
|
||||
PruningFunctionCloner(Function *newFunc, const Function *oldFunc,
|
||||
ValueToValueMapTy &valueMap, bool moduleLevelChanges,
|
||||
const char *nameSuffix, ClonedCodeInfo *codeInfo,
|
||||
CloningDirector *Director)
|
||||
const char *nameSuffix, ClonedCodeInfo *codeInfo)
|
||||
: NewFunc(newFunc), OldFunc(oldFunc), VMap(valueMap),
|
||||
ModuleLevelChanges(moduleLevelChanges), NameSuffix(nameSuffix),
|
||||
CodeInfo(codeInfo), Director(Director) {
|
||||
// These are optional components. The Director may return null.
|
||||
if (Director) {
|
||||
TypeMapper = Director->getTypeRemapper();
|
||||
Materializer = Director->getValueMaterializer();
|
||||
} else {
|
||||
TypeMapper = nullptr;
|
||||
Materializer = nullptr;
|
||||
}
|
||||
}
|
||||
CodeInfo(codeInfo) {}
|
||||
|
||||
/// The specified block is found to be reachable, clone it and
|
||||
/// anything that it can reach.
|
||||
|
@ -332,23 +319,6 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
|
|||
// loop doesn't include the terminator.
|
||||
for (BasicBlock::const_iterator II = StartingInst, IE = --BB->end();
|
||||
II != IE; ++II) {
|
||||
// If the "Director" remaps the instruction, don't clone it.
|
||||
if (Director) {
|
||||
CloningDirector::CloningAction Action =
|
||||
Director->handleInstruction(VMap, &*II, NewBB);
|
||||
// If the cloning director says stop, we want to stop everything, not
|
||||
// just break out of the loop (which would cause the terminator to be
|
||||
// cloned). The cloning director is responsible for inserting a proper
|
||||
// terminator into the new basic block in this case.
|
||||
if (Action == CloningDirector::StopCloningBB)
|
||||
return;
|
||||
// If the cloning director says skip, continue to the next instruction.
|
||||
// In this case, the cloning director is responsible for mapping the
|
||||
// skipped instruction to some value that is defined in the new
|
||||
// basic block.
|
||||
if (Action == CloningDirector::SkipInstruction)
|
||||
continue;
|
||||
}
|
||||
|
||||
Instruction *NewInst = II->clone();
|
||||
|
||||
|
@ -356,8 +326,7 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
|
|||
// nodes for which we defer processing until we update the CFG.
|
||||
if (!isa<PHINode>(NewInst)) {
|
||||
RemapInstruction(NewInst, VMap,
|
||||
ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
|
||||
TypeMapper, Materializer);
|
||||
ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges);
|
||||
|
||||
// If we can simplify this instruction to some other value, simply add
|
||||
// a mapping to that value rather than inserting a new instruction into
|
||||
|
@ -397,26 +366,6 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
|
|||
// Finally, clone over the terminator.
|
||||
const TerminatorInst *OldTI = BB->getTerminator();
|
||||
bool TerminatorDone = false;
|
||||
if (Director) {
|
||||
CloningDirector::CloningAction Action
|
||||
= Director->handleInstruction(VMap, OldTI, NewBB);
|
||||
// If the cloning director says stop, we want to stop everything, not
|
||||
// just break out of the loop (which would cause the terminator to be
|
||||
// cloned). The cloning director is responsible for inserting a proper
|
||||
// terminator into the new basic block in this case.
|
||||
if (Action == CloningDirector::StopCloningBB)
|
||||
return;
|
||||
if (Action == CloningDirector::CloneSuccessors) {
|
||||
// If the director says to skip with a terminate instruction, we still
|
||||
// need to clone this block's successors.
|
||||
const TerminatorInst *TI = NewBB->getTerminator();
|
||||
for (const BasicBlock *Succ : TI->successors())
|
||||
ToClone.push_back(Succ);
|
||||
return;
|
||||
}
|
||||
assert(Action != CloningDirector::SkipInstruction &&
|
||||
"SkipInstruction is not valid for terminators.");
|
||||
}
|
||||
if (const BranchInst *BI = dyn_cast<BranchInst>(OldTI)) {
|
||||
if (BI->isConditional()) {
|
||||
// If the condition was a known constant in the callee...
|
||||
|
@ -485,19 +434,13 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
|
|||
ValueToValueMapTy &VMap,
|
||||
bool ModuleLevelChanges,
|
||||
SmallVectorImpl<ReturnInst *> &Returns,
|
||||
const char *NameSuffix,
|
||||
ClonedCodeInfo *CodeInfo,
|
||||
CloningDirector *Director) {
|
||||
const char *NameSuffix,
|
||||
ClonedCodeInfo *CodeInfo) {
|
||||
assert(NameSuffix && "NameSuffix cannot be null!");
|
||||
|
||||
ValueMapTypeRemapper *TypeMapper = nullptr;
|
||||
ValueMaterializer *Materializer = nullptr;
|
||||
|
||||
if (Director) {
|
||||
TypeMapper = Director->getTypeRemapper();
|
||||
Materializer = Director->getValueMaterializer();
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
// If the cloning starts at the beginning of the function, verify that
|
||||
// the function arguments are mapped.
|
||||
|
@ -507,7 +450,7 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
|
|||
#endif
|
||||
|
||||
PruningFunctionCloner PFC(NewFunc, OldFunc, VMap, ModuleLevelChanges,
|
||||
NameSuffix, CodeInfo, Director);
|
||||
NameSuffix, CodeInfo);
|
||||
const BasicBlock *StartingBB;
|
||||
if (StartingInst)
|
||||
StartingBB = StartingInst->getParent();
|
||||
|
@ -731,8 +674,7 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
|
|||
ClonedCodeInfo *CodeInfo,
|
||||
Instruction *TheCall) {
|
||||
CloneAndPruneIntoFromInst(NewFunc, OldFunc, &OldFunc->front().front(), VMap,
|
||||
ModuleLevelChanges, Returns, NameSuffix, CodeInfo,
|
||||
nullptr);
|
||||
ModuleLevelChanges, Returns, NameSuffix, CodeInfo);
|
||||
}
|
||||
|
||||
/// \brief Remaps instructions in \p Blocks using the mapping in \p VMap.
|
||||
|
|
Loading…
Reference in New Issue