From ed1193ff7d938d3ff49315e72bdf2d4f91f85670 Mon Sep 17 00:00:00 2001 From: Sam Elliott Date: Wed, 15 Oct 2025 17:24:04 -0700 Subject: [PATCH 1/2] [outliners] Turn nooutline into an Enum Attribute This change turns the `"nooutline"` attribute into an enum attribute called `nooutline`, and adds an auto-upgrader for bitcode to make the same change to existing IR. This IR attribute disables both the Machine Outliner (enabled at Oz for some targets), and the IR Outliner (disabled by default). --- llvm/docs/LangRef.rst | 2 +- llvm/include/llvm/Bitcode/LLVMBitCodes.h | 1 + llvm/include/llvm/IR/Attributes.td | 3 +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 2 ++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 ++ llvm/lib/CodeGen/MachineOutliner.cpp | 2 +- llvm/lib/IR/AutoUpgrade.cpp | 6 ++++++ llvm/lib/Transforms/IPO/IROutliner.cpp | 2 +- llvm/lib/Transforms/Utils/CodeExtractor.cpp | 4 ++++ llvm/test/Bitcode/upgrade-nooutline.ll | 12 ++++++++++++ .../AArch64/machine-outliner-mapper-debug-output.mir | 2 +- .../Transforms/IROutliner/nooutline-attribute.ll | 4 ++-- 12 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 llvm/test/Bitcode/upgrade-nooutline.ll diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index 4884e2dcbbe00..73887d1039488 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -2738,7 +2738,7 @@ For example: to signify an unbounded maximum. The syntax `vscale_range()` can be used to set both `min` and `max` to the same value. Functions that don't include this attribute make no assumptions about the value of `vscale`. -``"nooutline"`` +``nooutline`` This attribute indicates that outlining passes should not modify the function. diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h index 464f475098ec5..95596273aad69 100644 --- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h +++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h @@ -801,6 +801,7 @@ enum AttributeKindCodes { ATTR_KIND_CAPTURES = 102, ATTR_KIND_DEAD_ON_RETURN = 103, ATTR_KIND_SANITIZE_ALLOC_TOKEN = 104, + ATTR_KIND_NOOUTLINE = 105, }; enum ComdatSelectionKindCodes { diff --git a/llvm/include/llvm/IR/Attributes.td b/llvm/include/llvm/IR/Attributes.td index 8e7d9dcebfe2a..46a77ec121039 100644 --- a/llvm/include/llvm/IR/Attributes.td +++ b/llvm/include/llvm/IR/Attributes.td @@ -207,6 +207,9 @@ def NoImplicitFloat : EnumAttr<"noimplicitfloat", IntersectPreserve, [FnAttr]>; /// inline=never. def NoInline : EnumAttr<"noinline", IntersectPreserve, [FnAttr]>; +/// nooutline +def NoOutline : EnumAttr<"nooutline", IntersectPreserve, [FnAttr]>; + /// Function is called early and/or often, so lazy binding isn't worthwhile. def NonLazyBind : EnumAttr<"nonlazybind", IntersectPreserve, [FnAttr]>; diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index aaee1f0a7687c..ab80da376fdf8 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2257,6 +2257,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) { return Attribute::Captures; case bitc::ATTR_KIND_DEAD_ON_RETURN: return Attribute::DeadOnReturn; + case bitc::ATTR_KIND_NOOUTLINE: + return Attribute::NoOutline; } } diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 54e916e2dcfe1..0efe7e030e0dc 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -956,6 +956,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) { return bitc::ATTR_KIND_CAPTURES; case Attribute::DeadOnReturn: return bitc::ATTR_KIND_DEAD_ON_RETURN; + case Attribute::NoOutline: + return bitc::ATTR_KIND_NOOUTLINE; case Attribute::EndAttrKinds: llvm_unreachable("Can not encode end-attribute kinds marker."); case Attribute::None: diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp index 9feb9740de126..d6f7305278f38 100644 --- a/llvm/lib/CodeGen/MachineOutliner.cpp +++ b/llvm/lib/CodeGen/MachineOutliner.cpp @@ -1257,7 +1257,7 @@ void MachineOutliner::populateMapper(InstructionMapper &Mapper, Module &M) { for (Function &F : M) { LLVM_DEBUG(dbgs() << "MAPPING FUNCTION: " << F.getName() << "\n"); - if (F.hasFnAttribute("nooutline")) { + if (F.hasFnAttribute(Attribute::NoOutline)) { LLVM_DEBUG(dbgs() << "SKIP: Function has nooutline attribute\n"); continue; } diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index f28b98957cae4..f3b164e5d0603 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -5956,6 +5956,12 @@ void llvm::UpgradeFunctionAttributes(Function &F) { F.removeFnAttr("implicit-section-name"); } + if (Attribute A = F.getFnAttribute("nooutline"); + A.isValid() && A.isStringAttribute()) { + F.removeFnAttr("nooutline"); + F.addFnAttr(Attribute::NoOutline); + } + if (!F.empty()) { // For some reason this is called twice, and the first time is before any // instructions are loaded into the body. diff --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp index fdf0c3ac8007d..cdcff8fb19236 100644 --- a/llvm/lib/Transforms/IPO/IROutliner.cpp +++ b/llvm/lib/Transforms/IPO/IROutliner.cpp @@ -2419,7 +2419,7 @@ void IROutliner::pruneIncompatibleRegions( if (FnForCurrCand.hasOptNone()) continue; - if (FnForCurrCand.hasFnAttribute("nooutline")) { + if (FnForCurrCand.hasFnAttribute(Attribute::NoOutline)) { LLVM_DEBUG({ dbgs() << "... Skipping function with nooutline attribute: " << FnForCurrCand.getName() << "\n"; diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp index 5ba6f95f5fae8..2a94c62e7f357 100644 --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -933,6 +933,10 @@ Function *CodeExtractor::constructFunctionDeclaration( case Attribute::CoroDestroyOnlyWhenComplete: case Attribute::CoroElideSafe: case Attribute::NoDivergenceSource: + // CodeExtractor is used by the IROutliner, so we should not be extracting + // from a function with nooutline, but if we do, we should not be + // propagating this attribute. + case Attribute::NoOutline: continue; // Those attributes should be safe to propagate to the extracted function. case Attribute::AlwaysInline: diff --git a/llvm/test/Bitcode/upgrade-nooutline.ll b/llvm/test/Bitcode/upgrade-nooutline.ll new file mode 100644 index 0000000000000..fe0d954408c92 --- /dev/null +++ b/llvm/test/Bitcode/upgrade-nooutline.ll @@ -0,0 +1,12 @@ +; RUN: llvm-as < %s | llvm-dis - | FileCheck %s + +; CHECK: define void @f() [[ATTR:#[0-9]+]] +; CHECK-NOT: "nooutline" +; CHECK: attributes [[ATTR]] = { +; CHECK-NOT: "nooutline" +; CHECK-SAME: nooutline +; CHECK-NOT: "nooutline" + +define void @f() "nooutline" { + ret void +} diff --git a/llvm/test/CodeGen/AArch64/machine-outliner-mapper-debug-output.mir b/llvm/test/CodeGen/AArch64/machine-outliner-mapper-debug-output.mir index 826157e68d75c..056c5f18d492c 100644 --- a/llvm/test/CodeGen/AArch64/machine-outliner-mapper-debug-output.mir +++ b/llvm/test/CodeGen/AArch64/machine-outliner-mapper-debug-output.mir @@ -17,7 +17,7 @@ --- | define void @block_too_small() noredzone { unreachable } - define void @no_outline() noredzone "nooutline" { unreachable } + define void @no_outline() noredzone nooutline { unreachable } define void @redzone() { unreachable } declare void @no_mf() define void @block_addr_fn() noredzone { diff --git a/llvm/test/Transforms/IROutliner/nooutline-attribute.ll b/llvm/test/Transforms/IROutliner/nooutline-attribute.ll index eaf3afa3b15a1..a61a1614a3115 100644 --- a/llvm/test/Transforms/IROutliner/nooutline-attribute.ll +++ b/llvm/test/Transforms/IROutliner/nooutline-attribute.ll @@ -8,7 +8,7 @@ define void @outlinable() { ret void } -define i8 @nooutline1(ptr noalias %s, ptr noalias %d, i64 %len) "nooutline" { +define i8 @nooutline1(ptr noalias %s, ptr noalias %d, i64 %len) nooutline { %a = load i8, ptr %s %b = load i8, ptr %d call void @llvm.memcpy.p0.p0.i64(ptr %d, ptr %s, i64 %len, i1 false) @@ -17,7 +17,7 @@ define i8 @nooutline1(ptr noalias %s, ptr noalias %d, i64 %len) "nooutline" { ret i8 %ret } -define i8 @nooutline2(ptr noalias %s, ptr noalias %d, i64 %len) "nooutline" { +define i8 @nooutline2(ptr noalias %s, ptr noalias %d, i64 %len) nooutline { %a = load i8, ptr %s %b = load i8, ptr %d call void @llvm.memcpy.p0.p0.i64(ptr %d, ptr %s, i64 %len, i1 false) From a84c6451839e0e1fb71928526ebaedd2fee005b1 Mon Sep 17 00:00:00 2001 From: Sam Elliott Date: Thu, 16 Oct 2025 13:49:36 -0700 Subject: [PATCH 2/2] Release Note --- llvm/docs/ReleaseNotes.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md index 640516a2e0974..417f90338e6bc 100644 --- a/llvm/docs/ReleaseNotes.md +++ b/llvm/docs/ReleaseNotes.md @@ -63,6 +63,9 @@ Changes to the LLVM IR address component of a pointer type variable but unlike `ptrtoint` does not capture provenance ([#125687](https://github.com/llvm/llvm-project/pull/125687)). +* The `"nooutline"` attribute is now writen as `nooutline`. Existing IR and + bitcode will be automatically updated. + Changes to LLVM infrastructure ------------------------------