Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 1 | //===-- X86AsmPrinter.h - Convert X86 LLVM code to Intel assembly ---------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 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. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 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'. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef X86ASMPRINTER_H |
| 17 | #define X86ASMPRINTER_H |
| 18 | |
| 19 | #include "X86.h" |
| 20 | #include "llvm/CodeGen/AsmPrinter.h" |
Evan Cheng | 3c992d2 | 2006-03-07 02:02:57 +0000 | [diff] [blame^] | 21 | #include "llvm/CodeGen/DwarfWriter.h" |
| 22 | #include "llvm/CodeGen/MachineDebugInfo.h" |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/Statistic.h" |
Nate Begeman | 72b286b | 2005-07-08 00:23:26 +0000 | [diff] [blame] | 24 | #include <set> |
| 25 | |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 26 | |
| 27 | namespace llvm { |
| 28 | namespace x86 { |
| 29 | |
| 30 | extern Statistic<> EmittedInsts; |
| 31 | |
Evan Cheng | 3c992d2 | 2006-03-07 02:02:57 +0000 | [diff] [blame^] | 32 | /// X86DwarfWriter - Dwarf debug info writer customized for Darwin/Mac OS X |
| 33 | /// |
| 34 | struct X86DwarfWriter : public DwarfWriter { |
| 35 | // Ctor. |
| 36 | X86DwarfWriter(std::ostream &o, AsmPrinter *ap) |
| 37 | : DwarfWriter(o, ap) |
| 38 | { |
| 39 | needsSet = true; |
| 40 | DwarfAbbrevSection = ".section __DWARFA,__debug_abbrev"; |
| 41 | DwarfInfoSection = ".section __DWARFA,__debug_info"; |
| 42 | DwarfLineSection = ".section __DWARFA,__debug_line"; |
| 43 | DwarfFrameSection = ".section __DWARFA,__debug_frame"; |
| 44 | DwarfPubNamesSection = ".section __DWARFA,__debug_pubnames"; |
| 45 | DwarfPubTypesSection = ".section __DWARFA,__debug_pubtypes"; |
| 46 | DwarfStrSection = ".section __DWARFA,__debug_str"; |
| 47 | DwarfLocSection = ".section __DWARFA,__debug_loc"; |
| 48 | DwarfARangesSection = ".section __DWARFA,__debug_aranges"; |
| 49 | DwarfRangesSection = ".section __DWARFA,__debug_ranges"; |
| 50 | DwarfMacInfoSection = ".section __DWARFA,__debug_macinfo"; |
| 51 | TextSection = ".text"; |
| 52 | DataSection = ".data"; |
| 53 | } |
| 54 | }; |
| 55 | |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 56 | struct X86SharedAsmPrinter : public AsmPrinter { |
Evan Cheng | 3c992d2 | 2006-03-07 02:02:57 +0000 | [diff] [blame^] | 57 | X86DwarfWriter DW; |
| 58 | |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 59 | X86SharedAsmPrinter(std::ostream &O, TargetMachine &TM) |
Evan Cheng | 3c992d2 | 2006-03-07 02:02:57 +0000 | [diff] [blame^] | 60 | : AsmPrinter(O, TM), DW(O, this), forDarwin(false) { } |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 61 | |
| 62 | bool doInitialization(Module &M); |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 63 | bool doFinalization(Module &M); |
| 64 | |
Evan Cheng | 3c992d2 | 2006-03-07 02:02:57 +0000 | [diff] [blame^] | 65 | void getAnalysisUsage(AnalysisUsage &AU) const { |
| 66 | AU.setPreservesAll(); |
| 67 | AU.addRequired<MachineDebugInfo>(); |
| 68 | MachineFunctionPass::getAnalysisUsage(AU); |
| 69 | } |
| 70 | |
| 71 | bool forDarwin; // FIXME: eliminate. |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 72 | |
Nate Begeman | 72b286b | 2005-07-08 00:23:26 +0000 | [diff] [blame] | 73 | // Necessary for Darwin to print out the apprioriate types of linker stubs |
| 74 | std::set<std::string> FnStubs, GVStubs, LinkOnceStubs; |
| 75 | |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 76 | inline static bool isScale(const MachineOperand &MO) { |
| 77 | return MO.isImmediate() && |
| 78 | (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 || |
| 79 | MO.getImmedValue() == 4 || MO.getImmedValue() == 8); |
| 80 | } |
| 81 | |
| 82 | inline static bool isMem(const MachineInstr *MI, unsigned Op) { |
| 83 | if (MI->getOperand(Op).isFrameIndex()) return true; |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 84 | return Op+4 <= MI->getNumOperands() && |
| 85 | MI->getOperand(Op ).isRegister() && isScale(MI->getOperand(Op+1)) && |
Evan Cheng | c4ee50c | 2006-02-25 09:56:50 +0000 | [diff] [blame] | 86 | MI->getOperand(Op+2).isRegister() && |
| 87 | (MI->getOperand(Op+3).isImmediate() || |
| 88 | MI->getOperand(Op+3).isGlobalAddress() || |
| 89 | MI->getOperand(Op+3).isConstantPoolIndex()); |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 90 | } |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | } // end namespace x86 |
| 94 | } // end namespace llvm |
| 95 | |
| 96 | #endif |