mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-14 15:28:20 +00:00
Instruct the inliner to obey the noinline attribute. Add test case.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37481 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -15,11 +15,14 @@
|
|||||||
#include "llvm/CallingConv.h"
|
#include "llvm/CallingConv.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/IntrinsicInst.h"
|
#include "llvm/IntrinsicInst.h"
|
||||||
#include "llvm/Function.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Type.h"
|
#include "llvm/Type.h"
|
||||||
|
#include "llvm/Analysis/CallGraph.h"
|
||||||
#include "llvm/Support/CallSite.h"
|
#include "llvm/Support/CallSite.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
#include "llvm/Transforms/IPO.h"
|
#include "llvm/Transforms/IPO.h"
|
||||||
|
#include <set>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -53,10 +56,12 @@ namespace {
|
|||||||
|
|
||||||
class VISIBILITY_HIDDEN SimpleInliner : public Inliner {
|
class VISIBILITY_HIDDEN SimpleInliner : public Inliner {
|
||||||
std::map<const Function*, FunctionInfo> CachedFunctionInfo;
|
std::map<const Function*, FunctionInfo> CachedFunctionInfo;
|
||||||
|
std::set<const Function*> NeverInline; // Functions that are never inlined
|
||||||
public:
|
public:
|
||||||
SimpleInliner() : Inliner(&ID) {}
|
SimpleInliner() : Inliner(&ID) {}
|
||||||
static char ID; // Pass identification, replacement for typeid
|
static char ID; // Pass identification, replacement for typeid
|
||||||
int getInlineCost(CallSite CS);
|
int getInlineCost(CallSite CS);
|
||||||
|
virtual bool doInitialization(CallGraph &CG);
|
||||||
};
|
};
|
||||||
char SimpleInliner::ID = 0;
|
char SimpleInliner::ID = 0;
|
||||||
RegisterPass<SimpleInliner> X("inline", "Function Integration/Inlining");
|
RegisterPass<SimpleInliner> X("inline", "Function Integration/Inlining");
|
||||||
@@ -191,6 +196,9 @@ int SimpleInliner::getInlineCost(CallSite CS) {
|
|||||||
// Don't inline a directly recursive call.
|
// Don't inline a directly recursive call.
|
||||||
if (Caller == Callee) return 2000000000;
|
if (Caller == Callee) return 2000000000;
|
||||||
|
|
||||||
|
// Don't inline functions marked noinline
|
||||||
|
if (NeverInline.count(Callee)) return 2000000000;
|
||||||
|
|
||||||
// InlineCost - This value measures how good of an inline candidate this call
|
// InlineCost - This value measures how good of an inline candidate this call
|
||||||
// site is to inline. A lower inline cost make is more likely for the call to
|
// site is to inline. A lower inline cost make is more likely for the call to
|
||||||
// be inlined. This value may go negative.
|
// be inlined. This value may go negative.
|
||||||
@@ -274,3 +282,37 @@ int SimpleInliner::getInlineCost(CallSite CS) {
|
|||||||
return InlineCost;
|
return InlineCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// doInitialization - Initializes the vector of functions that have been
|
||||||
|
// annotated with the noinline attribute.
|
||||||
|
bool SimpleInliner::doInitialization(CallGraph &CG) {
|
||||||
|
|
||||||
|
Module &M = CG.getModule();
|
||||||
|
|
||||||
|
// Get llvm.noinline
|
||||||
|
GlobalVariable *GV = M.getNamedGlobal("llvm.noinline");
|
||||||
|
|
||||||
|
if(GV == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
|
||||||
|
|
||||||
|
if(InitList == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Iterate over each element and add to the NeverInline set
|
||||||
|
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
|
||||||
|
|
||||||
|
// Get Source
|
||||||
|
const Constant *Elt = InitList->getOperand(i);
|
||||||
|
|
||||||
|
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(Elt))
|
||||||
|
if (CE->getOpcode() == Instruction::BitCast)
|
||||||
|
Elt = CE->getOperand(0);
|
||||||
|
|
||||||
|
// Insert into set of functions to never inline
|
||||||
|
if(const Function *f = dyn_cast<Function>(Elt))
|
||||||
|
NeverInline.insert(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
46
test/Transforms/Inline/2007-06-06-NoInline.ll
Normal file
46
test/Transforms/Inline/2007-06-06-NoInline.ll
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
; RUN: llvm-as < %s | opt -inline -f - | llvm-dis | grep "define internal i32 @bar"
|
||||||
|
@llvm.noinline = appending global [1 x i8*] [ i8* bitcast (i32 (i32, i32)* @bar to i8*) ], section "llvm.metadata" ; <[1 x i8*]*> [#uses=0]
|
||||||
|
|
||||||
|
define internal i32 @bar(i32 %x, i32 %y) {
|
||||||
|
entry:
|
||||||
|
%x_addr = alloca i32 ; <i32*> [#uses=2]
|
||||||
|
%y_addr = alloca i32 ; <i32*> [#uses=2]
|
||||||
|
%retval = alloca i32, align 4 ; <i32*> [#uses=2]
|
||||||
|
%tmp = alloca i32, align 4 ; <i32*> [#uses=2]
|
||||||
|
%"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
|
||||||
|
store i32 %x, i32* %x_addr
|
||||||
|
store i32 %y, i32* %y_addr
|
||||||
|
%tmp1 = load i32* %x_addr ; <i32> [#uses=1]
|
||||||
|
%tmp2 = load i32* %y_addr ; <i32> [#uses=1]
|
||||||
|
%tmp3 = add i32 %tmp1, %tmp2 ; <i32> [#uses=1]
|
||||||
|
store i32 %tmp3, i32* %tmp
|
||||||
|
%tmp4 = load i32* %tmp ; <i32> [#uses=1]
|
||||||
|
store i32 %tmp4, i32* %retval
|
||||||
|
br label %return
|
||||||
|
|
||||||
|
return: ; preds = %entry
|
||||||
|
%retval5 = load i32* %retval ; <i32> [#uses=1]
|
||||||
|
ret i32 %retval5
|
||||||
|
}
|
||||||
|
|
||||||
|
define i32 @foo(i32 %a, i32 %b) {
|
||||||
|
entry:
|
||||||
|
%a_addr = alloca i32 ; <i32*> [#uses=2]
|
||||||
|
%b_addr = alloca i32 ; <i32*> [#uses=2]
|
||||||
|
%retval = alloca i32, align 4 ; <i32*> [#uses=2]
|
||||||
|
%tmp = alloca i32, align 4 ; <i32*> [#uses=2]
|
||||||
|
%"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
|
||||||
|
store i32 %a, i32* %a_addr
|
||||||
|
store i32 %b, i32* %b_addr
|
||||||
|
%tmp1 = load i32* %b_addr ; <i32> [#uses=1]
|
||||||
|
%tmp2 = load i32* %a_addr ; <i32> [#uses=1]
|
||||||
|
%tmp3 = call i32 @bar( i32 %tmp1, i32 %tmp2 ) ; <i32> [#uses=1]
|
||||||
|
store i32 %tmp3, i32* %tmp
|
||||||
|
%tmp4 = load i32* %tmp ; <i32> [#uses=1]
|
||||||
|
store i32 %tmp4, i32* %retval
|
||||||
|
br label %return
|
||||||
|
|
||||||
|
return: ; preds = %entry
|
||||||
|
%retval5 = load i32* %retval ; <i32> [#uses=1]
|
||||||
|
ret i32 %retval5
|
||||||
|
}
|
Reference in New Issue
Block a user