2008-09-03 19:52:17 +00:00
|
|
|
//===- InlineAlways.cpp - Code to inline always_inline functions ----------===//
|
2008-09-03 18:50:53 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-09-03 19:52:17 +00:00
|
|
|
// This file implements a custom inliner that handles only functions that
|
2008-09-03 20:25:40 +00:00
|
|
|
// are marked as "always inline".
|
2008-09-03 18:50:53 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "inline"
|
|
|
|
#include "llvm/CallingConv.h"
|
|
|
|
#include "llvm/Instructions.h"
|
|
|
|
#include "llvm/IntrinsicInst.h"
|
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/Type.h"
|
|
|
|
#include "llvm/Analysis/CallGraph.h"
|
2009-10-13 18:30:07 +00:00
|
|
|
#include "llvm/Analysis/InlineCost.h"
|
2008-09-03 18:50:53 +00:00
|
|
|
#include "llvm/Support/CallSite.h"
|
|
|
|
#include "llvm/Transforms/IPO.h"
|
|
|
|
#include "llvm/Transforms/IPO/InlinerPass.h"
|
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// AlwaysInliner only inlines functions that are mark as "always inline".
|
2009-10-25 06:33:48 +00:00
|
|
|
class AlwaysInliner : public Inliner {
|
2008-09-03 18:50:53 +00:00
|
|
|
// Functions that are never inlined
|
|
|
|
SmallPtrSet<const Function*, 16> NeverInline;
|
|
|
|
InlineCostAnalyzer CA;
|
|
|
|
public:
|
|
|
|
// Use extremely low threshold.
|
2010-10-19 17:21:58 +00:00
|
|
|
AlwaysInliner() : Inliner(ID, -2000000000) {
|
|
|
|
initializeAlwaysInlinerPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2008-09-03 18:50:53 +00:00
|
|
|
static char ID; // Pass identification, replacement for typeid
|
2008-10-30 19:26:59 +00:00
|
|
|
InlineCost getInlineCost(CallSite CS) {
|
2008-09-03 18:50:53 +00:00
|
|
|
return CA.getInlineCost(CS, NeverInline);
|
|
|
|
}
|
|
|
|
float getInlineFudgeFactor(CallSite CS) {
|
|
|
|
return CA.getInlineFudgeFactor(CS);
|
|
|
|
}
|
2009-01-09 01:30:11 +00:00
|
|
|
void resetCachedCostInfo(Function *Caller) {
|
2010-03-09 23:02:17 +00:00
|
|
|
CA.resetCachedCostInfo(Caller);
|
|
|
|
}
|
|
|
|
void growCachedCostInfo(Function* Caller, Function* Callee) {
|
|
|
|
CA.growCachedCostInfo(Caller, Callee);
|
2009-01-09 01:30:11 +00:00
|
|
|
}
|
2008-11-05 01:39:16 +00:00
|
|
|
virtual bool doFinalization(CallGraph &CG) {
|
|
|
|
return removeDeadFunctions(CG, &NeverInline);
|
|
|
|
}
|
2008-09-03 18:50:53 +00:00
|
|
|
virtual bool doInitialization(CallGraph &CG);
|
2010-05-15 04:26:25 +00:00
|
|
|
void releaseMemory() {
|
|
|
|
CA.clear();
|
|
|
|
}
|
2008-09-03 18:50:53 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
char AlwaysInliner::ID = 0;
|
2010-10-19 17:21:58 +00:00
|
|
|
INITIALIZE_PASS_BEGIN(AlwaysInliner, "always-inline",
|
|
|
|
"Inliner for always_inline functions", false, false)
|
|
|
|
INITIALIZE_AG_DEPENDENCY(CallGraph)
|
|
|
|
INITIALIZE_PASS_END(AlwaysInliner, "always-inline",
|
2010-10-07 22:25:06 +00:00
|
|
|
"Inliner for always_inline functions", false, false)
|
2008-09-03 18:50:53 +00:00
|
|
|
|
|
|
|
Pass *llvm::createAlwaysInlinerPass() { return new AlwaysInliner(); }
|
|
|
|
|
|
|
|
// doInitialization - Initializes the vector of functions that have not
|
|
|
|
// been annotated with the "always inline" attribute.
|
|
|
|
bool AlwaysInliner::doInitialization(CallGraph &CG) {
|
|
|
|
Module &M = CG.getModule();
|
|
|
|
|
|
|
|
for (Module::iterator I = M.begin(), E = M.end();
|
|
|
|
I != E; ++I)
|
2008-09-26 23:51:19 +00:00
|
|
|
if (!I->isDeclaration() && !I->hasFnAttr(Attribute::AlwaysInline))
|
2008-09-03 18:50:53 +00:00
|
|
|
NeverInline.insert(I);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|