Extend function cloning interface to support inlining
[oota-llvm.git] / include / llvm / Transforms / Utils / Cloning.h
1 //===- Cloning.h - Clone various parts of LLVM programs ---------*- C++ -*-===//
2 //
3 // This file defines various functions that are used to clone chunks of LLVM
4 // code for various purposes.  This varies from copying whole modules into new
5 // modules, to cloning functions with different arguments, to inlining
6 // functions, to copying basic blocks to support loop unrolling or superblock
7 // formation, etc.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef LLVM_TRANSFORMS_UTIlS_CLONING_H
12 #define LLVM_TRANSFORMS_UTIlS_CLONING_H
13
14 #include <vector>
15 class Module;
16 class Function;
17 class BasicBlock;
18 class Value;
19 class CallInst;
20 class ReturnInst;
21
22 // Clone OldFunc into NewFunc, transforming the old arguments into references to
23 // ArgMap values.  Note that if NewFunc already has basic blocks, the ones
24 // cloned into it will be added to the end of the function.  This function fills
25 // in a list of return instructions, and can optionally append the specified
26 // suffix to all values cloned.
27 //
28 void CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
29                        const std::vector<Value*> &ArgMap,
30                        std::vector<ReturnInst*> &Returns,
31                        const char *NameSuffix = "");
32
33
34 // InlineFunction - This function forcibly inlines the called function into the
35 // basic block of the caller.  This returns true if it is not possible to inline
36 // this call.  The program is still in a well defined state if this occurs 
37 // though.
38 //
39 // Note that this only does one level of inlining.  For example, if the 
40 // instruction 'call B' is inlined, and 'B' calls 'C', then the call to 'C' now 
41 // exists in the instruction stream.  Similiarly this will inline a recursive
42 // function by one level.
43 //
44 bool InlineFunction(CallInst *C);
45
46 #endif