Skip to content

[BOLT] Make DataflowAnalysis::getStateBefore() const (NFC) #133308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2025

Conversation

atrosinenko
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Mar 27, 2025

@llvm/pr-subscribers-bolt

Author: Anatoly Trosinenko (atrosinenko)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/133308.diff

2 Files Affected:

  • (modified) bolt/include/bolt/Passes/DataflowAnalysis.h (+7-4)
  • (modified) bolt/lib/Passes/PAuthGadgetScanner.cpp (+1-1)
diff --git a/bolt/include/bolt/Passes/DataflowAnalysis.h b/bolt/include/bolt/Passes/DataflowAnalysis.h
index 2afaa6d3043a6..f6ca39cf6f860 100644
--- a/bolt/include/bolt/Passes/DataflowAnalysis.h
+++ b/bolt/include/bolt/Passes/DataflowAnalysis.h
@@ -292,14 +292,17 @@ class DataflowAnalysis {
   /// Relies on a ptr map to fetch the previous instruction and then retrieve
   /// state. WARNING: Watch out for invalidated pointers. Do not use this
   /// function if you invalidated pointers after the analysis has been completed
-  ErrorOr<const StateTy &> getStateBefore(const MCInst &Point) {
-    return getStateAt(PrevPoint[&Point]);
+  ErrorOr<const StateTy &> getStateBefore(const MCInst &Point) const {
+    auto It = PrevPoint.find(&Point);
+    if (It == PrevPoint.end())
+      return make_error_code(std::errc::result_out_of_range);
+    return getStateAt(It->getSecond());
   }
 
-  ErrorOr<const StateTy &> getStateBefore(ProgramPoint Point) {
+  ErrorOr<const StateTy &> getStateBefore(ProgramPoint Point) const {
     if (Point.isBB())
       return getStateAt(*Point.getBB());
-    return getStateAt(PrevPoint[Point.getInst()]);
+    return getStateBefore(*Point.getInst());
   }
 
   /// Remove any state annotations left by this analysis
diff --git a/bolt/lib/Passes/PAuthGadgetScanner.cpp b/bolt/lib/Passes/PAuthGadgetScanner.cpp
index 16da08551a34d..86897937c95fe 100644
--- a/bolt/lib/Passes/PAuthGadgetScanner.cpp
+++ b/bolt/lib/Passes/PAuthGadgetScanner.cpp
@@ -448,7 +448,7 @@ class PacRetAnalysis
 public:
   std::vector<MCInstReference>
   getLastClobberingInsts(const MCInst &Inst, BinaryFunction &BF,
-                         const ArrayRef<MCPhysReg> UsedDirtyRegs) {
+                         const ArrayRef<MCPhysReg> UsedDirtyRegs) const {
     if (RegsToTrackInstsFor.empty())
       return {};
     auto MaybeState = getStateBefore(Inst);

Copy link
Contributor

@maksfb maksfb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@atrosinenko atrosinenko force-pushed the users/atrosinenko/bolt-gs-address-materialization branch from e611f6c to eebc0ca Compare March 31, 2025 17:47
@atrosinenko atrosinenko force-pushed the users/atrosinenko/bolt-make-getstatebefore-const branch 2 times, most recently from 12d4a20 to 33c6052 Compare April 1, 2025 14:01
@atrosinenko atrosinenko force-pushed the users/atrosinenko/bolt-gs-address-materialization branch from eebc0ca to a5d8504 Compare April 1, 2025 14:01
@atrosinenko atrosinenko force-pushed the users/atrosinenko/bolt-make-getstatebefore-const branch 2 times, most recently from 498e9a6 to 4f662e3 Compare April 2, 2025 20:02
@atrosinenko atrosinenko force-pushed the users/atrosinenko/bolt-gs-address-materialization branch from 9ddb906 to 2bf9f89 Compare April 3, 2025 13:43
@atrosinenko atrosinenko force-pushed the users/atrosinenko/bolt-make-getstatebefore-const branch 3 times, most recently from 46d771d to 05852d6 Compare April 4, 2025 16:27
Base automatically changed from users/atrosinenko/bolt-gs-address-materialization to main April 7, 2025 10:13
@atrosinenko atrosinenko force-pushed the users/atrosinenko/bolt-make-getstatebefore-const branch from 05852d6 to 79b70c1 Compare April 7, 2025 10:15
@atrosinenko atrosinenko merged commit 2c10723 into main Apr 7, 2025
10 checks passed
@atrosinenko atrosinenko deleted the users/atrosinenko/bolt-make-getstatebefore-const branch April 7, 2025 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants