[PATCH] D157615: [ExtendLifetimes][1/4] Add "disable-post-ra" function attribute to disable the post-regalloc scheduler

Stephen Tozer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 10 06:49:59 PDT 2023


StephenTozer created this revision.
StephenTozer added reviewers: dblaikie, aprantl, echristo.
StephenTozer added a project: debug-info.
Herald added subscribers: pengfei, javed.absar, hiraditya.
Herald added a project: All.
StephenTozer requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch is part of a set of patches that add an `-fextend-lifetimes` flag to clang, which extends the lifetimes of local variables and parameters for improved debuggability. In addition to that flag, the patch series adds a new function attribute to disable the post-RA scheduler (which is applied by `-fextend-lifetimes`), a pragma to selectively disable `-fextend-lifetimes`, and an `-fextend-this-ptr` flag which functions as `-fextend-lifetimes` for `this` pointers only. All changes and tests in these patches were written by @wolfgangp, though I will be managing these reviews and addressing any comments raised. Discussion on the approach of this patch series as a whole should be directed to the 3rd patch, D157613 <https://reviews.llvm.org/D157613>, in order to simplify review.

---

This particular patch implements the disable-post-ra function attribute, which trivially stops the post-register-allocation scheduler from running. This is useful when using the `-fextend-lifetimes` flag, as post-RA scheduling is not directly affected by that flag. The reason for creating an attribute instead of simply disabling the post-RA scheduler with a flag is that -fextend-lifetimes may be enabled or disabled for individual functions, and we only want to skip scheduling for the functions which desire extended lifetimes.

Although this patch is technically unrelated to debug info, I am bringing in debug info reviewers because of how this patch connects to the following patches in the sequence.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157615

Files:
  llvm/lib/CodeGen/PostRASchedulerList.cpp
  llvm/test/CodeGen/X86/suppress-post-ra.ll


Index: llvm/test/CodeGen/X86/suppress-post-ra.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/suppress-post-ra.ll
@@ -0,0 +1,51 @@
+; Check if the function attribute "disable-post-ra" suppresses the post-RA scheduler.
+; Note that we ignore the first line of the print-before and print-after output,
+; which should be the only difference.
+;
+; RUN: llc < %s -O2 -print-before=post-RA-sched 2>&1 > /dev/null - | tail -n +2 > %t1
+; RUN: llc < %s -O2 -print-after=post-RA-sched 2>&1 > /dev/null - | tail -n +2 > %t2
+; RUN: diff %t1 %t2
+;
+;
+; ModuleID = 't.cpp'
+
+ at data = global i32 17, align 4
+ at sum = global i32 0, align 4
+ at zero = global i32 0, align 4
+ at ptr = global i32* null, align 8
+
+define i32 @main() #0 {
+entry:
+  %val = alloca i32, align 4
+  %0 = bitcast i32* %val to i8*
+  call void @llvm.lifetime.start(i64 4, i8* %0) #3
+  %1 = load i32, i32* @data, align 4, !tbaa !2
+  store i32 %1, i32* %val, align 4, !tbaa !2
+  call void @_Z3fooiPi(i32 1, i32* nonnull %val) #3
+  call void @_Z3fooiPi(i32 2, i32* nonnull @data) #3
+  %2 = load i32, i32* @zero, align 4, !tbaa !2
+  call void @llvm.lifetime.end(i64 4, i8* %0) #3
+  %3 = load i32, i32* %val, align 4, !tbaa !2
+  call void (...) @llvm.fake.use(i32 %3)
+  ret i32 %2
+}
+
+declare void @llvm.lifetime.start(i64, i8* nocapture) #1
+
+declare void @_Z3fooiPi(i32, i32*)
+
+declare void @llvm.lifetime.end(i64, i8* nocapture)
+
+declare void @llvm.fake.use(...)
+
+attributes #0 = { "disable-post-ra" }
+
+!llvm.module.flags = !{!0}
+!llvm.ident = !{!1}
+
+!0 = !{i32 1, !"PIC Level", i32 2}
+!1 = !{!"clang version 3.8.1"}
+!2 = !{!3, !3, i64 0}
+!3 = !{!"int", !4, i64 0}
+!4 = !{!"omnipotent char", !5, i64 0}
+!5 = !{!"Simple C/C++ TBAA"}
Index: llvm/lib/CodeGen/PostRASchedulerList.cpp
===================================================================
--- llvm/lib/CodeGen/PostRASchedulerList.cpp
+++ llvm/lib/CodeGen/PostRASchedulerList.cpp
@@ -279,6 +279,9 @@
   if (skipFunction(Fn.getFunction()))
     return false;
 
+  if (Fn.getFunction().hasFnAttribute("disable-post-ra"))
+    return false;
+
   TII = Fn.getSubtarget().getInstrInfo();
   MachineLoopInfo &MLI = getAnalysis<MachineLoopInfo>();
   AliasAnalysis *AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157615.549017.patch
Type: text/x-patch
Size: 2325 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230810/a260a8c2/attachment.bin>


More information about the llvm-commits mailing list