llvm.org GIT mirror llvm / da92e11
Remove CloningDirector and associated code With the removal of the old landing pad code in r249918, CloningDirector is not used anywhere else. NFCI. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257185 91177308-0d34-0410-b5e6-96231b3b80d8 Easwaran Raman 4 years ago
2 changed file(s) with 10 addition(s) and 98 deletion(s). Raw diff Collapse all Expand all
146146 ValueMapTypeRemapper *TypeMapper = nullptr,
147147 ValueMaterializer *Materializer = nullptr);
148148
149 /// A helper class used with CloneAndPruneIntoFromInst to change the default
150 /// behavior while instructions are being cloned.
151 class CloningDirector {
152 public:
153 /// This enumeration describes the way CloneAndPruneIntoFromInst should
154 /// proceed after the CloningDirector has examined an instruction.
155 enum CloningAction {
156 ///< Continue cloning the instruction (default behavior).
157 CloneInstruction,
158 ///< Skip this instruction but continue cloning the current basic block.
159 SkipInstruction,
160 ///< Skip this instruction and stop cloning the current basic block.
161 StopCloningBB,
162 ///< Don't clone the terminator but clone the current block's successors.
163 CloneSuccessors
164 };
165
166 virtual ~CloningDirector() {}
167
168 /// Subclasses must override this function to customize cloning behavior.
169 virtual CloningAction handleInstruction(ValueToValueMapTy &VMap,
170 const Instruction *Inst,
171 BasicBlock *NewBB) = 0;
172
173 virtual ValueMapTypeRemapper *getTypeRemapper() { return nullptr; }
174 virtual ValueMaterializer *getValueMaterializer() { return nullptr; }
175 };
176
177149 void CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
178150 const Instruction *StartingInst,
179151 ValueToValueMapTy &VMap, bool ModuleLevelChanges,
180 SmallVectorImpl &Returns,
181 const char *NameSuffix = "",
182 ClonedCodeInfo *CodeInfo = nullptr,
183 CloningDirector *Director = nullptr);
184
152 SmallVectorImpl &Returns,
153 const char *NameSuffix = "",
154 ClonedCodeInfo *CodeInfo = nullptr);
185155
186156 /// CloneAndPruneFunctionInto - This works exactly like CloneFunctionInto,
187157 /// except that it does some simple constant prop and DCE on the fly. The
265265 bool ModuleLevelChanges;
266266 const char *NameSuffix;
267267 ClonedCodeInfo *CodeInfo;
268 CloningDirector *Director;
269 ValueMapTypeRemapper *TypeMapper;
270 ValueMaterializer *Materializer;
271268
272269 public:
273270 PruningFunctionCloner(Function *newFunc, const Function *oldFunc,
274271 ValueToValueMapTy &valueMap, bool moduleLevelChanges,
275 const char *nameSuffix, ClonedCodeInfo *codeInfo,
276 CloningDirector *Director)
272 const char *nameSuffix, ClonedCodeInfo *codeInfo)
277273 : NewFunc(newFunc), OldFunc(oldFunc), VMap(valueMap),
278274 ModuleLevelChanges(moduleLevelChanges), NameSuffix(nameSuffix),
279 CodeInfo(codeInfo), Director(Director) {
280 // These are optional components. The Director may return null.
281 if (Director) {
282 TypeMapper = Director->getTypeRemapper();
283 Materializer = Director->getValueMaterializer();
284 } else {
285 TypeMapper = nullptr;
286 Materializer = nullptr;
287 }
288 }
275 CodeInfo(codeInfo) {}
289276
290277 /// The specified block is found to be reachable, clone it and
291278 /// anything that it can reach.
331318 // loop doesn't include the terminator.
332319 for (BasicBlock::const_iterator II = StartingInst, IE = --BB->end();
333320 II != IE; ++II) {
334 // If the "Director" remaps the instruction, don't clone it.
335 if (Director) {
336 CloningDirector::CloningAction Action =
337 Director->handleInstruction(VMap, &*II, NewBB);
338 // If the cloning director says stop, we want to stop everything, not
339 // just break out of the loop (which would cause the terminator to be
340 // cloned). The cloning director is responsible for inserting a proper
341 // terminator into the new basic block in this case.
342 if (Action == CloningDirector::StopCloningBB)
343 return;
344 // If the cloning director says skip, continue to the next instruction.
345 // In this case, the cloning director is responsible for mapping the
346 // skipped instruction to some value that is defined in the new
347 // basic block.
348 if (Action == CloningDirector::SkipInstruction)
349 continue;
350 }
351321
352322 Instruction *NewInst = II->clone();
353323
355325 // nodes for which we defer processing until we update the CFG.
356326 if (!isa(NewInst)) {
357327 RemapInstruction(NewInst, VMap,
358 ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
359 TypeMapper, Materializer);
328 ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges);
360329
361330 // If we can simplify this instruction to some other value, simply add
362331 // a mapping to that value rather than inserting a new instruction into
396365 // Finally, clone over the terminator.
397366 const TerminatorInst *OldTI = BB->getTerminator();
398367 bool TerminatorDone = false;
399 if (Director) {
400 CloningDirector::CloningAction Action
401 = Director->handleInstruction(VMap, OldTI, NewBB);
402 // If the cloning director says stop, we want to stop everything, not
403 // just break out of the loop (which would cause the terminator to be
404 // cloned). The cloning director is responsible for inserting a proper
405 // terminator into the new basic block in this case.
406 if (Action == CloningDirector::StopCloningBB)
407 return;
408 if (Action == CloningDirector::CloneSuccessors) {
409 // If the director says to skip with a terminate instruction, we still
410 // need to clone this block's successors.
411 const TerminatorInst *TI = NewBB->getTerminator();
412 for (const BasicBlock *Succ : TI->successors())
413 ToClone.push_back(Succ);
414 return;
415 }
416 assert(Action != CloningDirector::SkipInstruction &&
417 "SkipInstruction is not valid for terminators.");
418 }
419368 if (const BranchInst *BI = dyn_cast(OldTI)) {
420369 if (BI->isConditional()) {
421370 // If the condition was a known constant in the callee...
484433 ValueToValueMapTy &VMap,
485434 bool ModuleLevelChanges,
486435 SmallVectorImpl &Returns,
487 const char *NameSuffix,
488 ClonedCodeInfo *CodeInfo,
489 CloningDirector *Director) {
436 const char *NameSuffix,
437 ClonedCodeInfo *CodeInfo) {
490438 assert(NameSuffix && "NameSuffix cannot be null!");
491439
492440 ValueMapTypeRemapper *TypeMapper = nullptr;
493441 ValueMaterializer *Materializer = nullptr;
494
495 if (Director) {
496 TypeMapper = Director->getTypeRemapper();
497 Materializer = Director->getValueMaterializer();
498 }
499442
500443 #ifndef NDEBUG
501444 // If the cloning starts at the beginning of the function, verify that
506449 #endif
507450
508451 PruningFunctionCloner PFC(NewFunc, OldFunc, VMap, ModuleLevelChanges,
509 NameSuffix, CodeInfo, Director);
452 NameSuffix, CodeInfo);
510453 const BasicBlock *StartingBB;
511454 if (StartingInst)
512455 StartingBB = StartingInst->getParent();
730673 ClonedCodeInfo *CodeInfo,
731674 Instruction *TheCall) {
732675 CloneAndPruneIntoFromInst(NewFunc, OldFunc, &OldFunc->front().front(), VMap,
733 ModuleLevelChanges, Returns, NameSuffix, CodeInfo,
734 nullptr);
676 ModuleLevelChanges, Returns, NameSuffix, CodeInfo);
735677 }
736678
737679 /// \brief Remaps instructions in \p Blocks using the mapping in \p VMap.