[MachineLICM] Add shouldHoist method to TargetInstrInfo
authorCarl Ritson <carl.ritson@amd.com>
Tue, 8 Feb 2022 06:01:07 +0000 (15:01 +0900)
committerCarl Ritson <carl.ritson@amd.com>
Tue, 8 Feb 2022 06:53:05 +0000 (15:53 +0900)
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

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

index 411811d..dd99369 100644 (file)
@@ -382,6 +382,17 @@ public:
   /// 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
index 500cf8e..145cd4c 100644 (file)
@@ -999,6 +999,9 @@ bool MachineLICMBase::IsLICMCandidate(MachineInstr &I) {
   if (I.isConvergent())
     return false;
 
+  if (!TII->shouldHoist(I, CurLoop))
+    return false;
+
   return true;
 }