From: Gerolf Hoflehner Date: Thu, 17 Apr 2014 00:21:52 +0000 (+0000) Subject: Inline a function when the always_inline attribute X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=d6312bbbbd7739c8bfd8cc1ddad7662b1c6ee158;hp=0fa7dc4762d6fe0ab811f86e5d2c87231f2abcfe Inline a function when the always_inline attribute is set even when it contains a indirect branch. The attribute overrules correctness concerns like the escape of a local block address. This is for rdar://16501761 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206429 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/IPA/InlineCost.cpp b/lib/Analysis/IPA/InlineCost.cpp index a803f8c3bf9..683637f5b7f 100644 --- a/lib/Analysis/IPA/InlineCost.cpp +++ b/lib/Analysis/IPA/InlineCost.cpp @@ -1300,8 +1300,14 @@ bool InlineCostAnalysis::isInlineViable(Function &F) { F.getAttributes().hasAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice); for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI) { - // Disallow inlining of functions which contain an indirect branch. - if (isa(BI->getTerminator())) + // Disallow inlining of functions which contain an indirect branch, + // unless the always_inline attribute is set. + // The attribute serves as a assertion that no local address + // like a block label can escpape the function. + // Revisit enabling inlining for functions with indirect branches + // when a more sophisticated espape/points-to analysis becomes available. + if (isa(BI->getTerminator()) && + !F.hasFnAttribute(Attribute::AlwaysInline)) return false; for (BasicBlock::iterator II = BI->begin(), IE = BI->end(); II != IE; diff --git a/test/Transforms/Inline/always-inline-attribute.ll b/test/Transforms/Inline/always-inline-attribute.ll new file mode 100644 index 00000000000..c146122e163 --- /dev/null +++ b/test/Transforms/Inline/always-inline-attribute.ll @@ -0,0 +1,26 @@ +; RUN: opt < %s -O3 -S | FileCheck %s +@gv = external global i32 + +define i32 @main() nounwind { +; CHECK-NOT: call i32 @foo + %1 = load i32* @gv, align 4 + %2 = tail call i32 @foo(i32 %1) + unreachable +} + +define internal i32 @foo(i32) alwaysinline { + br label %2 + +;