[llvm] 0057ec8 - [Statepoint] Factor-out utility function to get non-foldable area of STATEPOINT like instructions. NFC

Serguei Katkov via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 5 22:04:36 PDT 2021


Author: Serguei Katkov
Date: 2021-04-06T11:44:37+07:00
New Revision: 0057ec8034d8d99ffbcf088b208484d36a0e24e2

URL: https://github.com/llvm/llvm-project/commit/0057ec8034d8d99ffbcf088b208484d36a0e24e2
DIFF: https://github.com/llvm/llvm-project/commit/0057ec8034d8d99ffbcf088b208484d36a0e24e2.diff

LOG: [Statepoint] Factor-out utility function to get non-foldable area of STATEPOINT like instructions. NFC

Reviewers: reames, dantrushin
Reviewed By: reames
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D99875

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/TargetInstrInfo.h b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
index e603e69a50ba2..bc4fb7d5234ab 100644
--- a/llvm/include/llvm/CodeGen/TargetInstrInfo.h
+++ b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
@@ -1064,6 +1064,16 @@ class TargetInstrInfo : public MCInstrInfo {
   /// has the potential of causing nasty silent breakage in out-of-tree targets.
   virtual bool isSubregFoldable() const { return false; }
 
+  /// For a patchpoint, stackmap, or statepoint intrinsic, return the range of
+  /// operands which can't be folded into stack references. Operands outside
+  /// of the range are most likely foldable but it is not guaranteed.
+  /// These instructions are unique in that stack references for some operands
+  /// have the same execution cost (e.g. none) as the unfolded register forms.
+  /// The ranged return is guaranteed to include all operands which can't be
+  /// folded at zero cost.
+  virtual std::pair<unsigned, unsigned>
+  getPatchpointUnfoldableRange(const MachineInstr &MI) const;
+
   /// Attempt to fold a load or store of the specified stack
   /// slot into the specified machine instruction for the specified operand(s).
   /// If this is possible, a new instruction is returned with the specified

diff  --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp
index 320a013a864d2..2e4a656ea0c80 100644
--- a/llvm/lib/CodeGen/TargetInstrInfo.cpp
+++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp
@@ -474,32 +474,31 @@ static const TargetRegisterClass *canFoldCopy(const MachineInstr &MI,
 
 MCInst TargetInstrInfo::getNop() const { llvm_unreachable("Not implemented"); }
 
-static MachineInstr *foldPatchpoint(MachineFunction &MF, MachineInstr &MI,
-                                    ArrayRef<unsigned> Ops, int FrameIndex,
-                                    const TargetInstrInfo &TII) {
-  unsigned StartIdx = 0;
-  unsigned NumDefs = 0;
+std::pair<unsigned, unsigned>
+TargetInstrInfo::getPatchpointUnfoldableRange(const MachineInstr &MI) const {
   switch (MI.getOpcode()) {
-  case TargetOpcode::STACKMAP: {
+  case TargetOpcode::STACKMAP:
     // StackMapLiveValues are foldable
-    StartIdx = StackMapOpers(&MI).getVarIdx();
-    break;
-  }
-  case TargetOpcode::PATCHPOINT: {
+    return std::make_pair(0, StackMapOpers(&MI).getVarIdx());
+  case TargetOpcode::PATCHPOINT:
     // For PatchPoint, the call args are not foldable (even if reported in the
     // stackmap e.g. via anyregcc).
-    StartIdx = PatchPointOpers(&MI).getVarIdx();
-    break;
-  }
-  case TargetOpcode::STATEPOINT: {
+    return std::make_pair(0, PatchPointOpers(&MI).getVarIdx());
+  case TargetOpcode::STATEPOINT:
     // For statepoints, fold deopt and gc arguments, but not call arguments.
-    StartIdx = StatepointOpers(&MI).getVarIdx();
-    NumDefs = MI.getNumDefs();
-    break;
-  }
+    return std::make_pair(MI.getNumDefs(), StatepointOpers(&MI).getVarIdx());
   default:
     llvm_unreachable("unexpected stackmap opcode");
   }
+}
+
+static MachineInstr *foldPatchpoint(MachineFunction &MF, MachineInstr &MI,
+                                    ArrayRef<unsigned> Ops, int FrameIndex,
+                                    const TargetInstrInfo &TII) {
+  unsigned StartIdx = 0;
+  unsigned NumDefs = 0;
+  // getPatchpointUnfoldableRange throws guarantee if MI is not a patchpoint.
+  std::tie(NumDefs, StartIdx) = TII.getPatchpointUnfoldableRange(MI);
 
   unsigned DefToFoldIdx = MI.getNumOperands();
 


        


More information about the llvm-commits mailing list