1 //===-- X86AsmPrinter.h - Convert X86 LLVM code to Intel assembly ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file the shared super class printer that converts from our internal
11 // representation of machine-dependent LLVM code to Intel and AT&T format
12 // assembly language. This printer is the output mechanism used by `llc'.
14 //===----------------------------------------------------------------------===//
16 #ifndef X86ASMPRINTER_H
17 #define X86ASMPRINTER_H
20 #include "X86TargetMachine.h"
21 #include "llvm/CodeGen/AsmPrinter.h"
22 #include "llvm/CodeGen/DwarfWriter.h"
23 #include "llvm/CodeGen/MachineDebugInfo.h"
24 #include "llvm/ADT/Statistic.h"
30 extern Statistic<> EmittedInsts;
32 /// X86DwarfWriter - Dwarf debug info writer customized for Darwin/Mac OS X
34 struct X86DwarfWriter : public DwarfWriter {
35 X86DwarfWriter(std::ostream &o, AsmPrinter *ap) : DwarfWriter(o, ap) {
37 DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
38 DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
39 DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
40 DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
41 DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
42 DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
43 DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";
44 DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug";
45 DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug";
46 DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
47 DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
48 TextSection = ".text";
49 DataSection = ".data";
51 virtual void virtfn(); // out of line virtual fn.
54 struct X86SharedAsmPrinter : public AsmPrinter {
57 X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM)
58 : AsmPrinter(O, TM), DW(O, this) {
59 Subtarget = &TM.getSubtarget<X86Subtarget>();
62 bool doInitialization(Module &M);
63 bool doFinalization(Module &M);
65 void getAnalysisUsage(AnalysisUsage &AU) const {
67 if (Subtarget->isTargetDarwin()) {
68 AU.addRequired<MachineDebugInfo>();
70 MachineFunctionPass::getAnalysisUsage(AU);
73 const char *DefaultTextSection; // "_text" for MASM, ".text" for others.
74 const char *DefaultDataSection; // "_data" for MASM, ".data" for others.
75 const X86Subtarget *Subtarget;
77 // Necessary for Darwin to print out the apprioriate types of linker stubs
78 std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
80 inline static bool isScale(const MachineOperand &MO) {
81 return MO.isImmediate() &&
82 (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||
83 MO.getImmedValue() == 4 || MO.getImmedValue() == 8);
86 inline static bool isMem(const MachineInstr *MI, unsigned Op) {
87 if (MI->getOperand(Op).isFrameIndex()) return true;
88 return Op+4 <= MI->getNumOperands() &&
89 MI->getOperand(Op ).isRegister() && isScale(MI->getOperand(Op+1)) &&
90 MI->getOperand(Op+2).isRegister() &&
91 (MI->getOperand(Op+3).isImmediate() ||
92 MI->getOperand(Op+3).isGlobalAddress() ||
93 MI->getOperand(Op+3).isConstantPoolIndex());
97 } // end namespace llvm