1 //===- InlineAlways.cpp - Code to perform simple function inlining --------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements bottom-up inlining of functions into callees.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "inline"
15 #include "llvm/CallingConv.h"
16 #include "llvm/Instructions.h"
17 #include "llvm/IntrinsicInst.h"
18 #include "llvm/Module.h"
19 #include "llvm/Type.h"
20 #include "llvm/Analysis/CallGraph.h"
21 #include "llvm/Support/CallSite.h"
22 #include "llvm/Support/Compiler.h"
23 #include "llvm/Transforms/IPO.h"
24 #include "llvm/Transforms/IPO/InlinerPass.h"
25 #include "llvm/Transforms/Utils/InlineCost.h"
26 #include "llvm/ADT/SmallPtrSet.h"
32 // AlwaysInliner only inlines functions that are mark as "always inline".
33 class VISIBILITY_HIDDEN AlwaysInliner : public Inliner {
34 // Functions that are never inlined
35 SmallPtrSet<const Function*, 16> NeverInline;
36 InlineCostAnalyzer CA;
38 // Use extremely low threshold.
39 AlwaysInliner() : Inliner(&ID, -2000000000) {}
40 static char ID; // Pass identification, replacement for typeid
41 int getInlineCost(CallSite CS) {
42 return CA.getInlineCost(CS, NeverInline);
44 float getInlineFudgeFactor(CallSite CS) {
45 return CA.getInlineFudgeFactor(CS);
47 virtual bool doInitialization(CallGraph &CG);
51 char AlwaysInliner::ID = 0;
52 static RegisterPass<AlwaysInliner>
53 X("always-inline", "Inliner that handles always_inline functions");
55 Pass *llvm::createAlwaysInlinerPass() { return new AlwaysInliner(); }
57 // doInitialization - Initializes the vector of functions that have not
58 // been annotated with the "always inline" attribute.
59 bool AlwaysInliner::doInitialization(CallGraph &CG) {
61 Module &M = CG.getModule();
63 for (Module::iterator I = M.begin(), E = M.end();
65 if (!I->isDeclaration() && I->getNotes() != FN_NOTE_AlwaysInline)
66 NeverInline.insert(I);