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