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"
|
2011-10-01 01:39:05 +00:00
|
|
|
#include "llvm/Target/TargetData.h"
|
2008-09-03 18:50:53 +00:00
|
|
|
#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
|
2011-10-01 01:27:56 +00:00
|
|
|
SmallPtrSet<const Function*, 16> NeverInline;
|
2008-09-03 18:50:53 +00:00
|
|
|
InlineCostAnalyzer CA;
|
|
|
|
public:
|
2011-10-01 01:27:56 +00:00
|
|
|
// 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
|
|
|
}
|
2011-10-01 01:27:56 +00:00
|
|
|
virtual bool doFinalization(CallGraph &CG) {
|
|
|
|
return removeDeadFunctions(CG, &NeverInline);
|
2008-11-05 01:39:16 +00:00
|
|
|
}
|
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(); }
|
|
|
|
|
2011-10-01 01:27:56 +00:00
|
|
|
// doInitialization - Initializes the vector of functions that have not
|
2008-09-03 18:50:53 +00:00
|
|
|
// been annotated with the "always inline" attribute.
|
|
|
|
bool AlwaysInliner::doInitialization(CallGraph &CG) {
|
2011-10-01 01:39:05 +00:00
|
|
|
CA.setTargetData(getAnalysisIfAvailable<TargetData>());
|
|
|
|
|
2008-09-03 18:50:53 +00:00
|
|
|
Module &M = CG.getModule();
|
2011-10-01 01:27:56 +00:00
|
|
|
|
2008-09-03 18:50:53 +00:00
|
|
|
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;
|
|
|
|
}
|