add another target hook for branch folding.
authorChris Lattner <sabre@nondot.org>
Sat, 28 Oct 2006 17:29:57 +0000 (17:29 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 28 Oct 2006 17:29:57 +0000 (17:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31262 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetInstrInfo.h
lib/Target/X86/X86InstrInfo.cpp
lib/Target/X86/X86InstrInfo.h

index 9e269f3692e3b795b2c5c2b00c42838f8836b2f1..b0ac41b34d13e5abacde80ca575c31d0154ad24b 100644 (file)
@@ -318,6 +318,14 @@ public:
     assert(0 && "Target didn't implement TargetInstrInfo::InsertBranch!"); 
   }
   
+  /// BlockHasNoFallThrough - Return true if the specified block does not
+  /// fall-through into its successor block.  This is primarily used when a
+  /// branch is unanalyzable.  It is useful for things like unconditional
+  /// indirect branches (jump tables).
+  virtual bool BlockHasNoFallThrough(MachineBasicBlock &MBB) const {
+    return false;
+  }
+  
   /// ReverseBranchCondition - Reverses the branch condition of the specified
   /// condition list, returning false on success and true if it cannot be
   /// reversed.
index e89493bff3c6db06cba464ce21a360cd7154be9e..f34f00a32f5960e226e274b0d8d0fbe7c7211f78 100644 (file)
@@ -420,6 +420,18 @@ void X86InstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
   BuildMI(&MBB, X86::JMP, 1).addMBB(FBB);
 }
 
+bool X86InstrInfo::BlockHasNoFallThrough(MachineBasicBlock &MBB) const {
+  if (MBB.empty()) return false;
+  
+  switch (MBB.back().getOpcode()) {
+  case X86::JMP:     // Uncond branch.
+  case X86::JMP32r:  // Indirect branch.
+  case X86::JMP32m:  // Indirect branch through mem.
+    return true;
+  default: return false;
+  }
+}
+
 bool X86InstrInfo::
 ReverseBranchCondition(std::vector<MachineOperand> &Cond) const {
   assert(Cond.size() == 1 && "Invalid X86 branch condition!");
index 9886db301c09355343c8fe34924add42f1778e64..c9ce1fc920b314ecd55d0b12cfa363cfeda95934 100644 (file)
@@ -267,6 +267,7 @@ public:
   virtual void InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
                             MachineBasicBlock *FBB,
                             const std::vector<MachineOperand> &Cond) const;
+  virtual bool BlockHasNoFallThrough(MachineBasicBlock &MBB) const;
   virtual bool ReverseBranchCondition(std::vector<MachineOperand> &Cond) const;
 
   const TargetRegisterClass *getPointerRegClass() const;