Hooks for predication support.
authorEvan Cheng <evan.cheng@apple.com>
Wed, 16 May 2007 02:01:49 +0000 (02:01 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Wed, 16 May 2007 02:01:49 +0000 (02:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37093 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMInstrInfo.cpp
lib/Target/ARM/ARMInstrInfo.h
lib/Target/ARM/ARMTargetMachine.cpp
lib/Target/ARM/ARMTargetMachine.h

index 3f501a68ae1e93245c90aad4827e66c32ccd8ce8..de9ea48b26565a8a88b2efe5fe47d5783fb1d212 100644 (file)
@@ -423,6 +423,28 @@ ReverseBranchCondition(std::vector<MachineOperand> &Cond) const {
   return false;
 }
 
+bool ARMInstrInfo::isPredicatable(MachineInstr *MI) const {
+  const TargetInstrDescriptor *TID = MI->getInstrDescriptor();
+  if (TID->Flags & M_PREDICATED)
+    return true;
+
+  unsigned Opc = MI->getOpcode();
+  return Opc == ARM::B || Opc == ARM::tB;
+}
+
+void 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;
+  }
+
+  MachineOperand *PMO = MI->findFirstPredOperand();
+  PMO->setImm(Cond[0].getImmedValue());
+}
+
 
 /// FIXME: Works around a gcc miscompilation with -fstrict-aliasing
 static unsigned getNumJTEntries(const std::vector<MachineJumpTableEntry> &JT,
index ebec9e5a79b2d2ab076d93363f5da2259afd2086..d51b9bd74bec42b4345d9ebab2c1f43dd6baf3da 100644 (file)
@@ -102,6 +102,11 @@ public:
                             const std::vector<MachineOperand> &Cond) const;
   virtual bool BlockHasNoFallThrough(MachineBasicBlock &MBB) const;
   virtual bool ReverseBranchCondition(std::vector<MachineOperand> &Cond) const;
+
+  // Predication support.
+  virtual bool isPredicatable(MachineInstr *MI) const;
+  virtual void PredicateInstruction(MachineInstr *MI,
+                                    std::vector<MachineOperand> &Cond) const;
 };
 
   // Utility routines
index 3815875b22a0b80a71984b7077822308296547a3..57b644026db9ce6d34fd2bcf1d5e1dde4b4381fb 100644 (file)
@@ -17,6 +17,7 @@
 #include "ARM.h"
 #include "llvm/Module.h"
 #include "llvm/PassManager.h"
+#include "llvm/CodeGen/Passes.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Target/TargetMachineRegistry.h"
 #include "llvm/Target/TargetOptions.h"
@@ -24,6 +25,8 @@ using namespace llvm;
 
 static cl::opt<bool> DisableLdStOpti("disable-arm-loadstore-opti", cl::Hidden,
                               cl::desc("Disable load store optimization pass"));
+static cl::opt<bool> EnableIfConversion("enable-arm-if-conversion", cl::Hidden,
+                              cl::desc("Enable if-conversion pass"));
 
 namespace {
   // Register the target.
@@ -85,6 +88,14 @@ bool ARMTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
   return false;
 }
 
+bool ARMTargetMachine::addPostRegAlloc(FunctionPassManager &PM, bool Fast) {
+  if (Fast || !EnableIfConversion || Subtarget.isThumb())
+    return false;
+
+  PM.add(createIfConverterPass());
+  return true;
+}
+
 bool ARMTargetMachine::addPreEmitPass(FunctionPassManager &PM, bool Fast) {
   // FIXME: temporarily disabling load / store optimization pass for Thumb mode.
   if (!Fast && !DisableLdStOpti && !Subtarget.isThumb())
index a50275c675f784bf031471e84fe795964b17b8a8..dcdd1285f543df6e7f91bca292b9684b52aa9c8a 100644 (file)
@@ -53,6 +53,7 @@ public:
   
   // Pass Pipeline Configuration
   virtual bool addInstSelector(FunctionPassManager &PM, bool Fast);
+  virtual bool addPostRegAlloc(FunctionPassManager &PM, bool Fast);
   virtual bool addPreEmitPass(FunctionPassManager &PM, bool Fast);
   virtual bool addAssemblyEmitter(FunctionPassManager &PM, bool Fast, 
                                   std::ostream &Out);