[llvm] 42ac4e1 - [MachineLICM] Add shouldHoist method to TargetInstrInfo

Carl Ritson via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 7 22:53:30 PST 2022


Author: Carl Ritson
Date: 2022-02-08T15:53:05+09:00
New Revision: 42ac4e1a120c0d0784365c2c7f39c87854b507c4

URL: https://github.com/llvm/llvm-project/commit/42ac4e1a120c0d0784365c2c7f39c87854b507c4
DIFF: https://github.com/llvm/llvm-project/commit/42ac4e1a120c0d0784365c2c7f39c87854b507c4.diff

LOG: [MachineLICM] Add shouldHoist method to TargetInstrInfo

Add a shouldHoist method to TargetInstrInfo which is queried by
MachineLICM to override hoisting decisions for a given target.
This mirrors functionality provided by shouldSink.

Reviewed By: foad

Differential Revision: https://reviews.llvm.org/D118773

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/TargetInstrInfo.h
    llvm/lib/CodeGen/MachineLICM.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/TargetInstrInfo.h b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
index 411811d08c18..dd9936971f6c 100644
--- a/llvm/include/llvm/CodeGen/TargetInstrInfo.h
+++ b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
@@ -382,6 +382,17 @@ class TargetInstrInfo : public MCInstrInfo {
   /// to which instructions should be sunk.
   virtual bool shouldSink(const MachineInstr &MI) const { return true; }
 
+  /// Return false if the instruction should not be hoisted by MachineLICM.
+  ///
+  /// MachineLICM determines on its own whether the instruction is safe to
+  /// hoist; this gives the target a hook to extend this assessment and prevent
+  /// an instruction being hoisted from a given loop for target specific
+  /// reasons.
+  virtual bool shouldHoist(const MachineInstr &MI,
+                           const MachineLoop *FromLoop) const {
+    return true;
+  }
+
   /// Re-issue the specified 'original' instruction at the
   /// specific location targeting a new destination register.
   /// The register in Orig->getOperand(0).getReg() will be substituted by

diff  --git a/llvm/lib/CodeGen/MachineLICM.cpp b/llvm/lib/CodeGen/MachineLICM.cpp
index 500cf8e0b79b..145cd4c84c20 100644
--- a/llvm/lib/CodeGen/MachineLICM.cpp
+++ b/llvm/lib/CodeGen/MachineLICM.cpp
@@ -999,6 +999,9 @@ bool MachineLICMBase::IsLICMCandidate(MachineInstr &I) {
   if (I.isConvergent())
     return false;
 
+  if (!TII->shouldHoist(I, CurLoop))
+    return false;
+
   return true;
 }
 


        


More information about the llvm-commits mailing list