From f40944fcc506601b511018f3208af1c34a6db6e2 Mon Sep 17 00:00:00 2001 From: Edd Barrett Date: Mon, 21 Mar 2022 10:26:12 +0000 Subject: [PATCH] Add the `yk_outline` function attribute. This annotations does two things: - It tells the Yk JIT to outline (not inline) calls to the function, when preparing a trace. - It adds the `noinline` attribute to the function, thus preventing LLVM from re-inlining calls to the function when compiling traces. --- clang/include/clang/Basic/Attr.td | 7 +++++++ clang/include/clang/Basic/AttrDocs.td | 8 ++++++++ clang/lib/CodeGen/CodeGenModule.cpp | 7 +++++++ .../Misc/pragma-attribute-supported-attributes-list.test | 1 + 4 files changed, 23 insertions(+) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 12d09181a2ea87..a9d51d7d59e52c 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3823,3 +3823,10 @@ def EnforceTCBLeaf : InheritableAttr { let Documentation = [EnforceTCBLeafDocs]; bit InheritEvenIfAlreadyPresent = 1; } + +def YkOutline : InheritableAttr { + let Spellings = [GCC<"yk_outline">, Declspec<"yk_outline">]; + let Subjects = SubjectList<[Function]>; + let Documentation = [YkOutlineDocs]; + let SimpleHandler = 1; +} diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index c265a877e3b1ac..ad3846fd2c14b4 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -6045,3 +6045,11 @@ def EnforceTCBLeafDocs : Documentation { - ``enforce_tcb_leaf(Name)`` indicates that this function is a part of the TCB named ``Name`` }]; } + +def YkOutlineDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ + The ``yk_outline`` attribute tells the Yk JIT to outline (not inline) calls + to the annotated function. + }]; +} diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 49a1396b58e3a2..9347184bc20320 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1868,6 +1868,13 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, B.addAttribute(llvm::Attribute::MinSize); } + if (D->hasAttr()) { + // Prevent the Yk trace compiler from inlining the call. + B.addAttribute("yk_outline"); + // Prevent LLVM from inlining the call when optimising the trace. + B.addAttribute(llvm::Attribute::NoInline); + } + F->addAttributes(llvm::AttributeList::FunctionIndex, B); unsigned alignment = D->getMaxAlignment() / Context.getCharWidth(); diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test b/clang/test/Misc/pragma-attribute-supported-attributes-list.test index 290306bfb6a239..7a7a4fcb18907d 100644 --- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test +++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test @@ -185,4 +185,5 @@ // CHECK-NEXT: WorkGroupSizeHint (SubjectMatchRule_function) // CHECK-NEXT: XRayInstrument (SubjectMatchRule_function, SubjectMatchRule_objc_method) // CHECK-NEXT: XRayLogArgs (SubjectMatchRule_function, SubjectMatchRule_objc_method) +// CHECK-NEXT: YkOutline (SubjectMatchRule_function) // CHECK-NEXT: End of supported attributes.