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

Serguei Katkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 5 00:01:28 PDT 2021


skatkov created this revision.
skatkov added reviewers: reames, dantrushin.
Herald added a subscriber: hiraditya.
skatkov requested review of this revision.
Herald added a project: LLVM.

The patch is posted to agree on API.


https://reviews.llvm.org/D99875

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


Index: llvm/lib/CodeGen/TargetInstrInfo.cpp
===================================================================
--- llvm/lib/CodeGen/TargetInstrInfo.cpp
+++ llvm/lib/CodeGen/TargetInstrInfo.cpp
@@ -474,9 +474,8 @@
 
 MCInst TargetInstrInfo::getNop() const { llvm_unreachable("Not implemented"); }
 
-static MachineInstr *foldPatchpoint(MachineFunction &MF, MachineInstr &MI,
-                                    ArrayRef<unsigned> Ops, int FrameIndex,
-                                    const TargetInstrInfo &TII) {
+std::pair<unsigned, unsigned>
+TargetInstrInfo::getNonFoldableRange(const MachineInstr &MI) const {
   unsigned StartIdx = 0;
   unsigned NumDefs = 0;
   switch (MI.getOpcode()) {
@@ -498,8 +497,22 @@
     break;
   }
   default:
-    llvm_unreachable("unexpected stackmap opcode");
+    StartIdx = MI.getNumOperands();
+    break;
   }
+  return std::make_pair(NumDefs, StartIdx);
+}
+
+static MachineInstr *foldPatchpoint(MachineFunction &MF, MachineInstr &MI,
+                                    ArrayRef<unsigned> Ops, int FrameIndex,
+                                    const TargetInstrInfo &TII) {
+  unsigned StartIdx = 0;
+  unsigned NumDefs = 0;
+  assert((MI.getOpcode() == TargetOpcode::STACKMAP ||
+          MI.getOpcode() == TargetOpcode::PATCHPOINT ||
+          MI.getOpcode() == TargetOpcode::STATEPOINT) &&
+         "Unexpected stackmap opcode");
+  std::tie(NumDefs, StartIdx) = TII.getNonFoldableRange(MI);
 
   unsigned DefToFoldIdx = MI.getNumOperands();
 
Index: llvm/include/llvm/CodeGen/TargetInstrInfo.h
===================================================================
--- llvm/include/llvm/CodeGen/TargetInstrInfo.h
+++ llvm/include/llvm/CodeGen/TargetInstrInfo.h
@@ -1064,6 +1064,14 @@
   /// has the potential of causing nasty silent breakage in out-of-tree targets.
   virtual bool isSubregFoldable() const { return false; }
 
+  /// For given MI instruction returns the range of operands indices. Outside
+  /// of this range [first, second) memory operands are foldable.
+  /// The answer is conservative. Returning range might contain foldable memory
+  /// operands while operands outside of range does not contain non-foldable
+  /// memory operands.
+  virtual std::pair<unsigned, unsigned>
+  getNonFoldableRange(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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99875.335211.patch
Type: text/x-patch
Size: 2530 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210405/342c2a64/attachment.bin>


More information about the llvm-commits mailing list