Detemplatize the Statistic class. The only type it is instantiated with
[oota-llvm.git] / lib / Target / X86 / X86AsmPrinter.h
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 "X86MachineFunctionInfo.h"
21 #include "X86TargetMachine.h"
22 #include "llvm/CodeGen/AsmPrinter.h"
23 #include "llvm/CodeGen/DwarfWriter.h"
24 #include "llvm/CodeGen/MachineDebugInfo.h"
25 #include "llvm/ADT/Statistic.h"
26 #include <set>
27
28
29 namespace llvm {
30
31 extern Statistic EmittedInsts;
32
33 // FIXME: Move this to CodeGen/AsmPrinter.h
34 namespace PICStyle {
35   enum X86AsmPICStyle {
36     Stub, GOT
37   };
38 }
39
40 struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter {
41   DwarfWriter DW;
42
43   X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM,
44                       const TargetAsmInfo *T)
45     : AsmPrinter(O, TM, T), DW(O, this, T), X86PICStyle(PICStyle::GOT) {
46     Subtarget = &TM.getSubtarget<X86Subtarget>();
47   }
48
49   // We have to propagate some information about MachineFunction to
50   // AsmPrinter. It's ok, when we're printing the function, since we have
51   // access to MachineFunction and can get the appropriate MachineFunctionInfo.
52   // Unfortunately, this is not possible when we're printing reference to
53   // Function (e.g. calling it and so on). Even more, there is no way to get the
54   // corresponding MachineFunctions: it can even be not created at all. That's
55   // why we should use additional structure, when we're collecting all necessary
56   // information.
57   //
58   // This structure is using e.g. for name decoration for stdcall & fastcall'ed
59   // function, since we have to use arguments' size for decoration.
60   typedef std::map<const Function*, X86FunctionInfo> FMFInfoMap;
61   FMFInfoMap FunctionInfoMap;
62
63   void decorateName(std::string& Name, const GlobalValue* GV);
64
65   bool doInitialization(Module &M);
66   bool doFinalization(Module &M);
67
68   void getAnalysisUsage(AnalysisUsage &AU) const {
69     AU.setPreservesAll();
70     if (Subtarget->isTargetDarwin() ||
71         Subtarget->isTargetELF() ||
72         Subtarget->isTargetCygwin()) {
73       AU.addRequired<MachineDebugInfo>();
74     }
75     MachineFunctionPass::getAnalysisUsage(AU);
76   }
77
78   PICStyle::X86AsmPICStyle X86PICStyle;
79   
80   const X86Subtarget *Subtarget;
81
82   // Necessary for Darwin to print out the apprioriate types of linker stubs
83   std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
84
85   // Necessary for dllexport support
86   std::set<std::string> DLLExportedFns, DLLExportedGVs;
87
88   // Necessary for external weak linkage support
89   std::set<std::string> ExtWeakSymbols;
90   
91   inline static bool isScale(const MachineOperand &MO) {
92     return MO.isImmediate() &&
93           (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||
94           MO.getImmedValue() == 4 || MO.getImmedValue() == 8);
95   }
96
97   inline static bool isMem(const MachineInstr *MI, unsigned Op) {
98     if (MI->getOperand(Op).isFrameIndex()) return true;
99     return Op+4 <= MI->getNumOperands() &&
100       MI->getOperand(Op  ).isRegister() && isScale(MI->getOperand(Op+1)) &&
101       MI->getOperand(Op+2).isRegister() &&
102       (MI->getOperand(Op+3).isImmediate() ||
103        MI->getOperand(Op+3).isGlobalAddress() ||
104        MI->getOperand(Op+3).isConstantPoolIndex() ||
105        MI->getOperand(Op+3).isJumpTableIndex());
106   }
107 };
108
109 } // end namespace llvm
110
111 #endif