[PATCH] D23067: TargetInstrInfo: add two new target hooks to analyse branch offsets

Sjoerd Meijer via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 2 12:26:39 PDT 2016


SjoerdMeijer updated this revision to Diff 66521.
SjoerdMeijer added a comment.

Hi Matt, thanks for reviewing. I have changed the offsets to int64_t.
I had a look and there indeed appears to be some overlap.
The motivation for my change is to minimise branch distances by reordering machine blocks, for which I need these helper functions.


https://reviews.llvm.org/D23067

Files:
  include/llvm/Target/TargetInstrInfo.h
  lib/Target/ARM/ARMBaseInstrInfo.cpp
  lib/Target/ARM/ARMBaseInstrInfo.h

Index: lib/Target/ARM/ARMBaseInstrInfo.h
===================================================================
--- lib/Target/ARM/ARMBaseInstrInfo.h
+++ lib/Target/ARM/ARMBaseInstrInfo.h
@@ -120,6 +120,8 @@
                                      const ScheduleDAG *DAG) const override;
 
   // Branch analysis.
+  bool isBranchOffsetInRange(unsigned Opcode, int64_t Offset) const override;
+  unsigned shrunkBranchOpcode(unsigned Opcode) const override;
   bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
                      MachineBasicBlock *&FBB,
                      SmallVectorImpl<MachineOperand> &Cond,
Index: lib/Target/ARM/ARMBaseInstrInfo.cpp
===================================================================
--- lib/Target/ARM/ARMBaseInstrInfo.cpp
+++ lib/Target/ARM/ARMBaseInstrInfo.cpp
@@ -290,6 +290,29 @@
 }
 
 // Branch analysis.
+bool
+ARMBaseInstrInfo::isBranchOffsetInRange(unsigned Opcode, int64_t Offset) const {
+  switch (Opcode) {
+    case ARM::tBcc:
+      if (Offset < -256 || Offset > 254)
+        return false;
+    case ARM::tB:
+      if (Offset < -2048 || Offset > 2046)
+        return false;
+  }
+  return true;
+}
+
+unsigned ARMBaseInstrInfo::shrunkBranchOpcode(unsigned Opcode) const {
+  switch (Opcode) {
+  case ARM::t2B:
+    return ARM::tB;
+  case ARM::t2Bcc:
+    return ARM::tBcc;
+  }
+  return ~0U;
+}
+
 bool ARMBaseInstrInfo::analyzeBranch(MachineBasicBlock &MBB,
                                      MachineBasicBlock *&TBB,
                                      MachineBasicBlock *&FBB,
Index: include/llvm/Target/TargetInstrInfo.h
===================================================================
--- include/llvm/Target/TargetInstrInfo.h
+++ include/llvm/Target/TargetInstrInfo.h
@@ -480,6 +480,18 @@
     return true;
   }
 
+  /// Return true if the offset is in range of the branch instruction and
+  /// false otherwise.
+  virtual bool isBranchOffsetInRange(unsigned Opcode, int64_t Offset) const {
+    return true;
+  }
+
+  /// Return the opcode if there exist a branch instruction with a smaller
+  /// encoding, or ~0U otherwise.
+  virtual unsigned shrunkBranchOpcode(unsigned Opcode) const {
+    return ~0U;
+  }
+
   /// Represents a predicate at the MachineFunction level.  The control flow a
   /// MachineBranchPredicate represents is:
   ///


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23067.66521.patch
Type: text/x-patch
Size: 2340 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160802/77dab8b7/attachment.bin>


More information about the llvm-commits mailing list