summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwhitequark <whitequark@whitequark.org>2017-06-21 18:46:50 +0000
committerwhitequark <whitequark@whitequark.org>2017-06-21 18:46:50 +0000
commited54b4a7985000624229f2375233eb3c6a9b23fc (patch)
treeca66ba5e0f61c8b2d913d4e974bba1b53a363313
parent47f856095a0180c01a07e5c72769a4163efd9d98 (diff)
downloadbcm5719-llvm-ed54b4a7985000624229f2375233eb3c6a9b23fc.tar.gz
bcm5719-llvm-ed54b4a7985000624229f2375233eb3c6a9b23fc.zip
Add a "probe-stack" attribute
This attribute is used to ensure the guard page is triggered on stack overflow. Stack frames larger than the guard page size will generate a call to __probestack to touch each page so the guard page won't be skipped. Reviewed By: majnemer Differential Revision: https://reviews.llvm.org/D34386 llvm-svn: 305939
-rw-r--r--llvm/docs/LangRef.rst13
-rw-r--r--llvm/include/llvm/IR/Attributes.td1
-rw-r--r--llvm/lib/IR/Attributes.cpp7
-rw-r--r--llvm/test/Transforms/Inline/inline-probe-stack.ll20
4 files changed, 41 insertions, 0 deletions
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index a3d1d9fb12e..ef8178efa3b 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -1468,6 +1468,19 @@ example:
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,
diff --git a/llvm/include/llvm/IR/Attributes.td b/llvm/include/llvm/IR/Attributes.td
index 75867a6e583..4ca595d9773 100644
--- a/llvm/include/llvm/IR/Attributes.td
+++ b/llvm/include/llvm/IR/Attributes.td
@@ -214,3 +214,4 @@ def : MergeRule<"setAND<UnsafeFPMathAttr>">;
def : MergeRule<"setOR<NoImplicitFloatAttr>">;
def : MergeRule<"setOR<NoJumpTablesAttr>">;
def : MergeRule<"adjustCallerSSPLevel">;
+def : MergeRule<"adjustCallerStackProbes">;
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index a518f7b5c81..ba2ec93ac24 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -1638,6 +1638,13 @@ static void adjustCallerSSPLevel(Function &Caller, const Function &Callee) {
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"
diff --git a/llvm/test/Transforms/Inline/inline-probe-stack.ll b/llvm/test/Transforms/Inline/inline-probe-stack.ll
new file mode 100644
index 00000000000..bddee16d30b
--- /dev/null
+++ b/llvm/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" }
OpenPOWER on IntegriCloud