[PATCH] [PATCH] Teach the Inliner about attribute optnone
Andrea Di Biagio
Andrea_DiBiagio at sn.scee.net
Tue Sep 10 11:46:11 PDT 2013
I uploaded new version of the patch.
As suggested by Eric, I changed the description of attribute optnone in docs/LangRef.rst explaining why `optnone' functions are not inlined.
Please let me know what do you think.
Thanks
Andrea
http://llvm-reviews.chandlerc.com/D1642
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1642?vs=4172&id=4175#toc
Files:
docs/LangRef.rst
lib/Analysis/IPA/InlineCost.cpp
test/Transforms/Inline/inline-optnone.ll
Index: docs/LangRef.rst
===================================================================
--- docs/LangRef.rst
+++ docs/LangRef.rst
@@ -887,7 +887,9 @@
attribute; this attribute is also incompatible
with the ``minsize`` attribute and the ``optsize`` attribute.
- The inliner should never inline this function in any situation.
+ The inliner should never inline this function in any situation; this
+ is to guarantee that the code coming from an optnone function is
+ never optimized.
Only functions with the ``alwaysinline`` attribute are valid
candidates for inlining inside the body of this function.
``optsize``
Index: lib/Analysis/IPA/InlineCost.cpp
===================================================================
--- lib/Analysis/IPA/InlineCost.cpp
+++ lib/Analysis/IPA/InlineCost.cpp
@@ -1201,6 +1201,16 @@
return llvm::InlineCost::getNever();
}
+ // Never inline functions without always-inline attributes if the
+ // caller has optnone attribute.
+ if (CS.getCaller()->hasFnAttribute(Attribute::OptimizeNone))
+ return llvm::InlineCost::getNever();
+
+ // Don't inline this call if the caller has the optnone attribute
+ // (and the callee doesn't have always_inline, checked previously).
+ if (Callee->hasFnAttribute(Attribute::OptimizeNone))
+ return llvm::InlineCost::getNever();
+
// Never inline functions with conflicting attributes (unless callee has
// always-inline attribute).
if (!functionsHaveCompatibleAttributes(CS.getCaller(), Callee))
Index: test/Transforms/Inline/inline-optnone.ll
===================================================================
--- test/Transforms/Inline/inline-optnone.ll
+++ test/Transforms/Inline/inline-optnone.ll
@@ -0,0 +1,52 @@
+; RUN: opt < %s -inline -S | FileCheck %s
+
+; Test that functions with attribute optnone are not inlined.
+; Also test that only functions with attribute alwaysinline
+; are valid candidate for inlining if the caller has optnone attribute.
+
+; Function Attrs: alwaysinline nounwind readnone uwtable
+define i32 @alwaysInlineFunction(i32 %a) #0 {
+entry:
+ %mul = mul i32 %a, %a
+ ret i32 %mul
+}
+
+; Function Attrs: nounwind readnone uwtable
+define i32 @simpleFunction(i32 %a) #1 {
+entry:
+ %add = add i32 %a, %a
+ ret i32 %add
+}
+
+; Function Attrs: nounwind optnone readnone uwtable
+define i32 @OptnoneFunction(i32 %a) #2 {
+entry:
+ %0 = tail call i32 @alwaysInlineFunction(i32 %a)
+ %1 = tail call i32 @simpleFunction(i32 %a)
+ %add = add i32 %0, %1
+ ret i32 %add
+}
+
+; CHECK-LABEL: @OptnoneFunction
+; CHECK-NOT: call i32 @alwaysInlineFunction(i32 %a)
+; CHECK: call i32 @simpleFunction(i32 %a)
+; CHECK: ret
+
+; Function Attrs: nounwind readnone uwtable
+define i32 @bar(i32 %a) #1 {
+entry:
+ %0 = tail call i32 @OptnoneFunction(i32 5)
+ %1 = tail call i32 @simpleFunction(i32 6)
+ %add = add i32 %0, %1
+ ret i32 %add
+}
+
+; CHECK-LABEL: @bar
+; CHECK: call i32 @OptnoneFunction(i32 5)
+; CHECK-NOT: call i32 @simpleFunction(i32 6)
+; CHECK: ret
+
+
+attributes #0 = { alwaysinline nounwind readnone uwtable }
+attributes #1 = { nounwind readnone uwtable }
+attributes #2 = { nounwind optnone readnone uwtable }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1642.2.patch
Type: text/x-patch
Size: 3203 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130910/490f1408/attachment.bin>
More information about the llvm-commits
mailing list