[PM] Replace an abuse of inheritance to override a single function with

a more direct approach: a type-erased glorified function pointer. Now we
can pass a function pointer into this for the easy case and we can even
pass a lambda into it in the interesting case in the instruction
combiner.

I'll be using this shortly to simplify the interfaces to InstCombiner,
but this helps pave the way and seems like a better design for the
libcall simplifier utility.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226640 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chandler Carruth
2015-01-21 02:11:59 +00:00
parent 4d569edd37
commit b67fc33fa5
3 changed files with 27 additions and 35 deletions

View File

@ -2084,15 +2084,19 @@ Value *LibCallSimplifier::optimizeCall(CallInst *CI) {
return nullptr;
}
LibCallSimplifier::LibCallSimplifier(const DataLayout *DL,
const TargetLibraryInfo *TLI) :
FortifiedSimplifier(DL, TLI),
DL(DL),
TLI(TLI),
UnsafeFPShrink(false) {
LibCallSimplifier::LibCallSimplifier(
const DataLayout *DL, const TargetLibraryInfo *TLI,
function_ref<void(Instruction *, Value *)> Replacer)
: FortifiedSimplifier(DL, TLI), DL(DL), TLI(TLI), UnsafeFPShrink(false),
Replacer(Replacer) {}
void LibCallSimplifier::replaceAllUsesWith(Instruction *I, Value *With) {
// Indirect through the replacer used in this instance.
Replacer(I, With);
}
void LibCallSimplifier::replaceAllUsesWith(Instruction *I, Value *With) const {
/*static*/ void LibCallSimplifier::replaceAllUsesWithDefault(Instruction *I,
Value *With) {
I->replaceAllUsesWith(With);
I->eraseFromParent();
}