184bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattner//===- Cloning.h - Clone various parts of LLVM programs ---------*- C++ -*-===// 234695381d626485a560594f162701088079589dfMisha Brukman// 36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// The LLVM Compiler Infrastructure 46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// 57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source 67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details. 734695381d626485a560594f162701088079589dfMisha Brukman// 86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//===----------------------------------------------------------------------===// 984bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattner// 1084bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattner// This file defines various functions that are used to clone chunks of LLVM 1184bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattner// code for various purposes. This varies from copying whole modules into new 1284bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattner// modules, to cloning functions with different arguments, to inlining 1384bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattner// functions, to copying basic blocks to support loop unrolling or superblock 1484bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattner// formation, etc. 1584bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattner// 1684bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattner//===----------------------------------------------------------------------===// 1784bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattner 18a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner#ifndef LLVM_TRANSFORMS_UTILS_CLONING_H 19a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner#define LLVM_TRANSFORMS_UTILS_CLONING_H 2084bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattner 2160915146f4d35e12f10dcdaa155596fac79184daChris Lattner#include "llvm/ADT/SmallVector.h" 225deb57c68552a85094b786dfdbd16e3744716733Benjamin Kramer#include "llvm/ADT/Twine.h" 2336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/IR/ValueHandle.h" 2436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/IR/ValueMap.h" 251ed219a9d2279ce5a5bbcf16d9b7ccc05cce638cRafael Espindola#include "llvm/Transforms/Utils/ValueMapper.h" 26d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 27d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 28d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 2984bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattnerclass Module; 3084bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattnerclass Function; 3153bb5c95afe4ff2627cac513221af2e4e7c5d2e3Devang Patelclass Instruction; 324bc2a0b420c728e77a852bad9721e4edfd4b3f79Devang Patelclass Pass; 334bc2a0b420c728e77a852bad9721e4edfd4b3f79Devang Patelclass LPPassManager; 3484bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattnerclass BasicBlock; 3584bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattnerclass Value; 3684bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattnerclass CallInst; 379d3a1b2d972baf72b7da371a1ae72126bc5c6c04Chris Lattnerclass InvokeInst; 381c9985067bfedc219c1a6128bfc703cf3894b866Chris Lattnerclass ReturnInst; 399d3a1b2d972baf72b7da371a1ae72126bc5c6c04Chris Lattnerclass CallSite; 402b6d2eb2d0e44eb8d897fce107961767b9676a79Alkis Evlogimenosclass Trace; 414c2881ecb97ca9306396b74a61a6ce05f2b9a4f4Chris Lattnerclass CallGraph; 423574eca1b02600bac4e625297f4ecf745f4c4f32Micah Villmowclass DataLayout; 43c8d76d5afb023a1c6b439941be3b62789fcc0ed3Dan Gohmanclass Loop; 443dab223dc9a398b30484fca23d912433ea0033f3Chris Lattnerclass LoopInfo; 458f2718fbef6177966ff807af0732eb2431bd9a5fChris Lattnerclass AllocaInst; 4637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hinesclass AliasAnalysis; 47ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinesclass AssumptionCacheTracker; 4884bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattner 49d18015599cbe09dd327b5f73501581a865bf27daChris Lattner/// CloneModule - Return an exact copy of the specified module 50d18015599cbe09dd327b5f73501581a865bf27daChris Lattner/// 51d4fd3978056928b156bc51bff7cd4eb825bffb1aChris LattnerModule *CloneModule(const Module *M); 521ed219a9d2279ce5a5bbcf16d9b7ccc05cce638cRafael EspindolaModule *CloneModule(const Module *M, ValueToValueMapTy &VMap); 53d18015599cbe09dd327b5f73501581a865bf27daChris Lattner 54a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner/// ClonedCodeInfo - This struct can be used to capture information about code 55a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner/// being cloned, while it is being cloned. 56a4c29d20376f4736325a493cf39cda36bed62318Chris Lattnerstruct ClonedCodeInfo { 57a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner /// ContainsCalls - This is set to true if the cloned code contains a normal 58a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner /// call instruction. 59a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner bool ContainsCalls; 60dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 61a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner /// ContainsDynamicAllocas - This is set to true if the cloned code contains 62a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner /// a 'dynamic' alloca. Dynamic allocas are allocas that are either not in 63a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner /// the entry block or they are in the entry block but are not a constant 64a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner /// size. 65a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner bool ContainsDynamicAllocas; 66dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 678833ef03b9ceaa52063116819fff8b3d16fd8933Bill Wendling ClonedCodeInfo() : ContainsCalls(false), ContainsDynamicAllocas(false) {} 68a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner}; 69a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner 70a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// CloneBasicBlock - Return a copy of the specified basic block, but without 71a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// embedding the block into a particular function. The block returned is an 72a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// exact copy of the specified basic block, without any remapping having been 73a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// performed. Because of this, this is only suitable for applications where 74a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// the basic block will be inserted into the same function that it was cloned 75a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// from (loop unrolling would use this, for example). 76a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// 77a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// Also, note that this function makes a direct copy of the basic block, and 78a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// can thus produce illegal LLVM code. In particular, it will copy any PHI 79a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// nodes from the original block, even though there are no predecessors for the 80a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// newly cloned block (thus, phi nodes will have to be updated). Also, this 81a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// block will branch to the old successors of the original block: these 82a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// successors will have to have any PHI nodes updated to account for the new 83a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// incoming edges. 84a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// 85a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// The correlation between instructions in the source and result basic blocks 8629d3dd8a64791031eea00ffbae51843dc9982df9Devang Patel/// is recorded in the VMap map. 87a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// 88a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// If you have a particular suffix you'd like to use to add to any cloned 89cb2b3e5005c09f24afeb0dab49ac8bc1967e491aChris Lattner/// names, specify it as the optional third parameter. 90cb2b3e5005c09f24afeb0dab49ac8bc1967e491aChris Lattner/// 91cb2b3e5005c09f24afeb0dab49ac8bc1967e491aChris Lattner/// If you would like the basic block to be auto-inserted into the end of a 92cb2b3e5005c09f24afeb0dab49ac8bc1967e491aChris Lattner/// function, you can specify it as the optional fourth parameter. 93a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner/// 94a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner/// If you would like to collect additional information about the cloned 95a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner/// function, you can specify a ClonedCodeInfo object with the optional fifth 96a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner/// parameter. 97a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner/// 98ebe69fe11e48d322045d5949c83283927a0d790bStephen HinesBasicBlock *CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, 99dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines const Twine &NameSuffix = "", Function *F = nullptr, 100dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines ClonedCodeInfo *CodeInfo = nullptr); 101a107e5f11cf7aa362d2fdd5cebc7e64bb09ed22dChris Lattner 102d18015599cbe09dd327b5f73501581a865bf27daChris Lattner/// CloneFunction - Return a copy of the specified function, but without 103d18015599cbe09dd327b5f73501581a865bf27daChris Lattner/// embedding the function into another module. Also, any references specified 10429d3dd8a64791031eea00ffbae51843dc9982df9Devang Patel/// in the VMap are changed to refer to their mapped value instead of the 10529d3dd8a64791031eea00ffbae51843dc9982df9Devang Patel/// original one. If any of the arguments to the function are in the VMap, 10629d3dd8a64791031eea00ffbae51843dc9982df9Devang Patel/// the arguments are deleted from the resultant function. The VMap is 107d18015599cbe09dd327b5f73501581a865bf27daChris Lattner/// updated to include mappings from all of the instructions and basicblocks in 108a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner/// the function from their old to new values. The final argument captures 109a4c29d20376f4736325a493cf39cda36bed62318Chris Lattner/// information about the cloned code if non-null. 110d18015599cbe09dd327b5f73501581a865bf27daChris Lattner/// 1116cb8c23db1c3becdce6dfbf1b7f1677faca4251eDan Gohman/// If ModuleLevelChanges is false, VMap contains no non-identity GlobalValue 11236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines/// mappings, and debug info metadata will not be cloned. 1136cb8c23db1c3becdce6dfbf1b7f1677faca4251eDan Gohman/// 114ebe69fe11e48d322045d5949c83283927a0d790bStephen HinesFunction *CloneFunction(const Function *F, ValueToValueMapTy &VMap, 1156cb8c23db1c3becdce6dfbf1b7f1677faca4251eDan Gohman bool ModuleLevelChanges, 116dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines ClonedCodeInfo *CodeInfo = nullptr); 117d18015599cbe09dd327b5f73501581a865bf27daChris Lattner 118aa101c3147debcba3f0441c80b477782e456a03bChris Lattner/// Clone OldFunc into NewFunc, transforming the old arguments into references 1196cb8c23db1c3becdce6dfbf1b7f1677faca4251eDan Gohman/// to VMap values. Note that if NewFunc already has basic blocks, the ones 120aa101c3147debcba3f0441c80b477782e456a03bChris Lattner/// cloned into it will be added to the end of the function. This function 121d24397a9319a41e80169f572ad274a711f41d64eMon P Wang/// fills in a list of return instructions, and can optionally remap types 122d24397a9319a41e80169f572ad274a711f41d64eMon P Wang/// and/or append the specified suffix to all values cloned. 123aa101c3147debcba3f0441c80b477782e456a03bChris Lattner/// 1246cb8c23db1c3becdce6dfbf1b7f1677faca4251eDan Gohman/// If ModuleLevelChanges is false, VMap contains no non-identity GlobalValue 1256cb8c23db1c3becdce6dfbf1b7f1677faca4251eDan Gohman/// mappings. 1266cb8c23db1c3becdce6dfbf1b7f1677faca4251eDan Gohman/// 12784bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattnervoid CloneFunctionInto(Function *NewFunc, const Function *OldFunc, 128ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines ValueToValueMapTy &VMap, bool ModuleLevelChanges, 129ec1bea0d94372985a0a5eb283e644c6d0dd345dcChris Lattner SmallVectorImpl<ReturnInst*> &Returns, 130dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines const char *NameSuffix = "", 131dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines ClonedCodeInfo *CodeInfo = nullptr, 132dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines ValueMapTypeRemapper *TypeMapper = nullptr, 133dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines ValueMaterializer *Materializer = nullptr); 13484bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattner 135ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines/// A helper class used with CloneAndPruneIntoFromInst to change the default 136ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines/// behavior while instructions are being cloned. 137ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinesclass CloningDirector { 138ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinespublic: 139ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines /// This enumeration describes the way CloneAndPruneIntoFromInst should 140ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines /// proceed after the CloningDirector has examined an instruction. 141ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines enum CloningAction { 142ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines ///< Continue cloning the instruction (default behavior). 143ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines CloneInstruction, 144ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines ///< Skip this instruction but continue cloning the current basic block. 145ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines SkipInstruction, 146ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines ///< Skip this instruction and stop cloning the current basic block. 1474c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar StopCloningBB, 1484c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar ///< Don't clone the terminator but clone the current block's successors. 1494c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar CloneSuccessors 150ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines }; 151ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 152ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines virtual ~CloningDirector() {} 153ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 154ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines /// Subclasses must override this function to customize cloning behavior. 155ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines virtual CloningAction handleInstruction(ValueToValueMapTy &VMap, 156ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines const Instruction *Inst, 157ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines BasicBlock *NewBB) = 0; 158ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 159ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines virtual ValueMapTypeRemapper *getTypeRemapper() { return nullptr; } 160ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines virtual ValueMaterializer *getValueMaterializer() { return nullptr; } 161ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines}; 162ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 163ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinesvoid CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc, 164ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines const Instruction *StartingInst, 165ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines ValueToValueMapTy &VMap, bool ModuleLevelChanges, 166ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines SmallVectorImpl<ReturnInst*> &Returns, 167ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines const char *NameSuffix = "", 168ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines ClonedCodeInfo *CodeInfo = nullptr, 169ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines CloningDirector *Director = nullptr); 170ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 171ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 172f72716d81f64664e6897d9f2e8a7d071bad1de68Chris Lattner/// CloneAndPruneFunctionInto - This works exactly like CloneFunctionInto, 173f72716d81f64664e6897d9f2e8a7d071bad1de68Chris Lattner/// except that it does some simple constant prop and DCE on the fly. The 174f72716d81f64664e6897d9f2e8a7d071bad1de68Chris Lattner/// effect of this is to copy significantly less code in cases where (for 175f72716d81f64664e6897d9f2e8a7d071bad1de68Chris Lattner/// example) a function call with constant arguments is inlined, and those 176f72716d81f64664e6897d9f2e8a7d071bad1de68Chris Lattner/// constant arguments cause a significant amount of code in the callee to be 177f72716d81f64664e6897d9f2e8a7d071bad1de68Chris Lattner/// dead. Since this doesn't produce an exactly copy of the input, it can't be 178f72716d81f64664e6897d9f2e8a7d071bad1de68Chris Lattner/// used for things like CloneFunction or CloneModule. 1796cb8c23db1c3becdce6dfbf1b7f1677faca4251eDan Gohman/// 1806cb8c23db1c3becdce6dfbf1b7f1677faca4251eDan Gohman/// If ModuleLevelChanges is false, VMap contains no non-identity GlobalValue 1816cb8c23db1c3becdce6dfbf1b7f1677faca4251eDan Gohman/// mappings. 1826cb8c23db1c3becdce6dfbf1b7f1677faca4251eDan Gohman/// 183f72716d81f64664e6897d9f2e8a7d071bad1de68Chris Lattnervoid CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc, 184ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines ValueToValueMapTy &VMap, bool ModuleLevelChanges, 185ec1bea0d94372985a0a5eb283e644c6d0dd345dcChris Lattner SmallVectorImpl<ReturnInst*> &Returns, 186dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines const char *NameSuffix = "", 187dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines ClonedCodeInfo *CodeInfo = nullptr, 188dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Instruction *TheCall = nullptr); 189f72716d81f64664e6897d9f2e8a7d071bad1de68Chris Lattner 19060915146f4d35e12f10dcdaa155596fac79184daChris Lattner/// InlineFunctionInfo - This class captures the data input to the 191dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines/// InlineFunction call, and records the auxiliary results produced by it. 19260915146f4d35e12f10dcdaa155596fac79184daChris Lattnerclass InlineFunctionInfo { 19360915146f4d35e12f10dcdaa155596fac79184daChris Lattnerpublic: 19437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines explicit InlineFunctionInfo(CallGraph *cg = nullptr, 19537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines AliasAnalysis *AA = nullptr, 196ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines AssumptionCacheTracker *ACT = nullptr) 1974c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar : CG(cg), AA(AA), ACT(ACT) {} 198dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 19960915146f4d35e12f10dcdaa155596fac79184daChris Lattner /// CG - If non-null, InlineFunction will update the callgraph to reflect the 20060915146f4d35e12f10dcdaa155596fac79184daChris Lattner /// changes it makes. 20160915146f4d35e12f10dcdaa155596fac79184daChris Lattner CallGraph *CG; 20237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines AliasAnalysis *AA; 203ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines AssumptionCacheTracker *ACT; 20460915146f4d35e12f10dcdaa155596fac79184daChris Lattner 20560915146f4d35e12f10dcdaa155596fac79184daChris Lattner /// StaticAllocas - InlineFunction fills this in with all static allocas that 20660915146f4d35e12f10dcdaa155596fac79184daChris Lattner /// get copied into the caller. 207ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines SmallVector<AllocaInst *, 4> StaticAllocas; 208fe9af3b1f7e5d68ecc330bdf4f047d76838f8cc3Chris Lattner 2090ca2f28458ae9122f413a4092ddcee33a9dd21c6Chris Lattner /// InlinedCalls - InlineFunction fills this in with callsites that were 2100ca2f28458ae9122f413a4092ddcee33a9dd21c6Chris Lattner /// inlined from the callee. This is only filled in if CG is non-null. 2110ca2f28458ae9122f413a4092ddcee33a9dd21c6Chris Lattner SmallVector<WeakVH, 8> InlinedCalls; 212dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 21360915146f4d35e12f10dcdaa155596fac79184daChris Lattner void reset() { 21460915146f4d35e12f10dcdaa155596fac79184daChris Lattner StaticAllocas.clear(); 2150ca2f28458ae9122f413a4092ddcee33a9dd21c6Chris Lattner InlinedCalls.clear(); 21660915146f4d35e12f10dcdaa155596fac79184daChris Lattner } 21760915146f4d35e12f10dcdaa155596fac79184daChris Lattner}; 218dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 219aa101c3147debcba3f0441c80b477782e456a03bChris Lattner/// InlineFunction - This function inlines the called function into the basic 220a04e51f4c0dd981af9b8f6e8b219df495cccaa45Chris Lattner/// block of the caller. This returns false if it is not possible to inline 221a04e51f4c0dd981af9b8f6e8b219df495cccaa45Chris Lattner/// this call. The program is still in a well defined state if this occurs 222a04e51f4c0dd981af9b8f6e8b219df495cccaa45Chris Lattner/// though. 223aa101c3147debcba3f0441c80b477782e456a03bChris Lattner/// 22434695381d626485a560594f162701088079589dfMisha Brukman/// Note that this only does one level of inlining. For example, if the 225aa101c3147debcba3f0441c80b477782e456a03bChris Lattner/// instruction 'call B' is inlined, and 'B' calls 'C', then the call to 'C' now 2267a2bdde0a0eebcd2125055e0eacaca040f0b766cChris Lattner/// exists in the instruction stream. Similarly this will inline a recursive 227aa101c3147debcba3f0441c80b477782e456a03bChris Lattner/// function by one level. 228aa101c3147debcba3f0441c80b477782e456a03bChris Lattner/// 229ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinesbool InlineFunction(CallInst *C, InlineFunctionInfo &IFI, 230ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines bool InsertLifetime = true); 231ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinesbool InlineFunction(InvokeInst *II, InlineFunctionInfo &IFI, 232ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines bool InsertLifetime = true); 233ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinesbool InlineFunction(CallSite CS, InlineFunctionInfo &IFI, 234ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines bool InsertLifetime = true); 2352c49fc023ee0885c8c577829cd40c00ef48581fcTanya Lattner 236d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace 237d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 23884bf9880eaf57f00cc01b4ade40179553ea6fd08Chris Lattner#endif 239