Switch Alpha to new section handling stuff

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54457 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Anton Korobeynikov
2008-08-07 09:53:57 +00:00
parent fcd99bb428
commit 79579c911f

View File

@@ -46,15 +46,16 @@ namespace {
void printOp(const MachineOperand &MO, bool IsCallOp = false); void printOp(const MachineOperand &MO, bool IsCallOp = false);
void printOperand(const MachineInstr *MI, int opNum); void printOperand(const MachineInstr *MI, int opNum);
void printBaseOffsetPair (const MachineInstr *MI, int i, bool brackets=true); void printBaseOffsetPair (const MachineInstr *MI, int i, bool brackets=true);
void printModuleLevelGV(const GlobalVariable* GVar);
bool runOnMachineFunction(MachineFunction &F); bool runOnMachineFunction(MachineFunction &F);
bool doInitialization(Module &M); bool doInitialization(Module &M);
bool doFinalization(Module &M); bool doFinalization(Module &M);
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
unsigned AsmVariant, const char *ExtraCode); unsigned AsmVariant, const char *ExtraCode);
bool PrintAsmMemoryOperand(const MachineInstr *MI, bool PrintAsmMemoryOperand(const MachineInstr *MI,
unsigned OpNo, unsigned OpNo,
unsigned AsmVariant, unsigned AsmVariant,
const char *ExtraCode); const char *ExtraCode);
}; };
} // end of anonymous namespace } // end of anonymous namespace
@@ -148,7 +149,7 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// Print out labels for the function. // Print out labels for the function.
const Function *F = MF.getFunction(); const Function *F = MF.getFunction();
SwitchToTextSection(getSectionForFunction(*F).c_str(), F); SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
EmitAlignment(4, F); EmitAlignment(4, F);
switch (F->getLinkage()) { switch (F->getLinkage()) {
default: assert(0 && "Unknown linkage type!"); default: assert(0 && "Unknown linkage type!");
@@ -201,36 +202,38 @@ bool AlphaAsmPrinter::doInitialization(Module &M)
return AsmPrinter::doInitialization(M); return AsmPrinter::doInitialization(M);
} }
bool AlphaAsmPrinter::doFinalization(Module &M) { void AlphaAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
const TargetData *TD = TM.getTargetData(); const TargetData *TD = TM.getTargetData();
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) { if (!GVar->hasInitializer()) return; // External global require no code
if (!I->hasInitializer()) continue; // External global require no code // Check to see if this is a special global used by LLVM, if so, emit it.
if (EmitSpecialLLVMGlobal(GVar))
// Check to see if this is a special global used by LLVM, if so, emit it. return;
if (EmitSpecialLLVMGlobal(I))
continue; std::string SectionName = TAI->SectionForGlobal(GVar);
std::string name = Mang->getValueName(GVar);
std::string name = Mang->getValueName(I); Constant *C = GVar->getInitializer();
Constant *C = I->getInitializer(); unsigned Size = TD->getABITypeSize(C->getType());
unsigned Size = TD->getABITypeSize(C->getType()); unsigned Align = TD->getPreferredAlignmentLog(GVar);
unsigned Align = TD->getPreferredAlignmentLog(I);
// 0: Switch to section
//1: hidden? SwitchToDataSection(SectionName.c_str());
if (I->hasHiddenVisibility())
O << TAI->getHiddenDirective() << name << "\n"; // 1: Check visibility
if (GVar->hasHiddenVisibility())
//2: kind O << TAI->getHiddenDirective() << name << "\n";
switch (I->getLinkage()) {
case GlobalValue::LinkOnceLinkage: // 2: Kind
case GlobalValue::WeakLinkage: switch (GVar->getLinkage()) {
case GlobalValue::CommonLinkage: case GlobalValue::LinkOnceLinkage:
O << TAI->getWeakRefDirective() << name << '\n'; case GlobalValue::WeakLinkage:
break; case GlobalValue::CommonLinkage:
case GlobalValue::AppendingLinkage: O << TAI->getWeakRefDirective() << name << '\n';
case GlobalValue::ExternalLinkage: break;
O << "\t.globl " << name << "\n"; case GlobalValue::AppendingLinkage:
case GlobalValue::ExternalLinkage:
O << TAI->getGlobalDirective() << name << "\n";
break; break;
case GlobalValue::InternalLinkage: case GlobalValue::InternalLinkage:
break; break;
@@ -239,53 +242,47 @@ bool AlphaAsmPrinter::doFinalization(Module &M) {
cerr << "Unknown linkage type!\n"; cerr << "Unknown linkage type!\n";
abort(); abort();
} }
//3: Section (if changed) // 3: Type, Size, Align
if (I->hasSection() && if (TAI->hasDotTypeDotSizeDirective()) {
(I->getSection() == ".ctors" ||
I->getSection() == ".dtors")) {
std::string SectionName = ".section\t" + I->getSection()
+ ",\"aw\",@progbits";
SwitchToDataSection(SectionName.c_str());
} else {
if (C->isNullValue())
SwitchToDataSection("\t.section\t.bss", I);
else
SwitchToDataSection("\t.section\t.data", I);
}
//4: Type, Size, Align
O << "\t.type\t" << name << ", @object\n"; O << "\t.type\t" << name << ", @object\n";
O << "\t.size\t" << name << ", " << Size << "\n"; O << "\t.size\t" << name << ", " << Size << "\n";
EmitAlignment(Align, I);
O << name << ":\n";
// If the initializer is a extern weak symbol, remember to emit the weak
// reference!
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
EmitGlobalConstant(C);
O << '\n';
} }
EmitAlignment(Align, GVar);
O << name << ":\n";
// If the initializer is a extern weak symbol, remember to emit the weak
// reference!
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
EmitGlobalConstant(C);
O << '\n';
}
bool AlphaAsmPrinter::doFinalization(Module &M) {
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I)
printModuleLevelGV(I);
return AsmPrinter::doFinalization(M); return AsmPrinter::doFinalization(M);
} }
/// PrintAsmOperand - Print out an operand for an inline asm expression. /// PrintAsmOperand - Print out an operand for an inline asm expression.
/// ///
bool AlphaAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, bool AlphaAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
unsigned AsmVariant, unsigned AsmVariant,
const char *ExtraCode) { const char *ExtraCode) {
printOperand(MI, OpNo); printOperand(MI, OpNo);
return false; return false;
} }
bool AlphaAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, bool AlphaAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
unsigned OpNo, unsigned OpNo,
unsigned AsmVariant, unsigned AsmVariant,
const char *ExtraCode) { const char *ExtraCode) {
if (ExtraCode && ExtraCode[0]) if (ExtraCode && ExtraCode[0])
return true; // Unknown modifier. return true; // Unknown modifier.