Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 1 | //===-- ARMAsmPrinter.cpp - Print machine code to an ARM .s file ----------===// |
| 2 | // |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 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 |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains a printer that converts from our internal representation |
| 11 | // of machine-dependent LLVM code to GAS-format ARM assembly language. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Chris Lattner | 95b2c7d | 2006-12-19 22:59:26 +0000 | [diff] [blame] | 15 | #define DEBUG_TYPE "asm-printer" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 16 | #include "ARM.h" |
Jim Grosbach | baf120f | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 17 | #include "ARMAsmPrinter.h" |
Evan Cheng | b72d2a9 | 2011-01-11 21:46:47 +0000 | [diff] [blame] | 18 | #include "ARMAddressingModes.h" |
| 19 | #include "ARMBuildAttrs.h" |
| 20 | #include "ARMBaseRegisterInfo.h" |
| 21 | #include "ARMConstantPoolValue.h" |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 22 | #include "ARMMachineFunctionInfo.h" |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 23 | #include "ARMMCExpr.h" |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 24 | #include "ARMTargetMachine.h" |
Jason W Kim | 17b443d | 2010-10-11 23:01:44 +0000 | [diff] [blame] | 25 | #include "ARMTargetObjectFile.h" |
Evan Cheng | b72d2a9 | 2011-01-11 21:46:47 +0000 | [diff] [blame] | 26 | #include "InstPrinter/ARMInstPrinter.h" |
Dale Johannesen | 3f282aa | 2010-04-26 20:07:31 +0000 | [diff] [blame] | 27 | #include "llvm/Analysis/DebugInfo.h" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 28 | #include "llvm/Constants.h" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 29 | #include "llvm/Module.h" |
Benjamin Kramer | e55b15f | 2009-12-28 12:27:56 +0000 | [diff] [blame] | 30 | #include "llvm/Type.h" |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 31 | #include "llvm/Assembly/Writer.h" |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/MachineModuleInfoImpls.h" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/MachineJumpTableInfo.h" |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 35 | #include "llvm/MC/MCAsmInfo.h" |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 36 | #include "llvm/MC/MCAssembler.h" |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 37 | #include "llvm/MC/MCContext.h" |
Bill Wendling | becd83e | 2010-03-09 00:40:17 +0000 | [diff] [blame] | 38 | #include "llvm/MC/MCExpr.h" |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 39 | #include "llvm/MC/MCInst.h" |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 40 | #include "llvm/MC/MCSectionMachO.h" |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 41 | #include "llvm/MC/MCObjectStreamer.h" |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 42 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | 325d3dc | 2009-09-13 17:14:04 +0000 | [diff] [blame] | 43 | #include "llvm/MC/MCSymbol.h" |
Chris Lattner | d62f1b4 | 2010-03-12 21:19:23 +0000 | [diff] [blame] | 44 | #include "llvm/Target/Mangler.h" |
Rafael Espindola | b01c4bb | 2006-07-27 11:38:51 +0000 | [diff] [blame] | 45 | #include "llvm/Target/TargetData.h" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 46 | #include "llvm/Target/TargetMachine.h" |
Evan Cheng | 5be54b0 | 2007-01-19 19:25:36 +0000 | [diff] [blame] | 47 | #include "llvm/Target/TargetOptions.h" |
Daniel Dunbar | 51b198a | 2009-07-15 20:24:03 +0000 | [diff] [blame] | 48 | #include "llvm/Target/TargetRegistry.h" |
Evan Cheng | c324ecb | 2009-07-24 18:19:46 +0000 | [diff] [blame] | 49 | #include "llvm/ADT/SmallPtrSet.h" |
Jim Grosbach | c40d9f9 | 2009-09-01 18:49:12 +0000 | [diff] [blame] | 50 | #include "llvm/ADT/SmallString.h" |
Bob Wilson | 54c78ef | 2009-11-06 23:33:28 +0000 | [diff] [blame] | 51 | #include "llvm/ADT/StringExtras.h" |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 52 | #include "llvm/Support/CommandLine.h" |
Devang Patel | 59135f4 | 2010-08-04 22:39:39 +0000 | [diff] [blame] | 53 | #include "llvm/Support/Debug.h" |
Torok Edwin | 3046470 | 2009-07-08 20:55:50 +0000 | [diff] [blame] | 54 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | b23569a | 2010-04-04 08:18:47 +0000 | [diff] [blame] | 55 | #include "llvm/Support/raw_ostream.h" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 56 | #include <cctype> |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 57 | using namespace llvm; |
| 58 | |
Chris Lattner | 95b2c7d | 2006-12-19 22:59:26 +0000 | [diff] [blame] | 59 | namespace { |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 60 | |
| 61 | // Per section and per symbol attributes are not supported. |
| 62 | // To implement them we would need the ability to delay this emission |
| 63 | // until the assembly file is fully parsed/generated as only then do we |
| 64 | // know the symbol and section numbers. |
| 65 | class AttributeEmitter { |
| 66 | public: |
| 67 | virtual void MaybeSwitchVendor(StringRef Vendor) = 0; |
| 68 | virtual void EmitAttribute(unsigned Attribute, unsigned Value) = 0; |
Jason W Kim | f009a96 | 2011-02-07 00:49:53 +0000 | [diff] [blame] | 69 | virtual void EmitTextAttribute(unsigned Attribute, StringRef String) = 0; |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 70 | virtual void Finish() = 0; |
Rafael Espindola | 4921e23 | 2010-10-25 18:38:32 +0000 | [diff] [blame] | 71 | virtual ~AttributeEmitter() {} |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | class AsmAttributeEmitter : public AttributeEmitter { |
| 75 | MCStreamer &Streamer; |
| 76 | |
| 77 | public: |
| 78 | AsmAttributeEmitter(MCStreamer &Streamer_) : Streamer(Streamer_) {} |
| 79 | void MaybeSwitchVendor(StringRef Vendor) { } |
| 80 | |
| 81 | void EmitAttribute(unsigned Attribute, unsigned Value) { |
| 82 | Streamer.EmitRawText("\t.eabi_attribute " + |
| 83 | Twine(Attribute) + ", " + Twine(Value)); |
| 84 | } |
| 85 | |
Jason W Kim | f009a96 | 2011-02-07 00:49:53 +0000 | [diff] [blame] | 86 | void EmitTextAttribute(unsigned Attribute, StringRef String) { |
| 87 | switch (Attribute) { |
| 88 | case ARMBuildAttrs::CPU_name: |
Jason W Kim | c046d64 | 2011-02-07 19:07:11 +0000 | [diff] [blame] | 89 | Streamer.EmitRawText(StringRef("\t.cpu ") + LowercaseString(String)); |
Jason W Kim | f009a96 | 2011-02-07 00:49:53 +0000 | [diff] [blame] | 90 | break; |
Renato Golin | 728ff0d | 2011-02-28 22:04:27 +0000 | [diff] [blame] | 91 | /* GAS requires .fpu to be emitted regardless of EABI attribute */ |
| 92 | case ARMBuildAttrs::Advanced_SIMD_arch: |
| 93 | case ARMBuildAttrs::VFP_arch: |
| 94 | Streamer.EmitRawText(StringRef("\t.fpu ") + LowercaseString(String)); |
| 95 | break; |
Jason W Kim | f009a96 | 2011-02-07 00:49:53 +0000 | [diff] [blame] | 96 | default: assert(0 && "Unsupported Text attribute in ASM Mode"); break; |
| 97 | } |
| 98 | } |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 99 | void Finish() { } |
| 100 | }; |
| 101 | |
| 102 | class ObjectAttributeEmitter : public AttributeEmitter { |
| 103 | MCObjectStreamer &Streamer; |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 104 | StringRef CurrentVendor; |
| 105 | SmallString<64> Contents; |
| 106 | |
| 107 | public: |
| 108 | ObjectAttributeEmitter(MCObjectStreamer &Streamer_) : |
| 109 | Streamer(Streamer_), CurrentVendor("") { } |
| 110 | |
| 111 | void MaybeSwitchVendor(StringRef Vendor) { |
| 112 | assert(!Vendor.empty() && "Vendor cannot be empty."); |
| 113 | |
| 114 | if (CurrentVendor.empty()) |
| 115 | CurrentVendor = Vendor; |
| 116 | else if (CurrentVendor == Vendor) |
| 117 | return; |
| 118 | else |
| 119 | Finish(); |
| 120 | |
| 121 | CurrentVendor = Vendor; |
| 122 | |
Rafael Espindola | 3336384 | 2010-10-25 22:26:55 +0000 | [diff] [blame] | 123 | assert(Contents.size() == 0); |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void EmitAttribute(unsigned Attribute, unsigned Value) { |
| 127 | // FIXME: should be ULEB |
| 128 | Contents += Attribute; |
| 129 | Contents += Value; |
| 130 | } |
| 131 | |
Jason W Kim | f009a96 | 2011-02-07 00:49:53 +0000 | [diff] [blame] | 132 | void EmitTextAttribute(unsigned Attribute, StringRef String) { |
| 133 | Contents += Attribute; |
Jason W Kim | c046d64 | 2011-02-07 19:07:11 +0000 | [diff] [blame] | 134 | Contents += UppercaseString(String); |
Jason W Kim | f009a96 | 2011-02-07 00:49:53 +0000 | [diff] [blame] | 135 | Contents += 0; |
| 136 | } |
| 137 | |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 138 | void Finish() { |
Rafael Espindola | 3336384 | 2010-10-25 22:26:55 +0000 | [diff] [blame] | 139 | const size_t ContentsSize = Contents.size(); |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 140 | |
Rafael Espindola | 3336384 | 2010-10-25 22:26:55 +0000 | [diff] [blame] | 141 | // Vendor size + Vendor name + '\0' |
| 142 | const size_t VendorHeaderSize = 4 + CurrentVendor.size() + 1; |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 143 | |
Rafael Espindola | 3336384 | 2010-10-25 22:26:55 +0000 | [diff] [blame] | 144 | // Tag + Tag Size |
| 145 | const size_t TagHeaderSize = 1 + 4; |
| 146 | |
| 147 | Streamer.EmitIntValue(VendorHeaderSize + TagHeaderSize + ContentsSize, 4); |
| 148 | Streamer.EmitBytes(CurrentVendor, 0); |
| 149 | Streamer.EmitIntValue(0, 1); // '\0' |
| 150 | |
| 151 | Streamer.EmitIntValue(ARMBuildAttrs::File, 1); |
| 152 | Streamer.EmitIntValue(TagHeaderSize + ContentsSize, 4); |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 153 | |
| 154 | Streamer.EmitBytes(Contents, 0); |
Rafael Espindola | 3336384 | 2010-10-25 22:26:55 +0000 | [diff] [blame] | 155 | |
| 156 | Contents.clear(); |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 157 | } |
| 158 | }; |
| 159 | |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 160 | } // end of anonymous namespace |
| 161 | |
Jim Grosbach | baf120f | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 162 | MachineLocation ARMAsmPrinter:: |
| 163 | getDebugValueLocation(const MachineInstr *MI) const { |
| 164 | MachineLocation Location; |
| 165 | assert(MI->getNumOperands() == 4 && "Invalid no. of machine operands!"); |
| 166 | // Frame address. Currently handles register +- offset only. |
| 167 | if (MI->getOperand(0).isReg() && MI->getOperand(1).isImm()) |
| 168 | Location.set(MI->getOperand(0).getReg(), MI->getOperand(1).getImm()); |
| 169 | else { |
| 170 | DEBUG(dbgs() << "DBG_VALUE instruction ignored! " << *MI << "\n"); |
| 171 | } |
| 172 | return Location; |
| 173 | } |
| 174 | |
Devang Patel | c26f544 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 175 | /// getDwarfRegOpSize - get size required to emit given machine location using |
| 176 | /// dwarf encoding. |
| 177 | unsigned ARMAsmPrinter::getDwarfRegOpSize(const MachineLocation &MLoc) const { |
| 178 | const TargetRegisterInfo *RI = TM.getRegisterInfo(); |
| 179 | if (RI->getDwarfRegNum(MLoc.getReg(), false) != -1) |
| 180 | return AsmPrinter::getDwarfRegOpSize(MLoc); |
| 181 | else { |
| 182 | unsigned Reg = MLoc.getReg(); |
| 183 | if (Reg >= ARM::S0 && Reg <= ARM::S31) { |
| 184 | assert(ARM::S0 + 31 == ARM::S31 && "Unexpected ARM S register numbering"); |
| 185 | // S registers are described as bit-pieces of a register |
| 186 | // S[2x] = DW_OP_regx(256 + (x>>1)) DW_OP_bit_piece(32, 0) |
| 187 | // S[2x+1] = DW_OP_regx(256 + (x>>1)) DW_OP_bit_piece(32, 32) |
| 188 | |
| 189 | unsigned SReg = Reg - ARM::S0; |
| 190 | unsigned Rx = 256 + (SReg >> 1); |
Devang Patel | c26f544 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 191 | // DW_OP_regx + ULEB + DW_OP_bit_piece + ULEB + ULEB |
| 192 | // 1 + ULEB(Rx) + 1 + 1 + 1 |
| 193 | return 4 + MCAsmInfo::getULEB128Size(Rx); |
| 194 | } |
| 195 | |
| 196 | if (Reg >= ARM::Q0 && Reg <= ARM::Q15) { |
| 197 | assert(ARM::Q0 + 15 == ARM::Q15 && "Unexpected ARM Q register numbering"); |
| 198 | // Q registers Q0-Q15 are described by composing two D registers together. |
| 199 | // Qx = DW_OP_regx(256+2x) DW_OP_piece(8) DW_OP_regx(256+2x+1) DW_OP_piece(8) |
| 200 | |
| 201 | unsigned QReg = Reg - ARM::Q0; |
| 202 | unsigned D1 = 256 + 2 * QReg; |
| 203 | unsigned D2 = D1 + 1; |
| 204 | |
Devang Patel | c26f544 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 205 | // DW_OP_regx + ULEB + DW_OP_piece + ULEB(8) + |
| 206 | // DW_OP_regx + ULEB + DW_OP_piece + ULEB(8); |
| 207 | // 6 + ULEB(D1) + ULEB(D2) |
| 208 | return 6 + MCAsmInfo::getULEB128Size(D1) + MCAsmInfo::getULEB128Size(D2); |
| 209 | } |
| 210 | } |
| 211 | return 0; |
| 212 | } |
| 213 | |
Devang Patel | 27f5acb | 2011-04-21 22:48:26 +0000 | [diff] [blame] | 214 | /// EmitDwarfRegOp - Emit dwarf register operation. |
Devang Patel | 0be77df | 2011-04-27 20:29:27 +0000 | [diff] [blame] | 215 | void ARMAsmPrinter::EmitDwarfRegOp(const MachineLocation &MLoc) const { |
Devang Patel | 27f5acb | 2011-04-21 22:48:26 +0000 | [diff] [blame] | 216 | const TargetRegisterInfo *RI = TM.getRegisterInfo(); |
| 217 | if (RI->getDwarfRegNum(MLoc.getReg(), false) != -1) |
Devang Patel | 0be77df | 2011-04-27 20:29:27 +0000 | [diff] [blame] | 218 | AsmPrinter::EmitDwarfRegOp(MLoc); |
Devang Patel | 27f5acb | 2011-04-21 22:48:26 +0000 | [diff] [blame] | 219 | else { |
| 220 | unsigned Reg = MLoc.getReg(); |
| 221 | if (Reg >= ARM::S0 && Reg <= ARM::S31) { |
Devang Patel | 0a6ea83 | 2011-04-22 16:44:29 +0000 | [diff] [blame] | 222 | assert(ARM::S0 + 31 == ARM::S31 && "Unexpected ARM S register numbering"); |
Devang Patel | 27f5acb | 2011-04-21 22:48:26 +0000 | [diff] [blame] | 223 | // S registers are described as bit-pieces of a register |
| 224 | // S[2x] = DW_OP_regx(256 + (x>>1)) DW_OP_bit_piece(32, 0) |
| 225 | // S[2x+1] = DW_OP_regx(256 + (x>>1)) DW_OP_bit_piece(32, 32) |
| 226 | |
| 227 | unsigned SReg = Reg - ARM::S0; |
| 228 | bool odd = SReg & 0x1; |
| 229 | unsigned Rx = 256 + (SReg >> 1); |
Devang Patel | 27f5acb | 2011-04-21 22:48:26 +0000 | [diff] [blame] | 230 | |
| 231 | OutStreamer.AddComment("DW_OP_regx for S register"); |
| 232 | EmitInt8(dwarf::DW_OP_regx); |
| 233 | |
| 234 | OutStreamer.AddComment(Twine(SReg)); |
| 235 | EmitULEB128(Rx); |
| 236 | |
| 237 | if (odd) { |
| 238 | OutStreamer.AddComment("DW_OP_bit_piece 32 32"); |
| 239 | EmitInt8(dwarf::DW_OP_bit_piece); |
| 240 | EmitULEB128(32); |
| 241 | EmitULEB128(32); |
| 242 | } else { |
| 243 | OutStreamer.AddComment("DW_OP_bit_piece 32 0"); |
| 244 | EmitInt8(dwarf::DW_OP_bit_piece); |
| 245 | EmitULEB128(32); |
| 246 | EmitULEB128(0); |
| 247 | } |
Devang Patel | 71f3f11 | 2011-04-21 23:22:35 +0000 | [diff] [blame] | 248 | } else if (Reg >= ARM::Q0 && Reg <= ARM::Q15) { |
Devang Patel | 0a6ea83 | 2011-04-22 16:44:29 +0000 | [diff] [blame] | 249 | assert(ARM::Q0 + 15 == ARM::Q15 && "Unexpected ARM Q register numbering"); |
Devang Patel | 71f3f11 | 2011-04-21 23:22:35 +0000 | [diff] [blame] | 250 | // Q registers Q0-Q15 are described by composing two D registers together. |
| 251 | // Qx = DW_OP_regx(256+2x) DW_OP_piece(8) DW_OP_regx(256+2x+1) DW_OP_piece(8) |
| 252 | |
| 253 | unsigned QReg = Reg - ARM::Q0; |
| 254 | unsigned D1 = 256 + 2 * QReg; |
| 255 | unsigned D2 = D1 + 1; |
| 256 | |
Devang Patel | 71f3f11 | 2011-04-21 23:22:35 +0000 | [diff] [blame] | 257 | OutStreamer.AddComment("DW_OP_regx for Q register: D1"); |
| 258 | EmitInt8(dwarf::DW_OP_regx); |
| 259 | EmitULEB128(D1); |
| 260 | OutStreamer.AddComment("DW_OP_piece 8"); |
| 261 | EmitInt8(dwarf::DW_OP_piece); |
| 262 | EmitULEB128(8); |
| 263 | |
| 264 | OutStreamer.AddComment("DW_OP_regx for Q register: D2"); |
| 265 | EmitInt8(dwarf::DW_OP_regx); |
| 266 | EmitULEB128(D2); |
| 267 | OutStreamer.AddComment("DW_OP_piece 8"); |
| 268 | EmitInt8(dwarf::DW_OP_piece); |
| 269 | EmitULEB128(8); |
Devang Patel | 27f5acb | 2011-04-21 22:48:26 +0000 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
Chris Lattner | 953ebb7 | 2010-01-27 23:58:11 +0000 | [diff] [blame] | 274 | void ARMAsmPrinter::EmitFunctionEntryLabel() { |
| 275 | if (AFI->isThumbFunction()) { |
Jim Grosbach | ce79299 | 2010-11-05 22:08:08 +0000 | [diff] [blame] | 276 | OutStreamer.EmitAssemblerFlag(MCAF_Code16); |
Rafael Espindola | 6469540 | 2011-05-16 16:17:21 +0000 | [diff] [blame] | 277 | OutStreamer.EmitThumbFunc(CurrentFnSym); |
Chris Lattner | 953ebb7 | 2010-01-27 23:58:11 +0000 | [diff] [blame] | 278 | } |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 279 | |
Chris Lattner | 953ebb7 | 2010-01-27 23:58:11 +0000 | [diff] [blame] | 280 | OutStreamer.EmitLabel(CurrentFnSym); |
| 281 | } |
| 282 | |
Jim Grosbach | 2317e40 | 2010-09-30 01:57:53 +0000 | [diff] [blame] | 283 | /// runOnMachineFunction - This uses the EmitInstruction() |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 284 | /// method to print assembly for each instruction. |
| 285 | /// |
| 286 | bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 287 | AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 6d63a72 | 2008-09-18 07:27:23 +0000 | [diff] [blame] | 288 | MCP = MF.getConstantPool(); |
Rafael Espindola | 4b442b5 | 2006-05-23 02:48:20 +0000 | [diff] [blame] | 289 | |
Chris Lattner | d49fe1b | 2010-01-28 01:28:58 +0000 | [diff] [blame] | 290 | return AsmPrinter::runOnMachineFunction(MF); |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 293 | void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum, |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 294 | raw_ostream &O, const char *Modifier) { |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 295 | const MachineOperand &MO = MI->getOperand(OpNum); |
Anton Korobeynikov | 5cdc3a9 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 296 | unsigned TF = MO.getTargetFlags(); |
| 297 | |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 298 | switch (MO.getType()) { |
Chris Lattner | 8bc86cb | 2009-10-19 20:59:55 +0000 | [diff] [blame] | 299 | default: |
| 300 | assert(0 && "<unknown operand type>"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 301 | case MachineOperand::MO_Register: { |
| 302 | unsigned Reg = MO.getReg(); |
Chris Lattner | 8bc86cb | 2009-10-19 20:59:55 +0000 | [diff] [blame] | 303 | assert(TargetRegisterInfo::isPhysicalRegister(Reg)); |
Jim Grosbach | 3563628 | 2010-10-06 21:22:32 +0000 | [diff] [blame] | 304 | assert(!MO.getSubReg() && "Subregs should be eliminated!"); |
| 305 | O << ARMInstPrinter::getRegisterName(Reg); |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 306 | break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 307 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 308 | case MachineOperand::MO_Immediate: { |
Evan Cheng | 5adb66a | 2009-09-28 09:14:39 +0000 | [diff] [blame] | 309 | int64_t Imm = MO.getImm(); |
Anton Korobeynikov | 632606c | 2009-10-08 20:43:22 +0000 | [diff] [blame] | 310 | O << '#'; |
Anton Korobeynikov | 5cdc3a9 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 311 | if ((Modifier && strcmp(Modifier, "lo16") == 0) || |
Jason W Kim | 650b7d7 | 2011-01-12 23:21:49 +0000 | [diff] [blame] | 312 | (TF == ARMII::MO_LO16)) |
Anton Korobeynikov | 5cdc3a9 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 313 | O << ":lower16:"; |
| 314 | else if ((Modifier && strcmp(Modifier, "hi16") == 0) || |
Jason W Kim | 650b7d7 | 2011-01-12 23:21:49 +0000 | [diff] [blame] | 315 | (TF == ARMII::MO_HI16)) |
Anton Korobeynikov | 5cdc3a9 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 316 | O << ":upper16:"; |
Anton Korobeynikov | 632606c | 2009-10-08 20:43:22 +0000 | [diff] [blame] | 317 | O << Imm; |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 318 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 319 | } |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 320 | case MachineOperand::MO_MachineBasicBlock: |
Chris Lattner | 1b2eb0e | 2010-03-13 21:04:28 +0000 | [diff] [blame] | 321 | O << *MO.getMBB()->getSymbol(); |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 322 | return; |
Rafael Espindola | 84b19be | 2006-07-16 01:02:57 +0000 | [diff] [blame] | 323 | case MachineOperand::MO_GlobalAddress: { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 324 | const GlobalValue *GV = MO.getGlobal(); |
Anton Korobeynikov | 5cdc3a9 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 325 | if ((Modifier && strcmp(Modifier, "lo16") == 0) || |
| 326 | (TF & ARMII::MO_LO16)) |
| 327 | O << ":lower16:"; |
| 328 | else if ((Modifier && strcmp(Modifier, "hi16") == 0) || |
| 329 | (TF & ARMII::MO_HI16)) |
| 330 | O << ":upper16:"; |
Chris Lattner | d62f1b4 | 2010-03-12 21:19:23 +0000 | [diff] [blame] | 331 | O << *Mang->getSymbol(GV); |
Anton Korobeynikov | 7751ad9 | 2008-11-22 16:15:34 +0000 | [diff] [blame] | 332 | |
Chris Lattner | 0c08d09 | 2010-04-03 22:28:33 +0000 | [diff] [blame] | 333 | printOffset(MO.getOffset(), O); |
Jim Grosbach | 1d6111c | 2010-10-06 21:36:43 +0000 | [diff] [blame] | 334 | if (TF == ARMII::MO_PLT) |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 335 | O << "(PLT)"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 336 | break; |
Rafael Espindola | 84b19be | 2006-07-16 01:02:57 +0000 | [diff] [blame] | 337 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 338 | case MachineOperand::MO_ExternalSymbol: { |
Chris Lattner | 10b318b | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 339 | O << *GetExternalSymbolSymbol(MO.getSymbolName()); |
Jim Grosbach | 1d6111c | 2010-10-06 21:36:43 +0000 | [diff] [blame] | 340 | if (TF == ARMII::MO_PLT) |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 341 | O << "(PLT)"; |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 342 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 343 | } |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 344 | case MachineOperand::MO_ConstantPoolIndex: |
Chris Lattner | 1b46f43 | 2010-01-23 07:00:21 +0000 | [diff] [blame] | 345 | O << *GetCPISymbol(MO.getIndex()); |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 346 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 347 | case MachineOperand::MO_JumpTableIndex: |
Chris Lattner | 1b46f43 | 2010-01-23 07:00:21 +0000 | [diff] [blame] | 348 | O << *GetJTISymbol(MO.getIndex()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 349 | break; |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 350 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 351 | } |
| 352 | |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 353 | //===--------------------------------------------------------------------===// |
| 354 | |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 355 | MCSymbol *ARMAsmPrinter:: |
| 356 | GetARMSetPICJumpTableLabel2(unsigned uid, unsigned uid2, |
| 357 | const MachineBasicBlock *MBB) const { |
| 358 | SmallString<60> Name; |
| 359 | raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() |
Chris Lattner | bfcb096 | 2010-01-25 19:39:52 +0000 | [diff] [blame] | 360 | << getFunctionNumber() << '_' << uid << '_' << uid2 |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 361 | << "_set_" << MBB->getNumber(); |
Chris Lattner | 9b97a73 | 2010-03-30 18:10:53 +0000 | [diff] [blame] | 362 | return OutContext.GetOrCreateSymbol(Name.str()); |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | MCSymbol *ARMAsmPrinter:: |
| 366 | GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const { |
| 367 | SmallString<60> Name; |
| 368 | raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "JTI" |
Chris Lattner | 281e776 | 2010-01-25 23:28:03 +0000 | [diff] [blame] | 369 | << getFunctionNumber() << '_' << uid << '_' << uid2; |
Chris Lattner | 9b97a73 | 2010-03-30 18:10:53 +0000 | [diff] [blame] | 370 | return OutContext.GetOrCreateSymbol(Name.str()); |
Chris Lattner | bfcb096 | 2010-01-25 19:39:52 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Jim Grosbach | 433a578 | 2010-09-24 20:47:58 +0000 | [diff] [blame] | 373 | |
| 374 | MCSymbol *ARMAsmPrinter::GetARMSJLJEHLabel(void) const { |
| 375 | SmallString<60> Name; |
| 376 | raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "SJLJEH" |
| 377 | << getFunctionNumber(); |
| 378 | return OutContext.GetOrCreateSymbol(Name.str()); |
| 379 | } |
| 380 | |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 381 | bool ARMAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum, |
Chris Lattner | c75c028 | 2010-04-04 05:29:35 +0000 | [diff] [blame] | 382 | unsigned AsmVariant, const char *ExtraCode, |
| 383 | raw_ostream &O) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 384 | // Does this asm operand have a single letter operand modifier? |
| 385 | if (ExtraCode && ExtraCode[0]) { |
| 386 | if (ExtraCode[1] != 0) return true; // Unknown modifier. |
Anton Korobeynikov | 8e9ece7 | 2009-08-08 23:10:41 +0000 | [diff] [blame] | 387 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 388 | switch (ExtraCode[0]) { |
| 389 | default: return true; // Unknown modifier. |
Bob Wilson | 9b4b00a | 2009-07-09 23:54:51 +0000 | [diff] [blame] | 390 | case 'a': // Print as a memory address. |
| 391 | if (MI->getOperand(OpNum).isReg()) { |
Jim Grosbach | 2f24c4e | 2010-09-30 15:25:22 +0000 | [diff] [blame] | 392 | O << "[" |
| 393 | << ARMInstPrinter::getRegisterName(MI->getOperand(OpNum).getReg()) |
| 394 | << "]"; |
Bob Wilson | 9b4b00a | 2009-07-09 23:54:51 +0000 | [diff] [blame] | 395 | return false; |
| 396 | } |
| 397 | // Fallthrough |
| 398 | case 'c': // Don't print "#" before an immediate operand. |
Bob Wilson | 4f38b38 | 2009-08-21 21:58:55 +0000 | [diff] [blame] | 399 | if (!MI->getOperand(OpNum).isImm()) |
| 400 | return true; |
Jim Grosbach | 2317e40 | 2010-09-30 01:57:53 +0000 | [diff] [blame] | 401 | O << MI->getOperand(OpNum).getImm(); |
Bob Wilson | 8f34346 | 2009-04-06 21:46:51 +0000 | [diff] [blame] | 402 | return false; |
Evan Cheng | e21e396 | 2007-04-04 00:13:29 +0000 | [diff] [blame] | 403 | case 'P': // Print a VFP double precision register. |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 404 | case 'q': // Print a NEON quad precision register. |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 405 | printOperand(MI, OpNum, O); |
Evan Cheng | 23a9570 | 2007-03-08 22:42:46 +0000 | [diff] [blame] | 406 | return false; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 407 | case 'Q': |
Bob Wilson | d984eb6 | 2010-05-27 20:23:42 +0000 | [diff] [blame] | 408 | case 'R': |
Bob Wilson | d984eb6 | 2010-05-27 20:23:42 +0000 | [diff] [blame] | 409 | case 'H': |
Bob Wilson | 9bb43e1 | 2010-12-17 23:06:42 +0000 | [diff] [blame] | 410 | // These modifiers are not yet supported. |
Bob Wilson | d984eb6 | 2010-05-27 20:23:42 +0000 | [diff] [blame] | 411 | return true; |
Evan Cheng | 84f60b7 | 2010-05-27 22:08:38 +0000 | [diff] [blame] | 412 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 413 | } |
Jim Grosbach | e995221 | 2009-09-04 01:38:51 +0000 | [diff] [blame] | 414 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 415 | printOperand(MI, OpNum, O); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 416 | return false; |
| 417 | } |
| 418 | |
Bob Wilson | 224c244 | 2009-05-19 05:53:42 +0000 | [diff] [blame] | 419 | bool ARMAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 420 | unsigned OpNum, unsigned AsmVariant, |
Chris Lattner | c75c028 | 2010-04-04 05:29:35 +0000 | [diff] [blame] | 421 | const char *ExtraCode, |
| 422 | raw_ostream &O) { |
Bob Wilson | 224c244 | 2009-05-19 05:53:42 +0000 | [diff] [blame] | 423 | if (ExtraCode && ExtraCode[0]) |
| 424 | return true; // Unknown modifier. |
Bob Wilson | 765cc0b | 2009-10-13 20:50:28 +0000 | [diff] [blame] | 425 | |
| 426 | const MachineOperand &MO = MI->getOperand(OpNum); |
| 427 | assert(MO.isReg() && "unexpected inline asm memory operand"); |
Jim Grosbach | 2317e40 | 2010-09-30 01:57:53 +0000 | [diff] [blame] | 428 | O << "[" << ARMInstPrinter::getRegisterName(MO.getReg()) << "]"; |
Bob Wilson | 224c244 | 2009-05-19 05:53:42 +0000 | [diff] [blame] | 429 | return false; |
| 430 | } |
| 431 | |
Bob Wilson | 812209a | 2009-09-30 22:06:26 +0000 | [diff] [blame] | 432 | void ARMAsmPrinter::EmitStartOfAsmFile(Module &M) { |
Bob Wilson | 0fb3468 | 2009-09-30 00:23:42 +0000 | [diff] [blame] | 433 | if (Subtarget->isTargetDarwin()) { |
| 434 | Reloc::Model RelocM = TM.getRelocationModel(); |
| 435 | if (RelocM == Reloc::PIC_ || RelocM == Reloc::DynamicNoPIC) { |
| 436 | // Declare all the text sections up front (before the DWARF sections |
| 437 | // emitted by AsmPrinter::doInitialization) so the assembler will keep |
| 438 | // them together at the beginning of the object file. This helps |
| 439 | // avoid out-of-range branches that are due a fundamental limitation of |
| 440 | // the way symbol offsets are encoded with the current Darwin ARM |
| 441 | // relocations. |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 442 | const TargetLoweringObjectFileMachO &TLOFMacho = |
Dan Gohman | 0d805c3 | 2010-04-17 16:44:48 +0000 | [diff] [blame] | 443 | static_cast<const TargetLoweringObjectFileMachO &>( |
| 444 | getObjFileLowering()); |
Bob Wilson | 29e0669 | 2009-09-30 22:25:37 +0000 | [diff] [blame] | 445 | OutStreamer.SwitchSection(TLOFMacho.getTextSection()); |
| 446 | OutStreamer.SwitchSection(TLOFMacho.getTextCoalSection()); |
| 447 | OutStreamer.SwitchSection(TLOFMacho.getConstTextCoalSection()); |
| 448 | if (RelocM == Reloc::DynamicNoPIC) { |
| 449 | const MCSection *sect = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 450 | OutContext.getMachOSection("__TEXT", "__symbol_stub4", |
| 451 | MCSectionMachO::S_SYMBOL_STUBS, |
| 452 | 12, SectionKind::getText()); |
Bob Wilson | 29e0669 | 2009-09-30 22:25:37 +0000 | [diff] [blame] | 453 | OutStreamer.SwitchSection(sect); |
| 454 | } else { |
| 455 | const MCSection *sect = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 456 | OutContext.getMachOSection("__TEXT", "__picsymbolstub4", |
| 457 | MCSectionMachO::S_SYMBOL_STUBS, |
| 458 | 16, SectionKind::getText()); |
Bob Wilson | 29e0669 | 2009-09-30 22:25:37 +0000 | [diff] [blame] | 459 | OutStreamer.SwitchSection(sect); |
| 460 | } |
Bob Wilson | 63db594 | 2010-07-30 19:55:47 +0000 | [diff] [blame] | 461 | const MCSection *StaticInitSect = |
| 462 | OutContext.getMachOSection("__TEXT", "__StaticInit", |
| 463 | MCSectionMachO::S_REGULAR | |
| 464 | MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, |
| 465 | SectionKind::getText()); |
| 466 | OutStreamer.SwitchSection(StaticInitSect); |
Bob Wilson | 0fb3468 | 2009-09-30 00:23:42 +0000 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 470 | // Use unified assembler syntax. |
Jason W Kim | afd1cc2 | 2010-09-30 02:45:56 +0000 | [diff] [blame] | 471 | OutStreamer.EmitAssemblerFlag(MCAF_SyntaxUnified); |
Anton Korobeynikov | d61eca5 | 2009-06-17 23:43:18 +0000 | [diff] [blame] | 472 | |
Anton Korobeynikov | 88ce667 | 2009-05-23 19:51:20 +0000 | [diff] [blame] | 473 | // Emit ARM Build Attributes |
| 474 | if (Subtarget->isTargetELF()) { |
Anton Korobeynikov | 88ce667 | 2009-05-23 19:51:20 +0000 | [diff] [blame] | 475 | |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 476 | emitAttributes(); |
Anton Korobeynikov | 88ce667 | 2009-05-23 19:51:20 +0000 | [diff] [blame] | 477 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Anton Korobeynikov | 0f3cc65 | 2008-08-07 09:54:23 +0000 | [diff] [blame] | 480 | |
Chris Lattner | 4a071d6 | 2009-10-19 17:59:19 +0000 | [diff] [blame] | 481 | void ARMAsmPrinter::EmitEndOfAsmFile(Module &M) { |
Evan Cheng | 5be54b0 | 2007-01-19 19:25:36 +0000 | [diff] [blame] | 482 | if (Subtarget->isTargetDarwin()) { |
Chris Lattner | f61159b | 2009-08-03 22:18:15 +0000 | [diff] [blame] | 483 | // All darwin targets use mach-o. |
Dan Gohman | 0d805c3 | 2010-04-17 16:44:48 +0000 | [diff] [blame] | 484 | const TargetLoweringObjectFileMachO &TLOFMacho = |
| 485 | static_cast<const TargetLoweringObjectFileMachO &>(getObjFileLowering()); |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 486 | MachineModuleInfoMachO &MMIMacho = |
| 487 | MMI->getObjFileInfo<MachineModuleInfoMachO>(); |
Jim Grosbach | e995221 | 2009-09-04 01:38:51 +0000 | [diff] [blame] | 488 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 489 | // Output non-lazy-pointers for external and common global variables. |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 490 | MachineModuleInfoMachO::SymbolListTy Stubs = MMIMacho.GetGVStubList(); |
Bill Wendling | cebae36 | 2010-03-10 22:34:10 +0000 | [diff] [blame] | 491 | |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 492 | if (!Stubs.empty()) { |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 493 | // Switch with ".non_lazy_symbol_pointer" directive. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 494 | OutStreamer.SwitchSection(TLOFMacho.getNonLazySymbolPointerSection()); |
Chris Lattner | c076a97 | 2009-08-10 18:01:34 +0000 | [diff] [blame] | 495 | EmitAlignment(2); |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 496 | for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { |
Bill Wendling | becd83e | 2010-03-09 00:40:17 +0000 | [diff] [blame] | 497 | // L_foo$stub: |
| 498 | OutStreamer.EmitLabel(Stubs[i].first); |
| 499 | // .indirect_symbol _foo |
Bill Wendling | 52a50e5 | 2010-03-11 01:18:13 +0000 | [diff] [blame] | 500 | MachineModuleInfoImpl::StubValueTy &MCSym = Stubs[i].second; |
| 501 | OutStreamer.EmitSymbolAttribute(MCSym.getPointer(),MCSA_IndirectSymbol); |
Bill Wendling | cf6f28d | 2010-03-09 00:43:34 +0000 | [diff] [blame] | 502 | |
Bill Wendling | 52a50e5 | 2010-03-11 01:18:13 +0000 | [diff] [blame] | 503 | if (MCSym.getInt()) |
Bill Wendling | cf6f28d | 2010-03-09 00:43:34 +0000 | [diff] [blame] | 504 | // External to current translation unit. |
| 505 | OutStreamer.EmitIntValue(0, 4/*size*/, 0/*addrspace*/); |
| 506 | else |
| 507 | // Internal to current translation unit. |
Bill Wendling | 5e1b55d | 2010-03-31 18:47:10 +0000 | [diff] [blame] | 508 | // |
Jim Grosbach | 1b935a3 | 2010-09-22 16:45:13 +0000 | [diff] [blame] | 509 | // When we place the LSDA into the TEXT section, the type info |
| 510 | // pointers need to be indirect and pc-rel. We accomplish this by |
| 511 | // using NLPs; however, sometimes the types are local to the file. |
| 512 | // We need to fill in the value for the NLP in those cases. |
Bill Wendling | 52a50e5 | 2010-03-11 01:18:13 +0000 | [diff] [blame] | 513 | OutStreamer.EmitValue(MCSymbolRefExpr::Create(MCSym.getPointer(), |
| 514 | OutContext), |
Bill Wendling | cf6f28d | 2010-03-09 00:43:34 +0000 | [diff] [blame] | 515 | 4/*size*/, 0/*addrspace*/); |
Evan Cheng | ae94e59 | 2008-12-05 01:06:39 +0000 | [diff] [blame] | 516 | } |
Bill Wendling | becd83e | 2010-03-09 00:40:17 +0000 | [diff] [blame] | 517 | |
| 518 | Stubs.clear(); |
| 519 | OutStreamer.AddBlankLine(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Chris Lattner | e4d9ea8 | 2009-10-19 18:44:38 +0000 | [diff] [blame] | 522 | Stubs = MMIMacho.GetHiddenGVStubList(); |
| 523 | if (!Stubs.empty()) { |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 524 | OutStreamer.SwitchSection(getObjFileLowering().getDataSection()); |
Chris Lattner | f3231de | 2009-08-10 18:02:16 +0000 | [diff] [blame] | 525 | EmitAlignment(2); |
Bill Wendling | becd83e | 2010-03-09 00:40:17 +0000 | [diff] [blame] | 526 | for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { |
| 527 | // L_foo$stub: |
| 528 | OutStreamer.EmitLabel(Stubs[i].first); |
| 529 | // .long _foo |
Bill Wendling | cebae36 | 2010-03-10 22:34:10 +0000 | [diff] [blame] | 530 | OutStreamer.EmitValue(MCSymbolRefExpr:: |
| 531 | Create(Stubs[i].second.getPointer(), |
| 532 | OutContext), |
Bill Wendling | becd83e | 2010-03-09 00:40:17 +0000 | [diff] [blame] | 533 | 4/*size*/, 0/*addrspace*/); |
| 534 | } |
Bill Wendling | cf6f28d | 2010-03-09 00:43:34 +0000 | [diff] [blame] | 535 | |
| 536 | Stubs.clear(); |
| 537 | OutStreamer.AddBlankLine(); |
Evan Cheng | ae94e59 | 2008-12-05 01:06:39 +0000 | [diff] [blame] | 538 | } |
| 539 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 540 | // Funny Darwin hack: This flag tells the linker that no global symbols |
| 541 | // contain code that falls through to other global symbols (e.g. the obvious |
| 542 | // implementation of multiple entry points). If this doesn't occur, the |
| 543 | // linker can safely perform dead code stripping. Since LLVM never |
| 544 | // generates code that does this, it is always safe to set. |
Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 545 | OutStreamer.EmitAssemblerFlag(MCAF_SubsectionsViaSymbols); |
Rafael Espindola | b01c4bb | 2006-07-27 11:38:51 +0000 | [diff] [blame] | 546 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 547 | } |
Anton Korobeynikov | 0bd8971 | 2008-08-17 13:55:10 +0000 | [diff] [blame] | 548 | |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 549 | //===----------------------------------------------------------------------===// |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 550 | // Helper routines for EmitStartOfAsmFile() and EmitEndOfAsmFile() |
| 551 | // FIXME: |
| 552 | // The following seem like one-off assembler flags, but they actually need |
Jim Grosbach | fa7fb64 | 2010-10-06 22:46:47 +0000 | [diff] [blame] | 553 | // to appear in the .ARM.attributes section in ELF. |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 554 | // Instead of subclassing the MCELFStreamer, we do the work here. |
| 555 | |
| 556 | void ARMAsmPrinter::emitAttributes() { |
Jim Grosbach | fa7fb64 | 2010-10-06 22:46:47 +0000 | [diff] [blame] | 557 | |
Jason W Kim | 17b443d | 2010-10-11 23:01:44 +0000 | [diff] [blame] | 558 | emitARMAttributeSection(); |
| 559 | |
Renato Golin | 728ff0d | 2011-02-28 22:04:27 +0000 | [diff] [blame] | 560 | /* GAS expect .fpu to be emitted, regardless of VFP build attribute */ |
| 561 | bool emitFPU = false; |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 562 | AttributeEmitter *AttrEmitter; |
Renato Golin | 728ff0d | 2011-02-28 22:04:27 +0000 | [diff] [blame] | 563 | if (OutStreamer.hasRawTextSupport()) { |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 564 | AttrEmitter = new AsmAttributeEmitter(OutStreamer); |
Renato Golin | 728ff0d | 2011-02-28 22:04:27 +0000 | [diff] [blame] | 565 | emitFPU = true; |
| 566 | } else { |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 567 | MCObjectStreamer &O = static_cast<MCObjectStreamer&>(OutStreamer); |
| 568 | AttrEmitter = new ObjectAttributeEmitter(O); |
| 569 | } |
| 570 | |
| 571 | AttrEmitter->MaybeSwitchVendor("aeabi"); |
| 572 | |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 573 | std::string CPUString = Subtarget->getCPUString(); |
Jason W Kim | f009a96 | 2011-02-07 00:49:53 +0000 | [diff] [blame] | 574 | |
| 575 | if (CPUString == "cortex-a8" || |
| 576 | Subtarget->isCortexA8()) { |
Jason W Kim | c046d64 | 2011-02-07 19:07:11 +0000 | [diff] [blame] | 577 | AttrEmitter->EmitTextAttribute(ARMBuildAttrs::CPU_name, "cortex-a8"); |
Jason W Kim | f009a96 | 2011-02-07 00:49:53 +0000 | [diff] [blame] | 578 | AttrEmitter->EmitAttribute(ARMBuildAttrs::CPU_arch, ARMBuildAttrs::v7); |
| 579 | AttrEmitter->EmitAttribute(ARMBuildAttrs::CPU_arch_profile, |
| 580 | ARMBuildAttrs::ApplicationProfile); |
| 581 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ARM_ISA_use, |
| 582 | ARMBuildAttrs::Allowed); |
| 583 | AttrEmitter->EmitAttribute(ARMBuildAttrs::THUMB_ISA_use, |
| 584 | ARMBuildAttrs::AllowThumb32); |
| 585 | // Fixme: figure out when this is emitted. |
| 586 | //AttrEmitter->EmitAttribute(ARMBuildAttrs::WMMX_arch, |
| 587 | // ARMBuildAttrs::AllowWMMXv1); |
| 588 | // |
| 589 | |
| 590 | /// ADD additional Else-cases here! |
Rafael Espindola | b8adb8a | 2011-05-20 20:10:34 +0000 | [diff] [blame] | 591 | } else if (CPUString == "xscale") { |
| 592 | AttrEmitter->EmitAttribute(ARMBuildAttrs::CPU_arch, ARMBuildAttrs::v5TEJ); |
| 593 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ARM_ISA_use, |
| 594 | ARMBuildAttrs::Allowed); |
| 595 | AttrEmitter->EmitAttribute(ARMBuildAttrs::THUMB_ISA_use, |
| 596 | ARMBuildAttrs::Allowed); |
Jason W Kim | f009a96 | 2011-02-07 00:49:53 +0000 | [diff] [blame] | 597 | } else if (CPUString == "generic") { |
Dale Johannesen | 7179d1e | 2010-11-08 19:17:22 +0000 | [diff] [blame] | 598 | // FIXME: Why these defaults? |
| 599 | AttrEmitter->EmitAttribute(ARMBuildAttrs::CPU_arch, ARMBuildAttrs::v4T); |
Jason W Kim | f009a96 | 2011-02-07 00:49:53 +0000 | [diff] [blame] | 600 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ARM_ISA_use, |
| 601 | ARMBuildAttrs::Allowed); |
| 602 | AttrEmitter->EmitAttribute(ARMBuildAttrs::THUMB_ISA_use, |
| 603 | ARMBuildAttrs::Allowed); |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 604 | } |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 605 | |
Renato Golin | e89a053 | 2011-03-02 21:20:09 +0000 | [diff] [blame] | 606 | if (Subtarget->hasNEON() && emitFPU) { |
Renato Golin | 728ff0d | 2011-02-28 22:04:27 +0000 | [diff] [blame] | 607 | /* NEON is not exactly a VFP architecture, but GAS emit one of |
| 608 | * neon/vfpv3/vfpv2 for .fpu parameters */ |
| 609 | AttrEmitter->EmitTextAttribute(ARMBuildAttrs::Advanced_SIMD_arch, "neon"); |
| 610 | /* If emitted for NEON, omit from VFP below, since you can have both |
| 611 | * NEON and VFP in build attributes but only one .fpu */ |
| 612 | emitFPU = false; |
| 613 | } |
| 614 | |
| 615 | /* VFPv3 + .fpu */ |
| 616 | if (Subtarget->hasVFP3()) { |
| 617 | AttrEmitter->EmitAttribute(ARMBuildAttrs::VFP_arch, |
| 618 | ARMBuildAttrs::AllowFPv3A); |
| 619 | if (emitFPU) |
| 620 | AttrEmitter->EmitTextAttribute(ARMBuildAttrs::VFP_arch, "vfpv3"); |
| 621 | |
| 622 | /* VFPv2 + .fpu */ |
| 623 | } else if (Subtarget->hasVFP2()) { |
Jason W Kim | f009a96 | 2011-02-07 00:49:53 +0000 | [diff] [blame] | 624 | AttrEmitter->EmitAttribute(ARMBuildAttrs::VFP_arch, |
| 625 | ARMBuildAttrs::AllowFPv2); |
Renato Golin | 728ff0d | 2011-02-28 22:04:27 +0000 | [diff] [blame] | 626 | if (emitFPU) |
| 627 | AttrEmitter->EmitTextAttribute(ARMBuildAttrs::VFP_arch, "vfpv2"); |
| 628 | } |
| 629 | |
| 630 | /* TODO: ARMBuildAttrs::Allowed is not completely accurate, |
| 631 | * since NEON can have 1 (allowed) or 2 (fused MAC operations) */ |
| 632 | if (Subtarget->hasNEON()) { |
| 633 | AttrEmitter->EmitAttribute(ARMBuildAttrs::Advanced_SIMD_arch, |
| 634 | ARMBuildAttrs::Allowed); |
| 635 | } |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 636 | |
| 637 | // Signal various FP modes. |
| 638 | if (!UnsafeFPMath) { |
Jason W Kim | f009a96 | 2011-02-07 00:49:53 +0000 | [diff] [blame] | 639 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ABI_FP_denormal, |
| 640 | ARMBuildAttrs::Allowed); |
| 641 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ABI_FP_exceptions, |
| 642 | ARMBuildAttrs::Allowed); |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | if (NoInfsFPMath && NoNaNsFPMath) |
Jason W Kim | f009a96 | 2011-02-07 00:49:53 +0000 | [diff] [blame] | 646 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ABI_FP_number_model, |
| 647 | ARMBuildAttrs::Allowed); |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 648 | else |
Jason W Kim | f009a96 | 2011-02-07 00:49:53 +0000 | [diff] [blame] | 649 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ABI_FP_number_model, |
| 650 | ARMBuildAttrs::AllowIEE754); |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 651 | |
Jason W Kim | f009a96 | 2011-02-07 00:49:53 +0000 | [diff] [blame] | 652 | // FIXME: add more flags to ARMBuildAttrs.h |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 653 | // 8-bytes alignment stuff. |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 654 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ABI_align8_needed, 1); |
| 655 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ABI_align8_preserved, 1); |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 656 | |
| 657 | // Hard float. Use both S and D registers and conform to AAPCS-VFP. |
| 658 | if (Subtarget->isAAPCS_ABI() && FloatABIType == FloatABI::Hard) { |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 659 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ABI_HardFP_use, 3); |
| 660 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ABI_VFP_args, 1); |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 661 | } |
| 662 | // FIXME: Should we signal R9 usage? |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 663 | |
Jason W Kim | f009a96 | 2011-02-07 00:49:53 +0000 | [diff] [blame] | 664 | if (Subtarget->hasDivide()) |
| 665 | AttrEmitter->EmitAttribute(ARMBuildAttrs::DIV_use, 1); |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 666 | |
| 667 | AttrEmitter->Finish(); |
| 668 | delete AttrEmitter; |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 669 | } |
| 670 | |
Jason W Kim | 17b443d | 2010-10-11 23:01:44 +0000 | [diff] [blame] | 671 | void ARMAsmPrinter::emitARMAttributeSection() { |
| 672 | // <format-version> |
| 673 | // [ <section-length> "vendor-name" |
| 674 | // [ <file-tag> <size> <attribute>* |
| 675 | // | <section-tag> <size> <section-number>* 0 <attribute>* |
| 676 | // | <symbol-tag> <size> <symbol-number>* 0 <attribute>* |
| 677 | // ]+ |
| 678 | // ]* |
| 679 | |
| 680 | if (OutStreamer.hasRawTextSupport()) |
| 681 | return; |
| 682 | |
| 683 | const ARMElfTargetObjectFile &TLOFELF = |
| 684 | static_cast<const ARMElfTargetObjectFile &> |
| 685 | (getObjFileLowering()); |
| 686 | |
| 687 | OutStreamer.SwitchSection(TLOFELF.getAttributesSection()); |
Jason W Kim | 17b443d | 2010-10-11 23:01:44 +0000 | [diff] [blame] | 688 | |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 689 | // Format version |
| 690 | OutStreamer.EmitIntValue(0x41, 1); |
Jason W Kim | 17b443d | 2010-10-11 23:01:44 +0000 | [diff] [blame] | 691 | } |
| 692 | |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 693 | //===----------------------------------------------------------------------===// |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 694 | |
Jim Grosbach | 988ce09 | 2010-09-18 00:05:05 +0000 | [diff] [blame] | 695 | static MCSymbol *getPICLabel(const char *Prefix, unsigned FunctionNumber, |
| 696 | unsigned LabelId, MCContext &Ctx) { |
| 697 | |
| 698 | MCSymbol *Label = Ctx.GetOrCreateSymbol(Twine(Prefix) |
| 699 | + "PC" + Twine(FunctionNumber) + "_" + Twine(LabelId)); |
| 700 | return Label; |
| 701 | } |
| 702 | |
Jim Grosbach | 2c4d512 | 2010-11-10 03:26:07 +0000 | [diff] [blame] | 703 | static MCSymbolRefExpr::VariantKind |
| 704 | getModifierVariantKind(ARMCP::ARMCPModifier Modifier) { |
| 705 | switch (Modifier) { |
| 706 | default: llvm_unreachable("Unknown modifier!"); |
| 707 | case ARMCP::no_modifier: return MCSymbolRefExpr::VK_None; |
| 708 | case ARMCP::TLSGD: return MCSymbolRefExpr::VK_ARM_TLSGD; |
| 709 | case ARMCP::TPOFF: return MCSymbolRefExpr::VK_ARM_TPOFF; |
| 710 | case ARMCP::GOTTPOFF: return MCSymbolRefExpr::VK_ARM_GOTTPOFF; |
| 711 | case ARMCP::GOT: return MCSymbolRefExpr::VK_ARM_GOT; |
| 712 | case ARMCP::GOTOFF: return MCSymbolRefExpr::VK_ARM_GOTOFF; |
| 713 | } |
| 714 | return MCSymbolRefExpr::VK_None; |
| 715 | } |
| 716 | |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 717 | MCSymbol *ARMAsmPrinter::GetARMGVSymbol(const GlobalValue *GV) { |
| 718 | bool isIndirect = Subtarget->isTargetDarwin() && |
| 719 | Subtarget->GVIsIndirectSymbol(GV, TM.getRelocationModel()); |
| 720 | if (!isIndirect) |
| 721 | return Mang->getSymbol(GV); |
| 722 | |
| 723 | // FIXME: Remove this when Darwin transition to @GOT like syntax. |
| 724 | MCSymbol *MCSym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr"); |
| 725 | MachineModuleInfoMachO &MMIMachO = |
| 726 | MMI->getObjFileInfo<MachineModuleInfoMachO>(); |
| 727 | MachineModuleInfoImpl::StubValueTy &StubSym = |
| 728 | GV->hasHiddenVisibility() ? MMIMachO.getHiddenGVStubEntry(MCSym) : |
| 729 | MMIMachO.getGVStubEntry(MCSym); |
| 730 | if (StubSym.getPointer() == 0) |
| 731 | StubSym = MachineModuleInfoImpl:: |
| 732 | StubValueTy(Mang->getSymbol(GV), !GV->hasInternalLinkage()); |
| 733 | return MCSym; |
| 734 | } |
| 735 | |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 736 | void ARMAsmPrinter:: |
| 737 | EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) { |
| 738 | int Size = TM.getTargetData()->getTypeAllocSize(MCPV->getType()); |
| 739 | |
| 740 | ARMConstantPoolValue *ACPV = static_cast<ARMConstantPoolValue*>(MCPV); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 741 | |
Jim Grosbach | 7c7ddb2 | 2010-11-10 17:59:10 +0000 | [diff] [blame] | 742 | MCSymbol *MCSym; |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 743 | if (ACPV->isLSDA()) { |
Jim Grosbach | 7c7ddb2 | 2010-11-10 17:59:10 +0000 | [diff] [blame] | 744 | SmallString<128> Str; |
| 745 | raw_svector_ostream OS(Str); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 746 | OS << MAI->getPrivateGlobalPrefix() << "_LSDA_" << getFunctionNumber(); |
Jim Grosbach | 7c7ddb2 | 2010-11-10 17:59:10 +0000 | [diff] [blame] | 747 | MCSym = OutContext.GetOrCreateSymbol(OS.str()); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 748 | } else if (ACPV->isBlockAddress()) { |
Jim Grosbach | 7c7ddb2 | 2010-11-10 17:59:10 +0000 | [diff] [blame] | 749 | MCSym = GetBlockAddressSymbol(ACPV->getBlockAddress()); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 750 | } else if (ACPV->isGlobalValue()) { |
| 751 | const GlobalValue *GV = ACPV->getGV(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 752 | MCSym = GetARMGVSymbol(GV); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 753 | } else { |
| 754 | assert(ACPV->isExtSymbol() && "unrecognized constant pool value"); |
Jim Grosbach | 7c7ddb2 | 2010-11-10 17:59:10 +0000 | [diff] [blame] | 755 | MCSym = GetExternalSymbolSymbol(ACPV->getSymbol()); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | // Create an MCSymbol for the reference. |
Jim Grosbach | 2c4d512 | 2010-11-10 03:26:07 +0000 | [diff] [blame] | 759 | const MCExpr *Expr = |
| 760 | MCSymbolRefExpr::Create(MCSym, getModifierVariantKind(ACPV->getModifier()), |
| 761 | OutContext); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 762 | |
Jim Grosbach | 2c4d512 | 2010-11-10 03:26:07 +0000 | [diff] [blame] | 763 | if (ACPV->getPCAdjustment()) { |
| 764 | MCSymbol *PCLabel = getPICLabel(MAI->getPrivateGlobalPrefix(), |
| 765 | getFunctionNumber(), |
| 766 | ACPV->getLabelId(), |
| 767 | OutContext); |
| 768 | const MCExpr *PCRelExpr = MCSymbolRefExpr::Create(PCLabel, OutContext); |
| 769 | PCRelExpr = |
| 770 | MCBinaryExpr::CreateAdd(PCRelExpr, |
| 771 | MCConstantExpr::Create(ACPV->getPCAdjustment(), |
| 772 | OutContext), |
| 773 | OutContext); |
| 774 | if (ACPV->mustAddCurrentAddress()) { |
| 775 | // We want "(<expr> - .)", but MC doesn't have a concept of the '.' |
| 776 | // label, so just emit a local label end reference that instead. |
| 777 | MCSymbol *DotSym = OutContext.CreateTempSymbol(); |
| 778 | OutStreamer.EmitLabel(DotSym); |
| 779 | const MCExpr *DotExpr = MCSymbolRefExpr::Create(DotSym, OutContext); |
| 780 | PCRelExpr = MCBinaryExpr::CreateSub(PCRelExpr, DotExpr, OutContext); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 781 | } |
Jim Grosbach | 2c4d512 | 2010-11-10 03:26:07 +0000 | [diff] [blame] | 782 | Expr = MCBinaryExpr::CreateSub(Expr, PCRelExpr, OutContext); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 783 | } |
Jim Grosbach | 2c4d512 | 2010-11-10 03:26:07 +0000 | [diff] [blame] | 784 | OutStreamer.EmitValue(Expr, Size); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 785 | } |
| 786 | |
Jim Grosbach | a2244cb | 2010-09-22 17:39:48 +0000 | [diff] [blame] | 787 | void ARMAsmPrinter::EmitJumpTable(const MachineInstr *MI) { |
| 788 | unsigned Opcode = MI->getOpcode(); |
| 789 | int OpNum = 1; |
| 790 | if (Opcode == ARM::BR_JTadd) |
| 791 | OpNum = 2; |
| 792 | else if (Opcode == ARM::BR_JTm) |
| 793 | OpNum = 3; |
| 794 | |
| 795 | const MachineOperand &MO1 = MI->getOperand(OpNum); |
| 796 | const MachineOperand &MO2 = MI->getOperand(OpNum+1); // Unique Id |
| 797 | unsigned JTI = MO1.getIndex(); |
| 798 | |
| 799 | // Emit a label for the jump table. |
| 800 | MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel2(JTI, MO2.getImm()); |
| 801 | OutStreamer.EmitLabel(JTISymbol); |
| 802 | |
| 803 | // Emit each entry of the table. |
| 804 | const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo(); |
| 805 | const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables(); |
| 806 | const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs; |
| 807 | |
| 808 | for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) { |
| 809 | MachineBasicBlock *MBB = JTBBs[i]; |
| 810 | // Construct an MCExpr for the entry. We want a value of the form: |
| 811 | // (BasicBlockAddr - TableBeginAddr) |
| 812 | // |
| 813 | // For example, a table with entries jumping to basic blocks BB0 and BB1 |
| 814 | // would look like: |
| 815 | // LJTI_0_0: |
| 816 | // .word (LBB0 - LJTI_0_0) |
| 817 | // .word (LBB1 - LJTI_0_0) |
| 818 | const MCExpr *Expr = MCSymbolRefExpr::Create(MBB->getSymbol(), OutContext); |
| 819 | |
| 820 | if (TM.getRelocationModel() == Reloc::PIC_) |
| 821 | Expr = MCBinaryExpr::CreateSub(Expr, MCSymbolRefExpr::Create(JTISymbol, |
| 822 | OutContext), |
| 823 | OutContext); |
| 824 | OutStreamer.EmitValue(Expr, 4); |
| 825 | } |
| 826 | } |
| 827 | |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 828 | void ARMAsmPrinter::EmitJump2Table(const MachineInstr *MI) { |
| 829 | unsigned Opcode = MI->getOpcode(); |
| 830 | int OpNum = (Opcode == ARM::t2BR_JT) ? 2 : 1; |
| 831 | const MachineOperand &MO1 = MI->getOperand(OpNum); |
| 832 | const MachineOperand &MO2 = MI->getOperand(OpNum+1); // Unique Id |
| 833 | unsigned JTI = MO1.getIndex(); |
| 834 | |
| 835 | // Emit a label for the jump table. |
| 836 | MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel2(JTI, MO2.getImm()); |
| 837 | OutStreamer.EmitLabel(JTISymbol); |
| 838 | |
| 839 | // Emit each entry of the table. |
| 840 | const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo(); |
| 841 | const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables(); |
| 842 | const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs; |
Jim Grosbach | 205a5fa | 2010-09-22 17:15:35 +0000 | [diff] [blame] | 843 | unsigned OffsetWidth = 4; |
Jim Grosbach | d092a87 | 2010-11-29 21:28:32 +0000 | [diff] [blame] | 844 | if (MI->getOpcode() == ARM::t2TBB_JT) |
Jim Grosbach | 205a5fa | 2010-09-22 17:15:35 +0000 | [diff] [blame] | 845 | OffsetWidth = 1; |
Jim Grosbach | d092a87 | 2010-11-29 21:28:32 +0000 | [diff] [blame] | 846 | else if (MI->getOpcode() == ARM::t2TBH_JT) |
Jim Grosbach | 205a5fa | 2010-09-22 17:15:35 +0000 | [diff] [blame] | 847 | OffsetWidth = 2; |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 848 | |
| 849 | for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) { |
| 850 | MachineBasicBlock *MBB = JTBBs[i]; |
Jim Grosbach | 205a5fa | 2010-09-22 17:15:35 +0000 | [diff] [blame] | 851 | const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::Create(MBB->getSymbol(), |
| 852 | OutContext); |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 853 | // If this isn't a TBB or TBH, the entries are direct branch instructions. |
Jim Grosbach | 205a5fa | 2010-09-22 17:15:35 +0000 | [diff] [blame] | 854 | if (OffsetWidth == 4) { |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 855 | MCInst BrInst; |
| 856 | BrInst.setOpcode(ARM::t2B); |
Jim Grosbach | 205a5fa | 2010-09-22 17:15:35 +0000 | [diff] [blame] | 857 | BrInst.addOperand(MCOperand::CreateExpr(MBBSymbolExpr)); |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 858 | OutStreamer.EmitInstruction(BrInst); |
| 859 | continue; |
| 860 | } |
| 861 | // Otherwise it's an offset from the dispatch instruction. Construct an |
Jim Grosbach | 205a5fa | 2010-09-22 17:15:35 +0000 | [diff] [blame] | 862 | // MCExpr for the entry. We want a value of the form: |
| 863 | // (BasicBlockAddr - TableBeginAddr) / 2 |
| 864 | // |
| 865 | // For example, a TBB table with entries jumping to basic blocks BB0 and BB1 |
| 866 | // would look like: |
| 867 | // LJTI_0_0: |
| 868 | // .byte (LBB0 - LJTI_0_0) / 2 |
| 869 | // .byte (LBB1 - LJTI_0_0) / 2 |
| 870 | const MCExpr *Expr = |
| 871 | MCBinaryExpr::CreateSub(MBBSymbolExpr, |
| 872 | MCSymbolRefExpr::Create(JTISymbol, OutContext), |
| 873 | OutContext); |
| 874 | Expr = MCBinaryExpr::CreateDiv(Expr, MCConstantExpr::Create(2, OutContext), |
| 875 | OutContext); |
| 876 | OutStreamer.EmitValue(Expr, OffsetWidth); |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | |
Jim Grosbach | 2d0f53b | 2010-09-28 17:05:56 +0000 | [diff] [blame] | 880 | void ARMAsmPrinter::PrintDebugValueComment(const MachineInstr *MI, |
| 881 | raw_ostream &OS) { |
| 882 | unsigned NOps = MI->getNumOperands(); |
| 883 | assert(NOps==4); |
| 884 | OS << '\t' << MAI->getCommentString() << "DEBUG_VALUE: "; |
| 885 | // cast away const; DIetc do not take const operands for some reason. |
| 886 | DIVariable V(const_cast<MDNode *>(MI->getOperand(NOps-1).getMetadata())); |
| 887 | OS << V.getName(); |
| 888 | OS << " <- "; |
| 889 | // Frame address. Currently handles register +- offset only. |
| 890 | assert(MI->getOperand(0).isReg() && MI->getOperand(1).isImm()); |
| 891 | OS << '['; printOperand(MI, 0, OS); OS << '+'; printOperand(MI, 1, OS); |
| 892 | OS << ']'; |
| 893 | OS << "+"; |
| 894 | printOperand(MI, NOps-2, OS); |
| 895 | } |
| 896 | |
Jim Grosbach | 40edf73 | 2010-12-14 21:10:47 +0000 | [diff] [blame] | 897 | static void populateADROperands(MCInst &Inst, unsigned Dest, |
| 898 | const MCSymbol *Label, |
| 899 | unsigned pred, unsigned ccreg, |
| 900 | MCContext &Ctx) { |
| 901 | const MCExpr *SymbolExpr = MCSymbolRefExpr::Create(Label, Ctx); |
| 902 | Inst.addOperand(MCOperand::CreateReg(Dest)); |
| 903 | Inst.addOperand(MCOperand::CreateExpr(SymbolExpr)); |
| 904 | // Add predicate operands. |
| 905 | Inst.addOperand(MCOperand::CreateImm(pred)); |
| 906 | Inst.addOperand(MCOperand::CreateReg(ccreg)); |
| 907 | } |
| 908 | |
Anton Korobeynikov | 4d72860 | 2011-01-01 20:38:38 +0000 | [diff] [blame] | 909 | void ARMAsmPrinter::EmitPatchedInstruction(const MachineInstr *MI, |
| 910 | unsigned Opcode) { |
| 911 | MCInst TmpInst; |
| 912 | |
| 913 | // Emit the instruction as usual, just patch the opcode. |
| 914 | LowerARMMachineInstrToMCInst(MI, TmpInst, *this); |
| 915 | TmpInst.setOpcode(Opcode); |
| 916 | OutStreamer.EmitInstruction(TmpInst); |
| 917 | } |
| 918 | |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 919 | void ARMAsmPrinter::EmitUnwindingInstruction(const MachineInstr *MI) { |
| 920 | assert(MI->getFlag(MachineInstr::FrameSetup) && |
| 921 | "Only instruction which are involved into frame setup code are allowed"); |
| 922 | |
| 923 | const MachineFunction &MF = *MI->getParent()->getParent(); |
| 924 | const TargetRegisterInfo *RegInfo = MF.getTarget().getRegisterInfo(); |
Anton Korobeynikov | b3fcc06 | 2011-03-05 18:43:55 +0000 | [diff] [blame] | 925 | const ARMFunctionInfo &AFI = *MF.getInfo<ARMFunctionInfo>(); |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 926 | |
| 927 | unsigned FramePtr = RegInfo->getFrameRegister(MF); |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 928 | unsigned Opc = MI->getOpcode(); |
Anton Korobeynikov | 7a76416 | 2011-03-05 18:43:43 +0000 | [diff] [blame] | 929 | unsigned SrcReg, DstReg; |
| 930 | |
Anton Korobeynikov | 3daccd8 | 2011-03-05 18:43:50 +0000 | [diff] [blame] | 931 | if (Opc == ARM::tPUSH || Opc == ARM::tLDRpci) { |
| 932 | // Two special cases: |
| 933 | // 1) tPUSH does not have src/dst regs. |
| 934 | // 2) for Thumb1 code we sometimes materialize the constant via constpool |
| 935 | // load. Yes, this is pretty fragile, but for now I don't see better |
| 936 | // way... :( |
Anton Korobeynikov | 7a76416 | 2011-03-05 18:43:43 +0000 | [diff] [blame] | 937 | SrcReg = DstReg = ARM::SP; |
| 938 | } else { |
Anton Korobeynikov | 3daccd8 | 2011-03-05 18:43:50 +0000 | [diff] [blame] | 939 | SrcReg = MI->getOperand(1).getReg(); |
Anton Korobeynikov | 7a76416 | 2011-03-05 18:43:43 +0000 | [diff] [blame] | 940 | DstReg = MI->getOperand(0).getReg(); |
| 941 | } |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 942 | |
| 943 | // Try to figure out the unwinding opcode out of src / dst regs. |
| 944 | if (MI->getDesc().mayStore()) { |
| 945 | // Register saves. |
| 946 | assert(DstReg == ARM::SP && |
| 947 | "Only stack pointer as a destination reg is supported"); |
| 948 | |
| 949 | SmallVector<unsigned, 4> RegList; |
Anton Korobeynikov | 7a76416 | 2011-03-05 18:43:43 +0000 | [diff] [blame] | 950 | // Skip src & dst reg, and pred ops. |
| 951 | unsigned StartOp = 2 + 2; |
| 952 | // Use all the operands. |
| 953 | unsigned NumOffset = 0; |
| 954 | |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 955 | switch (Opc) { |
| 956 | default: |
| 957 | MI->dump(); |
| 958 | assert(0 && "Unsupported opcode for unwinding information"); |
Anton Korobeynikov | 7a76416 | 2011-03-05 18:43:43 +0000 | [diff] [blame] | 959 | case ARM::tPUSH: |
| 960 | // Special case here: no src & dst reg, but two extra imp ops. |
| 961 | StartOp = 2; NumOffset = 2; |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 962 | case ARM::STMDB_UPD: |
Anton Korobeynikov | 7a76416 | 2011-03-05 18:43:43 +0000 | [diff] [blame] | 963 | case ARM::t2STMDB_UPD: |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 964 | case ARM::VSTMDDB_UPD: |
| 965 | assert(SrcReg == ARM::SP && |
| 966 | "Only stack pointer as a source reg is supported"); |
Anton Korobeynikov | 7a76416 | 2011-03-05 18:43:43 +0000 | [diff] [blame] | 967 | for (unsigned i = StartOp, NumOps = MI->getNumOperands() - NumOffset; |
| 968 | i != NumOps; ++i) |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 969 | RegList.push_back(MI->getOperand(i).getReg()); |
| 970 | break; |
| 971 | case ARM::STR_PRE: |
| 972 | assert(MI->getOperand(2).getReg() == ARM::SP && |
| 973 | "Only stack pointer as a source reg is supported"); |
| 974 | RegList.push_back(SrcReg); |
| 975 | break; |
| 976 | } |
| 977 | OutStreamer.EmitRegSave(RegList, Opc == ARM::VSTMDDB_UPD); |
| 978 | } else { |
| 979 | // Changes of stack / frame pointer. |
| 980 | if (SrcReg == ARM::SP) { |
| 981 | int64_t Offset = 0; |
| 982 | switch (Opc) { |
| 983 | default: |
| 984 | MI->dump(); |
| 985 | assert(0 && "Unsupported opcode for unwinding information"); |
| 986 | case ARM::MOVr: |
Anton Korobeynikov | 7a76416 | 2011-03-05 18:43:43 +0000 | [diff] [blame] | 987 | case ARM::tMOVgpr2gpr: |
Anton Korobeynikov | 3daccd8 | 2011-03-05 18:43:50 +0000 | [diff] [blame] | 988 | case ARM::tMOVgpr2tgpr: |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 989 | Offset = 0; |
| 990 | break; |
| 991 | case ARM::ADDri: |
| 992 | Offset = -MI->getOperand(2).getImm(); |
| 993 | break; |
| 994 | case ARM::SUBri: |
Anton Korobeynikov | 7a76416 | 2011-03-05 18:43:43 +0000 | [diff] [blame] | 995 | case ARM::t2SUBrSPi: |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 996 | Offset = MI->getOperand(2).getImm(); |
| 997 | break; |
Anton Korobeynikov | 7a76416 | 2011-03-05 18:43:43 +0000 | [diff] [blame] | 998 | case ARM::tSUBspi: |
| 999 | Offset = MI->getOperand(2).getImm()*4; |
| 1000 | break; |
| 1001 | case ARM::tADDspi: |
| 1002 | case ARM::tADDrSPi: |
| 1003 | Offset = -MI->getOperand(2).getImm()*4; |
| 1004 | break; |
Anton Korobeynikov | b3fcc06 | 2011-03-05 18:43:55 +0000 | [diff] [blame] | 1005 | case ARM::tLDRpci: { |
| 1006 | // Grab the constpool index and check, whether it corresponds to |
| 1007 | // original or cloned constpool entry. |
| 1008 | unsigned CPI = MI->getOperand(1).getIndex(); |
| 1009 | const MachineConstantPool *MCP = MF.getConstantPool(); |
| 1010 | if (CPI >= MCP->getConstants().size()) |
| 1011 | CPI = AFI.getOriginalCPIdx(CPI); |
| 1012 | assert(CPI != -1U && "Invalid constpool index"); |
| 1013 | |
| 1014 | // Derive the actual offset. |
| 1015 | const MachineConstantPoolEntry &CPE = MCP->getConstants()[CPI]; |
| 1016 | assert(!CPE.isMachineConstantPoolEntry() && "Invalid constpool entry"); |
| 1017 | // FIXME: Check for user, it should be "add" instruction! |
| 1018 | Offset = -cast<ConstantInt>(CPE.Val.ConstVal)->getSExtValue(); |
Anton Korobeynikov | 3daccd8 | 2011-03-05 18:43:50 +0000 | [diff] [blame] | 1019 | break; |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 1020 | } |
Anton Korobeynikov | b3fcc06 | 2011-03-05 18:43:55 +0000 | [diff] [blame] | 1021 | } |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 1022 | |
| 1023 | if (DstReg == FramePtr && FramePtr != ARM::SP) |
Anton Korobeynikov | e516379 | 2011-03-05 18:44:00 +0000 | [diff] [blame] | 1024 | // Set-up of the frame pointer. Positive values correspond to "add" |
| 1025 | // instruction. |
| 1026 | OutStreamer.EmitSetFP(FramePtr, ARM::SP, -Offset); |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 1027 | else if (DstReg == ARM::SP) { |
Anton Korobeynikov | e516379 | 2011-03-05 18:44:00 +0000 | [diff] [blame] | 1028 | // Change of SP by an offset. Positive values correspond to "sub" |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 1029 | // instruction. |
| 1030 | OutStreamer.EmitPad(Offset); |
| 1031 | } else { |
| 1032 | MI->dump(); |
| 1033 | assert(0 && "Unsupported opcode for unwinding information"); |
| 1034 | } |
| 1035 | } else if (DstReg == ARM::SP) { |
| 1036 | // FIXME: .movsp goes here |
| 1037 | MI->dump(); |
| 1038 | assert(0 && "Unsupported opcode for unwinding information"); |
| 1039 | } |
| 1040 | else { |
| 1041 | MI->dump(); |
| 1042 | assert(0 && "Unsupported opcode for unwinding information"); |
| 1043 | } |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | extern cl::opt<bool> EnableARMEHABI; |
| 1048 | |
Jim Grosbach | b454cda | 2010-09-29 15:23:40 +0000 | [diff] [blame] | 1049 | void ARMAsmPrinter::EmitInstruction(const MachineInstr *MI) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1050 | unsigned Opc = MI->getOpcode(); |
| 1051 | switch (Opc) { |
Chris Lattner | 4d15222 | 2009-10-19 22:23:04 +0000 | [diff] [blame] | 1052 | default: break; |
Jim Grosbach | 72422d3 | 2011-03-11 23:24:15 +0000 | [diff] [blame] | 1053 | case ARM::B: { |
| 1054 | // B is just a Bcc with an 'always' predicate. |
| 1055 | MCInst TmpInst; |
| 1056 | LowerARMMachineInstrToMCInst(MI, TmpInst, *this); |
| 1057 | TmpInst.setOpcode(ARM::Bcc); |
| 1058 | // Add predicate operands. |
| 1059 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1060 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1061 | OutStreamer.EmitInstruction(TmpInst); |
| 1062 | return; |
| 1063 | } |
Jim Grosbach | dd11988 | 2011-03-11 22:51:41 +0000 | [diff] [blame] | 1064 | case ARM::LDMIA_RET: { |
| 1065 | // LDMIA_RET is just a normal LDMIA_UPD instruction that targets PC and as |
| 1066 | // such has additional code-gen properties and scheduling information. |
| 1067 | // To emit it, we just construct as normal and set the opcode to LDMIA_UPD. |
| 1068 | MCInst TmpInst; |
| 1069 | LowerARMMachineInstrToMCInst(MI, TmpInst, *this); |
| 1070 | TmpInst.setOpcode(ARM::LDMIA_UPD); |
| 1071 | OutStreamer.EmitInstruction(TmpInst); |
| 1072 | return; |
| 1073 | } |
Jim Grosbach | 9702e60 | 2010-12-09 01:22:19 +0000 | [diff] [blame] | 1074 | case ARM::t2ADDrSPi: |
| 1075 | case ARM::t2ADDrSPi12: |
| 1076 | case ARM::t2SUBrSPi: |
| 1077 | case ARM::t2SUBrSPi12: |
Jim Grosbach | 766a63d | 2010-12-09 01:23:51 +0000 | [diff] [blame] | 1078 | assert ((MI->getOperand(1).getReg() == ARM::SP) && |
| 1079 | "Unexpected source register!"); |
Jim Grosbach | 9702e60 | 2010-12-09 01:22:19 +0000 | [diff] [blame] | 1080 | break; |
| 1081 | |
Chris Lattner | 112f239 | 2010-11-14 20:31:06 +0000 | [diff] [blame] | 1082 | case ARM::t2MOVi32imm: assert(0 && "Should be lowered by thumb2it pass"); |
Jim Grosbach | 2d0f53b | 2010-09-28 17:05:56 +0000 | [diff] [blame] | 1083 | case ARM::DBG_VALUE: { |
| 1084 | if (isVerbose() && OutStreamer.hasRawTextSupport()) { |
| 1085 | SmallString<128> TmpStr; |
| 1086 | raw_svector_ostream OS(TmpStr); |
| 1087 | PrintDebugValueComment(MI, OS); |
| 1088 | OutStreamer.EmitRawText(StringRef(OS.str())); |
| 1089 | } |
| 1090 | return; |
| 1091 | } |
Jim Grosbach | 3efad8f | 2010-12-16 19:11:16 +0000 | [diff] [blame] | 1092 | case ARM::tBfar: { |
| 1093 | MCInst TmpInst; |
| 1094 | TmpInst.setOpcode(ARM::tBL); |
| 1095 | TmpInst.addOperand(MCOperand::CreateExpr(MCSymbolRefExpr::Create( |
| 1096 | MI->getOperand(0).getMBB()->getSymbol(), OutContext))); |
| 1097 | OutStreamer.EmitInstruction(TmpInst); |
| 1098 | return; |
| 1099 | } |
Jim Grosbach | 40edf73 | 2010-12-14 21:10:47 +0000 | [diff] [blame] | 1100 | case ARM::LEApcrel: |
Jim Grosbach | d40963c | 2010-12-14 22:28:03 +0000 | [diff] [blame] | 1101 | case ARM::tLEApcrel: |
Jim Grosbach | 40edf73 | 2010-12-14 21:10:47 +0000 | [diff] [blame] | 1102 | case ARM::t2LEApcrel: { |
Jim Grosbach | dff84b0 | 2010-12-02 00:28:45 +0000 | [diff] [blame] | 1103 | // FIXME: Need to also handle globals and externals |
Jim Grosbach | dff84b0 | 2010-12-02 00:28:45 +0000 | [diff] [blame] | 1104 | MCInst TmpInst; |
Jim Grosbach | d40963c | 2010-12-14 22:28:03 +0000 | [diff] [blame] | 1105 | TmpInst.setOpcode(MI->getOpcode() == ARM::t2LEApcrel ? ARM::t2ADR |
| 1106 | : (MI->getOpcode() == ARM::tLEApcrel ? ARM::tADR |
| 1107 | : ARM::ADR)); |
Jim Grosbach | 40edf73 | 2010-12-14 21:10:47 +0000 | [diff] [blame] | 1108 | populateADROperands(TmpInst, MI->getOperand(0).getReg(), |
| 1109 | GetCPISymbol(MI->getOperand(1).getIndex()), |
| 1110 | MI->getOperand(2).getImm(), MI->getOperand(3).getReg(), |
| 1111 | OutContext); |
Jim Grosbach | dff84b0 | 2010-12-02 00:28:45 +0000 | [diff] [blame] | 1112 | OutStreamer.EmitInstruction(TmpInst); |
| 1113 | return; |
| 1114 | } |
Jim Grosbach | d40963c | 2010-12-14 22:28:03 +0000 | [diff] [blame] | 1115 | case ARM::LEApcrelJT: |
| 1116 | case ARM::tLEApcrelJT: |
| 1117 | case ARM::t2LEApcrelJT: { |
Jim Grosbach | 5d14f9b | 2010-12-01 19:47:31 +0000 | [diff] [blame] | 1118 | MCInst TmpInst; |
Jim Grosbach | d40963c | 2010-12-14 22:28:03 +0000 | [diff] [blame] | 1119 | TmpInst.setOpcode(MI->getOpcode() == ARM::t2LEApcrelJT ? ARM::t2ADR |
| 1120 | : (MI->getOpcode() == ARM::tLEApcrelJT ? ARM::tADR |
| 1121 | : ARM::ADR)); |
Jim Grosbach | 40edf73 | 2010-12-14 21:10:47 +0000 | [diff] [blame] | 1122 | populateADROperands(TmpInst, MI->getOperand(0).getReg(), |
| 1123 | GetARMJTIPICJumpTableLabel2(MI->getOperand(1).getIndex(), |
| 1124 | MI->getOperand(2).getImm()), |
| 1125 | MI->getOperand(3).getImm(), MI->getOperand(4).getReg(), |
| 1126 | OutContext); |
Jim Grosbach | 5d14f9b | 2010-12-01 19:47:31 +0000 | [diff] [blame] | 1127 | OutStreamer.EmitInstruction(TmpInst); |
| 1128 | return; |
| 1129 | } |
Jim Grosbach | 2e812e1 | 2010-11-30 18:56:36 +0000 | [diff] [blame] | 1130 | case ARM::MOVPCRX: { |
| 1131 | MCInst TmpInst; |
| 1132 | TmpInst.setOpcode(ARM::MOVr); |
| 1133 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1134 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1135 | // Add predicate operands. |
| 1136 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1137 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1138 | // Add 's' bit operand (always reg0 for this) |
| 1139 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1140 | OutStreamer.EmitInstruction(TmpInst); |
| 1141 | return; |
| 1142 | } |
Jim Grosbach | f859a54 | 2011-03-12 00:45:26 +0000 | [diff] [blame] | 1143 | // Darwin call instructions are just normal call instructions with different |
| 1144 | // clobber semantics (they clobber R9). |
| 1145 | case ARM::BLr9: |
| 1146 | case ARM::BLr9_pred: |
| 1147 | case ARM::BLXr9: |
| 1148 | case ARM::BLXr9_pred: { |
| 1149 | unsigned newOpc; |
| 1150 | switch (Opc) { |
| 1151 | default: assert(0); |
| 1152 | case ARM::BLr9: newOpc = ARM::BL; break; |
| 1153 | case ARM::BLr9_pred: newOpc = ARM::BL_pred; break; |
| 1154 | case ARM::BLXr9: newOpc = ARM::BLX; break; |
| 1155 | case ARM::BLXr9_pred: newOpc = ARM::BLX_pred; break; |
| 1156 | } |
| 1157 | MCInst TmpInst; |
| 1158 | LowerARMMachineInstrToMCInst(MI, TmpInst, *this); |
| 1159 | TmpInst.setOpcode(newOpc); |
| 1160 | OutStreamer.EmitInstruction(TmpInst); |
| 1161 | return; |
| 1162 | } |
Jim Grosbach | a0d2c8a | 2010-11-30 18:30:19 +0000 | [diff] [blame] | 1163 | case ARM::BXr9_CALL: |
| 1164 | case ARM::BX_CALL: { |
| 1165 | { |
| 1166 | MCInst TmpInst; |
| 1167 | TmpInst.setOpcode(ARM::MOVr); |
| 1168 | TmpInst.addOperand(MCOperand::CreateReg(ARM::LR)); |
| 1169 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1170 | // Add predicate operands. |
| 1171 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1172 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1173 | // Add 's' bit operand (always reg0 for this) |
| 1174 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1175 | OutStreamer.EmitInstruction(TmpInst); |
| 1176 | } |
| 1177 | { |
| 1178 | MCInst TmpInst; |
| 1179 | TmpInst.setOpcode(ARM::BX); |
| 1180 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1181 | OutStreamer.EmitInstruction(TmpInst); |
| 1182 | } |
| 1183 | return; |
| 1184 | } |
| 1185 | case ARM::BMOVPCRXr9_CALL: |
| 1186 | case ARM::BMOVPCRX_CALL: { |
| 1187 | { |
| 1188 | MCInst TmpInst; |
| 1189 | TmpInst.setOpcode(ARM::MOVr); |
| 1190 | TmpInst.addOperand(MCOperand::CreateReg(ARM::LR)); |
| 1191 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1192 | // Add predicate operands. |
| 1193 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1194 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1195 | // Add 's' bit operand (always reg0 for this) |
| 1196 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1197 | OutStreamer.EmitInstruction(TmpInst); |
| 1198 | } |
| 1199 | { |
| 1200 | MCInst TmpInst; |
| 1201 | TmpInst.setOpcode(ARM::MOVr); |
| 1202 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1203 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1204 | // Add predicate operands. |
| 1205 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1206 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1207 | // Add 's' bit operand (always reg0 for this) |
| 1208 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1209 | OutStreamer.EmitInstruction(TmpInst); |
| 1210 | } |
| 1211 | return; |
| 1212 | } |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 1213 | case ARM::MOVi16_ga_pcrel: |
| 1214 | case ARM::t2MOVi16_ga_pcrel: { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1215 | MCInst TmpInst; |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 1216 | TmpInst.setOpcode(Opc == ARM::MOVi16_ga_pcrel? ARM::MOVi16 : ARM::t2MOVi16); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1217 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1218 | |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 1219 | unsigned TF = MI->getOperand(1).getTargetFlags(); |
| 1220 | bool isPIC = TF == ARMII::MO_LO16_NONLAZY_PIC; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1221 | const GlobalValue *GV = MI->getOperand(1).getGlobal(); |
| 1222 | MCSymbol *GVSym = GetARMGVSymbol(GV); |
| 1223 | const MCExpr *GVSymExpr = MCSymbolRefExpr::Create(GVSym, OutContext); |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 1224 | if (isPIC) { |
| 1225 | MCSymbol *LabelSym = getPICLabel(MAI->getPrivateGlobalPrefix(), |
| 1226 | getFunctionNumber(), |
| 1227 | MI->getOperand(2).getImm(), OutContext); |
| 1228 | const MCExpr *LabelSymExpr= MCSymbolRefExpr::Create(LabelSym, OutContext); |
| 1229 | unsigned PCAdj = (Opc == ARM::MOVi16_ga_pcrel) ? 8 : 4; |
| 1230 | const MCExpr *PCRelExpr = |
| 1231 | ARMMCExpr::CreateLower16(MCBinaryExpr::CreateSub(GVSymExpr, |
| 1232 | MCBinaryExpr::CreateAdd(LabelSymExpr, |
| 1233 | MCConstantExpr::Create(PCAdj, OutContext), |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1234 | OutContext), OutContext), OutContext); |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 1235 | TmpInst.addOperand(MCOperand::CreateExpr(PCRelExpr)); |
| 1236 | } else { |
| 1237 | const MCExpr *RefExpr= ARMMCExpr::CreateLower16(GVSymExpr, OutContext); |
| 1238 | TmpInst.addOperand(MCOperand::CreateExpr(RefExpr)); |
| 1239 | } |
| 1240 | |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1241 | // Add predicate operands. |
| 1242 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1243 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1244 | // Add 's' bit operand (always reg0 for this) |
| 1245 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1246 | OutStreamer.EmitInstruction(TmpInst); |
| 1247 | return; |
| 1248 | } |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 1249 | case ARM::MOVTi16_ga_pcrel: |
| 1250 | case ARM::t2MOVTi16_ga_pcrel: { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1251 | MCInst TmpInst; |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 1252 | TmpInst.setOpcode(Opc == ARM::MOVTi16_ga_pcrel |
| 1253 | ? ARM::MOVTi16 : ARM::t2MOVTi16); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1254 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1255 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg())); |
| 1256 | |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 1257 | unsigned TF = MI->getOperand(2).getTargetFlags(); |
| 1258 | bool isPIC = TF == ARMII::MO_HI16_NONLAZY_PIC; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1259 | const GlobalValue *GV = MI->getOperand(2).getGlobal(); |
| 1260 | MCSymbol *GVSym = GetARMGVSymbol(GV); |
| 1261 | const MCExpr *GVSymExpr = MCSymbolRefExpr::Create(GVSym, OutContext); |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 1262 | if (isPIC) { |
| 1263 | MCSymbol *LabelSym = getPICLabel(MAI->getPrivateGlobalPrefix(), |
| 1264 | getFunctionNumber(), |
| 1265 | MI->getOperand(3).getImm(), OutContext); |
| 1266 | const MCExpr *LabelSymExpr= MCSymbolRefExpr::Create(LabelSym, OutContext); |
| 1267 | unsigned PCAdj = (Opc == ARM::MOVTi16_ga_pcrel) ? 8 : 4; |
| 1268 | const MCExpr *PCRelExpr = |
| 1269 | ARMMCExpr::CreateUpper16(MCBinaryExpr::CreateSub(GVSymExpr, |
| 1270 | MCBinaryExpr::CreateAdd(LabelSymExpr, |
| 1271 | MCConstantExpr::Create(PCAdj, OutContext), |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1272 | OutContext), OutContext), OutContext); |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 1273 | TmpInst.addOperand(MCOperand::CreateExpr(PCRelExpr)); |
| 1274 | } else { |
| 1275 | const MCExpr *RefExpr= ARMMCExpr::CreateUpper16(GVSymExpr, OutContext); |
| 1276 | TmpInst.addOperand(MCOperand::CreateExpr(RefExpr)); |
| 1277 | } |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1278 | // Add predicate operands. |
| 1279 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1280 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1281 | // Add 's' bit operand (always reg0 for this) |
| 1282 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1283 | OutStreamer.EmitInstruction(TmpInst); |
| 1284 | return; |
| 1285 | } |
Jim Grosbach | fbd1873 | 2010-09-17 23:41:53 +0000 | [diff] [blame] | 1286 | case ARM::tPICADD: { |
| 1287 | // This is a pseudo op for a label + instruction sequence, which looks like: |
| 1288 | // LPC0: |
| 1289 | // add r0, pc |
| 1290 | // This adds the address of LPC0 to r0. |
| 1291 | |
| 1292 | // Emit the label. |
Jim Grosbach | 988ce09 | 2010-09-18 00:05:05 +0000 | [diff] [blame] | 1293 | OutStreamer.EmitLabel(getPICLabel(MAI->getPrivateGlobalPrefix(), |
| 1294 | getFunctionNumber(), MI->getOperand(2).getImm(), |
| 1295 | OutContext)); |
Jim Grosbach | fbd1873 | 2010-09-17 23:41:53 +0000 | [diff] [blame] | 1296 | |
| 1297 | // Form and emit the add. |
| 1298 | MCInst AddInst; |
| 1299 | AddInst.setOpcode(ARM::tADDhirr); |
| 1300 | AddInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1301 | AddInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1302 | AddInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1303 | // Add predicate operands. |
| 1304 | AddInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1305 | AddInst.addOperand(MCOperand::CreateReg(0)); |
| 1306 | OutStreamer.EmitInstruction(AddInst); |
| 1307 | return; |
| 1308 | } |
Jim Grosbach | a3fbadf | 2010-09-30 19:53:58 +0000 | [diff] [blame] | 1309 | case ARM::PICADD: { |
Chris Lattner | 4d15222 | 2009-10-19 22:23:04 +0000 | [diff] [blame] | 1310 | // This is a pseudo op for a label + instruction sequence, which looks like: |
| 1311 | // LPC0: |
| 1312 | // add r0, pc, r0 |
| 1313 | // This adds the address of LPC0 to r0. |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1314 | |
Chris Lattner | 4d15222 | 2009-10-19 22:23:04 +0000 | [diff] [blame] | 1315 | // Emit the label. |
Jim Grosbach | 988ce09 | 2010-09-18 00:05:05 +0000 | [diff] [blame] | 1316 | OutStreamer.EmitLabel(getPICLabel(MAI->getPrivateGlobalPrefix(), |
| 1317 | getFunctionNumber(), MI->getOperand(2).getImm(), |
| 1318 | OutContext)); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1319 | |
Jim Grosbach | f3f0952 | 2010-09-14 21:05:34 +0000 | [diff] [blame] | 1320 | // Form and emit the add. |
Chris Lattner | 4d15222 | 2009-10-19 22:23:04 +0000 | [diff] [blame] | 1321 | MCInst AddInst; |
| 1322 | AddInst.setOpcode(ARM::ADDrr); |
| 1323 | AddInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1324 | AddInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1325 | AddInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg())); |
Jim Grosbach | 5b46d62 | 2010-09-14 21:28:17 +0000 | [diff] [blame] | 1326 | // Add predicate operands. |
| 1327 | AddInst.addOperand(MCOperand::CreateImm(MI->getOperand(3).getImm())); |
| 1328 | AddInst.addOperand(MCOperand::CreateReg(MI->getOperand(4).getReg())); |
| 1329 | // Add 's' bit operand (always reg0 for this) |
| 1330 | AddInst.addOperand(MCOperand::CreateReg(0)); |
Chris Lattner | 850d2e2 | 2010-02-03 01:16:28 +0000 | [diff] [blame] | 1331 | OutStreamer.EmitInstruction(AddInst); |
Chris Lattner | 4d15222 | 2009-10-19 22:23:04 +0000 | [diff] [blame] | 1332 | return; |
| 1333 | } |
Jim Grosbach | a28abbe | 2010-09-17 16:25:52 +0000 | [diff] [blame] | 1334 | case ARM::PICSTR: |
| 1335 | case ARM::PICSTRB: |
| 1336 | case ARM::PICSTRH: |
| 1337 | case ARM::PICLDR: |
| 1338 | case ARM::PICLDRB: |
| 1339 | case ARM::PICLDRH: |
| 1340 | case ARM::PICLDRSB: |
| 1341 | case ARM::PICLDRSH: { |
Jim Grosbach | b74ca9d | 2010-09-16 17:43:25 +0000 | [diff] [blame] | 1342 | // This is a pseudo op for a label + instruction sequence, which looks like: |
| 1343 | // LPC0: |
Jim Grosbach | a28abbe | 2010-09-17 16:25:52 +0000 | [diff] [blame] | 1344 | // OP r0, [pc, r0] |
Jim Grosbach | b74ca9d | 2010-09-16 17:43:25 +0000 | [diff] [blame] | 1345 | // The LCP0 label is referenced by a constant pool entry in order to get |
| 1346 | // a PC-relative address at the ldr instruction. |
| 1347 | |
| 1348 | // Emit the label. |
Jim Grosbach | 988ce09 | 2010-09-18 00:05:05 +0000 | [diff] [blame] | 1349 | OutStreamer.EmitLabel(getPICLabel(MAI->getPrivateGlobalPrefix(), |
| 1350 | getFunctionNumber(), MI->getOperand(2).getImm(), |
| 1351 | OutContext)); |
Jim Grosbach | b74ca9d | 2010-09-16 17:43:25 +0000 | [diff] [blame] | 1352 | |
| 1353 | // Form and emit the load |
Jim Grosbach | a28abbe | 2010-09-17 16:25:52 +0000 | [diff] [blame] | 1354 | unsigned Opcode; |
| 1355 | switch (MI->getOpcode()) { |
| 1356 | default: |
| 1357 | llvm_unreachable("Unexpected opcode!"); |
Jim Grosbach | 7e3383c | 2010-10-27 23:12:14 +0000 | [diff] [blame] | 1358 | case ARM::PICSTR: Opcode = ARM::STRrs; break; |
| 1359 | case ARM::PICSTRB: Opcode = ARM::STRBrs; break; |
Jim Grosbach | a28abbe | 2010-09-17 16:25:52 +0000 | [diff] [blame] | 1360 | case ARM::PICSTRH: Opcode = ARM::STRH; break; |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 1361 | case ARM::PICLDR: Opcode = ARM::LDRrs; break; |
Jim Grosbach | c1d3021 | 2010-10-27 00:19:44 +0000 | [diff] [blame] | 1362 | case ARM::PICLDRB: Opcode = ARM::LDRBrs; break; |
Jim Grosbach | a28abbe | 2010-09-17 16:25:52 +0000 | [diff] [blame] | 1363 | case ARM::PICLDRH: Opcode = ARM::LDRH; break; |
| 1364 | case ARM::PICLDRSB: Opcode = ARM::LDRSB; break; |
| 1365 | case ARM::PICLDRSH: Opcode = ARM::LDRSH; break; |
| 1366 | } |
| 1367 | MCInst LdStInst; |
| 1368 | LdStInst.setOpcode(Opcode); |
| 1369 | LdStInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1370 | LdStInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1371 | LdStInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg())); |
| 1372 | LdStInst.addOperand(MCOperand::CreateImm(0)); |
Jim Grosbach | b74ca9d | 2010-09-16 17:43:25 +0000 | [diff] [blame] | 1373 | // Add predicate operands. |
Jim Grosbach | a28abbe | 2010-09-17 16:25:52 +0000 | [diff] [blame] | 1374 | LdStInst.addOperand(MCOperand::CreateImm(MI->getOperand(3).getImm())); |
| 1375 | LdStInst.addOperand(MCOperand::CreateReg(MI->getOperand(4).getReg())); |
| 1376 | OutStreamer.EmitInstruction(LdStInst); |
Jim Grosbach | b74ca9d | 2010-09-16 17:43:25 +0000 | [diff] [blame] | 1377 | |
| 1378 | return; |
| 1379 | } |
Jim Grosbach | a3fbadf | 2010-09-30 19:53:58 +0000 | [diff] [blame] | 1380 | case ARM::CONSTPOOL_ENTRY: { |
Chris Lattner | a70e644 | 2009-10-19 22:33:05 +0000 | [diff] [blame] | 1381 | /// CONSTPOOL_ENTRY - This instruction represents a floating constant pool |
| 1382 | /// in the function. The first operand is the ID# for this instruction, the |
| 1383 | /// second is the index into the MachineConstantPool that this is, the third |
| 1384 | /// is the size in bytes of this constant pool entry. |
| 1385 | unsigned LabelId = (unsigned)MI->getOperand(0).getImm(); |
| 1386 | unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex(); |
| 1387 | |
| 1388 | EmitAlignment(2); |
Chris Lattner | 1b46f43 | 2010-01-23 07:00:21 +0000 | [diff] [blame] | 1389 | OutStreamer.EmitLabel(GetCPISymbol(LabelId)); |
Chris Lattner | a70e644 | 2009-10-19 22:33:05 +0000 | [diff] [blame] | 1390 | |
| 1391 | const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx]; |
| 1392 | if (MCPE.isMachineConstantPoolEntry()) |
| 1393 | EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal); |
| 1394 | else |
| 1395 | EmitGlobalConstant(MCPE.Val.ConstVal); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1396 | |
Chris Lattner | a70e644 | 2009-10-19 22:33:05 +0000 | [diff] [blame] | 1397 | return; |
| 1398 | } |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 1399 | case ARM::t2BR_JT: { |
| 1400 | // Lower and emit the instruction itself, then the jump table following it. |
| 1401 | MCInst TmpInst; |
Jim Grosbach | 5ca6669 | 2010-11-29 22:37:40 +0000 | [diff] [blame] | 1402 | TmpInst.setOpcode(ARM::tMOVgpr2gpr); |
| 1403 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1404 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1405 | // Add predicate operands. |
| 1406 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1407 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 1408 | OutStreamer.EmitInstruction(TmpInst); |
Jim Grosbach | 5ca6669 | 2010-11-29 22:37:40 +0000 | [diff] [blame] | 1409 | // Output the data for the jump table itself |
| 1410 | EmitJump2Table(MI); |
| 1411 | return; |
| 1412 | } |
| 1413 | case ARM::t2TBB_JT: { |
| 1414 | // Lower and emit the instruction itself, then the jump table following it. |
| 1415 | MCInst TmpInst; |
| 1416 | |
| 1417 | TmpInst.setOpcode(ARM::t2TBB); |
| 1418 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1419 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1420 | // Add predicate operands. |
| 1421 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1422 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1423 | OutStreamer.EmitInstruction(TmpInst); |
| 1424 | // Output the data for the jump table itself |
| 1425 | EmitJump2Table(MI); |
| 1426 | // Make sure the next instruction is 2-byte aligned. |
| 1427 | EmitAlignment(1); |
| 1428 | return; |
| 1429 | } |
| 1430 | case ARM::t2TBH_JT: { |
| 1431 | // Lower and emit the instruction itself, then the jump table following it. |
| 1432 | MCInst TmpInst; |
| 1433 | |
| 1434 | TmpInst.setOpcode(ARM::t2TBH); |
| 1435 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1436 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1437 | // Add predicate operands. |
| 1438 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1439 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1440 | OutStreamer.EmitInstruction(TmpInst); |
| 1441 | // Output the data for the jump table itself |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 1442 | EmitJump2Table(MI); |
| 1443 | return; |
| 1444 | } |
Jim Grosbach | f1aa47d | 2010-11-29 19:32:47 +0000 | [diff] [blame] | 1445 | case ARM::tBR_JTr: |
Jim Grosbach | 2dc7768 | 2010-11-29 18:37:44 +0000 | [diff] [blame] | 1446 | case ARM::BR_JTr: { |
| 1447 | // Lower and emit the instruction itself, then the jump table following it. |
| 1448 | // mov pc, target |
| 1449 | MCInst TmpInst; |
Jim Grosbach | 5ca6669 | 2010-11-29 22:37:40 +0000 | [diff] [blame] | 1450 | unsigned Opc = MI->getOpcode() == ARM::BR_JTr ? |
| 1451 | ARM::MOVr : ARM::tMOVgpr2gpr; |
Jim Grosbach | f1aa47d | 2010-11-29 19:32:47 +0000 | [diff] [blame] | 1452 | TmpInst.setOpcode(Opc); |
Jim Grosbach | 2dc7768 | 2010-11-29 18:37:44 +0000 | [diff] [blame] | 1453 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1454 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1455 | // Add predicate operands. |
| 1456 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1457 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
Jim Grosbach | a0d2c8a | 2010-11-30 18:30:19 +0000 | [diff] [blame] | 1458 | // Add 's' bit operand (always reg0 for this) |
| 1459 | if (Opc == ARM::MOVr) |
| 1460 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
Jim Grosbach | 2dc7768 | 2010-11-29 18:37:44 +0000 | [diff] [blame] | 1461 | OutStreamer.EmitInstruction(TmpInst); |
| 1462 | |
Jim Grosbach | f1aa47d | 2010-11-29 19:32:47 +0000 | [diff] [blame] | 1463 | // Make sure the Thumb jump table is 4-byte aligned. |
Bill Wendling | a68a4fd | 2010-12-18 02:13:59 +0000 | [diff] [blame] | 1464 | if (Opc == ARM::tMOVgpr2gpr) |
Jim Grosbach | f1aa47d | 2010-11-29 19:32:47 +0000 | [diff] [blame] | 1465 | EmitAlignment(2); |
| 1466 | |
Jim Grosbach | 2dc7768 | 2010-11-29 18:37:44 +0000 | [diff] [blame] | 1467 | // Output the data for the jump table itself |
| 1468 | EmitJumpTable(MI); |
| 1469 | return; |
| 1470 | } |
| 1471 | case ARM::BR_JTm: { |
| 1472 | // Lower and emit the instruction itself, then the jump table following it. |
| 1473 | // ldr pc, target |
| 1474 | MCInst TmpInst; |
| 1475 | if (MI->getOperand(1).getReg() == 0) { |
| 1476 | // literal offset |
| 1477 | TmpInst.setOpcode(ARM::LDRi12); |
| 1478 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1479 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1480 | TmpInst.addOperand(MCOperand::CreateImm(MI->getOperand(2).getImm())); |
| 1481 | } else { |
| 1482 | TmpInst.setOpcode(ARM::LDRrs); |
| 1483 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1484 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1485 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg())); |
| 1486 | TmpInst.addOperand(MCOperand::CreateImm(0)); |
| 1487 | } |
| 1488 | // Add predicate operands. |
| 1489 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1490 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1491 | OutStreamer.EmitInstruction(TmpInst); |
| 1492 | |
| 1493 | // Output the data for the jump table itself |
Jim Grosbach | a2244cb | 2010-09-22 17:39:48 +0000 | [diff] [blame] | 1494 | EmitJumpTable(MI); |
| 1495 | return; |
| 1496 | } |
Jim Grosbach | f8dabac | 2010-11-17 21:05:55 +0000 | [diff] [blame] | 1497 | case ARM::BR_JTadd: { |
| 1498 | // Lower and emit the instruction itself, then the jump table following it. |
| 1499 | // add pc, target, idx |
Jim Grosbach | 2dc7768 | 2010-11-29 18:37:44 +0000 | [diff] [blame] | 1500 | MCInst TmpInst; |
| 1501 | TmpInst.setOpcode(ARM::ADDrr); |
| 1502 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1503 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1504 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg())); |
Jim Grosbach | f8dabac | 2010-11-17 21:05:55 +0000 | [diff] [blame] | 1505 | // Add predicate operands. |
Jim Grosbach | 2dc7768 | 2010-11-29 18:37:44 +0000 | [diff] [blame] | 1506 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1507 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
Jim Grosbach | f8dabac | 2010-11-17 21:05:55 +0000 | [diff] [blame] | 1508 | // Add 's' bit operand (always reg0 for this) |
Jim Grosbach | 2dc7768 | 2010-11-29 18:37:44 +0000 | [diff] [blame] | 1509 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1510 | OutStreamer.EmitInstruction(TmpInst); |
Jim Grosbach | f8dabac | 2010-11-17 21:05:55 +0000 | [diff] [blame] | 1511 | |
| 1512 | // Output the data for the jump table itself |
| 1513 | EmitJumpTable(MI); |
| 1514 | return; |
| 1515 | } |
Jim Grosbach | 2e6ae13 | 2010-09-23 18:05:37 +0000 | [diff] [blame] | 1516 | case ARM::TRAP: { |
| 1517 | // Non-Darwin binutils don't yet support the "trap" mnemonic. |
| 1518 | // FIXME: Remove this special case when they do. |
| 1519 | if (!Subtarget->isTargetDarwin()) { |
Jim Grosbach | 78890f4 | 2010-10-01 23:21:38 +0000 | [diff] [blame] | 1520 | //.long 0xe7ffdefe @ trap |
Jim Grosbach | b2dda4b | 2010-09-23 19:42:17 +0000 | [diff] [blame] | 1521 | uint32_t Val = 0xe7ffdefeUL; |
Jim Grosbach | 2e6ae13 | 2010-09-23 18:05:37 +0000 | [diff] [blame] | 1522 | OutStreamer.AddComment("trap"); |
| 1523 | OutStreamer.EmitIntValue(Val, 4); |
| 1524 | return; |
| 1525 | } |
| 1526 | break; |
| 1527 | } |
| 1528 | case ARM::tTRAP: { |
| 1529 | // Non-Darwin binutils don't yet support the "trap" mnemonic. |
| 1530 | // FIXME: Remove this special case when they do. |
| 1531 | if (!Subtarget->isTargetDarwin()) { |
Jim Grosbach | 78890f4 | 2010-10-01 23:21:38 +0000 | [diff] [blame] | 1532 | //.short 57086 @ trap |
Benjamin Kramer | c8ab9eb | 2010-09-23 18:57:26 +0000 | [diff] [blame] | 1533 | uint16_t Val = 0xdefe; |
Jim Grosbach | 2e6ae13 | 2010-09-23 18:05:37 +0000 | [diff] [blame] | 1534 | OutStreamer.AddComment("trap"); |
| 1535 | OutStreamer.EmitIntValue(Val, 2); |
| 1536 | return; |
| 1537 | } |
| 1538 | break; |
| 1539 | } |
Jim Grosbach | 433a578 | 2010-09-24 20:47:58 +0000 | [diff] [blame] | 1540 | case ARM::t2Int_eh_sjlj_setjmp: |
| 1541 | case ARM::t2Int_eh_sjlj_setjmp_nofp: |
Jim Grosbach | a3fbadf | 2010-09-30 19:53:58 +0000 | [diff] [blame] | 1542 | case ARM::tInt_eh_sjlj_setjmp: { |
Jim Grosbach | 433a578 | 2010-09-24 20:47:58 +0000 | [diff] [blame] | 1543 | // Two incoming args: GPR:$src, GPR:$val |
| 1544 | // mov $val, pc |
| 1545 | // adds $val, #7 |
| 1546 | // str $val, [$src, #4] |
| 1547 | // movs r0, #0 |
| 1548 | // b 1f |
| 1549 | // movs r0, #1 |
| 1550 | // 1: |
| 1551 | unsigned SrcReg = MI->getOperand(0).getReg(); |
| 1552 | unsigned ValReg = MI->getOperand(1).getReg(); |
| 1553 | MCSymbol *Label = GetARMSJLJEHLabel(); |
| 1554 | { |
| 1555 | MCInst TmpInst; |
| 1556 | TmpInst.setOpcode(ARM::tMOVgpr2tgpr); |
| 1557 | TmpInst.addOperand(MCOperand::CreateReg(ValReg)); |
| 1558 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1559 | // 's' bit operand |
| 1560 | TmpInst.addOperand(MCOperand::CreateReg(ARM::CPSR)); |
| 1561 | OutStreamer.AddComment("eh_setjmp begin"); |
| 1562 | OutStreamer.EmitInstruction(TmpInst); |
| 1563 | } |
| 1564 | { |
| 1565 | MCInst TmpInst; |
| 1566 | TmpInst.setOpcode(ARM::tADDi3); |
| 1567 | TmpInst.addOperand(MCOperand::CreateReg(ValReg)); |
| 1568 | // 's' bit operand |
| 1569 | TmpInst.addOperand(MCOperand::CreateReg(ARM::CPSR)); |
| 1570 | TmpInst.addOperand(MCOperand::CreateReg(ValReg)); |
| 1571 | TmpInst.addOperand(MCOperand::CreateImm(7)); |
| 1572 | // Predicate. |
| 1573 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1574 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1575 | OutStreamer.EmitInstruction(TmpInst); |
| 1576 | } |
| 1577 | { |
| 1578 | MCInst TmpInst; |
Bill Wendling | f4caf69 | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 1579 | TmpInst.setOpcode(ARM::tSTRi); |
Jim Grosbach | 433a578 | 2010-09-24 20:47:58 +0000 | [diff] [blame] | 1580 | TmpInst.addOperand(MCOperand::CreateReg(ValReg)); |
| 1581 | TmpInst.addOperand(MCOperand::CreateReg(SrcReg)); |
| 1582 | // The offset immediate is #4. The operand value is scaled by 4 for the |
| 1583 | // tSTR instruction. |
| 1584 | TmpInst.addOperand(MCOperand::CreateImm(1)); |
Jim Grosbach | 433a578 | 2010-09-24 20:47:58 +0000 | [diff] [blame] | 1585 | // Predicate. |
| 1586 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1587 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1588 | OutStreamer.EmitInstruction(TmpInst); |
| 1589 | } |
| 1590 | { |
| 1591 | MCInst TmpInst; |
| 1592 | TmpInst.setOpcode(ARM::tMOVi8); |
| 1593 | TmpInst.addOperand(MCOperand::CreateReg(ARM::R0)); |
| 1594 | TmpInst.addOperand(MCOperand::CreateReg(ARM::CPSR)); |
| 1595 | TmpInst.addOperand(MCOperand::CreateImm(0)); |
| 1596 | // Predicate. |
| 1597 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1598 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1599 | OutStreamer.EmitInstruction(TmpInst); |
| 1600 | } |
| 1601 | { |
| 1602 | const MCExpr *SymbolExpr = MCSymbolRefExpr::Create(Label, OutContext); |
| 1603 | MCInst TmpInst; |
| 1604 | TmpInst.setOpcode(ARM::tB); |
| 1605 | TmpInst.addOperand(MCOperand::CreateExpr(SymbolExpr)); |
| 1606 | OutStreamer.EmitInstruction(TmpInst); |
| 1607 | } |
| 1608 | { |
| 1609 | MCInst TmpInst; |
| 1610 | TmpInst.setOpcode(ARM::tMOVi8); |
| 1611 | TmpInst.addOperand(MCOperand::CreateReg(ARM::R0)); |
| 1612 | TmpInst.addOperand(MCOperand::CreateReg(ARM::CPSR)); |
| 1613 | TmpInst.addOperand(MCOperand::CreateImm(1)); |
| 1614 | // Predicate. |
| 1615 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1616 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1617 | OutStreamer.AddComment("eh_setjmp end"); |
| 1618 | OutStreamer.EmitInstruction(TmpInst); |
| 1619 | } |
| 1620 | OutStreamer.EmitLabel(Label); |
| 1621 | return; |
| 1622 | } |
| 1623 | |
Jim Grosbach | 4539008 | 2010-09-23 23:33:56 +0000 | [diff] [blame] | 1624 | case ARM::Int_eh_sjlj_setjmp_nofp: |
Jim Grosbach | a3fbadf | 2010-09-30 19:53:58 +0000 | [diff] [blame] | 1625 | case ARM::Int_eh_sjlj_setjmp: { |
Jim Grosbach | 4539008 | 2010-09-23 23:33:56 +0000 | [diff] [blame] | 1626 | // Two incoming args: GPR:$src, GPR:$val |
| 1627 | // add $val, pc, #8 |
| 1628 | // str $val, [$src, #+4] |
| 1629 | // mov r0, #0 |
| 1630 | // add pc, pc, #0 |
| 1631 | // mov r0, #1 |
| 1632 | unsigned SrcReg = MI->getOperand(0).getReg(); |
| 1633 | unsigned ValReg = MI->getOperand(1).getReg(); |
| 1634 | |
| 1635 | { |
| 1636 | MCInst TmpInst; |
| 1637 | TmpInst.setOpcode(ARM::ADDri); |
| 1638 | TmpInst.addOperand(MCOperand::CreateReg(ValReg)); |
| 1639 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1640 | TmpInst.addOperand(MCOperand::CreateImm(8)); |
| 1641 | // Predicate. |
| 1642 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1643 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1644 | // 's' bit operand (always reg0 for this). |
| 1645 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1646 | OutStreamer.AddComment("eh_setjmp begin"); |
| 1647 | OutStreamer.EmitInstruction(TmpInst); |
| 1648 | } |
| 1649 | { |
| 1650 | MCInst TmpInst; |
Jim Grosbach | 7e3383c | 2010-10-27 23:12:14 +0000 | [diff] [blame] | 1651 | TmpInst.setOpcode(ARM::STRi12); |
Jim Grosbach | 4539008 | 2010-09-23 23:33:56 +0000 | [diff] [blame] | 1652 | TmpInst.addOperand(MCOperand::CreateReg(ValReg)); |
| 1653 | TmpInst.addOperand(MCOperand::CreateReg(SrcReg)); |
Jim Grosbach | 4539008 | 2010-09-23 23:33:56 +0000 | [diff] [blame] | 1654 | TmpInst.addOperand(MCOperand::CreateImm(4)); |
| 1655 | // Predicate. |
| 1656 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1657 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1658 | OutStreamer.EmitInstruction(TmpInst); |
| 1659 | } |
| 1660 | { |
| 1661 | MCInst TmpInst; |
| 1662 | TmpInst.setOpcode(ARM::MOVi); |
| 1663 | TmpInst.addOperand(MCOperand::CreateReg(ARM::R0)); |
| 1664 | TmpInst.addOperand(MCOperand::CreateImm(0)); |
| 1665 | // Predicate. |
| 1666 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1667 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1668 | // 's' bit operand (always reg0 for this). |
| 1669 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1670 | OutStreamer.EmitInstruction(TmpInst); |
| 1671 | } |
| 1672 | { |
| 1673 | MCInst TmpInst; |
| 1674 | TmpInst.setOpcode(ARM::ADDri); |
| 1675 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1676 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1677 | TmpInst.addOperand(MCOperand::CreateImm(0)); |
| 1678 | // Predicate. |
| 1679 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1680 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1681 | // 's' bit operand (always reg0 for this). |
| 1682 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1683 | OutStreamer.EmitInstruction(TmpInst); |
| 1684 | } |
| 1685 | { |
| 1686 | MCInst TmpInst; |
| 1687 | TmpInst.setOpcode(ARM::MOVi); |
| 1688 | TmpInst.addOperand(MCOperand::CreateReg(ARM::R0)); |
| 1689 | TmpInst.addOperand(MCOperand::CreateImm(1)); |
| 1690 | // Predicate. |
| 1691 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1692 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1693 | // 's' bit operand (always reg0 for this). |
| 1694 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1695 | OutStreamer.AddComment("eh_setjmp end"); |
| 1696 | OutStreamer.EmitInstruction(TmpInst); |
| 1697 | } |
| 1698 | return; |
| 1699 | } |
Jim Grosbach | 5acb3de | 2010-09-27 21:47:04 +0000 | [diff] [blame] | 1700 | case ARM::Int_eh_sjlj_longjmp: { |
| 1701 | // ldr sp, [$src, #8] |
| 1702 | // ldr $scratch, [$src, #4] |
| 1703 | // ldr r7, [$src] |
| 1704 | // bx $scratch |
| 1705 | unsigned SrcReg = MI->getOperand(0).getReg(); |
| 1706 | unsigned ScratchReg = MI->getOperand(1).getReg(); |
| 1707 | { |
| 1708 | MCInst TmpInst; |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 1709 | TmpInst.setOpcode(ARM::LDRi12); |
Jim Grosbach | 5acb3de | 2010-09-27 21:47:04 +0000 | [diff] [blame] | 1710 | TmpInst.addOperand(MCOperand::CreateReg(ARM::SP)); |
| 1711 | TmpInst.addOperand(MCOperand::CreateReg(SrcReg)); |
Jim Grosbach | 5acb3de | 2010-09-27 21:47:04 +0000 | [diff] [blame] | 1712 | TmpInst.addOperand(MCOperand::CreateImm(8)); |
| 1713 | // Predicate. |
| 1714 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1715 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1716 | OutStreamer.EmitInstruction(TmpInst); |
| 1717 | } |
| 1718 | { |
| 1719 | MCInst TmpInst; |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 1720 | TmpInst.setOpcode(ARM::LDRi12); |
Jim Grosbach | 5acb3de | 2010-09-27 21:47:04 +0000 | [diff] [blame] | 1721 | TmpInst.addOperand(MCOperand::CreateReg(ScratchReg)); |
| 1722 | TmpInst.addOperand(MCOperand::CreateReg(SrcReg)); |
Jim Grosbach | 5acb3de | 2010-09-27 21:47:04 +0000 | [diff] [blame] | 1723 | TmpInst.addOperand(MCOperand::CreateImm(4)); |
| 1724 | // Predicate. |
| 1725 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1726 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1727 | OutStreamer.EmitInstruction(TmpInst); |
| 1728 | } |
| 1729 | { |
| 1730 | MCInst TmpInst; |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 1731 | TmpInst.setOpcode(ARM::LDRi12); |
Jim Grosbach | 5acb3de | 2010-09-27 21:47:04 +0000 | [diff] [blame] | 1732 | TmpInst.addOperand(MCOperand::CreateReg(ARM::R7)); |
| 1733 | TmpInst.addOperand(MCOperand::CreateReg(SrcReg)); |
Jim Grosbach | 5acb3de | 2010-09-27 21:47:04 +0000 | [diff] [blame] | 1734 | TmpInst.addOperand(MCOperand::CreateImm(0)); |
| 1735 | // Predicate. |
| 1736 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1737 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1738 | OutStreamer.EmitInstruction(TmpInst); |
| 1739 | } |
| 1740 | { |
| 1741 | MCInst TmpInst; |
Bill Wendling | 6e46d84 | 2010-11-30 00:48:15 +0000 | [diff] [blame] | 1742 | TmpInst.setOpcode(ARM::BX); |
Jim Grosbach | 5acb3de | 2010-09-27 21:47:04 +0000 | [diff] [blame] | 1743 | TmpInst.addOperand(MCOperand::CreateReg(ScratchReg)); |
| 1744 | // Predicate. |
| 1745 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1746 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1747 | OutStreamer.EmitInstruction(TmpInst); |
| 1748 | } |
| 1749 | return; |
| 1750 | } |
Jim Grosbach | 385cc5e | 2010-09-27 22:28:11 +0000 | [diff] [blame] | 1751 | case ARM::tInt_eh_sjlj_longjmp: { |
| 1752 | // ldr $scratch, [$src, #8] |
| 1753 | // mov sp, $scratch |
| 1754 | // ldr $scratch, [$src, #4] |
| 1755 | // ldr r7, [$src] |
| 1756 | // bx $scratch |
| 1757 | unsigned SrcReg = MI->getOperand(0).getReg(); |
| 1758 | unsigned ScratchReg = MI->getOperand(1).getReg(); |
| 1759 | { |
| 1760 | MCInst TmpInst; |
Bill Wendling | f4caf69 | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 1761 | TmpInst.setOpcode(ARM::tLDRi); |
Jim Grosbach | 385cc5e | 2010-09-27 22:28:11 +0000 | [diff] [blame] | 1762 | TmpInst.addOperand(MCOperand::CreateReg(ScratchReg)); |
| 1763 | TmpInst.addOperand(MCOperand::CreateReg(SrcReg)); |
| 1764 | // The offset immediate is #8. The operand value is scaled by 4 for the |
Bill Wendling | f4caf69 | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 1765 | // tLDR instruction. |
Jim Grosbach | 385cc5e | 2010-09-27 22:28:11 +0000 | [diff] [blame] | 1766 | TmpInst.addOperand(MCOperand::CreateImm(2)); |
Jim Grosbach | 385cc5e | 2010-09-27 22:28:11 +0000 | [diff] [blame] | 1767 | // Predicate. |
| 1768 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1769 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1770 | OutStreamer.EmitInstruction(TmpInst); |
| 1771 | } |
| 1772 | { |
| 1773 | MCInst TmpInst; |
| 1774 | TmpInst.setOpcode(ARM::tMOVtgpr2gpr); |
| 1775 | TmpInst.addOperand(MCOperand::CreateReg(ARM::SP)); |
| 1776 | TmpInst.addOperand(MCOperand::CreateReg(ScratchReg)); |
| 1777 | // Predicate. |
| 1778 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1779 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1780 | OutStreamer.EmitInstruction(TmpInst); |
| 1781 | } |
| 1782 | { |
| 1783 | MCInst TmpInst; |
Bill Wendling | f4caf69 | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 1784 | TmpInst.setOpcode(ARM::tLDRi); |
Jim Grosbach | 385cc5e | 2010-09-27 22:28:11 +0000 | [diff] [blame] | 1785 | TmpInst.addOperand(MCOperand::CreateReg(ScratchReg)); |
| 1786 | TmpInst.addOperand(MCOperand::CreateReg(SrcReg)); |
| 1787 | TmpInst.addOperand(MCOperand::CreateImm(1)); |
Jim Grosbach | 385cc5e | 2010-09-27 22:28:11 +0000 | [diff] [blame] | 1788 | // Predicate. |
| 1789 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1790 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1791 | OutStreamer.EmitInstruction(TmpInst); |
| 1792 | } |
| 1793 | { |
| 1794 | MCInst TmpInst; |
Bill Wendling | f4caf69 | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 1795 | TmpInst.setOpcode(ARM::tLDRr); |
Jim Grosbach | 385cc5e | 2010-09-27 22:28:11 +0000 | [diff] [blame] | 1796 | TmpInst.addOperand(MCOperand::CreateReg(ARM::R7)); |
| 1797 | TmpInst.addOperand(MCOperand::CreateReg(SrcReg)); |
Jim Grosbach | 385cc5e | 2010-09-27 22:28:11 +0000 | [diff] [blame] | 1798 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1799 | // Predicate. |
| 1800 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1801 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1802 | OutStreamer.EmitInstruction(TmpInst); |
| 1803 | } |
| 1804 | { |
| 1805 | MCInst TmpInst; |
| 1806 | TmpInst.setOpcode(ARM::tBX_RET_vararg); |
| 1807 | TmpInst.addOperand(MCOperand::CreateReg(ScratchReg)); |
| 1808 | // Predicate. |
| 1809 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1810 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1811 | OutStreamer.EmitInstruction(TmpInst); |
| 1812 | } |
| 1813 | return; |
| 1814 | } |
Jim Grosbach | 5edf24e | 2011-03-15 00:30:40 +0000 | [diff] [blame] | 1815 | // Tail jump branches are really just branch instructions with additional |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1816 | // code-gen attributes. Convert them to the canonical form here. |
Jim Grosbach | 5edf24e | 2011-03-15 00:30:40 +0000 | [diff] [blame] | 1817 | case ARM::TAILJMPd: |
| 1818 | case ARM::TAILJMPdND: { |
| 1819 | MCInst TmpInst, TmpInst2; |
| 1820 | // Lower the instruction as-is to get the operands properly converted. |
| 1821 | LowerARMMachineInstrToMCInst(MI, TmpInst2, *this); |
| 1822 | TmpInst.setOpcode(ARM::Bcc); |
| 1823 | TmpInst.addOperand(TmpInst2.getOperand(0)); |
| 1824 | // Add predicate operands. |
| 1825 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1826 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1827 | OutStreamer.AddComment("TAILCALL"); |
| 1828 | OutStreamer.EmitInstruction(TmpInst); |
| 1829 | return; |
| 1830 | } |
| 1831 | case ARM::tTAILJMPd: |
| 1832 | case ARM::tTAILJMPdND: { |
| 1833 | MCInst TmpInst, TmpInst2; |
| 1834 | LowerARMMachineInstrToMCInst(MI, TmpInst2, *this); |
Cameron Zwarich | d34d429 | 2011-05-23 01:57:17 +0000 | [diff] [blame^] | 1835 | // The Darwin toolchain doesn't support tail call relocations of 16-bit |
| 1836 | // branches. |
| 1837 | TmpInst.setOpcode(Opc == ARM::tTAILJMPd ? ARM::t2B : ARM::tB); |
Jim Grosbach | 5edf24e | 2011-03-15 00:30:40 +0000 | [diff] [blame] | 1838 | TmpInst.addOperand(TmpInst2.getOperand(0)); |
| 1839 | OutStreamer.AddComment("TAILCALL"); |
| 1840 | OutStreamer.EmitInstruction(TmpInst); |
| 1841 | return; |
| 1842 | } |
| 1843 | case ARM::TAILJMPrND: |
| 1844 | case ARM::tTAILJMPrND: |
| 1845 | case ARM::TAILJMPr: |
| 1846 | case ARM::tTAILJMPr: { |
| 1847 | unsigned newOpc = (Opc == ARM::TAILJMPr || Opc == ARM::TAILJMPrND) |
| 1848 | ? ARM::BX : ARM::tBX; |
| 1849 | MCInst TmpInst; |
| 1850 | TmpInst.setOpcode(newOpc); |
| 1851 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1852 | // Predicate. |
| 1853 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1854 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1855 | OutStreamer.AddComment("TAILCALL"); |
| 1856 | OutStreamer.EmitInstruction(TmpInst); |
| 1857 | return; |
| 1858 | } |
| 1859 | |
Anton Korobeynikov | 4d72860 | 2011-01-01 20:38:38 +0000 | [diff] [blame] | 1860 | // These are the pseudos created to comply with stricter operand restrictions |
| 1861 | // on ARMv5. Lower them now to "normal" instructions, since all the |
| 1862 | // restrictions are already satisfied. |
| 1863 | case ARM::MULv5: |
| 1864 | EmitPatchedInstruction(MI, ARM::MUL); |
| 1865 | return; |
| 1866 | case ARM::MLAv5: |
| 1867 | EmitPatchedInstruction(MI, ARM::MLA); |
| 1868 | return; |
| 1869 | case ARM::SMULLv5: |
| 1870 | EmitPatchedInstruction(MI, ARM::SMULL); |
| 1871 | return; |
| 1872 | case ARM::UMULLv5: |
| 1873 | EmitPatchedInstruction(MI, ARM::UMULL); |
| 1874 | return; |
| 1875 | case ARM::SMLALv5: |
| 1876 | EmitPatchedInstruction(MI, ARM::SMLAL); |
| 1877 | return; |
| 1878 | case ARM::UMLALv5: |
| 1879 | EmitPatchedInstruction(MI, ARM::UMLAL); |
| 1880 | return; |
| 1881 | case ARM::UMAALv5: |
| 1882 | EmitPatchedInstruction(MI, ARM::UMAAL); |
| 1883 | return; |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 1884 | } |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1885 | |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 1886 | MCInst TmpInst; |
Chris Lattner | 30e2cc2 | 2010-11-14 21:00:02 +0000 | [diff] [blame] | 1887 | LowerARMMachineInstrToMCInst(MI, TmpInst, *this); |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 1888 | |
| 1889 | // Emit unwinding stuff for frame-related instructions |
| 1890 | if (EnableARMEHABI && MI->getFlag(MachineInstr::FrameSetup)) |
| 1891 | EmitUnwindingInstruction(MI); |
| 1892 | |
Chris Lattner | 850d2e2 | 2010-02-03 01:16:28 +0000 | [diff] [blame] | 1893 | OutStreamer.EmitInstruction(TmpInst); |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 1894 | } |
Daniel Dunbar | 2685a29 | 2009-10-20 05:15:36 +0000 | [diff] [blame] | 1895 | |
| 1896 | //===----------------------------------------------------------------------===// |
| 1897 | // Target Registry Stuff |
| 1898 | //===----------------------------------------------------------------------===// |
| 1899 | |
| 1900 | static MCInstPrinter *createARMMCInstPrinter(const Target &T, |
Bill Wendling | a5c177e | 2011-03-21 04:13:46 +0000 | [diff] [blame] | 1901 | TargetMachine &TM, |
Daniel Dunbar | 2685a29 | 2009-10-20 05:15:36 +0000 | [diff] [blame] | 1902 | unsigned SyntaxVariant, |
Chris Lattner | d374087 | 2010-04-04 05:04:31 +0000 | [diff] [blame] | 1903 | const MCAsmInfo &MAI) { |
Daniel Dunbar | 2685a29 | 2009-10-20 05:15:36 +0000 | [diff] [blame] | 1904 | if (SyntaxVariant == 0) |
Bill Wendling | a5c177e | 2011-03-21 04:13:46 +0000 | [diff] [blame] | 1905 | return new ARMInstPrinter(TM, MAI); |
Daniel Dunbar | 2685a29 | 2009-10-20 05:15:36 +0000 | [diff] [blame] | 1906 | return 0; |
| 1907 | } |
| 1908 | |
| 1909 | // Force static initialization. |
| 1910 | extern "C" void LLVMInitializeARMAsmPrinter() { |
| 1911 | RegisterAsmPrinter<ARMAsmPrinter> X(TheARMTarget); |
| 1912 | RegisterAsmPrinter<ARMAsmPrinter> Y(TheThumbTarget); |
| 1913 | |
| 1914 | TargetRegistry::RegisterMCInstPrinter(TheARMTarget, createARMMCInstPrinter); |
| 1915 | TargetRegistry::RegisterMCInstPrinter(TheThumbTarget, createARMMCInstPrinter); |
| 1916 | } |
| 1917 | |