Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1 | //===-- MipsAsmPrinter.cpp - Mips LLVM assembly writer --------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 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. |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains a printer that converts from our internal representation |
| 11 | // of machine-dependent LLVM code to GAS-format MIPS assembly language. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #define DEBUG_TYPE "mips-asm-printer" |
| 16 | |
| 17 | #include "Mips.h" |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 18 | #include "MipsSubtarget.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 19 | #include "MipsInstrInfo.h" |
| 20 | #include "MipsTargetMachine.h" |
Bruno Cardoso Lopes | a4e8200 | 2007-07-11 23:24:41 +0000 | [diff] [blame] | 21 | #include "MipsMachineFunction.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 22 | #include "llvm/Constants.h" |
| 23 | #include "llvm/DerivedTypes.h" |
| 24 | #include "llvm/Module.h" |
Devang Patel | e4c0c0f | 2009-06-25 00:47:42 +0000 | [diff] [blame] | 25 | #include "llvm/MDNode.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/AsmPrinter.h" |
Bill Wendling | cb819f1 | 2009-02-18 23:12:06 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/DwarfWriter.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 29 | #include "llvm/CodeGen/MachineConstantPool.h" |
Bruno Cardoso Lopes | a4e8200 | 2007-07-11 23:24:41 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineInstr.h" |
| 32 | #include "llvm/Target/TargetAsmInfo.h" |
| 33 | #include "llvm/Target/TargetData.h" |
| 34 | #include "llvm/Target/TargetMachine.h" |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 35 | #include "llvm/Target/TargetOptions.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 36 | #include "llvm/Support/Mangler.h" |
| 37 | #include "llvm/ADT/Statistic.h" |
| 38 | #include "llvm/ADT/StringExtras.h" |
Bruno Cardoso Lopes | a4e8200 | 2007-07-11 23:24:41 +0000 | [diff] [blame] | 39 | #include "llvm/Support/Debug.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 40 | #include "llvm/Support/CommandLine.h" |
| 41 | #include "llvm/Support/MathExtras.h" |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 42 | #include "llvm/Support/raw_ostream.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 43 | #include <cctype> |
| 44 | |
| 45 | using namespace llvm; |
| 46 | |
| 47 | STATISTIC(EmittedInsts, "Number of machine instrs printed"); |
| 48 | |
| 49 | namespace { |
Bill Wendling | 57f0db8 | 2009-02-24 08:30:20 +0000 | [diff] [blame] | 50 | class VISIBILITY_HIDDEN MipsAsmPrinter : public AsmPrinter { |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 51 | const MipsSubtarget *Subtarget; |
Bill Wendling | 57f0db8 | 2009-02-24 08:30:20 +0000 | [diff] [blame] | 52 | public: |
Bill Wendling | be8cc2a | 2009-04-29 00:15:41 +0000 | [diff] [blame] | 53 | explicit MipsAsmPrinter(raw_ostream &O, MipsTargetMachine &TM, |
Bill Wendling | 98a366d | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 54 | const TargetAsmInfo *T, CodeGenOpt::Level OL, |
| 55 | bool V) |
Bill Wendling | be8cc2a | 2009-04-29 00:15:41 +0000 | [diff] [blame] | 56 | : AsmPrinter(O, TM, T, OL, V) { |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 57 | Subtarget = &TM.getSubtarget<MipsSubtarget>(); |
| 58 | } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 59 | |
| 60 | virtual const char *getPassName() const { |
| 61 | return "Mips Assembly Printer"; |
| 62 | } |
| 63 | |
Bruno Cardoso Lopes | 91ef849 | 2008-08-02 19:42:36 +0000 | [diff] [blame] | 64 | bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
| 65 | unsigned AsmVariant, const char *ExtraCode); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 66 | void printOperand(const MachineInstr *MI, int opNum); |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 67 | void printUnsignedImm(const MachineInstr *MI, int opNum); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 68 | void printMemOperand(const MachineInstr *MI, int opNum, |
| 69 | const char *Modifier = 0); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 70 | void printFCCOperand(const MachineInstr *MI, int opNum, |
| 71 | const char *Modifier = 0); |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 72 | void printModuleLevelGV(const GlobalVariable* GVar); |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 73 | void printSavedRegsBitmask(MachineFunction &MF); |
Bruno Cardoso Lopes | a4e8200 | 2007-07-11 23:24:41 +0000 | [diff] [blame] | 74 | void printHex32(unsigned int Value); |
Bruno Cardoso Lopes | dc0c04c | 2007-08-28 05:06:17 +0000 | [diff] [blame] | 75 | |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 76 | const char *emitCurrentABIString(void); |
Bruno Cardoso Lopes | a4e8200 | 2007-07-11 23:24:41 +0000 | [diff] [blame] | 77 | void emitFunctionStart(MachineFunction &MF); |
Bruno Cardoso Lopes | 0a60400 | 2007-10-09 03:01:19 +0000 | [diff] [blame] | 78 | void emitFunctionEnd(MachineFunction &MF); |
Bruno Cardoso Lopes | a4e8200 | 2007-07-11 23:24:41 +0000 | [diff] [blame] | 79 | void emitFrameDirective(MachineFunction &MF); |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 80 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 81 | bool printInstruction(const MachineInstr *MI); // autogenerated. |
| 82 | bool runOnMachineFunction(MachineFunction &F); |
| 83 | bool doInitialization(Module &M); |
| 84 | bool doFinalization(Module &M); |
| 85 | }; |
| 86 | } // end of anonymous namespace |
| 87 | |
| 88 | #include "MipsGenAsmWriter.inc" |
| 89 | |
| 90 | /// createMipsCodePrinterPass - Returns a pass that prints the MIPS |
| 91 | /// assembly code for a MachineFunction to the given output stream, |
| 92 | /// using the given target machine description. This should work |
| 93 | /// regardless of whether the function is in SSA form. |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 94 | FunctionPass *llvm::createMipsCodePrinterPass(raw_ostream &o, |
Bill Wendling | 57f0db8 | 2009-02-24 08:30:20 +0000 | [diff] [blame] | 95 | MipsTargetMachine &tm, |
Bill Wendling | 98a366d | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 96 | CodeGenOpt::Level OptLevel, |
| 97 | bool verbose) { |
Bill Wendling | be8cc2a | 2009-04-29 00:15:41 +0000 | [diff] [blame] | 98 | return new MipsAsmPrinter(o, tm, tm.getTargetAsmInfo(), OptLevel, verbose); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Bruno Cardoso Lopes | dc0c04c | 2007-08-28 05:06:17 +0000 | [diff] [blame] | 101 | //===----------------------------------------------------------------------===// |
| 102 | // |
| 103 | // Mips Asm Directives |
| 104 | // |
| 105 | // -- Frame directive "frame Stackpointer, Stacksize, RARegister" |
| 106 | // Describe the stack frame. |
| 107 | // |
| 108 | // -- Mask directives "(f)mask bitmask, offset" |
| 109 | // Tells the assembler which registers are saved and where. |
| 110 | // bitmask - contain a little endian bitset indicating which registers are |
| 111 | // saved on function prologue (e.g. with a 0x80000000 mask, the |
| 112 | // assembler knows the register 31 (RA) is saved at prologue. |
| 113 | // offset - the position before stack pointer subtraction indicating where |
| 114 | // the first saved register on prologue is located. (e.g. with a |
| 115 | // |
| 116 | // Consider the following function prologue: |
| 117 | // |
Bill Wendling | 6ef781f | 2008-02-27 06:33:05 +0000 | [diff] [blame] | 118 | // .frame $fp,48,$ra |
| 119 | // .mask 0xc0000000,-8 |
| 120 | // addiu $sp, $sp, -48 |
| 121 | // sw $ra, 40($sp) |
| 122 | // sw $fp, 36($sp) |
Bruno Cardoso Lopes | dc0c04c | 2007-08-28 05:06:17 +0000 | [diff] [blame] | 123 | // |
| 124 | // With a 0xc0000000 mask, the assembler knows the register 31 (RA) and |
| 125 | // 30 (FP) are saved at prologue. As the save order on prologue is from |
| 126 | // left to right, RA is saved first. A -8 offset means that after the |
| 127 | // stack pointer subtration, the first register in the mask (RA) will be |
| 128 | // saved at address 48-8=40. |
| 129 | // |
| 130 | //===----------------------------------------------------------------------===// |
| 131 | |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 132 | //===----------------------------------------------------------------------===// |
| 133 | // Mask directives |
| 134 | //===----------------------------------------------------------------------===// |
| 135 | |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 136 | // Create a bitmask with all callee saved registers for CPU or Floating Point |
| 137 | // registers. For CPU registers consider RA, GP and FP for saving if necessary. |
Bruno Cardoso Lopes | dc0c04c | 2007-08-28 05:06:17 +0000 | [diff] [blame] | 138 | void MipsAsmPrinter:: |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 139 | printSavedRegsBitmask(MachineFunction &MF) |
Bruno Cardoso Lopes | dc0c04c | 2007-08-28 05:06:17 +0000 | [diff] [blame] | 140 | { |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 141 | const TargetRegisterInfo &RI = *TM.getRegisterInfo(); |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 142 | MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); |
Bruno Cardoso Lopes | dc0c04c | 2007-08-28 05:06:17 +0000 | [diff] [blame] | 143 | |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 144 | // CPU and FPU Saved Registers Bitmasks |
| 145 | unsigned int CPUBitmask = 0; |
| 146 | unsigned int FPUBitmask = 0; |
Bruno Cardoso Lopes | dc0c04c | 2007-08-28 05:06:17 +0000 | [diff] [blame] | 147 | |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 148 | // Set the CPU and FPU Bitmasks |
Bruno Cardoso Lopes | dc0c04c | 2007-08-28 05:06:17 +0000 | [diff] [blame] | 149 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 150 | const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo(); |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 151 | for (unsigned i = 0, e = CSI.size(); i != e; ++i) { |
| 152 | unsigned RegNum = MipsRegisterInfo::getRegisterNumbering(CSI[i].getReg()); |
| 153 | if (CSI[i].getRegClass() == Mips::CPURegsRegisterClass) |
| 154 | CPUBitmask |= (1 << RegNum); |
| 155 | else |
| 156 | FPUBitmask |= (1 << RegNum); |
| 157 | } |
Bruno Cardoso Lopes | dc0c04c | 2007-08-28 05:06:17 +0000 | [diff] [blame] | 158 | |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 159 | // Return Address and Frame registers must also be set in CPUBitmask. |
Bruno Cardoso Lopes | dc0c04c | 2007-08-28 05:06:17 +0000 | [diff] [blame] | 160 | if (RI.hasFP(MF)) |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 161 | CPUBitmask |= (1 << MipsRegisterInfo:: |
Bruno Cardoso Lopes | 0a60400 | 2007-10-09 03:01:19 +0000 | [diff] [blame] | 162 | getRegisterNumbering(RI.getFrameRegister(MF))); |
Bruno Cardoso Lopes | dc0c04c | 2007-08-28 05:06:17 +0000 | [diff] [blame] | 163 | |
| 164 | if (MF.getFrameInfo()->hasCalls()) |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 165 | CPUBitmask |= (1 << MipsRegisterInfo:: |
Bruno Cardoso Lopes | 0a60400 | 2007-10-09 03:01:19 +0000 | [diff] [blame] | 166 | getRegisterNumbering(RI.getRARegister())); |
Bruno Cardoso Lopes | dc0c04c | 2007-08-28 05:06:17 +0000 | [diff] [blame] | 167 | |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 168 | // Print CPUBitmask |
| 169 | O << "\t.mask \t"; printHex32(CPUBitmask); O << ',' |
| 170 | << MipsFI->getCPUTopSavedRegOff() << '\n'; |
| 171 | |
| 172 | // Print FPUBitmask |
| 173 | O << "\t.fmask\t"; printHex32(FPUBitmask); O << "," |
| 174 | << MipsFI->getFPUTopSavedRegOff() << '\n'; |
Bruno Cardoso Lopes | dc0c04c | 2007-08-28 05:06:17 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | // Print a 32 bit hex number with all numbers. |
| 178 | void MipsAsmPrinter:: |
| 179 | printHex32(unsigned int Value) |
| 180 | { |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 181 | O << "0x"; |
Bruno Cardoso Lopes | dc0c04c | 2007-08-28 05:06:17 +0000 | [diff] [blame] | 182 | for (int i = 7; i >= 0; i--) |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 183 | O << utohexstr( (Value & (0xF << (i*4))) >> (i*4) ); |
Bruno Cardoso Lopes | a4e8200 | 2007-07-11 23:24:41 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 186 | //===----------------------------------------------------------------------===// |
| 187 | // Frame and Set directives |
| 188 | //===----------------------------------------------------------------------===// |
| 189 | |
| 190 | /// Frame Directive |
| 191 | void MipsAsmPrinter:: |
| 192 | emitFrameDirective(MachineFunction &MF) |
| 193 | { |
| 194 | const TargetRegisterInfo &RI = *TM.getRegisterInfo(); |
| 195 | |
| 196 | unsigned stackReg = RI.getFrameRegister(MF); |
| 197 | unsigned returnReg = RI.getRARegister(); |
| 198 | unsigned stackSize = MF.getFrameInfo()->getStackSize(); |
| 199 | |
| 200 | |
Anton Korobeynikov | 055a76b | 2008-07-19 13:16:32 +0000 | [diff] [blame] | 201 | O << "\t.frame\t" << '$' << LowercaseString(RI.get(stackReg).AsmName) |
| 202 | << ',' << stackSize << ',' |
| 203 | << '$' << LowercaseString(RI.get(returnReg).AsmName) |
| 204 | << '\n'; |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | /// Emit Set directives. |
| 208 | const char * MipsAsmPrinter:: |
| 209 | emitCurrentABIString(void) |
| 210 | { |
| 211 | switch(Subtarget->getTargetABI()) { |
| 212 | case MipsSubtarget::O32: return "abi32"; |
| 213 | case MipsSubtarget::O64: return "abiO64"; |
| 214 | case MipsSubtarget::N32: return "abiN32"; |
| 215 | case MipsSubtarget::N64: return "abi64"; |
| 216 | case MipsSubtarget::EABI: return "eabi32"; // TODO: handle eabi64 |
| 217 | default: break; |
| 218 | } |
| 219 | |
| 220 | assert(0 && "Unknown Mips ABI"); |
| 221 | return NULL; |
| 222 | } |
| 223 | |
Bruno Cardoso Lopes | a4e8200 | 2007-07-11 23:24:41 +0000 | [diff] [blame] | 224 | /// Emit the directives used by GAS on the start of functions |
| 225 | void MipsAsmPrinter:: |
| 226 | emitFunctionStart(MachineFunction &MF) |
| 227 | { |
| 228 | // Print out the label for the function. |
| 229 | const Function *F = MF.getFunction(); |
Anton Korobeynikov | c25e1ea | 2008-09-24 22:14:23 +0000 | [diff] [blame] | 230 | SwitchToSection(TAI->SectionForGlobal(F)); |
Bruno Cardoso Lopes | a4e8200 | 2007-07-11 23:24:41 +0000 | [diff] [blame] | 231 | |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 232 | // 2 bits aligned |
| 233 | EmitAlignment(2, F); |
Bruno Cardoso Lopes | a4e8200 | 2007-07-11 23:24:41 +0000 | [diff] [blame] | 234 | |
Anton Korobeynikov | 055a76b | 2008-07-19 13:16:32 +0000 | [diff] [blame] | 235 | O << "\t.globl\t" << CurrentFnName << '\n'; |
| 236 | O << "\t.ent\t" << CurrentFnName << '\n'; |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 237 | |
Anton Korobeynikov | f5b6a47 | 2008-08-08 18:25:07 +0000 | [diff] [blame] | 238 | printVisibility(CurrentFnName, F->getVisibility()); |
| 239 | |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 240 | if ((TAI->hasDotTypeDotSizeDirective()) && Subtarget->isLinux()) |
| 241 | O << "\t.type\t" << CurrentFnName << ", @function\n"; |
| 242 | |
Bruno Cardoso Lopes | a4e8200 | 2007-07-11 23:24:41 +0000 | [diff] [blame] | 243 | O << CurrentFnName << ":\n"; |
| 244 | |
| 245 | emitFrameDirective(MF); |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 246 | printSavedRegsBitmask(MF); |
Bruno Cardoso Lopes | 0a60400 | 2007-10-09 03:01:19 +0000 | [diff] [blame] | 247 | |
Anton Korobeynikov | 055a76b | 2008-07-19 13:16:32 +0000 | [diff] [blame] | 248 | O << '\n'; |
Bruno Cardoso Lopes | a4e8200 | 2007-07-11 23:24:41 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | /// Emit the directives used by GAS on the end of functions |
| 252 | void MipsAsmPrinter:: |
Bruno Cardoso Lopes | 0a60400 | 2007-10-09 03:01:19 +0000 | [diff] [blame] | 253 | emitFunctionEnd(MachineFunction &MF) |
| 254 | { |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 255 | // There are instruction for this macros, but they must |
| 256 | // always be at the function end, and we can't emit and |
| 257 | // break with BB logic. |
| 258 | O << "\t.set\tmacro\n"; |
| 259 | O << "\t.set\treorder\n"; |
Bruno Cardoso Lopes | 0a60400 | 2007-10-09 03:01:19 +0000 | [diff] [blame] | 260 | |
Anton Korobeynikov | 055a76b | 2008-07-19 13:16:32 +0000 | [diff] [blame] | 261 | O << "\t.end\t" << CurrentFnName << '\n'; |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 262 | if (TAI->hasDotTypeDotSizeDirective() && !Subtarget->isLinux()) |
Anton Korobeynikov | 055a76b | 2008-07-19 13:16:32 +0000 | [diff] [blame] | 263 | O << "\t.size\t" << CurrentFnName << ", .-" << CurrentFnName << '\n'; |
Bruno Cardoso Lopes | a4e8200 | 2007-07-11 23:24:41 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 266 | /// runOnMachineFunction - This uses the printMachineInstruction() |
| 267 | /// method to print assembly for each instruction. |
| 268 | bool MipsAsmPrinter:: |
| 269 | runOnMachineFunction(MachineFunction &MF) |
| 270 | { |
Bill Wendling | 57f0db8 | 2009-02-24 08:30:20 +0000 | [diff] [blame] | 271 | this->MF = &MF; |
| 272 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 273 | SetupMachineFunction(MF); |
| 274 | |
| 275 | // Print out constants referenced by the function |
| 276 | EmitConstantPool(MF.getConstantPool()); |
| 277 | |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 278 | // Print out jump tables referenced by the function |
| 279 | EmitJumpTableInfo(MF.getJumpTableInfo(), MF); |
| 280 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 281 | O << "\n\n"; |
| 282 | |
Bruno Cardoso Lopes | a4e8200 | 2007-07-11 23:24:41 +0000 | [diff] [blame] | 283 | // Emit the function start directives |
| 284 | emitFunctionStart(MF); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 285 | |
| 286 | // Print out code for the function. |
| 287 | for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); |
| 288 | I != E; ++I) { |
| 289 | |
| 290 | // Print a label for the basic block. |
| 291 | if (I != MF.begin()) { |
Evan Cheng | fb8075d | 2008-02-28 00:43:03 +0000 | [diff] [blame] | 292 | printBasicBlockLabel(I, true, true); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 293 | O << '\n'; |
| 294 | } |
| 295 | |
| 296 | for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); |
| 297 | II != E; ++II) { |
| 298 | // Print the assembly for the instruction. |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 299 | printInstruction(II); |
| 300 | ++EmittedInsts; |
| 301 | } |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 302 | |
| 303 | // Each Basic Block is separated by a newline |
| 304 | O << '\n'; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Bruno Cardoso Lopes | a4e8200 | 2007-07-11 23:24:41 +0000 | [diff] [blame] | 307 | // Emit function end directives |
Bruno Cardoso Lopes | 0a60400 | 2007-10-09 03:01:19 +0000 | [diff] [blame] | 308 | emitFunctionEnd(MF); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 309 | |
| 310 | // We didn't modify anything. |
| 311 | return false; |
| 312 | } |
| 313 | |
Bruno Cardoso Lopes | 91ef849 | 2008-08-02 19:42:36 +0000 | [diff] [blame] | 314 | // Print out an operand for an inline asm expression. |
| 315 | bool MipsAsmPrinter:: |
| 316 | PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
| 317 | unsigned AsmVariant, const char *ExtraCode) |
| 318 | { |
| 319 | // Does this asm operand have a single letter operand modifier? |
| 320 | if (ExtraCode && ExtraCode[0]) |
| 321 | return true; // Unknown modifier. |
| 322 | |
| 323 | printOperand(MI, OpNo); |
| 324 | return false; |
| 325 | } |
| 326 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 327 | void MipsAsmPrinter:: |
| 328 | printOperand(const MachineInstr *MI, int opNum) |
| 329 | { |
| 330 | const MachineOperand &MO = MI->getOperand(opNum); |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 331 | const TargetRegisterInfo &RI = *TM.getRegisterInfo(); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 332 | bool closeP = false; |
| 333 | bool isPIC = (TM.getRelocationModel() == Reloc::PIC_); |
| 334 | bool isCodeLarge = (TM.getCodeModel() == CodeModel::Large); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 335 | |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 336 | // %hi and %lo used on mips gas to load global addresses on |
| 337 | // static code. %got is used to load global addresses when |
| 338 | // using PIC_. %call16 is used to load direct call targets |
| 339 | // on PIC_ and small code size. %call_lo and %call_hi load |
| 340 | // direct call targets on PIC_ and large code size. |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 341 | if (MI->getOpcode() == Mips::LUi && !MO.isReg() && !MO.isImm()) { |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 342 | if ((isPIC) && (isCodeLarge)) |
| 343 | O << "%call_hi("; |
| 344 | else |
| 345 | O << "%hi("; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 346 | closeP = true; |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 347 | } else if ((MI->getOpcode() == Mips::ADDiu) && !MO.isReg() && !MO.isImm()) { |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame] | 348 | const MachineOperand &firstMO = MI->getOperand(opNum-1); |
| 349 | if (firstMO.getReg() == Mips::GP) |
| 350 | O << "%gp_rel("; |
| 351 | else |
| 352 | O << "%lo("; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 353 | closeP = true; |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 354 | } else if ((isPIC) && (MI->getOpcode() == Mips::LW) && |
| 355 | (!MO.isReg()) && (!MO.isImm())) { |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 356 | const MachineOperand &firstMO = MI->getOperand(opNum-1); |
| 357 | const MachineOperand &lastMO = MI->getOperand(opNum+1); |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 358 | if ((firstMO.isReg()) && (lastMO.isReg())) { |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 359 | if ((firstMO.getReg() == Mips::T9) && (lastMO.getReg() == Mips::GP) |
| 360 | && (!isCodeLarge)) |
| 361 | O << "%call16("; |
| 362 | else if ((firstMO.getReg() != Mips::T9) && (lastMO.getReg() == Mips::GP)) |
| 363 | O << "%got("; |
| 364 | else if ((firstMO.getReg() == Mips::T9) && (lastMO.getReg() != Mips::GP) |
| 365 | && (isCodeLarge)) |
| 366 | O << "%call_lo("; |
| 367 | closeP = true; |
| 368 | } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | switch (MO.getType()) |
| 372 | { |
| 373 | case MachineOperand::MO_Register: |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 374 | if (TargetRegisterInfo::isPhysicalRegister(MO.getReg())) |
Anton Korobeynikov | 055a76b | 2008-07-19 13:16:32 +0000 | [diff] [blame] | 375 | O << '$' << LowercaseString (RI.get(MO.getReg()).AsmName); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 376 | else |
Anton Korobeynikov | 055a76b | 2008-07-19 13:16:32 +0000 | [diff] [blame] | 377 | O << '$' << MO.getReg(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 378 | break; |
| 379 | |
| 380 | case MachineOperand::MO_Immediate: |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 381 | O << (short int)MO.getImm(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 382 | break; |
| 383 | |
| 384 | case MachineOperand::MO_MachineBasicBlock: |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 385 | printBasicBlockLabel(MO.getMBB()); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 386 | return; |
| 387 | |
| 388 | case MachineOperand::MO_GlobalAddress: |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 389 | { |
| 390 | const GlobalValue *GV = MO.getGlobal(); |
| 391 | O << Mang->getValueName(GV); |
| 392 | } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 393 | break; |
| 394 | |
| 395 | case MachineOperand::MO_ExternalSymbol: |
| 396 | O << MO.getSymbolName(); |
| 397 | break; |
| 398 | |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 399 | case MachineOperand::MO_JumpTableIndex: |
| 400 | O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 401 | << '_' << MO.getIndex(); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 402 | break; |
| 403 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 404 | case MachineOperand::MO_ConstantPoolIndex: |
| 405 | O << TAI->getPrivateGlobalPrefix() << "CPI" |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 406 | << getFunctionNumber() << "_" << MO.getIndex(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 407 | break; |
| 408 | |
| 409 | default: |
| 410 | O << "<unknown operand type>"; abort (); break; |
| 411 | } |
| 412 | |
| 413 | if (closeP) O << ")"; |
| 414 | } |
| 415 | |
| 416 | void MipsAsmPrinter:: |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 417 | printUnsignedImm(const MachineInstr *MI, int opNum) |
| 418 | { |
| 419 | const MachineOperand &MO = MI->getOperand(opNum); |
| 420 | if (MO.getType() == MachineOperand::MO_Immediate) |
| 421 | O << (unsigned short int)MO.getImm(); |
| 422 | else |
| 423 | printOperand(MI, opNum); |
| 424 | } |
| 425 | |
| 426 | void MipsAsmPrinter:: |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 427 | printMemOperand(const MachineInstr *MI, int opNum, const char *Modifier) |
| 428 | { |
Bruno Cardoso Lopes | b42abeb | 2007-09-24 20:15:11 +0000 | [diff] [blame] | 429 | // when using stack locations for not load/store instructions |
| 430 | // print the same way as all normal 3 operand instructions. |
| 431 | if (Modifier && !strcmp(Modifier, "stackloc")) { |
| 432 | printOperand(MI, opNum+1); |
| 433 | O << ", "; |
| 434 | printOperand(MI, opNum); |
| 435 | return; |
| 436 | } |
| 437 | |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 438 | // Load/Store memory operands -- imm($reg) |
| 439 | // If PIC target the target is loaded as the |
| 440 | // pattern lw $25,%call16($28) |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 441 | printOperand(MI, opNum); |
| 442 | O << "("; |
| 443 | printOperand(MI, opNum+1); |
| 444 | O << ")"; |
| 445 | } |
| 446 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 447 | void MipsAsmPrinter:: |
| 448 | printFCCOperand(const MachineInstr *MI, int opNum, const char *Modifier) |
| 449 | { |
| 450 | const MachineOperand& MO = MI->getOperand(opNum); |
| 451 | O << Mips::MipsFCCToString((Mips::CondCode)MO.getImm()); |
| 452 | } |
| 453 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 454 | bool MipsAsmPrinter:: |
| 455 | doInitialization(Module &M) |
| 456 | { |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 457 | Mang = new Mangler(M, "", TAI->getPrivateGlobalPrefix()); |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 458 | |
| 459 | // Tell the assembler which ABI we are using |
Anton Korobeynikov | 055a76b | 2008-07-19 13:16:32 +0000 | [diff] [blame] | 460 | O << "\t.section .mdebug." << emitCurrentABIString() << '\n'; |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 461 | |
| 462 | // TODO: handle O64 ABI |
| 463 | if (Subtarget->isABI_EABI()) |
| 464 | O << "\t.section .gcc_compiled_long" << |
Anton Korobeynikov | 055a76b | 2008-07-19 13:16:32 +0000 | [diff] [blame] | 465 | (Subtarget->isGP32bit() ? "32" : "64") << '\n'; |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 466 | |
| 467 | // return to previous section |
Anton Korobeynikov | 055a76b | 2008-07-19 13:16:32 +0000 | [diff] [blame] | 468 | O << "\t.previous" << '\n'; |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 469 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 470 | return false; // success |
| 471 | } |
| 472 | |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 473 | void MipsAsmPrinter:: |
| 474 | printModuleLevelGV(const GlobalVariable* GVar) { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 475 | const TargetData *TD = TM.getTargetData(); |
| 476 | |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 477 | if (!GVar->hasInitializer()) |
| 478 | return; // External global require no code |
| 479 | |
| 480 | // Check to see if this is a special global used by LLVM, if so, emit it. |
| 481 | if (EmitSpecialLLVMGlobal(GVar)) |
| 482 | return; |
| 483 | |
| 484 | O << "\n\n"; |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 485 | std::string name = Mang->getValueName(GVar); |
| 486 | Constant *C = GVar->getInitializer(); |
Devang Patel | 0f05d22 | 2009-06-26 02:26:12 +0000 | [diff] [blame] | 487 | if (isa<MDNode>(C) || isa<MDString>(C)) |
Devang Patel | e4c0c0f | 2009-06-25 00:47:42 +0000 | [diff] [blame] | 488 | return; |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 489 | const Type *CTy = C->getType(); |
Duncan Sands | 777d230 | 2009-05-09 07:06:46 +0000 | [diff] [blame] | 490 | unsigned Size = TD->getTypeAllocSize(CTy); |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame] | 491 | const ConstantArray *CVA = dyn_cast<ConstantArray>(C); |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 492 | bool printSizeAndType = true; |
| 493 | |
| 494 | // A data structure or array is aligned in memory to the largest |
| 495 | // alignment boundary required by any data type inside it (this matches |
| 496 | // the Preferred Type Alignment). For integral types, the alignment is |
| 497 | // the type size. |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 498 | unsigned Align; |
| 499 | if (CTy->getTypeID() == Type::IntegerTyID || |
| 500 | CTy->getTypeID() == Type::VoidTyID) { |
| 501 | assert(!(Size & (Size-1)) && "Alignment is not a power of two!"); |
| 502 | Align = Log2_32(Size); |
| 503 | } else |
| 504 | Align = TD->getPreferredTypeAlignmentShift(CTy); |
| 505 | |
Anton Korobeynikov | f5b6a47 | 2008-08-08 18:25:07 +0000 | [diff] [blame] | 506 | printVisibility(name, GVar->getVisibility()); |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 507 | |
Anton Korobeynikov | c25e1ea | 2008-09-24 22:14:23 +0000 | [diff] [blame] | 508 | SwitchToSection(TAI->SectionForGlobal(GVar)); |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 509 | |
| 510 | if (C->isNullValue() && !GVar->hasSection()) { |
| 511 | if (!GVar->isThreadLocal() && |
Duncan Sands | 667d4b8 | 2009-03-07 15:45:40 +0000 | [diff] [blame] | 512 | (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) { |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 513 | if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. |
| 514 | |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 515 | if (GVar->hasLocalLinkage()) |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 516 | O << "\t.local\t" << name << '\n'; |
Anton Korobeynikov | f5b6a47 | 2008-08-08 18:25:07 +0000 | [diff] [blame] | 517 | |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 518 | O << TAI->getCOMMDirective() << name << ',' << Size; |
| 519 | if (TAI->getCOMMDirectiveTakesAlignment()) |
| 520 | O << ',' << (1 << Align); |
| 521 | |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 522 | O << '\n'; |
| 523 | return; |
| 524 | } |
| 525 | } |
| 526 | switch (GVar->getLinkage()) { |
Duncan Sands | 667d4b8 | 2009-03-07 15:45:40 +0000 | [diff] [blame] | 527 | case GlobalValue::LinkOnceAnyLinkage: |
| 528 | case GlobalValue::LinkOnceODRLinkage: |
Duncan Sands | 4dc2b39 | 2009-03-11 20:14:15 +0000 | [diff] [blame] | 529 | case GlobalValue::CommonLinkage: |
Duncan Sands | 667d4b8 | 2009-03-07 15:45:40 +0000 | [diff] [blame] | 530 | case GlobalValue::WeakAnyLinkage: |
| 531 | case GlobalValue::WeakODRLinkage: |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 532 | // FIXME: Verify correct for weak. |
| 533 | // Nonnull linkonce -> weak |
Anton Korobeynikov | 055a76b | 2008-07-19 13:16:32 +0000 | [diff] [blame] | 534 | O << "\t.weak " << name << '\n'; |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 535 | break; |
| 536 | case GlobalValue::AppendingLinkage: |
| 537 | // FIXME: appending linkage variables should go into a section of their name |
| 538 | // or something. For now, just emit them as external. |
| 539 | case GlobalValue::ExternalLinkage: |
| 540 | // If external or appending, declare as a global symbol |
Anton Korobeynikov | 055a76b | 2008-07-19 13:16:32 +0000 | [diff] [blame] | 541 | O << TAI->getGlobalDirective() << name << '\n'; |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 542 | // Fall Through |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 543 | case GlobalValue::PrivateLinkage: |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 544 | case GlobalValue::InternalLinkage: |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame] | 545 | if (CVA && CVA->isCString()) |
Anton Korobeynikov | fcd99bb | 2008-08-07 09:53:38 +0000 | [diff] [blame] | 546 | printSizeAndType = false; |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 547 | break; |
| 548 | case GlobalValue::GhostLinkage: |
| 549 | cerr << "Should not have any unmaterialized functions!\n"; |
| 550 | abort(); |
| 551 | case GlobalValue::DLLImportLinkage: |
| 552 | cerr << "DLLImport linkage is not supported by this target!\n"; |
| 553 | abort(); |
| 554 | case GlobalValue::DLLExportLinkage: |
| 555 | cerr << "DLLExport linkage is not supported by this target!\n"; |
| 556 | abort(); |
| 557 | default: |
| 558 | assert(0 && "Unknown linkage type!"); |
| 559 | } |
| 560 | |
Anton Korobeynikov | fcd99bb | 2008-08-07 09:53:38 +0000 | [diff] [blame] | 561 | EmitAlignment(Align, GVar); |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 562 | |
| 563 | if (TAI->hasDotTypeDotSizeDirective() && printSizeAndType) { |
| 564 | O << "\t.type " << name << ",@object\n"; |
Anton Korobeynikov | 055a76b | 2008-07-19 13:16:32 +0000 | [diff] [blame] | 565 | O << "\t.size " << name << ',' << Size << '\n'; |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | O << name << ":\n"; |
| 569 | EmitGlobalConstant(C); |
| 570 | } |
| 571 | |
| 572 | bool MipsAsmPrinter:: |
| 573 | doFinalization(Module &M) |
| 574 | { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 575 | // Print out module-level global variables here. |
| 576 | for (Module::const_global_iterator I = M.global_begin(), |
| 577 | E = M.global_end(); I != E; ++I) |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 578 | printModuleLevelGV(I); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 579 | |
Anton Korobeynikov | 055a76b | 2008-07-19 13:16:32 +0000 | [diff] [blame] | 580 | O << '\n'; |
Bruno Cardoso Lopes | d2947ee | 2008-06-04 01:45:25 +0000 | [diff] [blame] | 581 | |
Dan Gohman | b8275a3 | 2007-07-25 19:33:14 +0000 | [diff] [blame] | 582 | return AsmPrinter::doFinalization(M); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 583 | } |
Douglas Gregor | 1555a23 | 2009-06-16 20:12:29 +0000 | [diff] [blame] | 584 | |
Chris Lattner | e8f1018 | 2009-06-16 22:38:04 +0000 | [diff] [blame] | 585 | namespace { |
| 586 | static struct Register { |
| 587 | Register() { |
| 588 | MipsTargetMachine::registerAsmPrinter(createMipsCodePrinterPass); |
| 589 | } |
| 590 | } Registrator; |
| 591 | } |
| 592 | |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 593 | // Force static initialization. |
| 594 | extern "C" void LLVMInitializeMipsAsmPrinter() { } |