[llvm] 7ef8f9c - [IR/MachineOutliner] Add a "nooutline" function attr and respect it
Jessica Paquette via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 22 10:22:42 PST 2022
Author: Jessica Paquette
Date: 2022-12-22T10:22:08-08:00
New Revision: 7ef8f9c972bbcb37eba47d43b100c84c6ff8cb83
URL: https://github.com/llvm/llvm-project/commit/7ef8f9c972bbcb37eba47d43b100c84c6ff8cb83
DIFF: https://github.com/llvm/llvm-project/commit/7ef8f9c972bbcb37eba47d43b100c84c6ff8cb83.diff
LOG: [IR/MachineOutliner] Add a "nooutline" function attr and respect it
Add `nooutline` + update LangRef to say it exists.
This makes it possible to say "don't outline from this function ever."
We want to be able to toggle whether or not a function should be in the search
set regardless of default behaviour.
Add testcases for the IR Outliner + Machine Outliner.
Also remove an unnecessary check for an empty function in the Machine Outliner.
Differential Revision: https://reviews.llvm.org/D140438
Added:
llvm/test/CodeGen/AArch64/machine-outliner-nooutline-attribute.mir
llvm/test/Transforms/IROutliner/nooutline-attribute.ll
Modified:
llvm/docs/LangRef.rst
llvm/lib/CodeGen/MachineOutliner.cpp
llvm/lib/Transforms/IPO/IROutliner.cpp
Removed:
################################################################################
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index d99ee6644a66b..e102e8e773f48 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -2232,6 +2232,9 @@ example:
unbounded. If the optional max value is omitted then max is set to the
value of min. If the attribute is not present, no assumptions are made
about the range of vscale.
+ ``"nooutline"``
+ This attribute indicates that outlining passes should not modify the
+ function.
Call Site Attributes
----------------------
diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp
index 56c3d27d8c0cc..c7ba66bd36782 100644
--- a/llvm/lib/CodeGen/MachineOutliner.cpp
+++ b/llvm/lib/CodeGen/MachineOutliner.cpp
@@ -880,10 +880,13 @@ void MachineOutliner::populateMapper(InstructionMapper &Mapper, Module &M,
// iterating over each Function in M.
for (Function &F : M) {
- // If there's nothing in F, then there's no reason to try and outline from
- // it.
- if (F.empty())
+ if (F.hasFnAttribute("nooutline")) {
+ LLVM_DEBUG({
+ dbgs() << "... Skipping function with nooutline attribute: "
+ << F.getName() << "\n";
+ });
continue;
+ }
// There's something in F. Check if it has a MachineFunction associated with
// it.
diff --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp
index 7a961c0cc039e..35366d155d135 100644
--- a/llvm/lib/Transforms/IPO/IROutliner.cpp
+++ b/llvm/lib/Transforms/IPO/IROutliner.cpp
@@ -2426,6 +2426,7 @@ void IROutliner::pruneIncompatibleRegions(
PreviouslyOutlined = false;
unsigned StartIdx = IRSC.getStartIdx();
unsigned EndIdx = IRSC.getEndIdx();
+ const Function &FnForCurrCand = *IRSC.getFunction();
for (unsigned Idx = StartIdx; Idx <= EndIdx; Idx++)
if (Outlined.contains(Idx)) {
@@ -2445,9 +2446,17 @@ void IROutliner::pruneIncompatibleRegions(
if (BBHasAddressTaken)
continue;
- if (IRSC.getFunction()->hasOptNone())
+ if (FnForCurrCand.hasOptNone())
continue;
+ if (FnForCurrCand.hasFnAttribute("nooutline")) {
+ LLVM_DEBUG({
+ dbgs() << "... Skipping function with nooutline attribute: "
+ << FnForCurrCand.getName() << "\n";
+ });
+ continue;
+ }
+
if (IRSC.front()->Inst->getFunction()->hasLinkOnceODRLinkage() &&
!OutlineFromLinkODRs)
continue;
diff --git a/llvm/test/CodeGen/AArch64/machine-outliner-nooutline-attribute.mir b/llvm/test/CodeGen/AArch64/machine-outliner-nooutline-attribute.mir
new file mode 100644
index 0000000000000..477a16c841330
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/machine-outliner-nooutline-attribute.mir
@@ -0,0 +1,42 @@
+# RUN: llc -mtriple=aarch64 -debug-only=machine-outliner -run-pass=machine-outliner -verify-machineinstrs %s -o - 2>&1 | FileCheck %s
+# REQUIRES: asserts
+
+# CHECK: ... Skipping function with nooutline attribute: no_outline
+# CHECK-NOT: ... Skipping function with nooutline attribute: baz
+# CHECK-NOT: OUTLINED
+
+--- |
+ define void @no_outline() #0 { unreachable }
+ define void @baz() { unreachable }
+ attributes #0 = { noredzone "nooutline" }
+...
+---
+
+name: no_outline
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $w0, $lr, $w8
+ $sp = frame-setup SUBXri $sp, 32, 0
+ $fp = frame-setup ADDXri $sp, 16, 0
+ bb.1:
+ BL @baz, implicit-def dead $lr, implicit $sp
+ $w17 = ORRWri $wzr, 1
+ $w17 = ORRWri $wzr, 1
+ $w0 = ORRWri $wzr, 4
+ BL @baz, implicit-def dead $lr, implicit $sp
+ $w17 = ORRWri $wzr, 1
+ $w17 = ORRWri $wzr, 1
+ $w0 = ORRWri $wzr, 3
+ BL @baz, implicit-def dead $lr, implicit $sp
+ $w17 = ORRWri $wzr, 1
+ $w17 = ORRWri $wzr, 1
+ $w0 = ORRWri $wzr, 2
+ BL @baz, implicit-def dead $lr, implicit $sp
+ $w17 = ORRWri $wzr, 1
+ $w17 = ORRWri $wzr, 1
+ $w0 = ORRWri $wzr, 1
+ bb.2:
+ $fp, $lr = LDPXi $sp, 2
+ RET undef $lr
+
diff --git a/llvm/test/Transforms/IROutliner/nooutline-attribute.ll b/llvm/test/Transforms/IROutliner/nooutline-attribute.ll
new file mode 100644
index 0000000000000..233dfc341d7ad
--- /dev/null
+++ b/llvm/test/Transforms/IROutliner/nooutline-attribute.ll
@@ -0,0 +1,30 @@
+; RUN: opt -S -debug-only=iroutliner -p=iroutliner -ir-outlining-no-cost %s -o - 2>&1 | FileCheck %s
+; REQUIRES: asserts
+
+; CHECK-NOT: ... Skipping function with nooutline attribute: outlinable
+; CHECK-NOT: @outlined_ir_func
+; CHECK: ... Skipping function with nooutline attribute: nooutline1
+; CHECK: ... Skipping function with nooutline attribute: nooutline2
+
+define void @outlinable() { ret void }
+
+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.p0i8.p0i8.i64(ptr %d, ptr %s, i64 %len, i1 false)
+ %c = add i8 %a, %b
+ %ret = load i8, ptr %s
+ ret i8 %ret
+}
+
+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.p0i8.p0i8.i64(ptr %d, ptr %s, i64 %len, i1 false)
+ %c = add i8 %a, %b
+ %ret = load i8, ptr %s
+ ret i8 %ret
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1)
+
More information about the llvm-commits
mailing list