blob: 6c47e0c27e8f940fd729757e318f2ce0e3fa1ab6 [file] [log] [blame]
Chris Lattnerb9740462005-07-01 22:44:09 +00001//===-- X86AsmPrinter.h - Convert X86 LLVM code to Intel assembly ---------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnerb9740462005-07-01 22:44:09 +00007//
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"
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000020#include "X86MachineFunctionInfo.h"
Evan Cheng2dd2c652006-03-13 23:20:37 +000021#include "X86TargetMachine.h"
Chris Lattnerb9740462005-07-01 22:44:09 +000022#include "llvm/CodeGen/AsmPrinter.h"
Evan Cheng30d7b702006-03-07 02:02:57 +000023#include "llvm/CodeGen/DwarfWriter.h"
Jim Laskeyc56315c2007-01-26 21:22:28 +000024#include "llvm/CodeGen/MachineModuleInfo.h"
Chris Lattnerf06bb652006-12-06 18:14:47 +000025#include "llvm/Support/Compiler.h"
Nate Begemanb62a4c82005-07-08 00:23:26 +000026#include <set>
27
Chris Lattnerb9740462005-07-01 22:44:09 +000028
29namespace llvm {
Chris Lattnerb9740462005-07-01 22:44:09 +000030
Jim Laskeya6211dc2006-09-06 18:34:40 +000031struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter {
32 DwarfWriter DW;
Bill Wendling2b8fc312007-09-11 08:27:17 +000033 MachineModuleInfo *MMI;
Evan Cheng30d7b702006-03-07 02:02:57 +000034
Jim Laskeya6211dc2006-09-06 18:34:40 +000035 X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM,
Jim Laskey261779b2006-09-07 22:06:40 +000036 const TargetAsmInfo *T)
Bill Wendling2b8fc312007-09-11 08:27:17 +000037 : AsmPrinter(O, TM, T), DW(O, this, T), MMI(0) {
Evan Cheng2554e3d2006-05-25 21:59:08 +000038 Subtarget = &TM.getSubtarget<X86Subtarget>();
39 }
Chris Lattnerb9740462005-07-01 22:44:09 +000040
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000041 // We have to propagate some information about MachineFunction to
42 // AsmPrinter. It's ok, when we're printing the function, since we have
Chris Lattner104aa5d2006-09-26 03:57:53 +000043 // access to MachineFunction and can get the appropriate MachineFunctionInfo.
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000044 // Unfortunately, this is not possible when we're printing reference to
45 // Function (e.g. calling it and so on). Even more, there is no way to get the
46 // corresponding MachineFunctions: it can even be not created at all. That's
47 // why we should use additional structure, when we're collecting all necessary
48 // information.
Chris Lattner104aa5d2006-09-26 03:57:53 +000049 //
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000050 // This structure is using e.g. for name decoration for stdcall & fastcall'ed
51 // function, since we have to use arguments' size for decoration.
Chris Lattnerff0598d2007-04-17 17:21:52 +000052 typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap;
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000053 FMFInfoMap FunctionInfoMap;
54
55 void decorateName(std::string& Name, const GlobalValue* GV);
56
Chris Lattnerb9740462005-07-01 22:44:09 +000057 bool doInitialization(Module &M);
Chris Lattnerb9740462005-07-01 22:44:09 +000058 bool doFinalization(Module &M);
59
Evan Cheng30d7b702006-03-07 02:02:57 +000060 void getAnalysisUsage(AnalysisUsage &AU) const {
61 AU.setPreservesAll();
Anton Korobeynikovaa4c0f92006-10-31 08:31:24 +000062 if (Subtarget->isTargetDarwin() ||
63 Subtarget->isTargetELF() ||
Anton Korobeynikov4efbbc92007-01-03 11:43:14 +000064 Subtarget->isTargetCygMing()) {
Jim Laskeyc56315c2007-01-26 21:22:28 +000065 AU.addRequired<MachineModuleInfo>();
Jim Laskeyc169b872006-07-27 01:12:23 +000066 }
Gordon Henriksen0b7cf862007-09-30 13:39:29 +000067 AsmPrinter::getAnalysisUsage(AU);
Evan Cheng30d7b702006-03-07 02:02:57 +000068 }
69
Evan Cheng2554e3d2006-05-25 21:59:08 +000070 const X86Subtarget *Subtarget;
Chris Lattnerb9740462005-07-01 22:44:09 +000071
Nate Begemanb62a4c82005-07-08 00:23:26 +000072 // Necessary for Darwin to print out the apprioriate types of linker stubs
73 std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
74
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +000075 // Necessary for dllexport support
76 std::set<std::string> DLLExportedFns, DLLExportedGVs;
Anton Korobeynikov12c94942006-12-01 00:25:12 +000077
Chris Lattnerb9740462005-07-01 22:44:09 +000078 inline static bool isScale(const MachineOperand &MO) {
79 return MO.isImmediate() &&
Chris Lattner5c463782007-12-30 20:49:49 +000080 (MO.getImm() == 1 || MO.getImm() == 2 ||
81 MO.getImm() == 4 || MO.getImm() == 8);
Chris Lattnerb9740462005-07-01 22:44:09 +000082 }
83
84 inline static bool isMem(const MachineInstr *MI, unsigned Op) {
85 if (MI->getOperand(Op).isFrameIndex()) return true;
Chris Lattnerb9740462005-07-01 22:44:09 +000086 return Op+4 <= MI->getNumOperands() &&
87 MI->getOperand(Op ).isRegister() && isScale(MI->getOperand(Op+1)) &&
Evan Chenge4a8b742006-02-25 09:56:50 +000088 MI->getOperand(Op+2).isRegister() &&
89 (MI->getOperand(Op+3).isImmediate() ||
90 MI->getOperand(Op+3).isGlobalAddress() ||
Evan Cheng6d464142006-08-29 22:14:48 +000091 MI->getOperand(Op+3).isConstantPoolIndex() ||
92 MI->getOperand(Op+3).isJumpTableIndex());
Chris Lattnerb9740462005-07-01 22:44:09 +000093 }
Chris Lattnerb9740462005-07-01 22:44:09 +000094};
95
Chris Lattnerb9740462005-07-01 22:44:09 +000096} // end namespace llvm
97
98#endif