blob: abf0b4155920b9210199b218828597e51ae16ab0 [file] [log] [blame]
Chris Lattnerb36cbd02005-07-01 22:44:09 +00001//===-- 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"
Evan Chengc4c62572006-03-13 23:20:37 +000020#include "X86TargetMachine.h"
Chris Lattnerb36cbd02005-07-01 22:44:09 +000021#include "llvm/CodeGen/AsmPrinter.h"
Evan Cheng3c992d22006-03-07 02:02:57 +000022#include "llvm/CodeGen/DwarfWriter.h"
23#include "llvm/CodeGen/MachineDebugInfo.h"
Chris Lattnerb36cbd02005-07-01 22:44:09 +000024#include "llvm/ADT/Statistic.h"
Nate Begeman72b286b2005-07-08 00:23:26 +000025#include <set>
26
Chris Lattnerb36cbd02005-07-01 22:44:09 +000027
28namespace llvm {
Chris Lattnerb36cbd02005-07-01 22:44:09 +000029
30extern Statistic<> EmittedInsts;
31
Evan Cheng3c992d22006-03-07 02:02:57 +000032/// X86DwarfWriter - Dwarf debug info writer customized for Darwin/Mac OS X
33///
34struct X86DwarfWriter : public DwarfWriter {
Chris Lattnera3b59392006-07-14 23:05:05 +000035 X86DwarfWriter(std::ostream &o, AsmPrinter *ap) : DwarfWriter(o, ap) {
Jim Laskey6b59a362006-08-03 17:27:09 +000036 needsSet = true;
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";
Chris Lattnera3b59392006-07-14 23:05:05 +000050 }
51 virtual void virtfn(); // out of line virtual fn.
Evan Cheng3c992d22006-03-07 02:02:57 +000052};
53
Chris Lattnerb36cbd02005-07-01 22:44:09 +000054struct X86SharedAsmPrinter : public AsmPrinter {
Evan Cheng3c992d22006-03-07 02:02:57 +000055 X86DwarfWriter DW;
56
Evan Chengc4c62572006-03-13 23:20:37 +000057 X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM)
Evan Cheng932ad512006-05-25 21:59:08 +000058 : AsmPrinter(O, TM), DW(O, this) {
59 Subtarget = &TM.getSubtarget<X86Subtarget>();
60 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +000061
62 bool doInitialization(Module &M);
Chris Lattnerb36cbd02005-07-01 22:44:09 +000063 bool doFinalization(Module &M);
64
Evan Cheng3c992d22006-03-07 02:02:57 +000065 void getAnalysisUsage(AnalysisUsage &AU) const {
66 AU.setPreservesAll();
Jim Laskeyea348582006-07-27 02:05:13 +000067 if (Subtarget->isTargetDarwin()) {
Jim Laskey30ffe1b2006-07-27 01:12:23 +000068 AU.addRequired<MachineDebugInfo>();
69 }
Evan Cheng3c992d22006-03-07 02:02:57 +000070 MachineFunctionPass::getAnalysisUsage(AU);
71 }
72
Chris Lattnerdad9c5a2006-05-09 05:12:53 +000073 const char *DefaultTextSection; // "_text" for MASM, ".text" for others.
74 const char *DefaultDataSection; // "_data" for MASM, ".data" for others.
Evan Cheng932ad512006-05-25 21:59:08 +000075 const X86Subtarget *Subtarget;
Chris Lattnerb36cbd02005-07-01 22:44:09 +000076
Nate Begeman72b286b2005-07-08 00:23:26 +000077 // Necessary for Darwin to print out the apprioriate types of linker stubs
78 std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
79
Chris Lattnerb36cbd02005-07-01 22:44:09 +000080 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);
84 }
85
86 inline static bool isMem(const MachineInstr *MI, unsigned Op) {
87 if (MI->getOperand(Op).isFrameIndex()) return true;
Chris Lattnerb36cbd02005-07-01 22:44:09 +000088 return Op+4 <= MI->getNumOperands() &&
89 MI->getOperand(Op ).isRegister() && isScale(MI->getOperand(Op+1)) &&
Evan Chengc4ee50c2006-02-25 09:56:50 +000090 MI->getOperand(Op+2).isRegister() &&
91 (MI->getOperand(Op+3).isImmediate() ||
92 MI->getOperand(Op+3).isGlobalAddress() ||
93 MI->getOperand(Op+3).isConstantPoolIndex());
Chris Lattnerb36cbd02005-07-01 22:44:09 +000094 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +000095};
96
Chris Lattnerb36cbd02005-07-01 22:44:09 +000097} // end namespace llvm
98
99#endif