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