[llvm-commits] CVS: llvm/lib/Target/X86/FloatingPoint.cpp Printer.cpp X86InstrInfo.def X86InstrInfo.h

Brian Gaeke gaeke at cs.uiuc.edu
Thu Jun 26 19:01:18 PDT 2003


Changes in directory llvm/lib/Target/X86:

FloatingPoint.cpp updated: 1.2 -> 1.3
Printer.cpp updated: 1.40 -> 1.41
X86InstrInfo.def updated: 1.60 -> 1.61
X86InstrInfo.h updated: 1.23 -> 1.24

---
Log message:

Nice tasty llc fixes. These should fix LLC for x86 for everything in
SingleSource except oopack and Oscar.  (Sorry, Oscar.)

include/llvm/Target/TargetInstrInfo.h: Remove virtual print method. Add
 accessors for ImplicitUses/Defs.
lib/Target/TargetInstrInfo.cpp: Remove virtual print method. If you
 really wanted this, just use MI->print(O, TM); instead...
lib/Target/X86:
FloatingPoint.cpp: ...like this.
X86InstrInfo.h: Remove virtual print method. Define the PrintImplUses
 target-specific flag bit.
X86InstrInfo.def: Add the PrintImplUses flag to all the instructions
 which implicitly use CL, because the assembler needs to see the CL in
 order to generate the right instruction.
Printer.cpp: Ditch fnIndex at Chris's request. Now we use CurrentFnName
  to name constants in the constant pool for each function instead. This
  avoids keeping state between runOnMachineFunction() invocations, which
  is a no-no. Having MangledGlobals be global is a bogon I'd like to get
  rid of too, but making it a static member of Printer causes link errors
  (why???).
 Make NumberForBB into a member of Printer instead of a global, too.
 Make printOp and printMemReference into methods of Printer.
 X86InstrInfo::print is now Printer::printMachineInstruction, because
  TargetInstrInfo::print is history. (Because of this, we have to qualify
  the names of some TargetInstrInfo methods we call.)
 Print out the ImplicitUses field of any instruction we print that has
  the PrintImplUses bit set. 


---
Diffs of the changes:

Index: llvm/lib/Target/X86/FloatingPoint.cpp
diff -u llvm/lib/Target/X86/FloatingPoint.cpp:1.2 llvm/lib/Target/X86/FloatingPoint.cpp:1.3
--- llvm/lib/Target/X86/FloatingPoint.cpp:1.2	Tue Jan 14 15:59:16 2003
+++ llvm/lib/Target/X86/FloatingPoint.cpp	Thu Jun 26 19:00:45 2003
@@ -196,8 +196,8 @@
 	    MachineBasicBlock::iterator Start = I;
 	    // Rewind to first instruction newly inserted.
 	    while (Start != BB.begin() && *(Start-1) != PrevMI) --Start;
-	    std::cerr << "Inserted instructions:\n";
-	    do TII.print(*Start, std::cerr << "\t", MF.getTarget());
+	    std::cerr << "Inserted instructions:\n\t";
+	    (*Start)->print(std::cerr, MF.getTarget());
 	    while (++Start != I+1);
 	  }
 	  dumpStack();


Index: llvm/lib/Target/X86/Printer.cpp
diff -u llvm/lib/Target/X86/Printer.cpp:1.40 llvm/lib/Target/X86/Printer.cpp:1.41
--- llvm/lib/Target/X86/Printer.cpp:1.40	Thu Jun 26 13:02:30 2003
+++ llvm/lib/Target/X86/Printer.cpp	Thu Jun 26 19:00:46 2003
@@ -24,16 +24,25 @@
 #include "llvm/Module.h"
 
 namespace {
-  unsigned fnIndex;
-  std::set<const Value*> MangledGlobals;
+  std::set<const Value *> MangledGlobals;
   struct Printer : public MachineFunctionPass {
     std::ostream &O;
+    typedef std::map<const Value *, unsigned> ValueMapTy;
+    ValueMapTy NumberForBB;
     Printer(std::ostream &o) : O(o) {}
     const TargetData *TD;
+    std::string CurrentFnName;
     virtual const char *getPassName() const {
       return "X86 Assembly Printer";
     }
 
+    void printMachineInstruction(const MachineInstr *MI, std::ostream &O,
+				 const TargetMachine &TM) const;
+    void printOp(std::ostream &O, const MachineOperand &MO,
+		 const MRegisterInfo &RI, bool elideOffsetKeyword = false) const;
+    void printMemReference(std::ostream &O, const MachineInstr *MI,
+			   unsigned Op,
+			   const MRegisterInfo &RI) const;
     void printConstantPool(MachineConstantPool *MCP);
     bool runOnMachineFunction(MachineFunction &F);    
     std::string ConstantExprToString(const ConstantExpr* CE);
@@ -44,8 +53,7 @@
     void printConstantValueOnly(const Constant* CV, int numPadBytesAfter = 0);
     void printSingleConstantValue(const Constant* CV);
   };
-  std::map<const Value *, unsigned> NumberForBB;
-}
+} // end of anonymous namespace
 
 /// createX86CodePrinterPass - Print out the specified machine code function to
 /// the specified stream.  This function should work regardless of whether or
@@ -55,8 +63,8 @@
   return new Printer(O);
 }
 
-// We dont want identifier names with ., space, -  in them. 
-// So we replace them with _
+// We don't want identifier names with ., space, or - in them, 
+// so we replace them with underscores.
 static std::string makeNameProper(std::string x) {
   std::string tmp;
   for (std::string::iterator sI = x.begin(), sEnd = x.end(); sI != sEnd; sI++)
@@ -66,38 +74,32 @@
     case '-': tmp += "D_"; break;
     default:  tmp += *sI;
     }
-
   return tmp;
 }
 
-std::string getValueName(const Value *V) {
+static std::string getValueName(const Value *V) {
   if (V->hasName()) { // Print out the label if it exists...
-    
     // Name mangling occurs as follows:
     // - If V is not a global, mangling always occurs.
     // - Otherwise, mangling occurs when any of the following are true:
     //   1) V has internal linkage
     //   2) V's name would collide if it is not mangled.
     //
-    
     if(const GlobalValue* gv = dyn_cast<GlobalValue>(V)) {
       if(!gv->hasInternalLinkage() && !MangledGlobals.count(gv)) {
         // No internal linkage, name will not collide -> no mangling.
         return makeNameProper(gv->getName());
       }
     }
-    
     // Non-global, or global with internal linkage / colliding name -> mangle.
     return "l" + utostr(V->getType()->getUniqueID()) + "_" +
       makeNameProper(V->getName());      
   }
-
   static int Count = 0;
   Count++;
   return "ltmp_" + itostr(Count) + "_" + utostr(V->getType()->getUniqueID());
 }
 
-
 // valToExprString - Helper function for ConstantExprToString().
 // Appends result to argument string S.
 // 
@@ -391,7 +393,8 @@
     O << "\t.section .rodata\n";
     O << "\t.align " << (unsigned)TD->getTypeAlignment(CP[i]->getType())
       << "\n";
-    O << ".CPI" << fnIndex << "_" << i << ":\t\t\t\t\t#" << *CP[i] << "\n";
+    O << ".CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t#"
+      << *CP[i] << "\n";
     printConstantValueOnly (CP[i]);
   }
 }
@@ -404,16 +407,21 @@
   const TargetInstrInfo &TII = TM.getInstrInfo();
   TD = &TM.getTargetData();
 
+  // What's my mangled name?
+  CurrentFnName = getValueName(MF.getFunction());
+
   // Print out constants referenced by the function
   printConstantPool(MF.getConstantPool());
 
   // Print out labels for the function.
   O << "\t.text\n";
   O << "\t.align 16\n";
-  O << "\t.globl\t" << getValueName(MF.getFunction()) << "\n";
-  O << "\t.type\t" << getValueName(MF.getFunction()) << ", @function\n";
-  O << getValueName(MF.getFunction()) << ":\n";
+  O << "\t.globl\t" << CurrentFnName << "\n";
+  O << "\t.type\t" << CurrentFnName << ", @function\n";
+  O << CurrentFnName << ":\n";
 
+  // Number each basic block so that we can consistently refer to them
+  // in PC-relative references.
   NumberForBB.clear();
   for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
        I != E; ++I) {
@@ -430,11 +438,10 @@
 	 II != E; ++II) {
       // Print the assembly for the instruction.
       O << "\t";
-      TII.print(*II, O, TM);
+      printMachineInstruction(*II, O, TM);
     }
   }
 
-  fnIndex++;
   // We didn't modify anything.
   return false;
 }
@@ -453,8 +460,9 @@
     MI->getOperand(Op+2).isRegister() &&MI->getOperand(Op+3).isImmediate();
 }
 
-static void printOp(std::ostream &O, const MachineOperand &MO,
-                    const MRegisterInfo &RI, bool elideOffsetKeyword = false) {
+void Printer::printOp(std::ostream &O, const MachineOperand &MO,
+		      const MRegisterInfo &RI,
+		      bool elideOffsetKeyword /* = false */) const {
   switch (MO.getType()) {
   case MachineOperand::MO_VirtualRegister:
     if (Value *V = MO.getVRegValueOrNull()) {
@@ -474,8 +482,12 @@
     O << (int)MO.getImmedValue();
     return;
   case MachineOperand::MO_PCRelativeDisp:
-    O << ".BB" << NumberForBB[MO.getVRegValue()] << " # PC rel: "
-      << MO.getVRegValue()->getName();
+    {
+      ValueMapTy::const_iterator i = NumberForBB.find(MO.getVRegValue());
+      assert (i != NumberForBB.end()
+	      && "Could not find a BB I previously put in the NumberForBB map!");
+      O << ".BB" << i->second << " # PC rel: " << MO.getVRegValue()->getName();
+    }
     return;
   case MachineOperand::MO_GlobalAddress:
     if (!elideOffsetKeyword) O << "OFFSET "; O << getValueName(MO.getGlobal());
@@ -501,8 +513,9 @@
   }
 }
 
-static void printMemReference(std::ostream &O, const MachineInstr *MI,
-                              unsigned Op, const MRegisterInfo &RI) {
+void Printer::printMemReference(std::ostream &O, const MachineInstr *MI,
+				unsigned Op,
+				const MRegisterInfo &RI) const {
   assert(isMem(MI, Op) && "Invalid memory reference!");
 
   if (MI->getOperand(Op).isFrameIndex()) {
@@ -512,7 +525,7 @@
     O << "]";
     return;
   } else if (MI->getOperand(Op).isConstantPoolIndex()) {
-    O << "[.CPI" << fnIndex << "_"
+    O << "[.CPI" << CurrentFnName << "_"
       << MI->getOperand(Op).getConstantPoolIndex();
     if (MI->getOperand(Op+3).getImmedValue())
       O << " + " << MI->getOperand(Op+3).getImmedValue();
@@ -553,11 +566,14 @@
   O << "]";
 }
 
-// print - Print out an x86 instruction in intel syntax
-void X86InstrInfo::print(const MachineInstr *MI, std::ostream &O,
-                         const TargetMachine &TM) const {
+/// printMachineInstruction -- Print out an x86 instruction in intel syntax
+///
+void Printer::printMachineInstruction(const MachineInstr *MI, std::ostream &O,
+				      const TargetMachine &TM) const {
   unsigned Opcode = MI->getOpcode();
-  const TargetInstrDescriptor &Desc = get(Opcode);
+  const TargetInstrInfo &TII = TM.getInstrInfo();
+  const TargetInstrDescriptor &Desc = TII.get(Opcode);
+  const MRegisterInfo &RI = *TM.getRegisterInfo();
 
   switch (Desc.TSFlags & X86II::FormMask) {
   case X86II::Pseudo:
@@ -584,7 +600,7 @@
 	O << " = ";
 	++i;
       }
-      O << getName(MI->getOpcode());
+      O << TII.getName(MI->getOpcode());
 
       for (unsigned e = MI->getNumOperands(); i != e; ++i) {
 	O << " ";
@@ -610,7 +626,7 @@
 	     MI->getOperand(0).isGlobalAddress() ||
 	     MI->getOperand(0).isExternalSymbol())) &&
            "Illegal raw instruction!");
-    O << getName(MI->getOpcode()) << " ";
+    O << TII.getName(MI->getOpcode()) << " ";
 
     if (MI->getNumOperands() == 1) {
       printOp(O, MI->getOperand(0), RI, true); // Don't print "OFFSET"...
@@ -639,7 +655,7 @@
 
     unsigned Reg = MI->getOperand(0).getReg();
     
-    O << getName(MI->getOpCode()) << " ";
+    O << TII.getName(MI->getOpCode()) << " ";
     printOp(O, MI->getOperand(0), RI);
     if (MI->getNumOperands() == 2 &&
 	(!MI->getOperand(1).isRegister() ||
@@ -666,7 +682,7 @@
     // 4 Operands: This form is for instructions which are 3 operands forms, but
     // have a constant argument as well.
     //
-    bool isTwoAddr = isTwoAddrInstr(Opcode);
+    bool isTwoAddr = TII.isTwoAddrInstr(Opcode);
     assert(MI->getOperand(0).isRegister() &&
            (MI->getNumOperands() == 2 ||
 	    (isTwoAddr && MI->getOperand(1).isRegister() &&
@@ -675,7 +691,7 @@
 	      (MI->getNumOperands() == 4 && MI->getOperand(3).isImmediate()))))
            && "Bad format for MRMDestReg!");
 
-    O << getName(MI->getOpCode()) << " ";
+    O << TII.getName(MI->getOpCode()) << " ";
     printOp(O, MI->getOperand(0), RI);
     O << ", ";
     printOp(O, MI->getOperand(1+isTwoAddr), RI);
@@ -694,7 +710,7 @@
     assert(isMem(MI, 0) && MI->getNumOperands() == 4+1 &&
            MI->getOperand(4).isRegister() && "Bad format for MRMDestMem!");
 
-    O << getName(MI->getOpCode()) << " " << sizePtr(Desc) << " ";
+    O << TII.getName(MI->getOpCode()) << " " << sizePtr(Desc) << " ";
     printMemReference(O, MI, 0, RI);
     O << ", ";
     printOp(O, MI->getOperand(4), RI);
@@ -721,7 +737,7 @@
         MI->getOperand(0).getReg() != MI->getOperand(1).getReg())
       O << "**";
 
-    O << getName(MI->getOpCode()) << " ";
+    O << TII.getName(MI->getOpCode()) << " ";
     printOp(O, MI->getOperand(0), RI);
     O << ", ";
     printOp(O, MI->getOperand(MI->getNumOperands()-1), RI);
@@ -742,7 +758,7 @@
         MI->getOperand(0).getReg() != MI->getOperand(1).getReg())
       O << "**";
 
-    O << getName(MI->getOpCode()) << " ";
+    O << TII.getName(MI->getOpCode()) << " ";
     printOp(O, MI->getOperand(0), RI);
     O << ", " << sizePtr(Desc) << " ";
     printMemReference(O, MI, MI->getNumOperands()-4, RI);
@@ -773,12 +789,17 @@
         MI->getOperand(0).getReg() != MI->getOperand(1).getReg())
       O << "**";
 
-    O << getName(MI->getOpCode()) << " ";
+    O << TII.getName(MI->getOpCode()) << " ";
     printOp(O, MI->getOperand(0), RI);
     if (MI->getOperand(MI->getNumOperands()-1).isImmediate()) {
       O << ", ";
       printOp(O, MI->getOperand(MI->getNumOperands()-1), RI);
     }
+    if (Desc.TSFlags & X86II::PrintImplUses) {
+      for (const unsigned *p = Desc.ImplicitUses; *p; ++p) {
+	O << ", " << RI.get(*p).Name;
+      }
+    }
     O << "\n";
 
     return;
@@ -799,7 +820,7 @@
     assert((MI->getNumOperands() != 5 || MI->getOperand(4).isImmediate()) &&
            "Bad MRMSxM format!");
 
-    O << getName(MI->getOpCode()) << " ";
+    O << TII.getName(MI->getOpCode()) << " ";
     O << sizePtr(Desc) << " ";
     printMemReference(O, MI, 0, RI);
     if (MI->getNumOperands() == 5) {
@@ -821,9 +842,6 @@
   // with no % decorations on register names.
   O << "\t.intel_syntax noprefix\n";
 
-  // Start function index at 0
-  fnIndex = 0;
-
   // Ripped from CWriter:
   // Calculate which global values have names that will collide when we throw
   // away type information.
@@ -872,3 +890,5 @@
   MangledGlobals.clear();
   return false; // success
 }
+
+


Index: llvm/lib/Target/X86/X86InstrInfo.def
diff -u llvm/lib/Target/X86/X86InstrInfo.def:1.60 llvm/lib/Target/X86/X86InstrInfo.def:1.61
--- llvm/lib/Target/X86/X86InstrInfo.def:1.60	Sat Jun 21 12:13:35 2003
+++ llvm/lib/Target/X86/X86InstrInfo.def	Thu Jun 26 19:00:46 2003
@@ -220,29 +220,29 @@
 
 
 // Shift instructions
-I(SHLrr8      , "shl",  0xD2, M_2_ADDR_FLAG, X86II::MRMS4r, O_CL, NoIR)                                   // R8   <<= cl
-I(SHLrr16     , "shl",  0xD3, M_2_ADDR_FLAG, X86II::MRMS4r | X86II::OpSize, O_CL, NoIR)                   // R16  <<= cl
-I(SHLrr32     , "shl",  0xD3, M_2_ADDR_FLAG, X86II::MRMS4r, O_CL, NoIR)                                   // R32  <<= cl
+I(SHLrr8      , "shl",  0xD2, M_2_ADDR_FLAG, X86II::MRMS4r | X86II::PrintImplUses, O_CL, NoIR)            // R8   <<= cl
+I(SHLrr16     , "shl",  0xD3, M_2_ADDR_FLAG, X86II::MRMS4r | X86II::OpSize | X86II::PrintImplUses, O_CL, NoIR) // R16  <<= cl
+I(SHLrr32     , "shl",  0xD3, M_2_ADDR_FLAG, X86II::MRMS4r | X86II::PrintImplUses, O_CL, NoIR)            // R32  <<= cl
 I(SHLir8      , "shl",  0xC0, M_2_ADDR_FLAG, X86II::MRMS4r | X86II::Arg8, NoIR, NoIR)                     // R8   <<= imm8
 I(SHLir16     , "shl",  0xC1, M_2_ADDR_FLAG, X86II::MRMS4r | X86II::Arg8 | X86II::OpSize, NoIR, NoIR)     // R16  <<= imm8
 I(SHLir32     , "shl",  0xC1, M_2_ADDR_FLAG, X86II::MRMS4r | X86II::Arg8, NoIR, NoIR)                     // R32  <<= imm8
-I(SHRrr8      , "shr",  0xD2, M_2_ADDR_FLAG, X86II::MRMS5r, O_CL, NoIR)                                   // R8  >>>= cl
-I(SHRrr16     , "shr",  0xD3, M_2_ADDR_FLAG, X86II::MRMS5r | X86II::OpSize, O_CL, NoIR)                   // R16 >>>= cl
-I(SHRrr32     , "shr",  0xD3, M_2_ADDR_FLAG, X86II::MRMS5r, O_CL, NoIR)                                   // R32 >>>= cl
+I(SHRrr8      , "shr",  0xD2, M_2_ADDR_FLAG, X86II::MRMS5r | X86II::PrintImplUses, O_CL, NoIR)            // R8  >>>= cl
+I(SHRrr16     , "shr",  0xD3, M_2_ADDR_FLAG, X86II::MRMS5r | X86II::OpSize | X86II::PrintImplUses, O_CL, NoIR) // R16 >>>= cl
+I(SHRrr32     , "shr",  0xD3, M_2_ADDR_FLAG, X86II::MRMS5r | X86II::PrintImplUses, O_CL, NoIR)            // R32 >>>= cl
 I(SHRir8      , "shr",  0xC0, M_2_ADDR_FLAG, X86II::MRMS5r | X86II::Arg8, NoIR, NoIR)                     // R8  >>>= imm8
 I(SHRir16     , "shr",  0xC1, M_2_ADDR_FLAG, X86II::MRMS5r | X86II::Arg8 | X86II::OpSize, NoIR, NoIR)     // R16 >>>= imm8
 I(SHRir32     , "shr",  0xC1, M_2_ADDR_FLAG, X86II::MRMS5r | X86II::Arg8, NoIR, NoIR)                     // R32 >>>= imm8
-I(SARrr8      , "sar",  0xD2, M_2_ADDR_FLAG, X86II::MRMS7r, O_CL, NoIR)                                   // R8   >>= cl
-I(SARrr16     , "sar",  0xD3, M_2_ADDR_FLAG, X86II::MRMS7r | X86II::OpSize, O_CL, NoIR)                   // R16  >>= cl
-I(SARrr32     , "sar",  0xD3, M_2_ADDR_FLAG, X86II::MRMS7r, O_CL, NoIR)                                   // R32  >>= cl
+I(SARrr8      , "sar",  0xD2, M_2_ADDR_FLAG, X86II::MRMS7r | X86II::PrintImplUses, O_CL, NoIR)            // R8   >>= cl
+I(SARrr16     , "sar",  0xD3, M_2_ADDR_FLAG, X86II::MRMS7r | X86II::OpSize | X86II::PrintImplUses, O_CL, NoIR) // R16  >>= cl
+I(SARrr32     , "sar",  0xD3, M_2_ADDR_FLAG, X86II::MRMS7r | X86II::PrintImplUses, O_CL, NoIR)            // R32  >>= cl
 I(SARir8      , "sar",  0xC0, M_2_ADDR_FLAG, X86II::MRMS7r | X86II::Arg8, NoIR, NoIR)                     // R8   >>= imm8
 I(SARir16     , "sar",  0xC1, M_2_ADDR_FLAG, X86II::MRMS7r | X86II::Arg8 | X86II::OpSize, NoIR, NoIR)     // R16  >>= imm8
 I(SARir32     , "sar",  0xC1, M_2_ADDR_FLAG, X86II::MRMS7r | X86II::Arg8, NoIR, NoIR)                     // R32  >>= imm8
 
 I(SHLDir32    , "shld",  0xA4, M_2_ADDR_FLAG, X86II::MRMDestReg | X86II::TB | X86II::Arg8, NoIR, NoIR)    // R32 >>= R32,R32 imm8
-I(SHLDrr32    , "shld",  0xA5, M_2_ADDR_FLAG, X86II::MRMDestReg | X86II::TB, O_CL, NoIR)                  // R32 >>= R32,R32 cl
+I(SHLDrr32    , "shld",  0xA5, M_2_ADDR_FLAG, X86II::MRMDestReg | X86II::TB | X86II::PrintImplUses, O_CL, NoIR) // R32 >>= R32,R32 cl
 I(SHRDir32    , "shrd",  0xAC, M_2_ADDR_FLAG, X86II::MRMDestReg | X86II::TB | X86II::Arg8, NoIR, NoIR)    // R32 >>= R32,R32 imm8
-I(SHRDrr32    , "shrd",  0xAD, M_2_ADDR_FLAG, X86II::MRMDestReg | X86II::TB, O_CL, NoIR)                  // R32 >>= R32,R32 cl
+I(SHRDrr32    , "shrd",  0xAD, M_2_ADDR_FLAG, X86II::MRMDestReg | X86II::TB | X86II::PrintImplUses, O_CL, NoIR) // R32 >>= R32,R32 cl
 
 
 // Condition code ops, incl. set if equal/not equal/...


Index: llvm/lib/Target/X86/X86InstrInfo.h
diff -u llvm/lib/Target/X86/X86InstrInfo.h:1.23 llvm/lib/Target/X86/X86InstrInfo.h:1.24
--- llvm/lib/Target/X86/X86InstrInfo.h:1.23	Fri May 23 20:08:43 2003
+++ llvm/lib/Target/X86/X86InstrInfo.h	Thu Jun 26 19:00:46 2003
@@ -133,7 +133,10 @@
     // FPTypeMask - Mask for all of the FP types...
     FPTypeMask = 7 << 14,
 
-    // Bits 17 -> 31 are unused
+    // PrintImplUses - Print out implicit uses in the assembly output.
+    PrintImplUses = 1 << 17
+
+    // Bits 18 -> 31 are unused
   };
 }
 
@@ -159,11 +162,6 @@
   /// more than one way to `do nothing' but only one canonical way to slack off.
   ///
   bool isNOPinstr(const MachineInstr &MI) const;
-
-  /// print - Print out an x86 instruction in intel syntax
-  ///
-  virtual void print(const MachineInstr *MI, std::ostream &O,
-                     const TargetMachine &TM) const;
 
   // getBaseOpcodeFor - This function returns the "base" X86 opcode for the
   // specified opcode number.





More information about the llvm-commits mailing list