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 "X86TargetMachine.h"
21 #include "llvm/CodeGen/AsmPrinter.h"
22 #include "llvm/CodeGen/DwarfWriter.h"
23 #include "llvm/CodeGen/MachineDebugInfo.h"
24 #include "llvm/ADT/Statistic.h"
25 #include "llvm/Target/TargetAsmInfo.h"
31 extern Statistic<> EmittedInsts;
33 struct VISIBILITY_HIDDEN X86TargetAsmInfo : public TargetAsmInfo {
34 X86TargetAsmInfo(X86TargetMachine &TM);
37 struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter {
40 X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM,
42 : AsmPrinter(O, TM, T), DW(O, this, T) {
43 Subtarget = &TM.getSubtarget<X86Subtarget>();
46 bool doInitialization(Module &M);
47 bool doFinalization(Module &M);
49 void getAnalysisUsage(AnalysisUsage &AU) const {
51 if (Subtarget->isTargetDarwin()) {
52 AU.addRequired<MachineDebugInfo>();
54 MachineFunctionPass::getAnalysisUsage(AU);
57 const X86Subtarget *Subtarget;
59 // Necessary for Darwin to print out the apprioriate types of linker stubs
60 std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
62 inline static bool isScale(const MachineOperand &MO) {
63 return MO.isImmediate() &&
64 (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||
65 MO.getImmedValue() == 4 || MO.getImmedValue() == 8);
68 inline static bool isMem(const MachineInstr *MI, unsigned Op) {
69 if (MI->getOperand(Op).isFrameIndex()) return true;
70 return Op+4 <= MI->getNumOperands() &&
71 MI->getOperand(Op ).isRegister() && isScale(MI->getOperand(Op+1)) &&
72 MI->getOperand(Op+2).isRegister() &&
73 (MI->getOperand(Op+3).isImmediate() ||
74 MI->getOperand(Op+3).isGlobalAddress() ||
75 MI->getOperand(Op+3).isConstantPoolIndex() ||
76 MI->getOperand(Op+3).isJumpTableIndex());
80 } // end namespace llvm