2003-09-01 03:10:30 +08:00
|
|
|
//===- InlineSimple.cpp - Code to perform simple function inlining --------===//
|
2005-04-22 07:48:37 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-22 07:48:37 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-07 04:29:01 +08:00
|
|
|
//
|
2003-05-29 23:11:31 +08:00
|
|
|
// This file implements bottom-up inlining of functions into callees.
|
2002-04-19 02:52:03 +08:00
|
|
|
//
|
2001-06-07 04:29:01 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-06-20 06:29:50 +08:00
|
|
|
#define DEBUG_TYPE "inline"
|
2005-05-18 12:30:33 +08:00
|
|
|
#include "llvm/CallingConv.h"
|
2003-11-22 05:46:09 +08:00
|
|
|
#include "llvm/Instructions.h"
|
2004-11-23 01:21:44 +08:00
|
|
|
#include "llvm/IntrinsicInst.h"
|
2007-06-07 05:59:26 +08:00
|
|
|
#include "llvm/Module.h"
|
2004-03-14 07:15:45 +08:00
|
|
|
#include "llvm/Type.h"
|
2007-06-07 05:59:26 +08:00
|
|
|
#include "llvm/Analysis/CallGraph.h"
|
2003-08-24 14:59:28 +08:00
|
|
|
#include "llvm/Support/CallSite.h"
|
2007-02-06 07:32:05 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2003-09-01 03:10:30 +08:00
|
|
|
#include "llvm/Transforms/IPO.h"
|
2007-06-20 06:29:50 +08:00
|
|
|
#include "llvm/Transforms/IPO/InlinerPass.h"
|
2007-07-26 02:00:25 +08:00
|
|
|
#include "llvm/Transforms/Utils/InlineCost.h"
|
2007-07-28 02:34:27 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2007-06-07 05:59:26 +08:00
|
|
|
|
2003-11-22 05:46:09 +08:00
|
|
|
using namespace llvm;
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2003-05-29 23:11:31 +08:00
|
|
|
namespace {
|
2003-10-06 23:52:43 +08:00
|
|
|
|
2007-02-06 07:32:05 +08:00
|
|
|
class VISIBILITY_HIDDEN SimpleInliner : public Inliner {
|
2007-07-28 02:34:27 +08:00
|
|
|
// Functions that are never inlined
|
|
|
|
SmallPtrSet<const Function*, 16> NeverInline;
|
2007-07-26 02:00:25 +08:00
|
|
|
InlineCostAnalyzer CA;
|
2003-10-06 23:52:43 +08:00
|
|
|
public:
|
2007-05-07 07:13:56 +08:00
|
|
|
SimpleInliner() : Inliner(&ID) {}
|
2007-05-06 21:37:16 +08:00
|
|
|
static char ID; // Pass identification, replacement for typeid
|
2007-07-26 02:00:25 +08:00
|
|
|
int getInlineCost(CallSite CS) {
|
|
|
|
return CA.getInlineCost(CS, NeverInline);
|
|
|
|
}
|
2007-06-07 05:59:26 +08:00
|
|
|
virtual bool doInitialization(CallGraph &CG);
|
2003-05-29 23:11:31 +08:00
|
|
|
};
|
2007-05-03 09:11:54 +08:00
|
|
|
char SimpleInliner::ID = 0;
|
2006-08-28 06:42:52 +08:00
|
|
|
RegisterPass<SimpleInliner> X("inline", "Function Integration/Inlining");
|
2003-05-29 23:11:31 +08:00
|
|
|
}
|
|
|
|
|
2007-01-26 08:47:38 +08:00
|
|
|
Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
|
2003-11-22 05:46:09 +08:00
|
|
|
|
2007-06-07 05:59:26 +08:00
|
|
|
// doInitialization - Initializes the vector of functions that have been
|
|
|
|
// annotated with the noinline attribute.
|
|
|
|
bool SimpleInliner::doInitialization(CallGraph &CG) {
|
|
|
|
|
|
|
|
Module &M = CG.getModule();
|
|
|
|
|
|
|
|
// Get llvm.noinline
|
|
|
|
GlobalVariable *GV = M.getNamedGlobal("llvm.noinline");
|
|
|
|
|
2007-06-08 01:12:16 +08:00
|
|
|
if (GV == 0)
|
2007-06-07 05:59:26 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
const ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
|
|
|
|
|
2007-06-08 01:12:16 +08:00
|
|
|
if (InitList == 0)
|
2007-06-07 05:59:26 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Iterate over each element and add to the NeverInline set
|
|
|
|
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
|
|
|
|
|
|
|
|
// Get Source
|
|
|
|
const Constant *Elt = InitList->getOperand(i);
|
|
|
|
|
|
|
|
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(Elt))
|
|
|
|
if (CE->getOpcode() == Instruction::BitCast)
|
|
|
|
Elt = CE->getOperand(0);
|
|
|
|
|
|
|
|
// Insert into set of functions to never inline
|
2007-06-08 01:12:16 +08:00
|
|
|
if (const Function *F = dyn_cast<Function>(Elt))
|
|
|
|
NeverInline.insert(F);
|
2007-06-07 05:59:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2007-07-26 02:00:25 +08:00
|
|
|
|