[llvm-commits] CVS: llvm/lib/Target/PowerPC/PPC.h PPCAsmPrinter.cpp PPCInstrInfo.td

Chris Lattner sabre at nondot.org
Fri Nov 3 21:27:53 PST 2006



Changes in directory llvm/lib/Target/PowerPC:

PPC.h updated: 1.34 -> 1.35
PPCAsmPrinter.cpp updated: 1.206 -> 1.207
PPCInstrInfo.td updated: 1.251 -> 1.252
---
Log message:

Go through all kinds of trouble to mark 'blr' as having a predicate operand
that takes a register and condition code.  Print these pieces of BLR the
right way, even though it is currently set to 'always'.

Next up: get the JIT encoding right, then enhance branch folding to produce
predicated blr for simple examples.



---
Diffs of the changes:  (+62 -12)

 PPC.h             |   31 +++++++++++++++++++++++--------
 PPCAsmPrinter.cpp |   30 ++++++++++++++++++++++++++++++
 PPCInstrInfo.td   |   13 +++++++++----
 3 files changed, 62 insertions(+), 12 deletions(-)


Index: llvm/lib/Target/PowerPC/PPC.h
diff -u llvm/lib/Target/PowerPC/PPC.h:1.34 llvm/lib/Target/PowerPC/PPC.h:1.35
--- llvm/lib/Target/PowerPC/PPC.h:1.34	Wed Sep 20 12:12:19 2006
+++ llvm/lib/Target/PowerPC/PPC.h	Fri Nov  3 23:27:39 2006
@@ -17,13 +17,31 @@
 
 #include <iosfwd>
 
-namespace llvm {
 
-class PPCTargetMachine;
-class FunctionPassManager;
-class FunctionPass;
-class MachineCodeEmitter;
+// GCC #defines PPC on Linux but we use it as our namespace name
+#undef PPC
 
+namespace llvm {
+  class PPCTargetMachine;
+  class FunctionPassManager;
+  class FunctionPass;
+  class MachineCodeEmitter;
+  
+  namespace PPC {
+    /// Predicate - These are "(BO << 5) | BI"  for various predicates.
+    enum Predicate {
+      PRED_ALWAYS = (20 << 5) | 0,
+      PRED_LT     = (12 << 5) | 0,
+      PRED_LE     = ( 4 << 5) | 1,
+      PRED_EQ     = (12 << 5) | 2,
+      PRED_GE     = ( 4 << 5) | 0,
+      PRED_GT     = (12 << 5) | 1,
+      PRED_NE     = ( 4 << 5) | 2,
+      PRED_UN     = (12 << 5) | 3,
+      PRED_NU     = ( 4 << 5) | 3
+    };
+  }
+  
 FunctionPass *createPPCBranchSelectionPass();
 FunctionPass *createPPCISelDag(PPCTargetMachine &TM);
 FunctionPass *createPPCAsmPrinterPass(std::ostream &OS,
@@ -34,9 +52,6 @@
                                  PPCTargetMachine &tm);
 } // end namespace llvm;
 
-// GCC #defines PPC on Linux but we use it as our namespace name
-#undef PPC
-
 // Defines symbolic names for PowerPC registers.  This defines a mapping from
 // register name to register number.
 //


Index: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
diff -u llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp:1.206 llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp:1.207
--- llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp:1.206	Thu Nov  2 14:25:49 2006
+++ llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp	Fri Nov  3 23:27:39 2006
@@ -236,6 +236,9 @@
       printOperand(MI, OpNo+1);
     }
     
+    void printPredicateOperand(const MachineInstr *MI, unsigned OpNo, 
+                               const char *Modifier);
+    
     virtual bool runOnMachineFunction(MachineFunction &F) = 0;
     virtual bool doFinalization(Module &M) = 0;
   };
@@ -363,6 +366,33 @@
   return false;
 }
 
+void PPCAsmPrinter::printPredicateOperand(const MachineInstr *MI, unsigned OpNo, 
+                                          const char *Modifier) {
+  assert(Modifier && "Must specify 'cc' or 'reg' as predicate op modifier!");
+  unsigned Code = MI->getOperand(OpNo).getImm();
+  if (!strcmp(Modifier, "cc")) {
+    switch ((PPC::Predicate)Code) {
+    case PPC::PRED_ALWAYS: return; // Don't print anything for always.
+    case PPC::PRED_LT: O << "lt"; return;
+    case PPC::PRED_LE: O << "le"; return;
+    case PPC::PRED_EQ: O << "eq"; return;
+    case PPC::PRED_GE: O << "ge"; return;
+    case PPC::PRED_GT: O << "gt"; return;
+    case PPC::PRED_NE: O << "ne"; return;
+    case PPC::PRED_UN: O << "un"; return;
+    case PPC::PRED_NU: O << "nu"; return;
+    }
+      
+  } else {
+    assert(!strcmp(Modifier, "reg") &&
+           "Need to specify 'cc' or 'reg' as predicate op modifier!");
+    // Don't print the register for 'always'.
+    if (Code == PPC::PRED_ALWAYS) return;
+    printOperand(MI, OpNo+1);
+  }
+}
+
+
 /// printMachineInstruction -- Print out a single PowerPC MI in Darwin syntax to
 /// the current output stream.
 ///


Index: llvm/lib/Target/PowerPC/PPCInstrInfo.td
diff -u llvm/lib/Target/PowerPC/PPCInstrInfo.td:1.251 llvm/lib/Target/PowerPC/PPCInstrInfo.td:1.252
--- llvm/lib/Target/PowerPC/PPCInstrInfo.td:1.251	Fri Nov  3 17:53:25 2006
+++ llvm/lib/Target/PowerPC/PPCInstrInfo.td	Fri Nov  3 23:27:39 2006
@@ -255,9 +255,11 @@
   let MIOperandInfo = (ops i32imm, ptr_rc);
 }
 
-// PowerPC Predicate operand.  20 = always, CR0 is a dummy reg that doesn't
-// matter.
-def pred : PredicateOperand<(ops imm, CRRC), (ops 20, CR0)>;
+// PowerPC Predicate operand.  640 = ((20<<5)|0) = always, CR0 is a dummy reg
+// that doesn't matter.
+def pred : PredicateOperand<(ops imm, CRRC), (ops (i32 640), CR0)> {
+  let PrintMethod = "printPredicateOperand";
+}
 
 // Define PowerPC specific addressing mode.
 def iaddr  : ComplexPattern<iPTR, 2, "SelectAddrImm",    [], []>;
@@ -315,10 +317,13 @@
 
 let isTerminator = 1, isBarrier = 1, noResults = 1, PPC970_Unit = 7 in {
   let isReturn = 1 in
-    def BLR : XLForm_2_ext<19, 16, 20, 0, 0, (ops), "blr", BrB, [(retflag)]>;
+    def BLR : XLForm_2_ext<19, 16, 20, 0, 0,
+                           (ops pred:$p),
+                           "b${p:cc}lr ${p:reg}", BrB, [(retflag)]>;
   def BCTR : XLForm_2_ext<19, 528, 20, 0, 0, (ops), "bctr", BrB, []>;
 }
 
+
 let Defs = [LR] in
   def MovePCtoLR : Pseudo<(ops piclabel:$label), "bl $label", []>,
                    PPC970_Unit_BRU;






More information about the llvm-commits mailing list