LLVM API Documentation
00001 //===-- X86ATTAsmPrinter.h - Convert X86 LLVM code to AT&T assembly -------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // AT&T assembly code printer class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef X86ATTASMPRINTER_H 00015 #define X86ATTASMPRINTER_H 00016 00017 #include "../X86.h" 00018 #include "../X86MachineFunctionInfo.h" 00019 #include "../X86TargetMachine.h" 00020 #include "llvm/ADT/StringSet.h" 00021 #include "llvm/CodeGen/AsmPrinter.h" 00022 #include "llvm/CodeGen/DwarfWriter.h" 00023 #include "llvm/CodeGen/MachineModuleInfo.h" 00024 #include "llvm/CodeGen/ValueTypes.h" 00025 #include "llvm/Support/Compiler.h" 00026 00027 namespace llvm { 00028 00029 struct MachineJumpTableInfo; 00030 00031 struct VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter { 00032 DwarfWriter *DW; 00033 MachineModuleInfo *MMI; 00034 const X86Subtarget *Subtarget; 00035 00036 X86ATTAsmPrinter(raw_ostream &O, X86TargetMachine &TM, 00037 const TargetAsmInfo *T) 00038 : AsmPrinter(O, TM, T), DW(0), MMI(0) { 00039 Subtarget = &TM.getSubtarget<X86Subtarget>(); 00040 } 00041 00042 virtual const char *getPassName() const { 00043 return "X86 AT&T-Style Assembly Printer"; 00044 } 00045 00046 void getAnalysisUsage(AnalysisUsage &AU) const { 00047 AU.setPreservesAll(); 00048 if (Subtarget->isTargetDarwin() || 00049 Subtarget->isTargetELF() || 00050 Subtarget->isTargetCygMing()) { 00051 AU.addRequired<MachineModuleInfo>(); 00052 } 00053 AU.addRequired<DwarfWriter>(); 00054 AsmPrinter::getAnalysisUsage(AU); 00055 } 00056 00057 bool doInitialization(Module &M); 00058 bool doFinalization(Module &M); 00059 00060 /// printInstruction - This method is automatically generated by tablegen 00061 /// from the instruction set description. This method returns true if the 00062 /// machine instruction was sufficiently described to print it, otherwise it 00063 /// returns false. 00064 bool printInstruction(const MachineInstr *MI); 00065 00066 // These methods are used by the tablegen'erated instruction printer. 00067 void printOperand(const MachineInstr *MI, unsigned OpNo, 00068 const char *Modifier = 0, bool NotRIPRel = false); 00069 void printi8mem(const MachineInstr *MI, unsigned OpNo) { 00070 printMemReference(MI, OpNo); 00071 } 00072 void printi16mem(const MachineInstr *MI, unsigned OpNo) { 00073 printMemReference(MI, OpNo); 00074 } 00075 void printi32mem(const MachineInstr *MI, unsigned OpNo) { 00076 printMemReference(MI, OpNo); 00077 } 00078 void printi64mem(const MachineInstr *MI, unsigned OpNo) { 00079 printMemReference(MI, OpNo); 00080 } 00081 void printi128mem(const MachineInstr *MI, unsigned OpNo) { 00082 printMemReference(MI, OpNo); 00083 } 00084 void printf32mem(const MachineInstr *MI, unsigned OpNo) { 00085 printMemReference(MI, OpNo); 00086 } 00087 void printf64mem(const MachineInstr *MI, unsigned OpNo) { 00088 printMemReference(MI, OpNo); 00089 } 00090 void printf80mem(const MachineInstr *MI, unsigned OpNo) { 00091 printMemReference(MI, OpNo); 00092 } 00093 void printf128mem(const MachineInstr *MI, unsigned OpNo) { 00094 printMemReference(MI, OpNo); 00095 } 00096 void printlea64_32mem(const MachineInstr *MI, unsigned OpNo) { 00097 printMemReference(MI, OpNo, "subreg64"); 00098 } 00099 00100 bool printAsmMRegister(const MachineOperand &MO, const char Mode); 00101 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, 00102 unsigned AsmVariant, const char *ExtraCode); 00103 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, 00104 unsigned AsmVariant, const char *ExtraCode); 00105 00106 void printMachineInstruction(const MachineInstr *MI); 00107 void printSSECC(const MachineInstr *MI, unsigned Op); 00108 void printMemReference(const MachineInstr *MI, unsigned Op, 00109 const char *Modifier=NULL); 00110 void printPICJumpTableSetLabel(unsigned uid, 00111 const MachineBasicBlock *MBB) const; 00112 void printPICJumpTableSetLabel(unsigned uid, unsigned uid2, 00113 const MachineBasicBlock *MBB) const { 00114 AsmPrinter::printPICJumpTableSetLabel(uid, uid2, MBB); 00115 } 00116 void printPICJumpTableEntry(const MachineJumpTableInfo *MJTI, 00117 const MachineBasicBlock *MBB, 00118 unsigned uid) const; 00119 00120 void printPICLabel(const MachineInstr *MI, unsigned Op); 00121 void printModuleLevelGV(const GlobalVariable* GVar); 00122 00123 void printGVStub(const char *GV, const char *Prefix = NULL); 00124 void printHiddenGVStub(const char *GV, const char *Prefix = NULL); 00125 00126 bool runOnMachineFunction(MachineFunction &F); 00127 00128 void emitFunctionHeader(const MachineFunction &MF); 00129 00130 // Necessary for Darwin to print out the apprioriate types of linker stubs 00131 StringSet<> FnStubs, GVStubs, HiddenGVStubs; 00132 00133 // Necessary for dllexport support 00134 StringSet<> DLLExportedFns, DLLExportedGVs; 00135 00136 // We have to propagate some information about MachineFunction to 00137 // AsmPrinter. It's ok, when we're printing the function, since we have 00138 // access to MachineFunction and can get the appropriate MachineFunctionInfo. 00139 // Unfortunately, this is not possible when we're printing reference to 00140 // Function (e.g. calling it and so on). Even more, there is no way to get the 00141 // corresponding MachineFunctions: it can even be not created at all. That's 00142 // why we should use additional structure, when we're collecting all necessary 00143 // information. 00144 // 00145 // This structure is using e.g. for name decoration for stdcall & fastcall'ed 00146 // function, since we have to use arguments' size for decoration. 00147 typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap; 00148 FMFInfoMap FunctionInfoMap; 00149 00150 void decorateName(std::string& Name, const GlobalValue* GV); 00151 }; 00152 00153 } // end namespace llvm 00154 00155 #endif