From c12430644a9f49a056286f8ebe0e55ccc23bdde0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 20 Jun 2009 07:03:18 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73817 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCInst.h | 23 ++++++++++++- include/llvm/Target/Target.td | 1 + .../X86/AsmPrinter/X86ATTAsmPrinter.cpp | 33 +++++++++++++++++-- lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h | 8 ++--- .../X86/AsmPrinter/X86ATTInstPrinter.cpp | 31 ++++++++++------- lib/Target/X86/X86Instr64bit.td | 1 + 6 files changed, 78 insertions(+), 19 deletions(-) diff --git a/include/llvm/MC/MCInst.h b/include/llvm/MC/MCInst.h index 8eaec7b3720..cadc23ab710 100644 --- a/include/llvm/MC/MCInst.h +++ b/include/llvm/MC/MCInst.h @@ -29,13 +29,18 @@ class MCOperand { 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 @@ public: 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 @@ public: 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 @@ public: Kind = kImmediate; ImmVal = Val; } + void MakeMBBLabel(unsigned Fn, unsigned MBB) { + Kind = kMBBLabel; + MBBLabel.FunctionNo = Fn; + MBBLabel.BlockNo = MBB; + } }; @@ -91,6 +111,7 @@ public: 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); diff --git a/include/llvm/Target/Target.td b/include/llvm/Target/Target.td index 3f1cdd27ca3..ebd826a6f4a 100644 --- a/include/llvm/Target/Target.td +++ b/include/llvm/Target/Target.td @@ -274,6 +274,7 @@ def unknown; class Operand { ValueType Type = ty; string PrintMethod = "printOperand"; + string AsmOperandLowerMethod = ?; dag MIOperandInfo = (ops); } diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp index a34b6750332..059bb34bfe0 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp @@ -762,6 +762,18 @@ bool X86ATTAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, 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 @@ void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) { ++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 @@ void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) { 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 @@ void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) { 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. diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h index fb3a354ec58..2f28cf56b3c 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h +++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h @@ -70,10 +70,8 @@ class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter { 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 @@ class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter { printLeaMemReference(MI, OpNo); } void printlea64_32mem(const MCInst *MI, unsigned OpNo) { - printLeaMemReference(MI, OpNo, "subreg64"); + printLeaMemReference(MI, OpNo); } diff --git a/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp index 0267c4e5807..0311a10a171 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp @@ -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 @@ using namespace llvm; #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::printPICLabel(const MCInst *MI, unsigned Op) { 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 @@ void X86ATTAsmPrinter::printOperand(const MCInst *MI, unsigned OpNo, 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 << "<>"; @@ -338,9 +347,10 @@ void X86ATTAsmPrinter::printOperand(const MCInst *MI, unsigned OpNo, #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::printLeaMemReference(const MCInst *MI, unsigned Op, } } -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); } diff --git a/lib/Target/X86/X86Instr64bit.td b/lib/Target/X86/X86Instr64bit.td index ee0f0f43e1a..f2821287e6f 100644 --- a/lib/Target/X86/X86Instr64bit.td +++ b/lib/Target/X86/X86Instr64bit.td @@ -29,6 +29,7 @@ def lea64mem : Operand { def lea64_32mem : Operand { let PrintMethod = "printlea64_32mem"; + let AsmOperandLowerMethod = "lower_lea64_32mem"; let MIOperandInfo = (ops GR32, i8imm, GR32, i32imm); }