-#include "llvm/Transforms/Utils/Cloning.h"
-#include "llvm/Module.h"
-#include "llvm/Pass.h"
-#include "llvm/iTerminators.h"
-#include "llvm/iPHINode.h"
-#include "llvm/iOther.h"
-#include "llvm/Type.h"
-#include "Support/Statistic.h"
-#include <algorithm>
-
-static Statistic<> NumInlined("inline", "Number of functions inlined");
-using std::cerr;
-
-// InlineFunction - This function forcibly inlines the called function into the
-// basic block of the caller. This returns false if it is not possible to
-// inline this call. The program is still in a well defined state if this
-// occurs though.
-//
-// Note that this only does one level of inlining. For example, if the
-// instruction 'call B' is inlined, and 'B' calls 'C', then the call to 'C' now
-// exists in the instruction stream. Similiarly this will inline a recursive
-// function by one level.
-//
-bool InlineFunction(CallInst *CI) {
- assert(isa<CallInst>(CI) && "InlineFunction only works on CallInst nodes");
- assert(CI->getParent() && "Instruction not embedded in basic block!");
- assert(CI->getParent()->getParent() && "Instruction not in function!");
-
- const Function *CalledFunc = CI->getCalledFunction();
- if (CalledFunc == 0 || // Can't inline external function or indirect call!
- CalledFunc->isExternal()) return false;
-
- //cerr << "Inlining " << CalledFunc->getName() << " into "
- // << CurrentMeth->getName() << "\n";
-
- BasicBlock *OrigBB = CI->getParent();
-
- // Call splitBasicBlock - The original basic block now ends at the instruction
- // immediately before the call. The original basic block now ends with an
- // unconditional branch to NewBB, and NewBB starts with the call instruction.
- //
- BasicBlock *NewBB = OrigBB->splitBasicBlock(CI);
- NewBB->setName("InlinedFunctionReturnNode");
-
- // Remove (unlink) the CallInst from the start of the new basic block.
- NewBB->getInstList().remove(CI);
-
- // If we have a return value generated by this call, convert it into a PHI
- // node that gets values from each of the old RET instructions in the original
- // function.
- //
- PHINode *PHI = 0;
- if (!CI->use_empty()) {
- // The PHI node should go at the front of the new basic block to merge all
- // possible incoming values.
- //
- PHI = new PHINode(CalledFunc->getReturnType(), CI->getName(),
- NewBB->begin());
-
- // Anything that used the result of the function call should now use the PHI
- // node as their operand.
- //
- CI->replaceAllUsesWith(PHI);
- }
-
- // Get a pointer to the last basic block in the function, which will have the
- // new function inlined after it.
- //
- Function::iterator LastBlock = &OrigBB->getParent()->back();
-
- // Calculate the vector of arguments to pass into the function cloner...
- std::vector<Value*> ArgVector;
- for (unsigned i = 1, e = CI->getNumOperands(); i != e; ++i)
- ArgVector.push_back(CI->getOperand(i));
-
- // Since we are now done with the CallInst, we can delete it.
- delete CI;
+#include "llvm/Analysis/CallGraph.h"
+#include "llvm/Analysis/InlineCost.h"
+#include "llvm/IR/CallingConv.h"
+#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Type.h"
+#include "llvm/Support/CallSite.h"
+#include "llvm/Transforms/IPO/InlinerPass.h"
+
+using namespace llvm;