The inliner/cloner can now optionally take TargetData info, which can be
authorChris Lattner <sabre@nondot.org>
Tue, 30 Jan 2007 23:22:39 +0000 (23:22 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 30 Jan 2007 23:22:39 +0000 (23:22 +0000)
used by constant folding.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33676 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/Utils/Cloning.h
lib/Transforms/Utils/CloneFunction.cpp
lib/Transforms/Utils/InlineFunction.cpp

index 38fc5ba740df209b273122ce1436749c172043d3..f925c63468db7ae2c51520fee6ffaf0c41ecb70d 100644 (file)
@@ -33,6 +33,7 @@ class ReturnInst;
 class CallSite;
 class Trace;
 class CallGraph;
 class CallSite;
 class Trace;
 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::vector<ReturnInst*> &Returns,
                                const char *NameSuffix = "", 
                                std::map<const Value*, Value*> &ValueMap,
                                std::vector<ReturnInst*> &Returns,
                                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
 /// CallGraph to represent the program after inlining.
 ///
 /// If a non-null callgraph pointer is provided, these functions update the
 /// CallGraph to represent the program after inlining.
 ///
-bool InlineFunction(CallInst *C, CallGraph *CG = 0);
-bool InlineFunction(InvokeInst *II, CallGraph *CG = 0);
-bool InlineFunction(CallSite CS, CallGraph *CG = 0);
+bool InlineFunction(CallInst *C, CallGraph *CG = 0, const TargetData *TD = 0);
+bool InlineFunction(InvokeInst *II, CallGraph *CG = 0, const TargetData *TD =0);
+bool InlineFunction(CallSite CS, CallGraph *CG = 0, const TargetData *TD = 0);
 
 } // End llvm namespace
 
 
 } // End llvm namespace
 
index f47bf1b7bff152e163cd069f984b26d8d79f52ed..12dff3bf588a870f7d17638827969055bf68b844 100644 (file)
@@ -158,15 +158,17 @@ namespace {
     std::vector<ReturnInst*> &Returns;
     const char *NameSuffix;
     ClonedCodeInfo *CodeInfo;
     std::vector<ReturnInst*> &Returns;
     const char *NameSuffix;
     ClonedCodeInfo *CodeInfo;
+    const TargetData *TD;
 
   public:
     PruningFunctionCloner(Function *newFunc, const Function *oldFunc,
                           std::map<const Value*, Value*> &valueMap,
                           std::vector<ReturnInst*> &returns,
                           const char *nameSuffix, 
 
   public:
     PruningFunctionCloner(Function *newFunc, const Function *oldFunc,
                           std::map<const Value*, Value*> &valueMap,
                           std::vector<ReturnInst*> &returns,
                           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
       return 0;  // All operands not constant!
 
     else
       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::vector<ReturnInst*> &Returns,
                                      const char *NameSuffix, 
                                      std::map<const Value*, Value*> &ValueMap,
                                      std::vector<ReturnInst*> &Returns,
                                      const char *NameSuffix, 
-                                     ClonedCodeInfo *CodeInfo) {
+                                     ClonedCodeInfo *CodeInfo,
+                                     const TargetData *TD) {
   assert(NameSuffix && "NameSuffix cannot be null!");
   
 #ifndef NDEBUG
   assert(NameSuffix && "NameSuffix cannot be null!");
   
 #ifndef NDEBUG
@@ -314,7 +317,7 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
 #endif
   
   PruningFunctionCloner PFC(NewFunc, OldFunc, ValueMap, Returns, 
 #endif
   
   PruningFunctionCloner PFC(NewFunc, OldFunc, ValueMap, Returns, 
-                            NameSuffix, CodeInfo);
+                            NameSuffix, CodeInfo, TD);
 
   // Clone the entry block, and anything recursively reachable from it.
   PFC.CloneBlock(&OldFunc->getEntryBlock());
 
   // Clone the entry block, and anything recursively reachable from it.
   PFC.CloneBlock(&OldFunc->getEntryBlock());
index f4b1331c0f7fc9622763f8a170c7d16db69f390e..911bfe0a39a6640ebd2e16d3329ee6d85f1b906b 100644 (file)
 #include "llvm/Support/CallSite.h"
 using namespace llvm;
 
 #include "llvm/Support/CallSite.h"
 using namespace llvm;
 
-bool llvm::InlineFunction(CallInst *CI, CallGraph *CG) {
-  return InlineFunction(CallSite(CI), CG);
+bool llvm::InlineFunction(CallInst *CI, CallGraph *CG, const TargetData *TD) {
+  return InlineFunction(CallSite(CI), CG, TD);
 }
 }
-bool llvm::InlineFunction(InvokeInst *II, CallGraph *CG) {
-  return InlineFunction(CallSite(II), CG);
+bool llvm::InlineFunction(InvokeInst *II, CallGraph *CG, const TargetData *TD) {
+  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
 // function by one level.
 //
 // exists in the instruction stream.  Similiarly this will inline a recursive
 // 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();
   assert(TheCall->getParent() && TheCall->getParent()->getParent() &&
          "Instruction not in function!");
   Instruction *TheCall = CS.getInstruction();
   assert(TheCall->getParent() && TheCall->getParent()->getParent() &&
          "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
     // happy with whatever the cloner can do.
     CloneAndPruneFunctionInto(Caller, CalledFunc, ValueMap, Returns, ".i",
     // (which can happen, e.g., because an argument was constant), but we'll be
     // happy with whatever the cloner can do.
     CloneAndPruneFunctionInto(Caller, CalledFunc, ValueMap, Returns, ".i",
-                              &InlinedFunctionInfo);
+                              &InlinedFunctionInfo, TD);
     
     // Remember the first block that is newly cloned over.
     FirstNewBlock = LastBlock; ++FirstNewBlock;
     
     // Remember the first block that is newly cloned over.
     FirstNewBlock = LastBlock; ++FirstNewBlock;