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"
|
|
|
|
#include "llvm/Support/CallSite.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Transforms/IPO.h"
|
|
|
|
#include "llvm/Transforms/IPO/InlinerPass.h"
|
|
|
|
#include "llvm/Transforms/Utils/InlineCost.h"
|
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// AlwaysInliner only inlines functions that are mark as "always inline".
|
|
|
|
class VISIBILITY_HIDDEN AlwaysInliner : public Inliner {
|
|
|
|
// Functions that are never inlined
|
|
|
|
SmallPtrSet<const Function*, 16> NeverInline;
|
|
|
|
InlineCostAnalyzer CA;
|
|
|
|
public:
|
|
|
|
// Use extremely low threshold.
|
|
|
|
AlwaysInliner() : Inliner(&ID, -2000000000) {}
|
|
|
|
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);
|
|
|
|
}
|
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);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
char AlwaysInliner::ID = 0;
|
|
|
|
static RegisterPass<AlwaysInliner>
|
2008-10-28 23:24:26 +00:00
|
|
|
X("always-inline", "Inliner for always_inline functions");
|
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;
|
|
|
|
}
|