https://github.com/lenary updated https://github.com/llvm/llvm-project/pull/163665
>From c6e30bc58d821ee2142f7f956d7ba9ee03c82fce Mon Sep 17 00:00:00 2001 From: Sam Elliott <[email protected]> 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 28edd439b6900..00a4a00c5bf95 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -2766,7 +2766,7 @@ For example: to signify an unbounded maximum. The syntax `vscale_range(<val>)` 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. ``nocreateundeforpoison`` diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h index 811116a3e1756..bcf596a0d79b2 100644 --- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h +++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h @@ -808,6 +808,7 @@ enum AttributeKindCodes { ATTR_KIND_SANITIZE_ALLOC_TOKEN = 104, ATTR_KIND_NO_CREATE_UNDEF_OR_POISON = 105, ATTR_KIND_DENORMAL_FPENV = 106, + ATTR_KIND_NOOUTLINE = 107, }; enum ComdatSelectionKindCodes { diff --git a/llvm/include/llvm/IR/Attributes.td b/llvm/include/llvm/IR/Attributes.td index 7c5457459f243..941251003f5ba 100644 --- a/llvm/include/llvm/IR/Attributes.td +++ b/llvm/include/llvm/IR/Attributes.td @@ -212,6 +212,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 749df3f2fc612..32b936aa45eae 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2271,6 +2271,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) { return Attribute::NoCreateUndefOrPoison; case bitc::ATTR_KIND_DENORMAL_FPENV: return Attribute::DenormalFPEnv; + 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 2566b2a292300..6b332554bddd4 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_NO_CREATE_UNDEF_OR_POISON; case Attribute::DenormalFPEnv: return bitc::ATTR_KIND_DENORMAL_FPENV; + 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 245f97a17ea8d..7ef37a2ac7b20 100644 --- a/llvm/lib/CodeGen/MachineOutliner.cpp +++ b/llvm/lib/CodeGen/MachineOutliner.cpp @@ -1255,7 +1255,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 0efeeb999d3dd..785740c693030 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -6345,6 +6345,12 @@ void llvm::UpgradeFunctionAttributes(Function &F) { RemovingAttrs = true; } + 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 6e1ca9c4cd2d6..da135e2850712 100644 --- a/llvm/lib/Transforms/IPO/IROutliner.cpp +++ b/llvm/lib/Transforms/IPO/IROutliner.cpp @@ -2418,7 +2418,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 fe8758b942938..7361767301a69 100644 --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -933,6 +933,10 @@ Function *CodeExtractor::constructFunctionDeclaration( case Attribute::CoroElideSafe: case Attribute::NoDivergenceSource: case Attribute::NoCreateUndefOrPoison: + // 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 8e00878685dcd0b8d32d90fd1c1e633760be3e10 Mon Sep 17 00:00:00 2001 From: Sam Elliott <[email protected]> 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 30e74acf973ed..91726e7954052 100644 --- a/llvm/docs/ReleaseNotes.md +++ b/llvm/docs/ReleaseNotes.md @@ -66,6 +66,9 @@ Changes to the LLVM IR * "denormal-fp-math" and "denormal-fp-math-f32" string attributes were migrated to first-class denormal_fpenv attribute. +* The `"nooutline"` attribute is now writen as `nooutline`. Existing IR and + bitcode will be automatically updated. + Changes to LLVM infrastructure ------------------------------ _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
