1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

clean up the asmprinter header and privatize some stuff.

llvm-svn: 100342
This commit is contained in:
Chris Lattner 2010-04-04 18:52:31 +00:00
parent dd1f2b6e33
commit 328ffc8c32
6 changed files with 114 additions and 96 deletions

View File

@ -56,18 +56,10 @@ namespace llvm {
/// AsmPrinter - This class is intended to be used as a driving class for all
/// asm writers.
class AsmPrinter : public MachineFunctionPass {
static char ID;
/// If VerboseAsm is set, a pointer to the loop info for this
/// function.
///
MachineLoopInfo *LI;
protected:
public:
/// DW - If available, this is a pointer to the current dwarf writer.
DwarfWriter *DW;
public:
/// Target machine description.
///
@ -103,10 +95,6 @@ namespace llvm {
///
MCSymbol *CurrentFnSym;
/// VerboseAsm - Emit comments in assembly output if this is true.
///
bool VerboseAsm;
/// getObjFileLowering - Return information about object file lowering.
TargetLoweringObjectFile &getObjFileLowering() const;
@ -117,6 +105,16 @@ namespace llvm {
// GCMetadataPrinters - The garbage collection metadata printer table.
void *GCMetadataPrinters; // Really a DenseMap.
/// VerboseAsm - Emit comments in assembly output if this is true.
///
bool VerboseAsm;
static char ID;
/// If VerboseAsm is set, a pointer to the loop info for this
/// function.
///
MachineLoopInfo *LI;
protected:
explicit AsmPrinter(TargetMachine &TM, MCStreamer &Streamer);
@ -131,6 +129,10 @@ namespace llvm {
///
unsigned getFunctionNumber() const;
//===------------------------------------------------------------------===//
// MachineFunctionPass Implementation.
//===------------------------------------------------------------------===//
/// getAnalysisUsage - Record analysis usage.
///
void getAnalysisUsage(AnalysisUsage &AU) const;
@ -140,14 +142,6 @@ namespace llvm {
/// call this implementation.
bool doInitialization(Module &M);
/// EmitStartOfAsmFile - This virtual method can be overridden by targets
/// that want to emit something at the start of their file.
virtual void EmitStartOfAsmFile(Module &) {}
/// EmitEndOfAsmFile - This virtual method can be overridden by targets that
/// want to emit something at the end of their file.
virtual void EmitEndOfAsmFile(Module &) {}
/// doFinalization - Shut down the asmprinter. If you override this in your
/// pass, you must make sure to call it explicitly.
bool doFinalization(Module &M);
@ -161,6 +155,10 @@ namespace llvm {
return false;
}
//===------------------------------------------------------------------===//
// Coarse grained IR lowering routines.
//===------------------------------------------------------------------===//
/// SetupMachineFunction - This should be called when a new MachineFunction
/// is being processed from runOnMachineFunction.
void SetupMachineFunction(MachineFunction &MF);
@ -173,19 +171,6 @@ namespace llvm {
/// function.
void EmitFunctionBody();
/// EmitInstruction - Targets should implement this to emit instructions.
virtual void EmitInstruction(const MachineInstr *) {
assert(0 && "EmitInstruction not implemented");
}
/// EmitFunctionBodyStart - Targets can override this to emit stuff before
/// the first basic block in the function.
virtual void EmitFunctionBodyStart() {}
/// EmitFunctionBodyEnd - Targets can override this to emit stuff after
/// the last basic block in the function.
virtual void EmitFunctionBodyEnd() {}
/// EmitConstantPool - 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
@ -206,30 +191,38 @@ namespace llvm {
/// do nothing and return false.
bool EmitSpecialLLVMGlobal(const GlobalVariable *GV);
//===------------------------------------------------------------------===//
// Overridable Hooks
//===------------------------------------------------------------------===//
// Targets can, or in the case of EmitInstruction, must implement these to
// customize output.
/// EmitStartOfAsmFile - This virtual method can be overridden by targets
/// that want to emit something at the start of their file.
virtual void EmitStartOfAsmFile(Module &) {}
/// EmitEndOfAsmFile - This virtual method can be overridden by targets that
/// want to emit something at the end of their file.
virtual void EmitEndOfAsmFile(Module &) {}
/// EmitFunctionBodyStart - Targets can override this to emit stuff before
/// the first basic block in the function.
virtual void EmitFunctionBodyStart() {}
/// EmitFunctionBodyEnd - Targets can override this to emit stuff after
/// the last basic block in the function.
virtual void EmitFunctionBodyEnd() {}
/// EmitInstruction - Targets should implement this to emit instructions.
virtual void EmitInstruction(const MachineInstr *) {
assert(0 && "EmitInstruction not implemented");
}
//===------------------------------------------------------------------===//
// Lowering Routines.
//===------------------------------------------------------------------===//
public:
//===------------------------------------------------------------------===//
// Emission routines.
//
/// EmitInt8 - Emit a byte directive and value.
///
void EmitInt8(int Value) const;
/// EmitInt16 - Emit a short directive and value.
///
void EmitInt16(int Value) const;
/// EmitInt32 - Emit a long directive and value.
///
void EmitInt32(int Value) const;
/// EmitLabelDifference - Emit something like ".long Hi-Lo" where the size
/// in bytes of the directive is specified by Size and Hi/Lo specify the
/// labels. This implicitly uses .set if it is available.
void EmitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo,
unsigned Size) const;
//===------------------------------------------------------------------===//
/// EmitAlignment - Emit an alignment directive to the specified power of
/// two boundary. For example, if you pass in 3 here, you will get an 8
@ -286,7 +279,7 @@ namespace llvm {
// Data emission.
/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
void EmitGlobalConstant(const Constant* CV, unsigned AddrSpace = 0);
void EmitGlobalConstant(const Constant *CV, unsigned AddrSpace = 0);
protected:
virtual void EmitFunctionEntryLabel();
@ -323,6 +316,31 @@ namespace llvm {
void EmitXXStructorList(Constant *List);
GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy *C);
//===------------------------------------------------------------------===//
// Emission Helper Routines.
//===------------------------------------------------------------------===//
public:
/// EmitInt8 - Emit a byte directive and value.
///
void EmitInt8(int Value) const;
/// EmitInt16 - Emit a short directive and value.
///
void EmitInt16(int Value) const;
/// EmitInt32 - Emit a long directive and value.
///
void EmitInt32(int Value) const;
/// EmitLabelDifference - Emit something like ".long Hi-Lo" where the size
/// in bytes of the directive is specified by Size and Hi/Lo specify the
/// labels. This implicitly uses .set if it is available.
void EmitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo,
unsigned Size) const;
//===------------------------------------------------------------------===//
// Inline Asm Support
//===------------------------------------------------------------------===//

View File

@ -62,7 +62,7 @@ AsmPrinter::AsmPrinter(TargetMachine &tm, MCStreamer &Streamer)
OutContext(Streamer.getContext()),
OutStreamer(Streamer),
LastMI(0), LastFn(0), Counter(~0U), SetCounter(0) {
DW = 0; MMI = 0;
DW = 0; MMI = 0; LI = 0;
GCMetadataPrinters = 0;
VerboseAsm = Streamer.isVerboseAsm();
}
@ -101,7 +101,7 @@ void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
MachineFunctionPass::getAnalysisUsage(AU);
AU.addRequired<MachineModuleInfo>();
AU.addRequired<GCModuleInfo>();
if (VerboseAsm)
if (isVerbose())
AU.addRequired<MachineLoopInfo>();
}
@ -218,7 +218,7 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
if (GVKind.isCommon() || GVKind.isBSSLocal()) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
if (VerboseAsm) {
if (isVerbose()) {
WriteAsOperand(OutStreamer.GetCommentOS(), GV,
/*PrintType=*/false, GV->getParent());
OutStreamer.GetCommentOS() << '\n';
@ -271,7 +271,7 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
EmitLinkage(GV->getLinkage(), GVSym);
EmitAlignment(AlignLog, GV);
if (VerboseAsm) {
if (isVerbose()) {
WriteAsOperand(OutStreamer.GetCommentOS(), GV,
/*PrintType=*/false, GV->getParent());
OutStreamer.GetCommentOS() << '\n';
@ -305,7 +305,7 @@ void AsmPrinter::EmitFunctionHeader() {
if (MAI->hasDotTypeDotSizeDirective())
OutStreamer.EmitSymbolAttribute(CurrentFnSym, MCSA_ELF_TypeFunction);
if (VerboseAsm) {
if (isVerbose()) {
WriteAsOperand(OutStreamer.GetCommentOS(), F,
/*PrintType=*/false, F->getParent());
OutStreamer.GetCommentOS() << '\n';
@ -429,7 +429,7 @@ void AsmPrinter::EmitFunctionBody() {
if (ShouldPrintDebugScopes)
DW->BeginScope(II);
if (VerboseAsm)
if (isVerbose())
EmitComments(*II, OutStreamer.GetCommentOS());
switch (II->getOpcode()) {
@ -575,7 +575,7 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
// Get the function symbol.
CurrentFnSym = Mang->getSymbol(MF.getFunction());
if (VerboseAsm)
if (isVerbose())
LI = &getAnalysis<MachineLoopInfo>();
}
@ -663,7 +663,7 @@ void AsmPrinter::EmitConstantPool() {
Offset = NewOffset + TM.getTargetData()->getTypeAllocSize(Ty);
// Emit the label with a comment on it.
if (VerboseAsm) {
if (isVerbose()) {
OutStreamer.GetCommentOS() << "constant pool ";
WriteTypeSymbolic(OutStreamer.GetCommentOS(), CPE.getType(),
MF->getFunction()->getParent());
@ -1177,7 +1177,7 @@ static void EmitGlobalConstantFP(const ConstantFP *CFP, unsigned AddrSpace,
// FP Constants are printed as integer constants to avoid losing
// precision.
if (CFP->getType()->isDoubleTy()) {
if (AP.VerboseAsm) {
if (AP.isVerbose()) {
double Val = CFP->getValueAPF().convertToDouble();
AP.OutStreamer.GetCommentOS() << "double " << Val << '\n';
}
@ -1188,7 +1188,7 @@ static void EmitGlobalConstantFP(const ConstantFP *CFP, unsigned AddrSpace,
}
if (CFP->getType()->isFloatTy()) {
if (AP.VerboseAsm) {
if (AP.isVerbose()) {
float Val = CFP->getValueAPF().convertToFloat();
AP.OutStreamer.GetCommentOS() << "float " << Val << '\n';
}
@ -1202,7 +1202,7 @@ static void EmitGlobalConstantFP(const ConstantFP *CFP, unsigned AddrSpace,
// api needed to prevent premature destruction
APInt API = CFP->getValueAPF().bitcastToAPInt();
const uint64_t *p = API.getRawData();
if (AP.VerboseAsm) {
if (AP.isVerbose()) {
// Convert to double so we can print the approximate val as a comment.
APFloat DoubleVal = CFP->getValueAPF();
bool ignored;
@ -1273,7 +1273,7 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV, unsigned AddrSpace) {
case 2:
case 4:
case 8:
if (VerboseAsm)
if (isVerbose())
OutStreamer.GetCommentOS() << format("0x%llx\n", CI->getZExtValue());
OutStreamer.EmitIntValue(CI->getZExtValue(), Size, AddrSpace);
return;
@ -1327,7 +1327,7 @@ void AsmPrinter::printOffset(int64_t Offset, raw_ostream &OS) const {
/// EmitImplicitDef - This method emits the specified machine instruction
/// that is an implicit def.
void AsmPrinter::EmitImplicitDef(const MachineInstr *MI) const {
if (!VerboseAsm) return;
if (!isVerbose()) return;
unsigned RegNo = MI->getOperand(0).getReg();
OutStreamer.AddComment(Twine("implicit-def: ") +
TM.getRegisterInfo()->getName(RegNo));
@ -1335,7 +1335,7 @@ void AsmPrinter::EmitImplicitDef(const MachineInstr *MI) const {
}
void AsmPrinter::EmitKill(const MachineInstr *MI) const {
if (!VerboseAsm) return;
if (!isVerbose()) return;
std::string Str = "kill:";
for (unsigned n = 0, e = MI->getNumOperands(); n != e; ++n) {
@ -1478,7 +1478,7 @@ void AsmPrinter::EmitBasicBlockStart(const MachineBasicBlock *MBB) const {
// the references were generated.
if (MBB->hasAddressTaken()) {
const BasicBlock *BB = MBB->getBasicBlock();
if (VerboseAsm)
if (isVerbose())
OutStreamer.AddComment("Block address taken");
std::vector<MCSymbol*> Syms = MMI->getAddrLabelSymbolToEmit(BB);
@ -1489,7 +1489,7 @@ void AsmPrinter::EmitBasicBlockStart(const MachineBasicBlock *MBB) const {
// Print the main label for the block.
if (MBB->pred_empty() || isBlockOnlyReachableByFallthrough(MBB)) {
if (VerboseAsm && OutStreamer.hasRawTextSupport()) {
if (isVerbose() && OutStreamer.hasRawTextSupport()) {
if (const BasicBlock *BB = MBB->getBasicBlock())
if (BB->hasName())
OutStreamer.AddComment("%" + BB->getName());
@ -1501,7 +1501,7 @@ void AsmPrinter::EmitBasicBlockStart(const MachineBasicBlock *MBB) const {
Twine(MBB->getNumber()) + ":");
}
} else {
if (VerboseAsm) {
if (isVerbose()) {
if (const BasicBlock *BB = MBB->getBasicBlock())
if (BB->hasName())
OutStreamer.AddComment("%" + BB->getName());

View File

@ -2491,7 +2491,7 @@ void DwarfDebug::emitDIE(DIE *Die) {
const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
// Emit the code (index) for the abbreviation.
if (Asm->VerboseAsm)
if (Asm->isVerbose())
Asm->OutStreamer.AddComment("Abbrev [" + Twine(AbbrevNumber) + "] 0x" +
Twine::utohexstr(Die->getOffset()) + ":0x" +
Twine::utohexstr(Die->getSize()) + " " +
@ -2507,7 +2507,7 @@ void DwarfDebug::emitDIE(DIE *Die) {
unsigned Form = AbbrevData[i].getForm();
assert(Form && "Too many attributes for DIE (check abbreviation)");
if (Asm->VerboseAsm)
if (Asm->isVerbose())
Asm->OutStreamer.AddComment(dwarf::AttributeString(Attr));
switch (Attr) {
@ -2535,7 +2535,7 @@ void DwarfDebug::emitDIE(DIE *Die) {
for (unsigned j = 0, M = Children.size(); j < M; ++j)
emitDIE(Children[j]);
if (Asm->VerboseAsm)
if (Asm->isVerbose())
Asm->OutStreamer.AddComment("End Of Children Mark");
Asm->EmitInt8(0);
}
@ -2698,7 +2698,7 @@ void DwarfDebug::emitDebugLines() {
// Emit directories.
for (unsigned DI = 1, DE = getNumSourceDirectories()+1; DI != DE; ++DI) {
const std::string &Dir = getSourceDirectoryName(DI);
if (Asm->VerboseAsm) Asm->OutStreamer.AddComment("Directory");
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("Directory");
Asm->OutStreamer.EmitBytes(StringRef(Dir.c_str(), Dir.size()+1), 0);
}
@ -2710,7 +2710,7 @@ void DwarfDebug::emitDebugLines() {
// Remember source id starts at 1.
std::pair<unsigned, unsigned> Id = getSourceDirectoryAndFileIds(SI);
const std::string &FN = getSourceFileName(Id.second);
if (Asm->VerboseAsm) Asm->OutStreamer.AddComment("Source");
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("Source");
Asm->OutStreamer.EmitBytes(StringRef(FN.c_str(), FN.size()+1), 0);
EmitULEB128(Id.first, "Directory #");
@ -2927,7 +2927,7 @@ void DwarfDebug::emitDebugPubNames() {
Asm->OutStreamer.AddComment("DIE offset");
Asm->EmitInt32(Entity->getOffset());
if (Asm->VerboseAsm)
if (Asm->isVerbose())
Asm->OutStreamer.AddComment("External Name");
Asm->OutStreamer.EmitBytes(StringRef(Name, strlen(Name)+1), 0);
}
@ -2947,7 +2947,7 @@ void DwarfDebug::emitDebugPubTypes() {
Asm->OutStreamer.EmitLabel(getDWLabel("pubtypes_begin", ModuleCU->getID()));
if (Asm->VerboseAsm) Asm->OutStreamer.AddComment("DWARF Version");
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DWARF Version");
Asm->EmitInt16(dwarf::DWARF_VERSION);
Asm->OutStreamer.AddComment("Offset of Compilation ModuleCU Info");
@ -2965,10 +2965,10 @@ void DwarfDebug::emitDebugPubTypes() {
const char *Name = GI->getKeyData();
DIE * Entity = GI->second;
if (Asm->VerboseAsm) Asm->OutStreamer.AddComment("DIE offset");
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset");
Asm->EmitInt32(Entity->getOffset());
if (Asm->VerboseAsm) Asm->OutStreamer.AddComment("External Name");
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("External Name");
Asm->OutStreamer.EmitBytes(StringRef(Name, GI->getKeyLength()+1), 0);
}
@ -3106,10 +3106,10 @@ void DwarfDebug::emitDebugInlineInfo() {
for (SmallVector<InlineInfoLabels, 4>::iterator LI = Labels.begin(),
LE = Labels.end(); LI != LE; ++LI) {
if (Asm->VerboseAsm) Asm->OutStreamer.AddComment("DIE offset");
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset");
Asm->EmitInt32(LI->second->getOffset());
if (Asm->VerboseAsm) Asm->OutStreamer.AddComment("low_pc");
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("low_pc");
Asm->OutStreamer.EmitSymbolValue(LI->first, TD->getPointerSize(), 0);
}
}

View File

@ -109,7 +109,7 @@ static const char *DecodeDWARFEncoding(unsigned Encoding) {
/// describing the encoding. Desc is an optional string saying what the
/// encoding is specifying (e.g. "LSDA").
void DwarfPrinter::EmitEncodingByte(unsigned Val, const char *Desc) {
if (Asm->VerboseAsm) {
if (Asm->isVerbose()) {
if (Desc != 0)
Asm->OutStreamer.AddComment(Twine(Desc)+" Encoding = " +
Twine(DecodeDWARFEncoding(Val)));
@ -123,7 +123,7 @@ void DwarfPrinter::EmitEncodingByte(unsigned Val, const char *Desc) {
/// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value.
void DwarfPrinter::EmitCFAByte(unsigned Val) {
if (Asm->VerboseAsm) {
if (Asm->isVerbose()) {
if (Val >= dwarf::DW_CFA_offset && Val < dwarf::DW_CFA_offset+64)
Asm->OutStreamer.AddComment("DW_CFA_offset + Reg (" +
Twine(Val-dwarf::DW_CFA_offset) + ")");
@ -135,7 +135,7 @@ void DwarfPrinter::EmitCFAByte(unsigned Val) {
/// EmitSLEB128 - emit the specified signed leb128 value.
void DwarfPrinter::EmitSLEB128(int Value, const char *Desc) const {
if (Asm->VerboseAsm && Desc)
if (Asm->isVerbose() && Desc)
Asm->OutStreamer.AddComment(Desc);
if (MAI->hasLEB128()) {
@ -160,7 +160,7 @@ void DwarfPrinter::EmitSLEB128(int Value, const char *Desc) const {
/// EmitULEB128 - emit the specified signed leb128 value.
void DwarfPrinter::EmitULEB128(unsigned Value, const char *Desc,
unsigned PadTo) const {
if (Asm->VerboseAsm && Desc)
if (Asm->isVerbose() && Desc)
Asm->OutStreamer.AddComment(Desc);
if (MAI->hasLEB128() && PadTo == 0) {

View File

@ -418,7 +418,7 @@ void ARMAsmPrinter::printSOImmOperand(const MachineInstr *MI, int OpNum,
raw_ostream &O) {
const MachineOperand &MO = MI->getOperand(OpNum);
assert(MO.isImm() && "Not a valid so_imm value!");
printSOImm(O, MO.getImm(), VerboseAsm, MAI);
printSOImm(O, MO.getImm(), isVerbose(), MAI);
}
/// printSOImm2PartOperand - SOImm is broken into two pieces using a 'mov'
@ -429,7 +429,7 @@ void ARMAsmPrinter::printSOImm2PartOperand(const MachineInstr *MI, int OpNum,
assert(MO.isImm() && "Not a valid so_imm value!");
unsigned V1 = ARM_AM::getSOImmTwoPartFirst(MO.getImm());
unsigned V2 = ARM_AM::getSOImmTwoPartSecond(MO.getImm());
printSOImm(O, V1, VerboseAsm, MAI);
printSOImm(O, V1, isVerbose(), MAI);
O << "\n\torr";
printPredicateOperand(MI, 2, O);
O << "\t";
@ -437,7 +437,7 @@ void ARMAsmPrinter::printSOImm2PartOperand(const MachineInstr *MI, int OpNum,
O << ", ";
printOperand(MI, 0, O);
O << ", ";
printSOImm(O, V2, VerboseAsm, MAI);
printSOImm(O, V2, isVerbose(), MAI);
}
// so_reg is a 4-operand unit corresponding to register forms of the A5.1
@ -1021,7 +1021,7 @@ void ARMAsmPrinter::printVFPf32ImmOperand(const MachineInstr *MI, int OpNum,
raw_ostream &O) {
const ConstantFP *FP = MI->getOperand(OpNum).getFPImm();
O << '#' << FP->getValueAPF().convertToFloat();
if (VerboseAsm) {
if (isVerbose()) {
O << "\t\t" << MAI->getCommentString() << ' ';
WriteAsOperand(O, FP, /*PrintType=*/false);
}
@ -1031,7 +1031,7 @@ void ARMAsmPrinter::printVFPf64ImmOperand(const MachineInstr *MI, int OpNum,
raw_ostream &O) {
const ConstantFP *FP = MI->getOperand(OpNum).getFPImm();
O << '#' << FP->getValueAPF().convertToDouble();
if (VerboseAsm) {
if (isVerbose()) {
O << "\t\t" << MAI->getCommentString() << ' ';
WriteAsOperand(O, FP, /*PrintType=*/false);
}

View File

@ -388,7 +388,7 @@ void X86AsmPrinter::EmitInstruction(const MachineInstr *MI) {
X86MCInstLower MCInstLowering(OutContext, Mang, *this);
switch (MI->getOpcode()) {
case TargetOpcode::DBG_VALUE:
if (VerboseAsm && OutStreamer.hasRawTextSupport()) {
if (isVerbose() && OutStreamer.hasRawTextSupport()) {
std::string TmpStr;
raw_string_ostream OS(TmpStr);
PrintDebugValueComment(MI, OS);