blob: 8d32f59d8b17d9cb7a500808a3ff2ac4f37d0c70 [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
Jim Laskey563321a2006-09-06 18:34:40 +000032struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter {
33 DwarfWriter DW;
Evan Cheng3c992d22006-03-07 02:02:57 +000034
Jim Laskey563321a2006-09-06 18:34:40 +000035 X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM,
Jim Laskeya0f3d172006-09-07 22:06:40 +000036 const TargetAsmInfo *T)
Jim Laskey563321a2006-09-06 18:34:40 +000037 : AsmPrinter(O, TM, T), DW(O, this, T) {
Evan Cheng932ad512006-05-25 21:59:08 +000038 Subtarget = &TM.getSubtarget<X86Subtarget>();
39 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +000040
41 bool doInitialization(Module &M);
Chris Lattnerb36cbd02005-07-01 22:44:09 +000042 bool doFinalization(Module &M);
43
Evan Cheng3c992d22006-03-07 02:02:57 +000044 void getAnalysisUsage(AnalysisUsage &AU) const {
45 AU.setPreservesAll();
Jim Laskeyea348582006-07-27 02:05:13 +000046 if (Subtarget->isTargetDarwin()) {
Jim Laskey30ffe1b2006-07-27 01:12:23 +000047 AU.addRequired<MachineDebugInfo>();
48 }
Evan Cheng3c992d22006-03-07 02:02:57 +000049 MachineFunctionPass::getAnalysisUsage(AU);
50 }
51
Evan Cheng932ad512006-05-25 21:59:08 +000052 const X86Subtarget *Subtarget;
Chris Lattnerb36cbd02005-07-01 22:44:09 +000053
Nate Begeman72b286b2005-07-08 00:23:26 +000054 // Necessary for Darwin to print out the apprioriate types of linker stubs
55 std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
56
Chris Lattnerb36cbd02005-07-01 22:44:09 +000057 inline static bool isScale(const MachineOperand &MO) {
58 return MO.isImmediate() &&
59 (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||
60 MO.getImmedValue() == 4 || MO.getImmedValue() == 8);
61 }
62
63 inline static bool isMem(const MachineInstr *MI, unsigned Op) {
64 if (MI->getOperand(Op).isFrameIndex()) return true;
Chris Lattnerb36cbd02005-07-01 22:44:09 +000065 return Op+4 <= MI->getNumOperands() &&
66 MI->getOperand(Op ).isRegister() && isScale(MI->getOperand(Op+1)) &&
Evan Chengc4ee50c2006-02-25 09:56:50 +000067 MI->getOperand(Op+2).isRegister() &&
68 (MI->getOperand(Op+3).isImmediate() ||
69 MI->getOperand(Op+3).isGlobalAddress() ||
Evan Chengc9676de2006-08-29 22:14:48 +000070 MI->getOperand(Op+3).isConstantPoolIndex() ||
71 MI->getOperand(Op+3).isJumpTableIndex());
Chris Lattnerb36cbd02005-07-01 22:44:09 +000072 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +000073};
74
Chris Lattnerb36cbd02005-07-01 22:44:09 +000075} // end namespace llvm
76
77#endif