[PATCH] D34386: [PATCH 1/2] Add a "probe-stack" attribute (revised)

whitequark via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 21 11:47:51 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL305939: Add a "probe-stack" attribute (authored by whitequark).

Changed prior to commit:
  https://reviews.llvm.org/D34386?vs=103299&id=103433#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34386

Files:
  llvm/trunk/docs/LangRef.rst
  llvm/trunk/include/llvm/IR/Attributes.td
  llvm/trunk/lib/IR/Attributes.cpp
  llvm/trunk/test/Transforms/Inline/inline-probe-stack.ll


Index: llvm/trunk/docs/LangRef.rst
===================================================================
--- llvm/trunk/docs/LangRef.rst
+++ llvm/trunk/docs/LangRef.rst
@@ -1468,6 +1468,19 @@
     This attribute by itself does not imply restrictions on
     inter-procedural optimizations.  All of the semantic effects the
     patching may have to be separately conveyed via the linkage type.
+``"probe-stack"``
+    This attribute indicates that the function will trigger a guard region
+    in the end of the stack. It ensures that accesses to the stack must be
+    no further apart than the size of the guard region to a previous
+    access of the stack. It takes one required string value, the name of
+    the stack probing function that will be called.
+
+    If a function that has a ``"probe-stack"`` attribute is inlined into
+    a function with another ``"probe-stack"`` attribute, the resulting
+    function has the ``"probe-stack"`` attribute of the caller. If a
+    function that has a ``"probe-stack"`` attribute is inlined into a
+    function that has no ``"probe-stack"`` attribute at all, the resulting
+    function has the ``"probe-stack"`` attribute of the callee.
 ``readnone``
     On a function, this attribute indicates that the function computes its
     result (or decides to unwind an exception) based strictly on its arguments,
Index: llvm/trunk/include/llvm/IR/Attributes.td
===================================================================
--- llvm/trunk/include/llvm/IR/Attributes.td
+++ llvm/trunk/include/llvm/IR/Attributes.td
@@ -214,3 +214,4 @@
 def : MergeRule<"setOR<NoImplicitFloatAttr>">;
 def : MergeRule<"setOR<NoJumpTablesAttr>">;
 def : MergeRule<"adjustCallerSSPLevel">;
+def : MergeRule<"adjustCallerStackProbes">;
Index: llvm/trunk/test/Transforms/Inline/inline-probe-stack.ll
===================================================================
--- llvm/trunk/test/Transforms/Inline/inline-probe-stack.ll
+++ llvm/trunk/test/Transforms/Inline/inline-probe-stack.ll
@@ -0,0 +1,20 @@
+; RUN: opt %s -inline -S | FileCheck %s
+
+define internal void @inner() "probe-stack"="__probestackinner" {
+  ret void
+}
+
+define void @outerNoAttribute() {
+  call void @inner()
+  ret void
+}
+
+define void @outerConflictingAttribute() "probe-stack"="__probestackouter" {
+  call void @inner()
+  ret void
+}
+
+; CHECK: define void @outerNoAttribute() #0
+; CHECK: define void @outerConflictingAttribute() #1
+; CHECK: attributes #0 = { "probe-stack"="__probestackinner" }
+; CHECK: attributes #1 = { "probe-stack"="__probestackouter" }
Index: llvm/trunk/lib/IR/Attributes.cpp
===================================================================
--- llvm/trunk/lib/IR/Attributes.cpp
+++ llvm/trunk/lib/IR/Attributes.cpp
@@ -1638,6 +1638,13 @@
     Caller.addFnAttr(Attribute::StackProtect);
 }
 
+/// \brief If the inlined function required stack probes, then ensure that
+/// the calling function has those too.
+static void adjustCallerStackProbes(Function &Caller, const Function &Callee) {
+  if (!Caller.hasFnAttribute("probe-stack") && Callee.hasFnAttribute("probe-stack"))
+    Caller.addFnAttr("probe-stack", Callee.getFnAttribute("probe-stack").getValueAsString());
+}
+
 #define GET_ATTR_COMPAT_FUNC
 #include "AttributesCompatFunc.inc"
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34386.103433.patch
Type: text/x-patch
Size: 3291 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170621/8cbc103c/attachment.bin>


More information about the llvm-commits mailing list