The inliner/cloner can now optionally take TargetData info, which can be

used by constant folding.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33676 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2007-01-30 23:22:39 +00:00
parent 3cab071f6f
commit 1dfdf8255e
3 changed files with 20 additions and 15 deletions

View File

@ -33,6 +33,7 @@ class ReturnInst;
class CallSite; class CallSite;
class Trace; class Trace;
class CallGraph; class CallGraph;
class TargetData;
/// CloneModule - Return an exact copy of the specified module /// CloneModule - Return an exact copy of the specified module
/// ///
@ -141,7 +142,8 @@ void CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
std::map<const Value*, Value*> &ValueMap, std::map<const Value*, Value*> &ValueMap,
std::vector<ReturnInst*> &Returns, std::vector<ReturnInst*> &Returns,
const char *NameSuffix = "", const char *NameSuffix = "",
ClonedCodeInfo *CodeInfo = 0); ClonedCodeInfo *CodeInfo = 0,
const TargetData *TD = 0);
/// CloneTraceInto - Clone T into NewFunc. Original<->clone mapping is /// CloneTraceInto - Clone T into NewFunc. Original<->clone mapping is
@ -170,9 +172,9 @@ std::vector<BasicBlock *> CloneTrace(const std::vector<BasicBlock*> &origTrace);
/// If a non-null callgraph pointer is provided, these functions update the /// If a non-null callgraph pointer is provided, these functions update the
/// CallGraph to represent the program after inlining. /// CallGraph to represent the program after inlining.
/// ///
bool InlineFunction(CallInst *C, CallGraph *CG = 0); bool InlineFunction(CallInst *C, CallGraph *CG = 0, const TargetData *TD = 0);
bool InlineFunction(InvokeInst *II, CallGraph *CG = 0); bool InlineFunction(InvokeInst *II, CallGraph *CG = 0, const TargetData *TD =0);
bool InlineFunction(CallSite CS, CallGraph *CG = 0); bool InlineFunction(CallSite CS, CallGraph *CG = 0, const TargetData *TD = 0);
} // End llvm namespace } // End llvm namespace

View File

@ -158,15 +158,17 @@ namespace {
std::vector<ReturnInst*> &Returns; std::vector<ReturnInst*> &Returns;
const char *NameSuffix; const char *NameSuffix;
ClonedCodeInfo *CodeInfo; ClonedCodeInfo *CodeInfo;
const TargetData *TD;
public: public:
PruningFunctionCloner(Function *newFunc, const Function *oldFunc, PruningFunctionCloner(Function *newFunc, const Function *oldFunc,
std::map<const Value*, Value*> &valueMap, std::map<const Value*, Value*> &valueMap,
std::vector<ReturnInst*> &returns, std::vector<ReturnInst*> &returns,
const char *nameSuffix, const char *nameSuffix,
ClonedCodeInfo *codeInfo) ClonedCodeInfo *codeInfo,
const TargetData *td)
: NewFunc(newFunc), OldFunc(oldFunc), ValueMap(valueMap), Returns(returns), : NewFunc(newFunc), OldFunc(oldFunc), ValueMap(valueMap), Returns(returns),
NameSuffix(nameSuffix), CodeInfo(codeInfo) { NameSuffix(nameSuffix), CodeInfo(codeInfo), TD(td) {
} }
/// CloneBlock - The specified block is found to be reachable, clone it and /// CloneBlock - The specified block is found to be reachable, clone it and
@ -290,7 +292,7 @@ ConstantFoldMappedInstruction(const Instruction *I) {
else else
return 0; // All operands not constant! return 0; // All operands not constant!
return ConstantFoldInstOperands(I, &Ops[0], Ops.size()); return ConstantFoldInstOperands(I, &Ops[0], Ops.size(), TD);
} }
/// CloneAndPruneFunctionInto - This works exactly like CloneFunctionInto, /// CloneAndPruneFunctionInto - This works exactly like CloneFunctionInto,
@ -304,7 +306,8 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
std::map<const Value*, Value*> &ValueMap, std::map<const Value*, Value*> &ValueMap,
std::vector<ReturnInst*> &Returns, std::vector<ReturnInst*> &Returns,
const char *NameSuffix, const char *NameSuffix,
ClonedCodeInfo *CodeInfo) { ClonedCodeInfo *CodeInfo,
const TargetData *TD) {
assert(NameSuffix && "NameSuffix cannot be null!"); assert(NameSuffix && "NameSuffix cannot be null!");
#ifndef NDEBUG #ifndef NDEBUG
@ -314,7 +317,7 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
#endif #endif
PruningFunctionCloner PFC(NewFunc, OldFunc, ValueMap, Returns, PruningFunctionCloner PFC(NewFunc, OldFunc, ValueMap, Returns,
NameSuffix, CodeInfo); NameSuffix, CodeInfo, TD);
// Clone the entry block, and anything recursively reachable from it. // Clone the entry block, and anything recursively reachable from it.
PFC.CloneBlock(&OldFunc->getEntryBlock()); PFC.CloneBlock(&OldFunc->getEntryBlock());

View File

@ -22,11 +22,11 @@
#include "llvm/Support/CallSite.h" #include "llvm/Support/CallSite.h"
using namespace llvm; using namespace llvm;
bool llvm::InlineFunction(CallInst *CI, CallGraph *CG) { bool llvm::InlineFunction(CallInst *CI, CallGraph *CG, const TargetData *TD) {
return InlineFunction(CallSite(CI), CG); return InlineFunction(CallSite(CI), CG, TD);
} }
bool llvm::InlineFunction(InvokeInst *II, CallGraph *CG) { bool llvm::InlineFunction(InvokeInst *II, CallGraph *CG, const TargetData *TD) {
return InlineFunction(CallSite(II), CG); return InlineFunction(CallSite(II), CG, TD);
} }
/// HandleInlinedInvoke - If we inlined an invoke site, we need to convert calls /// HandleInlinedInvoke - If we inlined an invoke site, we need to convert calls
@ -177,7 +177,7 @@ static void UpdateCallGraphAfterInlining(const Function *Caller,
// exists in the instruction stream. Similiarly this will inline a recursive // exists in the instruction stream. Similiarly this will inline a recursive
// function by one level. // function by one level.
// //
bool llvm::InlineFunction(CallSite CS, CallGraph *CG) { bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
Instruction *TheCall = CS.getInstruction(); Instruction *TheCall = CS.getInstruction();
assert(TheCall->getParent() && TheCall->getParent()->getParent() && assert(TheCall->getParent() && TheCall->getParent()->getParent() &&
"Instruction not in function!"); "Instruction not in function!");
@ -225,7 +225,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG) {
// (which can happen, e.g., because an argument was constant), but we'll be // (which can happen, e.g., because an argument was constant), but we'll be
// happy with whatever the cloner can do. // happy with whatever the cloner can do.
CloneAndPruneFunctionInto(Caller, CalledFunc, ValueMap, Returns, ".i", CloneAndPruneFunctionInto(Caller, CalledFunc, ValueMap, Returns, ".i",
&InlinedFunctionInfo); &InlinedFunctionInfo, TD);
// Remember the first block that is newly cloned over. // Remember the first block that is newly cloned over.
FirstNewBlock = LastBlock; ++FirstNewBlock; FirstNewBlock = LastBlock; ++FirstNewBlock;