[llvm-commits] [llvm] r73817 - in /llvm/trunk: include/llvm/MC/MCInst.h include/llvm/Target/Target.td lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp lib/Target/X86/X86Instr64bit.td

Chris Lattner sabre at nondot.org
Sat Jun 20 00:03:18 PDT 2009


Author: lattner
Date: Sat Jun 20 02:03:18 2009
New Revision: 73817

URL: http://llvm.org/viewvc/llvm-project?rev=73817&view=rev
Log:
implement support for lowering subregs when preparing to print 
LEA64_32r, eliminating a bunch of modifier logic stuff on addr modes.

Implement support for printing mbb labels as operands.


Modified:
    llvm/trunk/include/llvm/MC/MCInst.h
    llvm/trunk/include/llvm/Target/Target.td
    llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
    llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h
    llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp
    llvm/trunk/lib/Target/X86/X86Instr64bit.td

Modified: llvm/trunk/include/llvm/MC/MCInst.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCInst.h?rev=73817&r1=73816&r2=73817&view=diff

==============================================================================
--- llvm/trunk/include/llvm/MC/MCInst.h (original)
+++ llvm/trunk/include/llvm/MC/MCInst.h Sat Jun 20 02:03:18 2009
@@ -29,13 +29,18 @@
   enum MachineOperandType {
     kInvalid,                 ///< Uninitialized.
     kRegister,                ///< Register operand.
-    kImmediate                ///< Immediate operand.
+    kImmediate,               ///< Immediate operand.
+    kMBBLabel                 ///< Basic block label.
   };
   unsigned char Kind;
   
   union {
     unsigned RegVal;
     int64_t ImmVal;
+    struct {
+      unsigned FunctionNo;
+      unsigned BlockNo;
+    } MBBLabel;
   };
 public:
   
@@ -44,6 +49,7 @@
 
   bool isReg() const { return Kind == kRegister; }
   bool isImm() const { return Kind == kImmediate; }
+  bool isMBBLabel() const { return Kind == kMBBLabel; }
   
   /// getReg - Returns the register number.
   unsigned getReg() const {
@@ -66,6 +72,15 @@
     ImmVal = Val;
   }
   
+  unsigned getMBBLabelFunction() const {
+    assert(isMBBLabel() && "Wrong accessor");
+    return MBBLabel.FunctionNo; 
+  }
+  unsigned getMBBLabelBlock() const {
+    assert(isMBBLabel() && "Wrong accessor");
+    return MBBLabel.BlockNo; 
+  }
+  
   void MakeReg(unsigned Reg) {
     Kind = kRegister;
     RegVal = Reg;
@@ -74,6 +89,11 @@
     Kind = kImmediate;
     ImmVal = Val;
   }
+  void MakeMBBLabel(unsigned Fn, unsigned MBB) {
+    Kind = kMBBLabel;
+    MBBLabel.FunctionNo = Fn;
+    MBBLabel.BlockNo = MBB;
+  }
 };
 
   
@@ -91,6 +111,7 @@
   DebugLoc getDebugLoc() const { return DebugLoc(); }
   
   const MCOperand &getOperand(unsigned i) const { return Operands[i]; }
+  MCOperand &getOperand(unsigned i) { return Operands[i]; }
   
   void addOperand(const MCOperand &Op) {
     Operands.push_back(Op);

Modified: llvm/trunk/include/llvm/Target/Target.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/Target.td?rev=73817&r1=73816&r2=73817&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/Target.td (original)
+++ llvm/trunk/include/llvm/Target/Target.td Sat Jun 20 02:03:18 2009
@@ -274,6 +274,7 @@
 class Operand<ValueType ty> {
   ValueType Type = ty;
   string PrintMethod = "printOperand";
+  string AsmOperandLowerMethod = ?;
   dag MIOperandInfo = (ops);
 }
 

Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp?rev=73817&r1=73816&r2=73817&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Sat Jun 20 02:03:18 2009
@@ -762,6 +762,18 @@
   return false;
 }
 
+static void lower_lea64_32mem(MCInst *MI, unsigned OpNo) {
+  // Convert registers in the addr mode according to subreg64.
+  for (unsigned i = 0; i != 4; ++i) {
+    if (!MI->getOperand(i).isReg()) continue;
+    
+    unsigned Reg = MI->getOperand(i).getReg();
+    if (Reg == 0) continue;
+    
+    MI->getOperand(i).setReg(getX86SubSuperRegister(Reg, MVT::i64));
+  }
+}
+
 /// printMachineInstruction -- Print out a single X86 LLVM instruction MI in
 /// AT&T syntax to the current output stream.
 ///
@@ -769,6 +781,21 @@
   ++EmittedInsts;
 
   if (NewAsmPrinter) {
+    if (MI->getOpcode() == TargetInstrInfo::INLINEASM) {
+      O << "\t";
+      printInlineAsm(MI);
+      return;
+    } else if (MI->isLabel()) {
+      printLabel(MI);
+      return;
+    } else if (MI->getOpcode() == TargetInstrInfo::DECLARE) {
+      printDeclare(MI);
+      return;
+    } else if (MI->getOpcode() == TargetInstrInfo::IMPLICIT_DEF) {
+      printImplicitDef(MI);
+      return;
+    }
+    
     O << "NEW: ";
     MCInst TmpInst;
     
@@ -782,6 +809,8 @@
         MCOp.MakeReg(MO.getReg());
       } else if (MO.isImm()) {
         MCOp.MakeImm(MO.getImm());
+      } else if (MO.isMBB()) {
+        MCOp.MakeMBBLabel(getFunctionNumber(), MO.getMBB()->getNumber());
       } else {
         assert(0 && "Unimp");
       }
@@ -789,9 +818,9 @@
       TmpInst.addOperand(MCOp);
     }
     
-    if (MI->getOpcode() == X86::LEA64_32r) {
+    if (TmpInst.getOpcode() == X86::LEA64_32r) {
       // Should handle the 'subreg rewriting' for the lea64_32mem operand.
-      
+      lower_lea64_32mem(&TmpInst, 1);
     }
     
     // FIXME: Convert TmpInst.

Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h?rev=73817&r1=73816&r2=73817&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h Sat Jun 20 02:03:18 2009
@@ -70,10 +70,8 @@
 
   void printOperand(const MCInst *MI, unsigned OpNo,
                     const char *Modifier = 0, bool NotRIPRel = false);
-  void printMemReference(const MCInst *MI, unsigned Op,
-                         const char *Modifier=NULL, bool NotRIPRel = false);
-  void printLeaMemReference(const MCInst *MI, unsigned Op,
-                            const char *Modifier=NULL, bool NotRIPRel = false);
+  void printMemReference(const MCInst *MI, unsigned Op);
+  void printLeaMemReference(const MCInst *MI, unsigned Op);
   void printSSECC(const MCInst *MI, unsigned Op);
   void printPICLabel(const MCInst *MI, unsigned Op);
 
@@ -111,7 +109,7 @@
     printLeaMemReference(MI, OpNo);
   }
   void printlea64_32mem(const MCInst *MI, unsigned OpNo) {
-    printLeaMemReference(MI, OpNo, "subreg64");
+    printLeaMemReference(MI, OpNo);
   }
   
   

Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp?rev=73817&r1=73816&r2=73817&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp Sat Jun 20 02:03:18 2009
@@ -15,6 +15,7 @@
 #define DEBUG_TYPE "asm-printer"
 #include "llvm/MC/MCInst.h"
 #include "X86ATTAsmPrinter.h"
+#include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
@@ -25,9 +26,8 @@
 #undef MachineInstr
 
 void X86ATTAsmPrinter::printSSECC(const MCInst *MI, unsigned Op) {
-  unsigned char value = MI->getOperand(Op).getImm();
-  assert(value <= 7 && "Invalid ssecc argument!");
-  switch (value) {
+  switch (MI->getOperand(Op).getImm()) {
+  default: assert(0 && "Invalid ssecc argument!");
   case 0: O << "eq"; break;
   case 1: O << "lt"; break;
   case 2: O << "le"; break;
@@ -48,7 +48,7 @@
 
 void X86ATTAsmPrinter::printOperand(const MCInst *MI, unsigned OpNo,
                                     const char *Modifier, bool NotRIPRel) {
-  //assert(Modifier == 0 && "Modifiers should not be used");
+  assert(Modifier == 0 && "Modifiers should not be used");
   
   const MCOperand &Op = MI->getOperand(OpNo);
   if (Op.isReg()) {
@@ -70,6 +70,15 @@
     O << '$';
     O << Op.getImm();
     return;
+  } else if (Op.isMBBLabel()) {
+    // FIXME: Keep in sync with printBasicBlockLabel.  printBasicBlockLabel
+    // should eventually call into this code, not the other way around.
+    
+    O << TAI->getPrivateGlobalPrefix() << "BB" << Op.getMBBLabelFunction()
+      << '_' << Op.getMBBLabelBlock();
+    
+    // FIXME: with verbose asm print llvm bb name, add to operand.
+    return;
   }
   
   O << "<<UNKNOWN OPERAND KIND>>";
@@ -338,9 +347,10 @@
 #endif
 }
 
-void X86ATTAsmPrinter::printLeaMemReference(const MCInst *MI, unsigned Op,
-                                            const char *Modifier,
-                                            bool NotRIPRel) {
+void X86ATTAsmPrinter::printLeaMemReference(const MCInst *MI, unsigned Op) {
+  const char *Modifier = 0;
+  bool NotRIPRel = false;
+
   const MCOperand &BaseReg  = MI->getOperand(Op);
   const MCOperand &IndexReg = MI->getOperand(Op+2);
   const MCOperand &DispSpec = MI->getOperand(Op+3);
@@ -386,13 +396,12 @@
   }
 }
 
-void X86ATTAsmPrinter::printMemReference(const MCInst *MI, unsigned Op,
-                                         const char *Modifier, bool NotRIPRel){
+void X86ATTAsmPrinter::printMemReference(const MCInst *MI, unsigned Op) {
   //assert(isMem(MI, Op) && "Invalid memory reference!");
   const MCOperand &Segment = MI->getOperand(Op+4);
   if (Segment.getReg()) {
-    printOperand(MI, Op+4, Modifier);
+    printOperand(MI, Op+4);
     O << ':';
   }
-  printLeaMemReference(MI, Op, Modifier, NotRIPRel);
+  printLeaMemReference(MI, Op);
 }

Modified: llvm/trunk/lib/Target/X86/X86Instr64bit.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86Instr64bit.td?rev=73817&r1=73816&r2=73817&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86Instr64bit.td (original)
+++ llvm/trunk/lib/Target/X86/X86Instr64bit.td Sat Jun 20 02:03:18 2009
@@ -29,6 +29,7 @@
 
 def lea64_32mem : Operand<i32> {
   let PrintMethod = "printlea64_32mem";
+  let AsmOperandLowerMethod = "lower_lea64_32mem";
   let MIOperandInfo = (ops GR32, i8imm, GR32, i32imm);
 }
 





More information about the llvm-commits mailing list