LLVM API Documentation
00001 //===-- X86AsmPrinter.h - Convert X86 LLVM code to Intel assembly ---------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file the shared super class printer that converts from our internal 00011 // representation of machine-dependent LLVM code to Intel and AT&T format 00012 // assembly language. This printer is the output mechanism used by `llc'. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef X86ASMPRINTER_H 00017 #define X86ASMPRINTER_H 00018 00019 #include "X86.h" 00020 #include "X86TargetMachine.h" 00021 #include "llvm/CodeGen/AsmPrinter.h" 00022 #include "llvm/CodeGen/DwarfWriter.h" 00023 #include "llvm/CodeGen/MachineDebugInfo.h" 00024 #include "llvm/ADT/Statistic.h" 00025 #include <set> 00026 00027 00028 namespace llvm { 00029 00030 extern Statistic<> EmittedInsts; 00031 00032 /// X86DwarfWriter - Dwarf debug info writer customized for Darwin/Mac OS X 00033 /// 00034 struct X86DwarfWriter : public DwarfWriter { 00035 X86DwarfWriter(std::ostream &o, AsmPrinter *ap) : DwarfWriter(o, ap) { 00036 needsSet = true; 00037 DwarfAbbrevSection = ".section __DWARFA,__debug_abbrev"; 00038 DwarfInfoSection = ".section __DWARFA,__debug_info"; 00039 DwarfLineSection = ".section __DWARFA,__debug_line"; 00040 DwarfFrameSection = ".section __DWARFA,__debug_frame"; 00041 DwarfPubNamesSection = ".section __DWARFA,__debug_pubnames"; 00042 DwarfPubTypesSection = ".section __DWARFA,__debug_pubtypes"; 00043 DwarfStrSection = ".section __DWARFA,__debug_str"; 00044 DwarfLocSection = ".section __DWARFA,__debug_loc"; 00045 DwarfARangesSection = ".section __DWARFA,__debug_aranges"; 00046 DwarfRangesSection = ".section __DWARFA,__debug_ranges"; 00047 DwarfMacInfoSection = ".section __DWARFA,__debug_macinfo"; 00048 TextSection = ".text"; 00049 DataSection = ".data"; 00050 } 00051 virtual void virtfn(); // out of line virtual fn. 00052 }; 00053 00054 struct X86SharedAsmPrinter : public AsmPrinter { 00055 X86DwarfWriter DW; 00056 00057 X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM) 00058 : AsmPrinter(O, TM), DW(O, this) { 00059 Subtarget = &TM.getSubtarget<X86Subtarget>(); 00060 } 00061 00062 bool doInitialization(Module &M); 00063 bool doFinalization(Module &M); 00064 00065 void getAnalysisUsage(AnalysisUsage &AU) const { 00066 AU.setPreservesAll(); 00067 if (Subtarget->isTargetDarwin()) { 00068 AU.addRequired<MachineDebugInfo>(); 00069 } 00070 MachineFunctionPass::getAnalysisUsage(AU); 00071 } 00072 00073 const char *DefaultTextSection; // "_text" for MASM, ".text" for others. 00074 const char *DefaultDataSection; // "_data" for MASM, ".data" for others. 00075 const X86Subtarget *Subtarget; 00076 00077 // Necessary for Darwin to print out the apprioriate types of linker stubs 00078 std::set<std::string> FnStubs, GVStubs, LinkOnceStubs; 00079 00080 inline static bool isScale(const MachineOperand &MO) { 00081 return MO.isImmediate() && 00082 (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 || 00083 MO.getImmedValue() == 4 || MO.getImmedValue() == 8); 00084 } 00085 00086 inline static bool isMem(const MachineInstr *MI, unsigned Op) { 00087 if (MI->getOperand(Op).isFrameIndex()) return true; 00088 return Op+4 <= MI->getNumOperands() && 00089 MI->getOperand(Op ).isRegister() && isScale(MI->getOperand(Op+1)) && 00090 MI->getOperand(Op+2).isRegister() && 00091 (MI->getOperand(Op+3).isImmediate() || 00092 MI->getOperand(Op+3).isGlobalAddress() || 00093 MI->getOperand(Op+3).isConstantPoolIndex()); 00094 } 00095 }; 00096 00097 } // end namespace llvm 00098 00099 #endif