PredicateInstruction returns true if the operation was successful.
authorEvan Cheng <evan.cheng@apple.com>
Wed, 16 May 2007 21:53:07 +0000 (21:53 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Wed, 16 May 2007 21:53:07 +0000 (21:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37124 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetInstrInfo.h
lib/Target/ARM/ARMInstrInfo.cpp
lib/Target/ARM/ARMInstrInfo.h
lib/Target/TargetInstrInfo.cpp

index 7c2cfac8359b633458636d406c7127f95baa8be7..00a05569b95d8ff0478d4dcbc67d84b80e21816f 100644 (file)
@@ -390,8 +390,8 @@ public:
   }
 
   /// PredicateInstruction - Convert the instruction into a predicated
-  /// instruction.
-  virtual void PredicateInstruction(MachineInstr *MI,
+  /// instruction. It returns true if the operation was successful.
+  virtual bool PredicateInstruction(MachineInstr *MI,
                                     std::vector<MachineOperand> &Cond) const;
 
   /// getPointerRegClass - Returns a TargetRegisterClass used for pointer
index b631124b6eb03461daff0ef8c497453ce4064900..891ae558f3d3338fdc41f43938abf8242397626f 100644 (file)
@@ -423,17 +423,21 @@ ReverseBranchCondition(std::vector<MachineOperand> &Cond) const {
   return false;
 }
 
-void ARMInstrInfo::PredicateInstruction(MachineInstr *MI,
+bool ARMInstrInfo::PredicateInstruction(MachineInstr *MI,
                                       std::vector<MachineOperand> &Cond) const {
   unsigned Opc = MI->getOpcode();
   if (Opc == ARM::B || Opc == ARM::tB) {
     MI->setInstrDescriptor(get(Opc == ARM::B ? ARM::Bcc : ARM::tBcc));
     MI->addImmOperand(Cond[0].getImmedValue());
-    return;
+    return true;
   }
 
   MachineOperand *PMO = MI->findFirstPredOperand();
-  PMO->setImm(Cond[0].getImmedValue());
+  if (PMO) {
+    PMO->setImm(Cond[0].getImmedValue());
+    return true;
+  }
+  return false;
 }
 
 
index cb0b812e161eb140cd71076b10851c6b885d82ad..33645b2d334a64275e6ab139c58ac60e2a846de3 100644 (file)
@@ -104,7 +104,7 @@ public:
   virtual bool ReverseBranchCondition(std::vector<MachineOperand> &Cond) const;
 
   // Predication support.
-  virtual void PredicateInstruction(MachineInstr *MI,
+  virtual bool PredicateInstruction(MachineInstr *MI,
                                     std::vector<MachineOperand> &Cond) const;
 };
 
index fe5ee1d25e08e8ad8d5b779cd242f013582278e0..d1413510fff27578b3c7a5b1f6a08342fa12dd5e 100644 (file)
@@ -60,22 +60,27 @@ MachineInstr *TargetInstrInfo::commuteInstruction(MachineInstr *MI) const {
   return MI;
 }
 
-void TargetInstrInfo::PredicateInstruction(MachineInstr *MI,
+bool TargetInstrInfo::PredicateInstruction(MachineInstr *MI,
                                       std::vector<MachineOperand> &Cond) const {
+  bool MadeChange = false;
   const TargetInstrDescriptor *TID = MI->getInstrDescriptor();
-  assert((TID->Flags & M_PREDICABLE) &&
-         "Predicating an unpredicable instruction!");
-
-  for (unsigned j = 0, i = 0, e = MI->getNumOperands(); i != e; ++i) {
-    if ((TID->OpInfo[i].Flags & M_PREDICATE_OPERAND)) {
-      MachineOperand &MO = MI->getOperand(i);
-      if (MO.isReg())
-        MO.setReg(Cond[j].getReg());
-      else if (MO.isImm())
-        MO.setImm(Cond[j].getImmedValue());
-      else if (MO.isMBB())
-        MO.setMachineBasicBlock(Cond[j].getMachineBasicBlock());
-      ++j;
+  if (TID->Flags & M_PREDICABLE) {
+    for (unsigned j = 0, i = 0, e = MI->getNumOperands(); i != e; ++i) {
+      if ((TID->OpInfo[i].Flags & M_PREDICATE_OPERAND)) {
+        MachineOperand &MO = MI->getOperand(i);
+        if (MO.isReg()) {
+          MO.setReg(Cond[j].getReg());
+          MadeChange = true;
+        } else if (MO.isImm()) {
+          MO.setImm(Cond[j].getImmedValue());
+          MadeChange = true;
+        } else if (MO.isMBB()) {
+          MO.setMachineBasicBlock(Cond[j].getMachineBasicBlock());
+          MadeChange = true;
+        }
+        ++j;
+      }
     }
   }
+  return MadeChange;
 }