1 //===-- X86AsmPrinter.h - Convert X86 LLVM code to Intel assembly ---------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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'.
14 //===----------------------------------------------------------------------===//
16 #ifndef X86ASMPRINTER_H
17 #define X86ASMPRINTER_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"
31 extern Statistic<> EmittedInsts;
33 // FIXME: Move this to CodeGen/AsmPrinter.h
40 struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter {
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>();
49 typedef std::map<const Function*, X86FunctionInfo> FMFInfoMap ;
51 // We have to propagate some information about MachineFunction to
52 // AsmPrinter. It's ok, when we're printing the function, since we have
53 // access to MachineFunction and can get the appropriate MachineFunctionInfo.
54 // Unfortunately, this is not possible when we're printing reference to
55 // Function (e.g. calling it and so on). Even more, there is no way to get the
56 // corresponding MachineFunctions: it can even be not created at all. That's
57 // why we should use additional structure, when we're collecting all necessary
60 // This structure is using e.g. for name decoration for stdcall & fastcall'ed
61 // function, since we have to use arguments' size for decoration.
62 FMFInfoMap FunctionInfoMap;
64 void decorateName(std::string& Name, const GlobalValue* GV);
66 bool doInitialization(Module &M);
67 bool doFinalization(Module &M);
69 void getAnalysisUsage(AnalysisUsage &AU) const {
71 if (Subtarget->isTargetDarwin()) {
72 AU.addRequired<MachineDebugInfo>();
74 MachineFunctionPass::getAnalysisUsage(AU);
77 PICStyle::X86AsmPICStyle X86PICStyle;
79 const X86Subtarget *Subtarget;
81 // Necessary for Darwin to print out the apprioriate types of linker stubs
82 std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
84 // Necessary for dllexport support
85 std::set<std::string> DLLExportedFns, DLLExportedGVs;
87 inline static bool isScale(const MachineOperand &MO) {
88 return MO.isImmediate() &&
89 (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||
90 MO.getImmedValue() == 4 || MO.getImmedValue() == 8);
93 inline static bool isMem(const MachineInstr *MI, unsigned Op) {
94 if (MI->getOperand(Op).isFrameIndex()) return true;
95 return Op+4 <= MI->getNumOperands() &&
96 MI->getOperand(Op ).isRegister() && isScale(MI->getOperand(Op+1)) &&
97 MI->getOperand(Op+2).isRegister() &&
98 (MI->getOperand(Op+3).isImmediate() ||
99 MI->getOperand(Op+3).isGlobalAddress() ||
100 MI->getOperand(Op+3).isConstantPoolIndex() ||
101 MI->getOperand(Op+3).isJumpTableIndex());
105 } // end namespace llvm