Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===-- X86AsmPrinter.h - Convert X86 LLVM code to Intel assembly ---------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 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/MachineModuleInfo.h" |
| 25 | #include "llvm/Support/Compiler.h" |
| 26 | #include <set> |
| 27 | |
| 28 | |
| 29 | namespace llvm { |
| 30 | |
| 31 | struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter { |
| 32 | DwarfWriter DW; |
Bill Wendling | d1bda4f | 2007-09-11 08:27:17 +0000 | [diff] [blame] | 33 | MachineModuleInfo *MMI; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 34 | |
| 35 | X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM, |
| 36 | const TargetAsmInfo *T) |
Bill Wendling | d1bda4f | 2007-09-11 08:27:17 +0000 | [diff] [blame] | 37 | : AsmPrinter(O, TM, T), DW(O, this, T), MMI(0) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 38 | Subtarget = &TM.getSubtarget<X86Subtarget>(); |
| 39 | } |
| 40 | |
| 41 | // We have to propagate some information about MachineFunction to |
| 42 | // AsmPrinter. It's ok, when we're printing the function, since we have |
| 43 | // access to MachineFunction and can get the appropriate MachineFunctionInfo. |
| 44 | // 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. |
| 49 | // |
| 50 | // This structure is using e.g. for name decoration for stdcall & fastcall'ed |
| 51 | // function, since we have to use arguments' size for decoration. |
| 52 | typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap; |
| 53 | FMFInfoMap FunctionInfoMap; |
| 54 | |
| 55 | void decorateName(std::string& Name, const GlobalValue* GV); |
| 56 | |
| 57 | bool doInitialization(Module &M); |
| 58 | bool doFinalization(Module &M); |
| 59 | |
| 60 | void getAnalysisUsage(AnalysisUsage &AU) const { |
| 61 | AU.setPreservesAll(); |
| 62 | if (Subtarget->isTargetDarwin() || |
| 63 | Subtarget->isTargetELF() || |
| 64 | Subtarget->isTargetCygMing()) { |
| 65 | AU.addRequired<MachineModuleInfo>(); |
| 66 | } |
Gordon Henriksen | 76e4b61 | 2007-09-30 13:39:29 +0000 | [diff] [blame] | 67 | AsmPrinter::getAnalysisUsage(AU); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | const X86Subtarget *Subtarget; |
| 71 | |
| 72 | // Necessary for Darwin to print out the apprioriate types of linker stubs |
| 73 | std::set<std::string> FnStubs, GVStubs, LinkOnceStubs; |
| 74 | |
| 75 | // Necessary for dllexport support |
| 76 | std::set<std::string> DLLExportedFns, DLLExportedGVs; |
| 77 | |
| 78 | inline static bool isScale(const MachineOperand &MO) { |
| 79 | return MO.isImmediate() && |
Chris Lattner | a96056a | 2007-12-30 20:49:49 +0000 | [diff] [blame] | 80 | (MO.getImm() == 1 || MO.getImm() == 2 || |
| 81 | MO.getImm() == 4 || MO.getImm() == 8); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | inline static bool isMem(const MachineInstr *MI, unsigned Op) { |
| 85 | if (MI->getOperand(Op).isFrameIndex()) return true; |
| 86 | return Op+4 <= MI->getNumOperands() && |
| 87 | MI->getOperand(Op ).isRegister() && isScale(MI->getOperand(Op+1)) && |
| 88 | MI->getOperand(Op+2).isRegister() && |
| 89 | (MI->getOperand(Op+3).isImmediate() || |
| 90 | MI->getOperand(Op+3).isGlobalAddress() || |
| 91 | MI->getOperand(Op+3).isConstantPoolIndex() || |
| 92 | MI->getOperand(Op+3).isJumpTableIndex()); |
| 93 | } |
| 94 | }; |
| 95 | |
| 96 | } // end namespace llvm |
| 97 | |
| 98 | #endif |