[PATCH] D150740: [clang] Add `__attribute__((nooutline))`
Jessica Paquette via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 16 17:13:13 PDT 2023
paquette created this revision.
paquette added reviewers: fhahn, aemerson, jroelofs, arphaman, ahatanak.
paquette added a project: clang.
Herald added a reviewer: aaron.ballman.
Herald added a subscriber: StephenFan.
Herald added a project: All.
paquette requested review of this revision.
Sometimes users want to toggle which functions should be outlined from. Users could be trying to:
1. Debug the compiler and disable outlining in some contexts
2. Control where outlining actually happens in their program
This adds a frontend attribute that will allow users to toggle this behaviour on specific functions.
https://reviews.llvm.org/D150740
Files:
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/attr-nooutline.c
Index: clang/test/CodeGen/attr-nooutline.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/attr-nooutline.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -S -emit-llvm -o - | FileCheck %s
+
+// CHECK: define i32 @has_attr_2() [[HAS_ATTR_2:#[0-9]+]]
+// CHECK: declare i32 @has_attr_1() [[HAS_ATTR_1:#[0-9]+]]
+
+__attribute__((nooutline)) int has_attr_1(void);
+__attribute__((nooutline)) int has_attr_2(void) { return has_attr_1(); }
+
+// CHECK: attributes [[HAS_ATTR_2]] = { {{.*}}"nooutline"{{.*}} }
+// CHECK: attributes [[HAS_ATTR_1]] = { {{.*}}"nooutline"{{.*}} }
Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2133,6 +2133,8 @@
if (D->hasAttr<MinSizeAttr>())
B.addAttribute(llvm::Attribute::MinSize);
}
+ if (D->hasAttr<NoOutlineAttr>())
+ B.addAttribute("nooutline");
F->addFnAttrs(B);
Index: clang/lib/CodeGen/CGCall.cpp
===================================================================
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2344,6 +2344,8 @@
FuncAttrs.addAttribute(llvm::Attribute::NoCfCheck);
if (TargetDecl->hasAttr<LeafAttr>())
FuncAttrs.addAttribute(llvm::Attribute::NoCallback);
+ if (TargetDecl->hasAttr<NoOutlineAttr>())
+ FuncAttrs.addAttribute("nooutline");
HasOptnone = TargetDecl->hasAttr<OptimizeNoneAttr>();
if (auto *AllocSize = TargetDecl->getAttr<AllocSizeAttr>()) {
Index: clang/include/clang/Basic/AttrDocs.td
===================================================================
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -580,6 +580,26 @@
}];
}
+def NoOutlineDocs : Documentation {
+ let Category = DocCatFunction;
+ let Content = [{
+
+Suppresses outlining from a function. Functions with this attribute will not
+be considered for outlining.
+
+.. code-block:: c
+
+ __attribute__((nooutline))
+ int example(void) {
+ int r;
+ foo();
+ bar();
+ return r;
+ }
+
+ }];
+}
+
def MustTailDocs : Documentation {
let Category = DocCatStmt;
let Content = [{
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1469,6 +1469,13 @@
let SimpleHandler = 1;
}
+def NoOutline : InheritableAttr {
+ let Spellings = [Clang<"nooutline">];
+ let Subjects = SubjectList<[Function, ObjCMethod]>;
+ let Documentation = [NoOutlineDocs];
+ let SimpleHandler = 1;
+}
+
def MustTail : StmtAttr {
let Spellings = [Clang<"musttail">];
let Documentation = [MustTailDocs];
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150740.522851.patch
Type: text/x-patch
Size: 2802 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230517/9dcea7df/attachment.bin>
More information about the cfe-commits
mailing list