diff --git a/lib/Target/Sparc/SparcAsmPrinter.cpp b/lib/Target/Sparc/SparcAsmPrinter.cpp index 8473c1556fb..8c275015758 100644 --- a/lib/Target/Sparc/SparcAsmPrinter.cpp +++ b/lib/Target/Sparc/SparcAsmPrinter.cpp @@ -35,7 +35,11 @@ namespace { Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed"); struct SparcV8AsmPrinter : public AsmPrinter { - SparcV8AsmPrinter(std::ostream &O, TargetMachine &TM) : AsmPrinter(O, TM) {} + SparcV8AsmPrinter(std::ostream &O, TargetMachine &TM) : AsmPrinter(O, TM) { + Data16bitsDirective = "\t.half\t"; + Data32bitsDirective = "\t.word\t"; + Data64bitsDirective = "\t.xword\t"; + } /// We name each basic block in a Function with a unique number, so /// that we can consistently refer to them later. This is cleared @@ -50,7 +54,6 @@ namespace { void emitConstantValueOnly(const Constant *CV); void emitGlobalConstant(const Constant *CV); - void printConstantPool(MachineConstantPool *MCP); void printOperand(const MachineInstr *MI, int opNum); bool printInstruction(const MachineInstr *MI); // autogenerated. bool runOnMachineFunction(MachineFunction &F); @@ -277,33 +280,15 @@ void SparcV8AsmPrinter::emitGlobalConstant(const Constant *CV) { O << "\n"; } -/// printConstantPool - Print to the current output stream assembly -/// representations of the constants in the constant pool MCP. This is -/// used to print out constants which have been "spilled to memory" by -/// the code generator. -/// -void SparcV8AsmPrinter::printConstantPool(MachineConstantPool *MCP) { - const std::vector &CP = MCP->getConstants(); - const TargetData &TD = TM.getTargetData(); - - if (CP.empty()) return; - - SwitchSection(".section \".rodata\"\n", 0); - for (unsigned i = 0, e = CP.size(); i != e; ++i) { - O << "\t.align " << (unsigned)TD.getTypeAlignment(CP[i]->getType()) - << "\n"; - O << ".CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t!" - << *CP[i] << "\n"; - emitGlobalConstant(CP[i]); - } -} - /// runOnMachineFunction - This uses the printMachineInstruction() /// method to print assembly for each instruction. /// bool SparcV8AsmPrinter::runOnMachineFunction(MachineFunction &MF) { SetupMachineFunction(MF); + // Print out constants referenced by the function + EmitConstantPool(MF.getConstantPool()); + // BBNumber is used here so that a given Printer will never give two // BBs the same name. (If you have a better way, please let me know!) static unsigned BBNumber = 0; @@ -312,9 +297,6 @@ bool SparcV8AsmPrinter::runOnMachineFunction(MachineFunction &MF) { // What's my mangled name? CurrentFnName = Mang->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"; @@ -398,7 +380,8 @@ void SparcV8AsmPrinter::printOperand(const MachineInstr *MI, int opNum) { O << MO.getSymbolName(); break; case MachineOperand::MO_ConstantPoolIndex: - O << ".CPI" << CurrentFnName << "_" << MO.getConstantPoolIndex(); + O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_" + << MO.getConstantPoolIndex(); break; default: O << ""; abort (); break; diff --git a/lib/Target/SparcV8/SparcV8AsmPrinter.cpp b/lib/Target/SparcV8/SparcV8AsmPrinter.cpp index 8473c1556fb..8c275015758 100644 --- a/lib/Target/SparcV8/SparcV8AsmPrinter.cpp +++ b/lib/Target/SparcV8/SparcV8AsmPrinter.cpp @@ -35,7 +35,11 @@ namespace { Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed"); struct SparcV8AsmPrinter : public AsmPrinter { - SparcV8AsmPrinter(std::ostream &O, TargetMachine &TM) : AsmPrinter(O, TM) {} + SparcV8AsmPrinter(std::ostream &O, TargetMachine &TM) : AsmPrinter(O, TM) { + Data16bitsDirective = "\t.half\t"; + Data32bitsDirective = "\t.word\t"; + Data64bitsDirective = "\t.xword\t"; + } /// We name each basic block in a Function with a unique number, so /// that we can consistently refer to them later. This is cleared @@ -50,7 +54,6 @@ namespace { void emitConstantValueOnly(const Constant *CV); void emitGlobalConstant(const Constant *CV); - void printConstantPool(MachineConstantPool *MCP); void printOperand(const MachineInstr *MI, int opNum); bool printInstruction(const MachineInstr *MI); // autogenerated. bool runOnMachineFunction(MachineFunction &F); @@ -277,33 +280,15 @@ void SparcV8AsmPrinter::emitGlobalConstant(const Constant *CV) { O << "\n"; } -/// printConstantPool - Print to the current output stream assembly -/// representations of the constants in the constant pool MCP. This is -/// used to print out constants which have been "spilled to memory" by -/// the code generator. -/// -void SparcV8AsmPrinter::printConstantPool(MachineConstantPool *MCP) { - const std::vector &CP = MCP->getConstants(); - const TargetData &TD = TM.getTargetData(); - - if (CP.empty()) return; - - SwitchSection(".section \".rodata\"\n", 0); - for (unsigned i = 0, e = CP.size(); i != e; ++i) { - O << "\t.align " << (unsigned)TD.getTypeAlignment(CP[i]->getType()) - << "\n"; - O << ".CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t!" - << *CP[i] << "\n"; - emitGlobalConstant(CP[i]); - } -} - /// runOnMachineFunction - This uses the printMachineInstruction() /// method to print assembly for each instruction. /// bool SparcV8AsmPrinter::runOnMachineFunction(MachineFunction &MF) { SetupMachineFunction(MF); + // Print out constants referenced by the function + EmitConstantPool(MF.getConstantPool()); + // BBNumber is used here so that a given Printer will never give two // BBs the same name. (If you have a better way, please let me know!) static unsigned BBNumber = 0; @@ -312,9 +297,6 @@ bool SparcV8AsmPrinter::runOnMachineFunction(MachineFunction &MF) { // What's my mangled name? CurrentFnName = Mang->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"; @@ -398,7 +380,8 @@ void SparcV8AsmPrinter::printOperand(const MachineInstr *MI, int opNum) { O << MO.getSymbolName(); break; case MachineOperand::MO_ConstantPoolIndex: - O << ".CPI" << CurrentFnName << "_" << MO.getConstantPoolIndex(); + O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_" + << MO.getConstantPoolIndex(); break; default: O << ""; abort (); break;