From 05af2616d0df19638e799d3e7afadea26d96a4ba Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 13 Sep 2009 20:08:00 +0000 Subject: [PATCH] make tblgen produce a function that returns the name for a physreg. Nothing is using this info yet. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81707 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp | 2 + .../Alpha/AsmPrinter/AlphaAsmPrinter.cpp | 2 + .../AsmPrinter/BlackfinAsmPrinter.cpp | 2 + .../CellSPU/AsmPrinter/SPUAsmPrinter.cpp | 6 +-- .../MSP430/AsmPrinter/MSP430AsmPrinter.cpp | 2 + lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp | 2 + lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h | 2 + .../PowerPC/AsmPrinter/PPCAsmPrinter.cpp | 2 + .../Sparc/AsmPrinter/SparcAsmPrinter.cpp | 2 + .../SystemZ/AsmPrinter/SystemZAsmPrinter.cpp | 2 + lib/Target/X86/AsmPrinter/X86ATTInstPrinter.h | 5 +- .../X86/AsmPrinter/X86IntelAsmPrinter.h | 2 + .../XCore/AsmPrinter/XCoreAsmPrinter.cpp | 2 + utils/TableGen/AsmWriterEmitter.cpp | 54 ++++++++++++++++--- utils/TableGen/AsmWriterEmitter.h | 3 ++ 15 files changed, 78 insertions(+), 12 deletions(-) diff --git a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp index 745faa7f3f5..876c4c89de3 100644 --- a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp @@ -146,6 +146,8 @@ namespace { void PrintGlobalVariable(const GlobalVariable* GVar); void printInstruction(const MachineInstr *MI); // autogenerated. + const char *getRegisterName(unsigned RegNo) const; + void printMachineInstruction(const MachineInstr *MI); bool runOnMachineFunction(MachineFunction &F); bool doInitialization(Module &M); diff --git a/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp b/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp index f0b7fd7f615..74d398b2724 100644 --- a/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp +++ b/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp @@ -49,6 +49,8 @@ namespace { return "Alpha Assembly Printer"; } void printInstruction(const MachineInstr *MI); + const char *getRegisterName(unsigned RegNo) const; + void printOp(const MachineOperand &MO, bool IsCallOp = false); void printOperand(const MachineInstr *MI, int opNum); void printBaseOffsetPair(const MachineInstr *MI, int i, bool brackets=true); diff --git a/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp b/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp index d83d914ec58..96f4e784ba1 100644 --- a/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp +++ b/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp @@ -51,6 +51,8 @@ namespace { void printOperand(const MachineInstr *MI, int opNum); void printMemoryOperand(const MachineInstr *MI, int opNum); void printInstruction(const MachineInstr *MI); // autogenerated. + const char *getRegisterName(unsigned RegNo) const; + void emitLinkage(const std::string &n, GlobalValue::LinkageTypes l); bool runOnMachineFunction(MachineFunction &F); bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, diff --git a/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp b/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp index cc320e5a2bc..21e9be430b7 100644 --- a/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp +++ b/lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp @@ -66,10 +66,10 @@ namespace { } /// printInstruction - This method is automatically generated by tablegen - /// from the instruction set description. This method returns true if the - /// machine instruction was sufficiently described to print it, otherwise it - /// returns false. + /// from the instruction set description. void printInstruction(const MachineInstr *MI); + const char *getRegisterName(unsigned RegNo) const; + void printMachineInstruction(const MachineInstr *MI); void printOp(const MachineOperand &MO); diff --git a/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp b/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp index cd0eb9cbde3..c82f96d1dd7 100644 --- a/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp +++ b/lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp @@ -58,6 +58,8 @@ namespace { const char* Modifier = 0); void printCCOperand(const MachineInstr *MI, int OpNum); void printInstruction(const MachineInstr *MI); // autogenerated. + const char *getRegisterName(unsigned RegNo) const; + void printMachineInstruction(const MachineInstr * MI); bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, diff --git a/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp b/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp index f4a9b36da8f..b9d543edc84 100644 --- a/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp +++ b/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp @@ -82,6 +82,8 @@ namespace { void emitFrameDirective(MachineFunction &MF); void printInstruction(const MachineInstr *MI); // autogenerated. + const char *getRegisterName(unsigned RegNo) const; + bool runOnMachineFunction(MachineFunction &F); bool doInitialization(Module &M); }; diff --git a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h b/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h index 8510eaa6221..e671feb8632 100644 --- a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h +++ b/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h @@ -45,6 +45,8 @@ namespace llvm { void printOperand(const MachineInstr *MI, int opNum); void printCCOperand(const MachineInstr *MI, int opNum); void printInstruction(const MachineInstr *MI); // definition autogenerated. + const char *getRegisterName(unsigned RegNo) const; + bool printMachineInstruction(const MachineInstr *MI); void EmitFunctionDecls (Module &M); void EmitUndefinedVars (Module &M); diff --git a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp index f21d371a4c3..658ac317e00 100644 --- a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp @@ -120,6 +120,8 @@ namespace { /// machine instruction was sufficiently described to print it, otherwise it /// returns false. void printInstruction(const MachineInstr *MI); + const char *getRegisterName(unsigned RegNo) const; + void printMachineInstruction(const MachineInstr *MI); void printOp(const MachineOperand &MO); diff --git a/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp b/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp index 0d5b70dc899..15e7fb02b2b 100644 --- a/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp +++ b/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp @@ -68,6 +68,8 @@ namespace { void printCCOperand(const MachineInstr *MI, int opNum); void printInstruction(const MachineInstr *MI); // autogenerated. + const char *getRegisterName(unsigned RegNo) const; + bool runOnMachineFunction(MachineFunction &F); bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode); diff --git a/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp b/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp index 82890102544..64843c902c3 100644 --- a/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp +++ b/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp @@ -67,6 +67,8 @@ namespace { } void printInstruction(const MachineInstr *MI); // autogenerated. + const char *getRegisterName(unsigned RegNo) const; + void printMachineInstruction(const MachineInstr * MI); void emitFunctionHeader(const MachineFunction &MF); diff --git a/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.h b/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.h index 76f151d8897..4460e4b492e 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.h +++ b/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.h @@ -28,8 +28,11 @@ class X86ATTInstPrinter { public: X86ATTInstPrinter(raw_ostream &o, const MCAsmInfo *mai, const TargetRegisterInfo *tri) : O(o), MAI(mai), TRI(tri) {} - + + // Autogenerated by tblgen. void printInstruction(const MCInst *MI); + const char *getRegisterName(unsigned RegNo) const; + void printOperand(const MCInst *MI, unsigned OpNo, const char *Modifier = 0); diff --git a/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.h b/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.h index 30505bfb7ee..222d2294c34 100644 --- a/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.h +++ b/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.h @@ -38,6 +38,8 @@ struct VISIBILITY_HIDDEN X86IntelAsmPrinter : public AsmPrinter { /// machine instruction was sufficiently described to print it, otherwise it /// returns false. void printInstruction(const MachineInstr *MI); + const char *getRegisterName(unsigned RegNo) const; + // This method is used by the tablegen'erated instruction printer. void printOperand(const MachineInstr *MI, unsigned OpNo, diff --git a/lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp b/lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp index bdb44efa2ee..5fe9b2bbf46 100644 --- a/lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp +++ b/lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp @@ -80,6 +80,8 @@ namespace { void emitFunctionEnd(MachineFunction &MF); void printInstruction(const MachineInstr *MI); // autogenerated. + const char *getRegisterName(unsigned RegNo) const; + void printMachineInstruction(const MachineInstr *MI); bool runOnMachineFunction(MachineFunction &F); bool doInitialization(Module &M); diff --git a/utils/TableGen/AsmWriterEmitter.cpp b/utils/TableGen/AsmWriterEmitter.cpp index a6f614958be..0455c9b5e81 100644 --- a/utils/TableGen/AsmWriterEmitter.cpp +++ b/utils/TableGen/AsmWriterEmitter.cpp @@ -538,19 +538,16 @@ FindUniqueOperandCommands(std::vector &UniqueOperandCommands, } - -void AsmWriterEmitter::run(raw_ostream &O) { - EmitSourceFileHeader("Assembly Writer Source Fragment", O); - +/// EmitPrintInstruction - Generate the code for the "printInstruction" method +/// implementation. +void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { CodeGenTarget Target; Record *AsmWriter = Target.getAsmWriter(); std::string ClassName = AsmWriter->getValueAsString("AsmWriterClassName"); - + O << "/// printInstruction - This method is automatically generated by tablegen\n" - "/// from the instruction set description. This method returns true if the\n" - "/// machine instruction was sufficiently described to print it, otherwise\n" - "/// it returns false.\n" + "/// from the instruction set description.\n" "void " << Target.getName() << ClassName << "::printInstruction(const MachineInstr *MI) {\n"; @@ -794,3 +791,44 @@ void AsmWriterEmitter::run(raw_ostream &O) { O << " return;\n"; O << "}\n"; } + + +void AsmWriterEmitter::EmitGetRegisterName(raw_ostream &O) { + CodeGenTarget Target; + Record *AsmWriter = Target.getAsmWriter(); + std::string ClassName = AsmWriter->getValueAsString("AsmWriterClassName"); + const std::vector &Registers = Target.getRegisters(); + + O << + "\n\n/// getRegisterName - This method is automatically generated by tblgen\n" + "/// from the register set description. This returns the assembler name\n" + "/// for the specified register.\n" + "const char *" << Target.getName() << ClassName + << "::getRegisterName(unsigned RegNo) const {\n" + << " assert(RegNo && RegNo < " << (Registers.size()+1) + << " && \"Invalid register number!\");\n" + << "\n" + << " static const char *const RegAsmNames[] = {\n"; + for (unsigned i = 0, e = Registers.size(); i != e; ++i) { + const CodeGenRegister &Reg = Registers[i]; + + std::string AsmName = Reg.TheDef->getValueAsString("AsmName"); + if (AsmName.empty()) + AsmName = Reg.getName(); + O << " \"" << AsmName << "\",\n"; + } + O << " 0\n" + << " };\n" + << "\n" + << " return RegAsmNames[RegNo-1];\n" + << "}\n"; +} + + +void AsmWriterEmitter::run(raw_ostream &O) { + EmitSourceFileHeader("Assembly Writer Source Fragment", O); + + EmitPrintInstruction(O); + EmitGetRegisterName(O); +} + diff --git a/utils/TableGen/AsmWriterEmitter.h b/utils/TableGen/AsmWriterEmitter.h index 75e69964ef8..7862caa25a8 100644 --- a/utils/TableGen/AsmWriterEmitter.h +++ b/utils/TableGen/AsmWriterEmitter.h @@ -35,6 +35,9 @@ namespace llvm { void run(raw_ostream &o); private: + void EmitPrintInstruction(raw_ostream &o); + void EmitGetRegisterName(raw_ostream &o); + AsmWriterInst *getAsmWriterInstByID(unsigned ID) const { assert(ID < NumberedInstructions.size()); std::map::const_iterator I =