summaryrefslogtreecommitdiffstats
path: root/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp')
-rw-r--r--lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp122
1 files changed, 48 insertions, 74 deletions
diff --git a/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp b/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp
index 982ef5e..d8e8b79 100644
--- a/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp
+++ b/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp
@@ -17,16 +17,20 @@
#include "AlphaInstrInfo.h"
#include "AlphaTargetMachine.h"
#include "llvm/Module.h"
-#include "llvm/MDNode.h"
#include "llvm/Type.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/DwarfWriter.h"
-#include "llvm/Target/TargetAsmInfo.h"
+#include "llvm/MC/MCStreamer.h"
+#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCSymbol.h"
+#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetRegistry.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Mangler.h"
-#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/FormattedStream.h"
#include "llvm/ADT/Statistic.h"
using namespace llvm;
@@ -37,21 +41,22 @@ namespace {
/// Unique incrementer for label values for referencing Global values.
///
- explicit AlphaAsmPrinter(raw_ostream &o, TargetMachine &tm,
- const TargetAsmInfo *T, bool V)
+ explicit AlphaAsmPrinter(formatted_raw_ostream &o, TargetMachine &tm,
+ const MCAsmInfo *T, bool V)
: AsmPrinter(o, tm, T, V) {}
virtual const char *getPassName() const {
return "Alpha Assembly Printer";
}
- bool printInstruction(const MachineInstr *MI);
+ void printInstruction(const MachineInstr *MI);
+ static const char *getRegisterName(unsigned RegNo);
+
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);
- void printModuleLevelGV(const GlobalVariable* GVar);
+ void printBaseOffsetPair(const MachineInstr *MI, int i, bool brackets=true);
+ void PrintGlobalVariable(const GlobalVariable *GVar);
bool runOnMachineFunction(MachineFunction &F);
- bool doInitialization(Module &M);
- bool doFinalization(Module &M);
+ void EmitStartOfAsmFile(Module &M);
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
unsigned AsmVariant, const char *ExtraCode);
@@ -62,17 +67,6 @@ namespace {
};
} // end of anonymous namespace
-/// createAlphaCodePrinterPass - Returns a pass that prints the Alpha
-/// assembly code for a MachineFunction to the given output stream,
-/// using the given target machine description. This should work
-/// regardless of whether the function is in SSA form.
-///
-FunctionPass *llvm::createAlphaCodePrinterPass(raw_ostream &o,
- TargetMachine &tm,
- bool verbose) {
- return new AlphaAsmPrinter(o, tm, tm.getTargetAsmInfo(), verbose);
-}
-
#include "AlphaGenAsmWriter.inc"
void AlphaAsmPrinter::printOperand(const MachineInstr *MI, int opNum)
@@ -81,7 +75,7 @@ void AlphaAsmPrinter::printOperand(const MachineInstr *MI, int opNum)
if (MO.getType() == MachineOperand::MO_Register) {
assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
"Not physreg??");
- O << TM.getRegisterInfo()->get(MO.getReg()).AsmName;
+ O << getRegisterName(MO.getReg());
} else if (MO.isImm()) {
O << MO.getImm();
assert(MO.getImm() < (1 << 30));
@@ -92,24 +86,21 @@ void AlphaAsmPrinter::printOperand(const MachineInstr *MI, int opNum)
void AlphaAsmPrinter::printOp(const MachineOperand &MO, bool IsCallOp) {
- const TargetRegisterInfo &RI = *TM.getRegisterInfo();
-
switch (MO.getType()) {
case MachineOperand::MO_Register:
- O << RI.get(MO.getReg()).AsmName;
+ O << getRegisterName(MO.getReg());
return;
case MachineOperand::MO_Immediate:
- cerr << "printOp() does not handle immediate values\n";
- abort();
+ llvm_unreachable("printOp() does not handle immediate values");
return;
case MachineOperand::MO_MachineBasicBlock:
- printBasicBlockLabel(MO.getMBB());
+ GetMBBSymbol(MO.getMBB()->getNumber())->print(O, MAI);
return;
case MachineOperand::MO_ConstantPoolIndex:
- O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
+ O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
<< MO.getIndex();
return;
@@ -117,14 +108,12 @@ void AlphaAsmPrinter::printOp(const MachineOperand &MO, bool IsCallOp) {
O << MO.getSymbolName();
return;
- case MachineOperand::MO_GlobalAddress: {
- GlobalValue *GV = MO.getGlobal();
- O << Mang->getValueName(GV);
+ case MachineOperand::MO_GlobalAddress:
+ O << Mang->getMangledName(MO.getGlobal());
return;
- }
case MachineOperand::MO_JumpTableIndex:
- O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
+ O << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
<< '_' << MO.getIndex();
return;
@@ -151,13 +140,14 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// Print out labels for the function.
const Function *F = MF.getFunction();
- SwitchToSection(TAI->SectionForGlobal(F));
+ OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang, TM));
EmitAlignment(MF.getAlignment(), F);
switch (F->getLinkage()) {
- default: assert(0 && "Unknown linkage type!");
+ default: llvm_unreachable("Unknown linkage type!");
case Function::InternalLinkage: // Symbols default to internal.
case Function::PrivateLinkage:
+ case Function::LinkerPrivateLinkage:
break;
case Function::ExternalLinkage:
O << "\t.globl " << CurrentFnName << "\n";
@@ -166,7 +156,7 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
case Function::WeakODRLinkage:
case Function::LinkOnceAnyLinkage:
case Function::LinkOnceODRLinkage:
- O << TAI->getWeakRefDirective() << CurrentFnName << "\n";
+ O << MAI->getWeakRefDirective() << CurrentFnName << "\n";
break;
}
@@ -180,17 +170,19 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
I != E; ++I) {
if (I != MF.begin()) {
- printBasicBlockLabel(I, true, true);
- O << '\n';
+ EmitBasicBlockStart(I);
}
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
II != E; ++II) {
// Print the assembly for the instruction.
++EmittedInsts;
- if (!printInstruction(II)) {
- assert(0 && "Unhandled instruction in asm writer!");
- abort();
- }
+ processDebugLoc(II, true);
+ printInstruction(II);
+
+ if (VerboseAsm && !II->getDebugLoc().isUnknown())
+ EmitComments(*II);
+ O << '\n';
+ processDebugLoc(II, false);
}
}
@@ -200,17 +192,15 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
return false;
}
-bool AlphaAsmPrinter::doInitialization(Module &M)
-{
- if(TM.getSubtarget<AlphaSubtarget>().hasCT())
+void AlphaAsmPrinter::EmitStartOfAsmFile(Module &M) {
+ if (TM.getSubtarget<AlphaSubtarget>().hasCT())
O << "\t.arch ev6\n"; //This might need to be ev67, so leave this test here
else
O << "\t.arch ev6\n";
O << "\t.set noat\n";
- return AsmPrinter::doInitialization(M);
}
-void AlphaAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
+void AlphaAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
const TargetData *TD = TM.getTargetData();
if (!GVar->hasInitializer()) return; // External global require no code
@@ -219,15 +209,14 @@ void AlphaAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
if (EmitSpecialLLVMGlobal(GVar))
return;
- std::string name = Mang->getValueName(GVar);
+ std::string name = Mang->getMangledName(GVar);
Constant *C = GVar->getInitializer();
- if (isa<MDNode>(C) || isa<MDString>(C))
- return;
unsigned Size = TD->getTypeAllocSize(C->getType());
unsigned Align = TD->getPreferredAlignmentLog(GVar);
// 0: Switch to section
- SwitchToSection(TAI->SectionForGlobal(GVar));
+ OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(GVar, Mang,
+ TM));
// 1: Check visibility
printVisibility(name, GVar->getVisibility());
@@ -239,23 +228,22 @@ void AlphaAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
case GlobalValue::WeakAnyLinkage:
case GlobalValue::WeakODRLinkage:
case GlobalValue::CommonLinkage:
- O << TAI->getWeakRefDirective() << name << '\n';
+ O << MAI->getWeakRefDirective() << name << '\n';
break;
case GlobalValue::AppendingLinkage:
case GlobalValue::ExternalLinkage:
- O << TAI->getGlobalDirective() << name << "\n";
+ O << MAI->getGlobalDirective() << name << "\n";
break;
case GlobalValue::InternalLinkage:
case GlobalValue::PrivateLinkage:
+ case GlobalValue::LinkerPrivateLinkage:
break;
default:
- assert(0 && "Unknown linkage type!");
- cerr << "Unknown linkage type!\n";
- abort();
+ llvm_unreachable("Unknown linkage type!");
}
// 3: Type, Size, Align
- if (TAI->hasDotTypeDotSizeDirective()) {
+ if (MAI->hasDotTypeDotSizeDirective()) {
O << "\t.type\t" << name << ", @object\n";
O << "\t.size\t" << name << ", " << Size << "\n";
}
@@ -268,14 +256,6 @@ void AlphaAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
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);
-}
-
/// PrintAsmOperand - Print out an operand for an inline asm expression.
///
bool AlphaAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
@@ -298,12 +278,6 @@ bool AlphaAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
}
// Force static initialization.
-extern "C" void LLVMInitializeAlphaAsmPrinter() { }
-
-namespace {
- static struct Register {
- Register() {
- AlphaTargetMachine::registerAsmPrinter(createAlphaCodePrinterPass);
- }
- } Registrator;
+extern "C" void LLVMInitializeAlphaAsmPrinter() {
+ RegisterAsmPrinter<AlphaAsmPrinter> X(TheAlphaTarget);
}
OpenPOWER on IntegriCloud