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