Start using alignment output routines from AsmPrinter.

Changes to make this more similar to the X86 asmprinter

Fix overalignment of globals.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15891 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2004-08-17 19:26:03 +00:00
parent c6393f82bf
commit 69d485e646
2 changed files with 24 additions and 24 deletions

View File

@ -49,6 +49,7 @@ namespace {
GlobalPrefix = "_"; GlobalPrefix = "_";
ZeroDirective = "\t.space\t"; // ".space N" emits N zeros. ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
Data64bitsDirective = 0; // we can't emit a 64-bit unit Data64bitsDirective = 0; // we can't emit a 64-bit unit
AlignmentIsInBytes = false; // Alignment is by power of 2.
} }
/// Unique incrementer for label values for referencing Global values. /// Unique incrementer for label values for referencing Global values.
@ -121,9 +122,8 @@ void PPC32AsmPrinter::printConstantPool(MachineConstantPool *MCP) {
for (unsigned i = 0, e = CP.size(); i != e; ++i) { for (unsigned i = 0, e = CP.size(); i != e; ++i) {
O << "\t.const\n"; O << "\t.const\n";
O << "\t.align " << (unsigned)TD.getTypeAlignment(CP[i]->getType()) emitAlignment(TD.getTypeAlignmentShift(CP[i]->getType()));
<< "\n"; O << ".CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t" << CommentChar
O << ".CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t;"
<< *CP[i] << "\n"; << *CP[i] << "\n";
emitGlobalConstant(CP[i]); emitGlobalConstant(CP[i]);
} }
@ -140,19 +140,19 @@ bool PPC32AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
printConstantPool(MF.getConstantPool()); printConstantPool(MF.getConstantPool());
// Print out labels for the function. // Print out labels for the function.
O << "\t.text\n"; O << "\t.text\n";
emitAlignment(2);
O << "\t.globl\t" << CurrentFnName << "\n"; O << "\t.globl\t" << CurrentFnName << "\n";
O << "\t.align 2\n";
O << CurrentFnName << ":\n"; O << CurrentFnName << ":\n";
// Print out code for the function. // Print out code for the function.
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
I != E; ++I) { I != E; ++I) {
// Print a label for the basic block. // Print a label for the basic block.
O << ".LBB" << CurrentFnName << "_" << I->getNumber() << ":\t; " O << ".LBB" << CurrentFnName << "_" << I->getNumber() << ":\t"
<< I->getBasicBlock()->getName() << "\n"; << CommentChar << " " << I->getBasicBlock()->getName() << "\n";
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
II != E; ++II) { II != E; ++II) {
// Print the assembly for the instruction. // Print the assembly for the instruction.
O << "\t"; O << "\t";
printMachineInstruction(II); printMachineInstruction(II);
@ -399,14 +399,14 @@ bool PPC32AsmPrinter::doFinalization(Module &M) {
std::string name = Mang->getValueName(I); std::string name = Mang->getValueName(I);
Constant *C = I->getInitializer(); Constant *C = I->getInitializer();
unsigned Size = TD.getTypeSize(C->getType()); unsigned Size = TD.getTypeSize(C->getType());
unsigned Align = TD.getTypeAlignment(C->getType()); unsigned Align = TD.getTypeAlignmentShift(C->getType());
if (C->isNullValue() && /* FIXME: Verify correct */ if (C->isNullValue() && /* FIXME: Verify correct */
(I->hasInternalLinkage() || I->hasWeakLinkage())) { (I->hasInternalLinkage() || I->hasWeakLinkage())) {
SwitchSection(O, CurSection, ".data"); SwitchSection(O, CurSection, ".data");
if (I->hasInternalLinkage()) if (I->hasInternalLinkage())
O << ".lcomm " << name << "," << TD.getTypeSize(C->getType()) O << ".lcomm " << name << "," << TD.getTypeSize(C->getType())
<< "," << (unsigned)TD.getTypeAlignment(C->getType()); << "," << Align;
else else
O << ".comm " << name << "," << TD.getTypeSize(C->getType()); O << ".comm " << name << "," << TD.getTypeSize(C->getType());
O << "\t\t; "; O << "\t\t; ";
@ -439,7 +439,7 @@ bool PPC32AsmPrinter::doFinalization(Module &M) {
break; break;
} }
O << "\t.align " << Align << "\n"; emitAlignment(Align);
O << name << ":\t\t\t\t; "; O << name << ":\t\t\t\t; ";
WriteAsOperand(O, I, true, true, &M); WriteAsOperand(O, I, true, true, &M);
O << " = "; O << " = ";
@ -455,7 +455,7 @@ bool PPC32AsmPrinter::doFinalization(Module &M) {
{ {
O << ".data\n"; O << ".data\n";
O << ".section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32\n"; O << ".section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32\n";
O << "\t.align 2\n"; emitAlignment(2);
O << "L" << *i << "$stub:\n"; O << "L" << *i << "$stub:\n";
O << "\t.indirect_symbol " << *i << "\n"; O << "\t.indirect_symbol " << *i << "\n";
O << "\tmflr r0\n"; O << "\tmflr r0\n";

View File

@ -49,6 +49,7 @@ namespace {
GlobalPrefix = "_"; GlobalPrefix = "_";
ZeroDirective = "\t.space\t"; // ".space N" emits N zeros. ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
Data64bitsDirective = 0; // we can't emit a 64-bit unit Data64bitsDirective = 0; // we can't emit a 64-bit unit
AlignmentIsInBytes = false; // Alignment is by power of 2.
} }
/// Unique incrementer for label values for referencing Global values. /// Unique incrementer for label values for referencing Global values.
@ -121,9 +122,8 @@ void PPC32AsmPrinter::printConstantPool(MachineConstantPool *MCP) {
for (unsigned i = 0, e = CP.size(); i != e; ++i) { for (unsigned i = 0, e = CP.size(); i != e; ++i) {
O << "\t.const\n"; O << "\t.const\n";
O << "\t.align " << (unsigned)TD.getTypeAlignment(CP[i]->getType()) emitAlignment(TD.getTypeAlignmentShift(CP[i]->getType()));
<< "\n"; O << ".CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t" << CommentChar
O << ".CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t;"
<< *CP[i] << "\n"; << *CP[i] << "\n";
emitGlobalConstant(CP[i]); emitGlobalConstant(CP[i]);
} }
@ -140,19 +140,19 @@ bool PPC32AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
printConstantPool(MF.getConstantPool()); printConstantPool(MF.getConstantPool());
// Print out labels for the function. // Print out labels for the function.
O << "\t.text\n"; O << "\t.text\n";
emitAlignment(2);
O << "\t.globl\t" << CurrentFnName << "\n"; O << "\t.globl\t" << CurrentFnName << "\n";
O << "\t.align 2\n";
O << CurrentFnName << ":\n"; O << CurrentFnName << ":\n";
// Print out code for the function. // Print out code for the function.
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
I != E; ++I) { I != E; ++I) {
// Print a label for the basic block. // Print a label for the basic block.
O << ".LBB" << CurrentFnName << "_" << I->getNumber() << ":\t; " O << ".LBB" << CurrentFnName << "_" << I->getNumber() << ":\t"
<< I->getBasicBlock()->getName() << "\n"; << CommentChar << " " << I->getBasicBlock()->getName() << "\n";
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
II != E; ++II) { II != E; ++II) {
// Print the assembly for the instruction. // Print the assembly for the instruction.
O << "\t"; O << "\t";
printMachineInstruction(II); printMachineInstruction(II);
@ -399,14 +399,14 @@ bool PPC32AsmPrinter::doFinalization(Module &M) {
std::string name = Mang->getValueName(I); std::string name = Mang->getValueName(I);
Constant *C = I->getInitializer(); Constant *C = I->getInitializer();
unsigned Size = TD.getTypeSize(C->getType()); unsigned Size = TD.getTypeSize(C->getType());
unsigned Align = TD.getTypeAlignment(C->getType()); unsigned Align = TD.getTypeAlignmentShift(C->getType());
if (C->isNullValue() && /* FIXME: Verify correct */ if (C->isNullValue() && /* FIXME: Verify correct */
(I->hasInternalLinkage() || I->hasWeakLinkage())) { (I->hasInternalLinkage() || I->hasWeakLinkage())) {
SwitchSection(O, CurSection, ".data"); SwitchSection(O, CurSection, ".data");
if (I->hasInternalLinkage()) if (I->hasInternalLinkage())
O << ".lcomm " << name << "," << TD.getTypeSize(C->getType()) O << ".lcomm " << name << "," << TD.getTypeSize(C->getType())
<< "," << (unsigned)TD.getTypeAlignment(C->getType()); << "," << Align;
else else
O << ".comm " << name << "," << TD.getTypeSize(C->getType()); O << ".comm " << name << "," << TD.getTypeSize(C->getType());
O << "\t\t; "; O << "\t\t; ";
@ -439,7 +439,7 @@ bool PPC32AsmPrinter::doFinalization(Module &M) {
break; break;
} }
O << "\t.align " << Align << "\n"; emitAlignment(Align);
O << name << ":\t\t\t\t; "; O << name << ":\t\t\t\t; ";
WriteAsOperand(O, I, true, true, &M); WriteAsOperand(O, I, true, true, &M);
O << " = "; O << " = ";
@ -455,7 +455,7 @@ bool PPC32AsmPrinter::doFinalization(Module &M) {
{ {
O << ".data\n"; O << ".data\n";
O << ".section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32\n"; O << ".section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32\n";
O << "\t.align 2\n"; emitAlignment(2);
O << "L" << *i << "$stub:\n"; O << "L" << *i << "$stub:\n";
O << "\t.indirect_symbol " << *i << "\n"; O << "\t.indirect_symbol " << *i << "\n";
O << "\tmflr r0\n"; O << "\tmflr r0\n";