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" |
Anton Korobeynikov | 88ce667 | 2009-05-23 19:51:20 +0000 | [diff] [blame] | 17 | #include "ARMBuildAttrs.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 18 | #include "ARMAddressingModes.h" |
| 19 | #include "ARMConstantPoolValue.h" |
Jim Grosbach | 7ac1609 | 2010-10-01 22:39:28 +0000 | [diff] [blame] | 20 | #include "InstPrinter/ARMInstPrinter.h" |
Jim Grosbach | baf120f | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 21 | #include "ARMAsmPrinter.h" |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 22 | #include "ARMMachineFunctionInfo.h" |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 23 | #include "ARMTargetMachine.h" |
Jason W Kim | 17b443d | 2010-10-11 23:01:44 +0000 | [diff] [blame] | 24 | #include "ARMTargetObjectFile.h" |
Dale Johannesen | 3f282aa | 2010-04-26 20:07:31 +0000 | [diff] [blame] | 25 | #include "llvm/Analysis/DebugInfo.h" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 26 | #include "llvm/Constants.h" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 27 | #include "llvm/Module.h" |
Benjamin Kramer | e55b15f | 2009-12-28 12:27:56 +0000 | [diff] [blame] | 28 | #include "llvm/Type.h" |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 29 | #include "llvm/Assembly/Writer.h" |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineModuleInfoImpls.h" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/MachineJumpTableInfo.h" |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 33 | #include "llvm/MC/MCAsmInfo.h" |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 34 | #include "llvm/MC/MCAssembler.h" |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 35 | #include "llvm/MC/MCContext.h" |
Bill Wendling | becd83e | 2010-03-09 00:40:17 +0000 | [diff] [blame] | 36 | #include "llvm/MC/MCExpr.h" |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 37 | #include "llvm/MC/MCInst.h" |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 38 | #include "llvm/MC/MCSectionMachO.h" |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 39 | #include "llvm/MC/MCObjectStreamer.h" |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 40 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | 325d3dc | 2009-09-13 17:14:04 +0000 | [diff] [blame] | 41 | #include "llvm/MC/MCSymbol.h" |
Chris Lattner | d62f1b4 | 2010-03-12 21:19:23 +0000 | [diff] [blame] | 42 | #include "llvm/Target/Mangler.h" |
Rafael Espindola | b01c4bb | 2006-07-27 11:38:51 +0000 | [diff] [blame] | 43 | #include "llvm/Target/TargetData.h" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 44 | #include "llvm/Target/TargetMachine.h" |
Evan Cheng | 5be54b0 | 2007-01-19 19:25:36 +0000 | [diff] [blame] | 45 | #include "llvm/Target/TargetOptions.h" |
Daniel Dunbar | 51b198a | 2009-07-15 20:24:03 +0000 | [diff] [blame] | 46 | #include "llvm/Target/TargetRegistry.h" |
Evan Cheng | c324ecb | 2009-07-24 18:19:46 +0000 | [diff] [blame] | 47 | #include "llvm/ADT/SmallPtrSet.h" |
Jim Grosbach | c40d9f9 | 2009-09-01 18:49:12 +0000 | [diff] [blame] | 48 | #include "llvm/ADT/SmallString.h" |
Bob Wilson | 54c78ef | 2009-11-06 23:33:28 +0000 | [diff] [blame] | 49 | #include "llvm/ADT/StringExtras.h" |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 50 | #include "llvm/Support/CommandLine.h" |
Devang Patel | 59135f4 | 2010-08-04 22:39:39 +0000 | [diff] [blame] | 51 | #include "llvm/Support/Debug.h" |
Torok Edwin | 3046470 | 2009-07-08 20:55:50 +0000 | [diff] [blame] | 52 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | b23569a | 2010-04-04 08:18:47 +0000 | [diff] [blame] | 53 | #include "llvm/Support/raw_ostream.h" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 54 | #include <cctype> |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 55 | using namespace llvm; |
| 56 | |
Chris Lattner | 95b2c7d | 2006-12-19 22:59:26 +0000 | [diff] [blame] | 57 | namespace { |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 58 | |
| 59 | // Per section and per symbol attributes are not supported. |
| 60 | // To implement them we would need the ability to delay this emission |
| 61 | // until the assembly file is fully parsed/generated as only then do we |
| 62 | // know the symbol and section numbers. |
| 63 | class AttributeEmitter { |
| 64 | public: |
| 65 | virtual void MaybeSwitchVendor(StringRef Vendor) = 0; |
| 66 | virtual void EmitAttribute(unsigned Attribute, unsigned Value) = 0; |
| 67 | virtual void Finish() = 0; |
Rafael Espindola | 4921e23 | 2010-10-25 18:38:32 +0000 | [diff] [blame] | 68 | virtual ~AttributeEmitter() {} |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | class AsmAttributeEmitter : public AttributeEmitter { |
| 72 | MCStreamer &Streamer; |
| 73 | |
| 74 | public: |
| 75 | AsmAttributeEmitter(MCStreamer &Streamer_) : Streamer(Streamer_) {} |
| 76 | void MaybeSwitchVendor(StringRef Vendor) { } |
| 77 | |
| 78 | void EmitAttribute(unsigned Attribute, unsigned Value) { |
| 79 | Streamer.EmitRawText("\t.eabi_attribute " + |
| 80 | Twine(Attribute) + ", " + Twine(Value)); |
| 81 | } |
| 82 | |
| 83 | void Finish() { } |
| 84 | }; |
| 85 | |
| 86 | class ObjectAttributeEmitter : public AttributeEmitter { |
| 87 | MCObjectStreamer &Streamer; |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 88 | StringRef CurrentVendor; |
| 89 | SmallString<64> Contents; |
| 90 | |
| 91 | public: |
| 92 | ObjectAttributeEmitter(MCObjectStreamer &Streamer_) : |
| 93 | Streamer(Streamer_), CurrentVendor("") { } |
| 94 | |
| 95 | void MaybeSwitchVendor(StringRef Vendor) { |
| 96 | assert(!Vendor.empty() && "Vendor cannot be empty."); |
| 97 | |
| 98 | if (CurrentVendor.empty()) |
| 99 | CurrentVendor = Vendor; |
| 100 | else if (CurrentVendor == Vendor) |
| 101 | return; |
| 102 | else |
| 103 | Finish(); |
| 104 | |
| 105 | CurrentVendor = Vendor; |
| 106 | |
Rafael Espindola | 3336384 | 2010-10-25 22:26:55 +0000 | [diff] [blame] | 107 | assert(Contents.size() == 0); |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | void EmitAttribute(unsigned Attribute, unsigned Value) { |
| 111 | // FIXME: should be ULEB |
| 112 | Contents += Attribute; |
| 113 | Contents += Value; |
| 114 | } |
| 115 | |
| 116 | void Finish() { |
Rafael Espindola | 3336384 | 2010-10-25 22:26:55 +0000 | [diff] [blame] | 117 | const size_t ContentsSize = Contents.size(); |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 118 | |
Rafael Espindola | 3336384 | 2010-10-25 22:26:55 +0000 | [diff] [blame] | 119 | // Vendor size + Vendor name + '\0' |
| 120 | const size_t VendorHeaderSize = 4 + CurrentVendor.size() + 1; |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 121 | |
Rafael Espindola | 3336384 | 2010-10-25 22:26:55 +0000 | [diff] [blame] | 122 | // Tag + Tag Size |
| 123 | const size_t TagHeaderSize = 1 + 4; |
| 124 | |
| 125 | Streamer.EmitIntValue(VendorHeaderSize + TagHeaderSize + ContentsSize, 4); |
| 126 | Streamer.EmitBytes(CurrentVendor, 0); |
| 127 | Streamer.EmitIntValue(0, 1); // '\0' |
| 128 | |
| 129 | Streamer.EmitIntValue(ARMBuildAttrs::File, 1); |
| 130 | Streamer.EmitIntValue(TagHeaderSize + ContentsSize, 4); |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 131 | |
| 132 | Streamer.EmitBytes(Contents, 0); |
Rafael Espindola | 3336384 | 2010-10-25 22:26:55 +0000 | [diff] [blame] | 133 | |
| 134 | Contents.clear(); |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 135 | } |
| 136 | }; |
| 137 | |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 138 | } // end of anonymous namespace |
| 139 | |
Jim Grosbach | baf120f | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 140 | MachineLocation ARMAsmPrinter:: |
| 141 | getDebugValueLocation(const MachineInstr *MI) const { |
| 142 | MachineLocation Location; |
| 143 | assert(MI->getNumOperands() == 4 && "Invalid no. of machine operands!"); |
| 144 | // Frame address. Currently handles register +- offset only. |
| 145 | if (MI->getOperand(0).isReg() && MI->getOperand(1).isImm()) |
| 146 | Location.set(MI->getOperand(0).getReg(), MI->getOperand(1).getImm()); |
| 147 | else { |
| 148 | DEBUG(dbgs() << "DBG_VALUE instruction ignored! " << *MI << "\n"); |
| 149 | } |
| 150 | return Location; |
| 151 | } |
| 152 | |
Chris Lattner | 953ebb7 | 2010-01-27 23:58:11 +0000 | [diff] [blame] | 153 | void ARMAsmPrinter::EmitFunctionEntryLabel() { |
| 154 | if (AFI->isThumbFunction()) { |
Jim Grosbach | ce79299 | 2010-11-05 22:08:08 +0000 | [diff] [blame] | 155 | OutStreamer.EmitAssemblerFlag(MCAF_Code16); |
| 156 | OutStreamer.EmitThumbFunc(Subtarget->isTargetDarwin()? CurrentFnSym : 0); |
Chris Lattner | 953ebb7 | 2010-01-27 23:58:11 +0000 | [diff] [blame] | 157 | } |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 158 | |
Chris Lattner | 953ebb7 | 2010-01-27 23:58:11 +0000 | [diff] [blame] | 159 | OutStreamer.EmitLabel(CurrentFnSym); |
| 160 | } |
| 161 | |
Jim Grosbach | 2317e40 | 2010-09-30 01:57:53 +0000 | [diff] [blame] | 162 | /// runOnMachineFunction - This uses the EmitInstruction() |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 163 | /// method to print assembly for each instruction. |
| 164 | /// |
| 165 | bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 166 | AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 6d63a72 | 2008-09-18 07:27:23 +0000 | [diff] [blame] | 167 | MCP = MF.getConstantPool(); |
Rafael Espindola | 4b442b5 | 2006-05-23 02:48:20 +0000 | [diff] [blame] | 168 | |
Chris Lattner | d49fe1b | 2010-01-28 01:28:58 +0000 | [diff] [blame] | 169 | return AsmPrinter::runOnMachineFunction(MF); |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 172 | void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum, |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 173 | raw_ostream &O, const char *Modifier) { |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 174 | const MachineOperand &MO = MI->getOperand(OpNum); |
Anton Korobeynikov | 5cdc3a9 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 175 | unsigned TF = MO.getTargetFlags(); |
| 176 | |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 177 | switch (MO.getType()) { |
Chris Lattner | 8bc86cb | 2009-10-19 20:59:55 +0000 | [diff] [blame] | 178 | default: |
| 179 | assert(0 && "<unknown operand type>"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 180 | case MachineOperand::MO_Register: { |
| 181 | unsigned Reg = MO.getReg(); |
Chris Lattner | 8bc86cb | 2009-10-19 20:59:55 +0000 | [diff] [blame] | 182 | assert(TargetRegisterInfo::isPhysicalRegister(Reg)); |
Jim Grosbach | 3563628 | 2010-10-06 21:22:32 +0000 | [diff] [blame] | 183 | assert(!MO.getSubReg() && "Subregs should be eliminated!"); |
| 184 | O << ARMInstPrinter::getRegisterName(Reg); |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 185 | break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 186 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 187 | case MachineOperand::MO_Immediate: { |
Evan Cheng | 5adb66a | 2009-09-28 09:14:39 +0000 | [diff] [blame] | 188 | int64_t Imm = MO.getImm(); |
Anton Korobeynikov | 632606c | 2009-10-08 20:43:22 +0000 | [diff] [blame] | 189 | O << '#'; |
Anton Korobeynikov | 5cdc3a9 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 190 | if ((Modifier && strcmp(Modifier, "lo16") == 0) || |
Jim Grosbach | 4dea941 | 2010-10-06 16:51:55 +0000 | [diff] [blame] | 191 | (TF == ARMII::MO_LO16)) |
Anton Korobeynikov | 5cdc3a9 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 192 | O << ":lower16:"; |
| 193 | else if ((Modifier && strcmp(Modifier, "hi16") == 0) || |
Jim Grosbach | 4dea941 | 2010-10-06 16:51:55 +0000 | [diff] [blame] | 194 | (TF == ARMII::MO_HI16)) |
Anton Korobeynikov | 5cdc3a9 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 195 | O << ":upper16:"; |
Anton Korobeynikov | 632606c | 2009-10-08 20:43:22 +0000 | [diff] [blame] | 196 | O << Imm; |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 197 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 198 | } |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 199 | case MachineOperand::MO_MachineBasicBlock: |
Chris Lattner | 1b2eb0e | 2010-03-13 21:04:28 +0000 | [diff] [blame] | 200 | O << *MO.getMBB()->getSymbol(); |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 201 | return; |
Rafael Espindola | 84b19be | 2006-07-16 01:02:57 +0000 | [diff] [blame] | 202 | case MachineOperand::MO_GlobalAddress: { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 203 | const GlobalValue *GV = MO.getGlobal(); |
Anton Korobeynikov | 5cdc3a9 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 204 | if ((Modifier && strcmp(Modifier, "lo16") == 0) || |
| 205 | (TF & ARMII::MO_LO16)) |
| 206 | O << ":lower16:"; |
| 207 | else if ((Modifier && strcmp(Modifier, "hi16") == 0) || |
| 208 | (TF & ARMII::MO_HI16)) |
| 209 | O << ":upper16:"; |
Chris Lattner | d62f1b4 | 2010-03-12 21:19:23 +0000 | [diff] [blame] | 210 | O << *Mang->getSymbol(GV); |
Anton Korobeynikov | 7751ad9 | 2008-11-22 16:15:34 +0000 | [diff] [blame] | 211 | |
Chris Lattner | 0c08d09 | 2010-04-03 22:28:33 +0000 | [diff] [blame] | 212 | printOffset(MO.getOffset(), O); |
Jim Grosbach | 1d6111c | 2010-10-06 21:36:43 +0000 | [diff] [blame] | 213 | if (TF == ARMII::MO_PLT) |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 214 | O << "(PLT)"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 215 | break; |
Rafael Espindola | 84b19be | 2006-07-16 01:02:57 +0000 | [diff] [blame] | 216 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 217 | case MachineOperand::MO_ExternalSymbol: { |
Chris Lattner | 10b318b | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 218 | O << *GetExternalSymbolSymbol(MO.getSymbolName()); |
Jim Grosbach | 1d6111c | 2010-10-06 21:36:43 +0000 | [diff] [blame] | 219 | if (TF == ARMII::MO_PLT) |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 220 | O << "(PLT)"; |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 221 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 222 | } |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 223 | case MachineOperand::MO_ConstantPoolIndex: |
Chris Lattner | 1b46f43 | 2010-01-23 07:00:21 +0000 | [diff] [blame] | 224 | O << *GetCPISymbol(MO.getIndex()); |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 225 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 226 | case MachineOperand::MO_JumpTableIndex: |
Chris Lattner | 1b46f43 | 2010-01-23 07:00:21 +0000 | [diff] [blame] | 227 | O << *GetJTISymbol(MO.getIndex()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 228 | break; |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 229 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 232 | //===--------------------------------------------------------------------===// |
| 233 | |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 234 | MCSymbol *ARMAsmPrinter:: |
| 235 | GetARMSetPICJumpTableLabel2(unsigned uid, unsigned uid2, |
| 236 | const MachineBasicBlock *MBB) const { |
| 237 | SmallString<60> Name; |
| 238 | raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() |
Chris Lattner | bfcb096 | 2010-01-25 19:39:52 +0000 | [diff] [blame] | 239 | << getFunctionNumber() << '_' << uid << '_' << uid2 |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 240 | << "_set_" << MBB->getNumber(); |
Chris Lattner | 9b97a73 | 2010-03-30 18:10:53 +0000 | [diff] [blame] | 241 | return OutContext.GetOrCreateSymbol(Name.str()); |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | MCSymbol *ARMAsmPrinter:: |
| 245 | GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const { |
| 246 | SmallString<60> Name; |
| 247 | raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "JTI" |
Chris Lattner | 281e776 | 2010-01-25 23:28:03 +0000 | [diff] [blame] | 248 | << getFunctionNumber() << '_' << uid << '_' << uid2; |
Chris Lattner | 9b97a73 | 2010-03-30 18:10:53 +0000 | [diff] [blame] | 249 | return OutContext.GetOrCreateSymbol(Name.str()); |
Chris Lattner | bfcb096 | 2010-01-25 19:39:52 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Jim Grosbach | 433a578 | 2010-09-24 20:47:58 +0000 | [diff] [blame] | 252 | |
| 253 | MCSymbol *ARMAsmPrinter::GetARMSJLJEHLabel(void) const { |
| 254 | SmallString<60> Name; |
| 255 | raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "SJLJEH" |
| 256 | << getFunctionNumber(); |
| 257 | return OutContext.GetOrCreateSymbol(Name.str()); |
| 258 | } |
| 259 | |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 260 | bool ARMAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum, |
Chris Lattner | c75c028 | 2010-04-04 05:29:35 +0000 | [diff] [blame] | 261 | unsigned AsmVariant, const char *ExtraCode, |
| 262 | raw_ostream &O) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 263 | // Does this asm operand have a single letter operand modifier? |
| 264 | if (ExtraCode && ExtraCode[0]) { |
| 265 | if (ExtraCode[1] != 0) return true; // Unknown modifier. |
Anton Korobeynikov | 8e9ece7 | 2009-08-08 23:10:41 +0000 | [diff] [blame] | 266 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 267 | switch (ExtraCode[0]) { |
| 268 | default: return true; // Unknown modifier. |
Bob Wilson | 9b4b00a | 2009-07-09 23:54:51 +0000 | [diff] [blame] | 269 | case 'a': // Print as a memory address. |
| 270 | if (MI->getOperand(OpNum).isReg()) { |
Jim Grosbach | 2f24c4e | 2010-09-30 15:25:22 +0000 | [diff] [blame] | 271 | O << "[" |
| 272 | << ARMInstPrinter::getRegisterName(MI->getOperand(OpNum).getReg()) |
| 273 | << "]"; |
Bob Wilson | 9b4b00a | 2009-07-09 23:54:51 +0000 | [diff] [blame] | 274 | return false; |
| 275 | } |
| 276 | // Fallthrough |
| 277 | case 'c': // Don't print "#" before an immediate operand. |
Bob Wilson | 4f38b38 | 2009-08-21 21:58:55 +0000 | [diff] [blame] | 278 | if (!MI->getOperand(OpNum).isImm()) |
| 279 | return true; |
Jim Grosbach | 2317e40 | 2010-09-30 01:57:53 +0000 | [diff] [blame] | 280 | O << MI->getOperand(OpNum).getImm(); |
Bob Wilson | 8f34346 | 2009-04-06 21:46:51 +0000 | [diff] [blame] | 281 | return false; |
Evan Cheng | e21e396 | 2007-04-04 00:13:29 +0000 | [diff] [blame] | 282 | case 'P': // Print a VFP double precision register. |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 283 | case 'q': // Print a NEON quad precision register. |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 284 | printOperand(MI, OpNum, O); |
Evan Cheng | 23a9570 | 2007-03-08 22:42:46 +0000 | [diff] [blame] | 285 | return false; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 286 | case 'Q': |
Bob Wilson | d984eb6 | 2010-05-27 20:23:42 +0000 | [diff] [blame] | 287 | case 'R': |
Bob Wilson | d984eb6 | 2010-05-27 20:23:42 +0000 | [diff] [blame] | 288 | case 'H': |
Bob Wilson | 9bb43e1 | 2010-12-17 23:06:42 +0000 | [diff] [blame^] | 289 | // These modifiers are not yet supported. |
Bob Wilson | d984eb6 | 2010-05-27 20:23:42 +0000 | [diff] [blame] | 290 | return true; |
Evan Cheng | 84f60b7 | 2010-05-27 22:08:38 +0000 | [diff] [blame] | 291 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 292 | } |
Jim Grosbach | e995221 | 2009-09-04 01:38:51 +0000 | [diff] [blame] | 293 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 294 | printOperand(MI, OpNum, O); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 295 | return false; |
| 296 | } |
| 297 | |
Bob Wilson | 224c244 | 2009-05-19 05:53:42 +0000 | [diff] [blame] | 298 | bool ARMAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 299 | unsigned OpNum, unsigned AsmVariant, |
Chris Lattner | c75c028 | 2010-04-04 05:29:35 +0000 | [diff] [blame] | 300 | const char *ExtraCode, |
| 301 | raw_ostream &O) { |
Bob Wilson | 224c244 | 2009-05-19 05:53:42 +0000 | [diff] [blame] | 302 | if (ExtraCode && ExtraCode[0]) |
| 303 | return true; // Unknown modifier. |
Bob Wilson | 765cc0b | 2009-10-13 20:50:28 +0000 | [diff] [blame] | 304 | |
| 305 | const MachineOperand &MO = MI->getOperand(OpNum); |
| 306 | assert(MO.isReg() && "unexpected inline asm memory operand"); |
Jim Grosbach | 2317e40 | 2010-09-30 01:57:53 +0000 | [diff] [blame] | 307 | O << "[" << ARMInstPrinter::getRegisterName(MO.getReg()) << "]"; |
Bob Wilson | 224c244 | 2009-05-19 05:53:42 +0000 | [diff] [blame] | 308 | return false; |
| 309 | } |
| 310 | |
Bob Wilson | 812209a | 2009-09-30 22:06:26 +0000 | [diff] [blame] | 311 | void ARMAsmPrinter::EmitStartOfAsmFile(Module &M) { |
Bob Wilson | 0fb3468 | 2009-09-30 00:23:42 +0000 | [diff] [blame] | 312 | if (Subtarget->isTargetDarwin()) { |
| 313 | Reloc::Model RelocM = TM.getRelocationModel(); |
| 314 | if (RelocM == Reloc::PIC_ || RelocM == Reloc::DynamicNoPIC) { |
| 315 | // Declare all the text sections up front (before the DWARF sections |
| 316 | // emitted by AsmPrinter::doInitialization) so the assembler will keep |
| 317 | // them together at the beginning of the object file. This helps |
| 318 | // avoid out-of-range branches that are due a fundamental limitation of |
| 319 | // the way symbol offsets are encoded with the current Darwin ARM |
| 320 | // relocations. |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 321 | const TargetLoweringObjectFileMachO &TLOFMacho = |
Dan Gohman | 0d805c3 | 2010-04-17 16:44:48 +0000 | [diff] [blame] | 322 | static_cast<const TargetLoweringObjectFileMachO &>( |
| 323 | getObjFileLowering()); |
Bob Wilson | 29e0669 | 2009-09-30 22:25:37 +0000 | [diff] [blame] | 324 | OutStreamer.SwitchSection(TLOFMacho.getTextSection()); |
| 325 | OutStreamer.SwitchSection(TLOFMacho.getTextCoalSection()); |
| 326 | OutStreamer.SwitchSection(TLOFMacho.getConstTextCoalSection()); |
| 327 | if (RelocM == Reloc::DynamicNoPIC) { |
| 328 | const MCSection *sect = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 329 | OutContext.getMachOSection("__TEXT", "__symbol_stub4", |
| 330 | MCSectionMachO::S_SYMBOL_STUBS, |
| 331 | 12, SectionKind::getText()); |
Bob Wilson | 29e0669 | 2009-09-30 22:25:37 +0000 | [diff] [blame] | 332 | OutStreamer.SwitchSection(sect); |
| 333 | } else { |
| 334 | const MCSection *sect = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 335 | OutContext.getMachOSection("__TEXT", "__picsymbolstub4", |
| 336 | MCSectionMachO::S_SYMBOL_STUBS, |
| 337 | 16, SectionKind::getText()); |
Bob Wilson | 29e0669 | 2009-09-30 22:25:37 +0000 | [diff] [blame] | 338 | OutStreamer.SwitchSection(sect); |
| 339 | } |
Bob Wilson | 63db594 | 2010-07-30 19:55:47 +0000 | [diff] [blame] | 340 | const MCSection *StaticInitSect = |
| 341 | OutContext.getMachOSection("__TEXT", "__StaticInit", |
| 342 | MCSectionMachO::S_REGULAR | |
| 343 | MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, |
| 344 | SectionKind::getText()); |
| 345 | OutStreamer.SwitchSection(StaticInitSect); |
Bob Wilson | 0fb3468 | 2009-09-30 00:23:42 +0000 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 349 | // Use unified assembler syntax. |
Jason W Kim | afd1cc2 | 2010-09-30 02:45:56 +0000 | [diff] [blame] | 350 | OutStreamer.EmitAssemblerFlag(MCAF_SyntaxUnified); |
Anton Korobeynikov | d61eca5 | 2009-06-17 23:43:18 +0000 | [diff] [blame] | 351 | |
Anton Korobeynikov | 88ce667 | 2009-05-23 19:51:20 +0000 | [diff] [blame] | 352 | // Emit ARM Build Attributes |
| 353 | if (Subtarget->isTargetELF()) { |
Anton Korobeynikov | 88ce667 | 2009-05-23 19:51:20 +0000 | [diff] [blame] | 354 | |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 355 | emitAttributes(); |
Anton Korobeynikov | 88ce667 | 2009-05-23 19:51:20 +0000 | [diff] [blame] | 356 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Anton Korobeynikov | 0f3cc65 | 2008-08-07 09:54:23 +0000 | [diff] [blame] | 359 | |
Chris Lattner | 4a071d6 | 2009-10-19 17:59:19 +0000 | [diff] [blame] | 360 | void ARMAsmPrinter::EmitEndOfAsmFile(Module &M) { |
Evan Cheng | 5be54b0 | 2007-01-19 19:25:36 +0000 | [diff] [blame] | 361 | if (Subtarget->isTargetDarwin()) { |
Chris Lattner | f61159b | 2009-08-03 22:18:15 +0000 | [diff] [blame] | 362 | // All darwin targets use mach-o. |
Dan Gohman | 0d805c3 | 2010-04-17 16:44:48 +0000 | [diff] [blame] | 363 | const TargetLoweringObjectFileMachO &TLOFMacho = |
| 364 | static_cast<const TargetLoweringObjectFileMachO &>(getObjFileLowering()); |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 365 | MachineModuleInfoMachO &MMIMacho = |
| 366 | MMI->getObjFileInfo<MachineModuleInfoMachO>(); |
Jim Grosbach | e995221 | 2009-09-04 01:38:51 +0000 | [diff] [blame] | 367 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 368 | // Output non-lazy-pointers for external and common global variables. |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 369 | MachineModuleInfoMachO::SymbolListTy Stubs = MMIMacho.GetGVStubList(); |
Bill Wendling | cebae36 | 2010-03-10 22:34:10 +0000 | [diff] [blame] | 370 | |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 371 | if (!Stubs.empty()) { |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 372 | // Switch with ".non_lazy_symbol_pointer" directive. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 373 | OutStreamer.SwitchSection(TLOFMacho.getNonLazySymbolPointerSection()); |
Chris Lattner | c076a97 | 2009-08-10 18:01:34 +0000 | [diff] [blame] | 374 | EmitAlignment(2); |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 375 | for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { |
Bill Wendling | becd83e | 2010-03-09 00:40:17 +0000 | [diff] [blame] | 376 | // L_foo$stub: |
| 377 | OutStreamer.EmitLabel(Stubs[i].first); |
| 378 | // .indirect_symbol _foo |
Bill Wendling | 52a50e5 | 2010-03-11 01:18:13 +0000 | [diff] [blame] | 379 | MachineModuleInfoImpl::StubValueTy &MCSym = Stubs[i].second; |
| 380 | OutStreamer.EmitSymbolAttribute(MCSym.getPointer(),MCSA_IndirectSymbol); |
Bill Wendling | cf6f28d | 2010-03-09 00:43:34 +0000 | [diff] [blame] | 381 | |
Bill Wendling | 52a50e5 | 2010-03-11 01:18:13 +0000 | [diff] [blame] | 382 | if (MCSym.getInt()) |
Bill Wendling | cf6f28d | 2010-03-09 00:43:34 +0000 | [diff] [blame] | 383 | // External to current translation unit. |
| 384 | OutStreamer.EmitIntValue(0, 4/*size*/, 0/*addrspace*/); |
| 385 | else |
| 386 | // Internal to current translation unit. |
Bill Wendling | 5e1b55d | 2010-03-31 18:47:10 +0000 | [diff] [blame] | 387 | // |
Jim Grosbach | 1b935a3 | 2010-09-22 16:45:13 +0000 | [diff] [blame] | 388 | // When we place the LSDA into the TEXT section, the type info |
| 389 | // pointers need to be indirect and pc-rel. We accomplish this by |
| 390 | // using NLPs; however, sometimes the types are local to the file. |
| 391 | // 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] | 392 | OutStreamer.EmitValue(MCSymbolRefExpr::Create(MCSym.getPointer(), |
| 393 | OutContext), |
Bill Wendling | cf6f28d | 2010-03-09 00:43:34 +0000 | [diff] [blame] | 394 | 4/*size*/, 0/*addrspace*/); |
Evan Cheng | ae94e59 | 2008-12-05 01:06:39 +0000 | [diff] [blame] | 395 | } |
Bill Wendling | becd83e | 2010-03-09 00:40:17 +0000 | [diff] [blame] | 396 | |
| 397 | Stubs.clear(); |
| 398 | OutStreamer.AddBlankLine(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Chris Lattner | e4d9ea8 | 2009-10-19 18:44:38 +0000 | [diff] [blame] | 401 | Stubs = MMIMacho.GetHiddenGVStubList(); |
| 402 | if (!Stubs.empty()) { |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 403 | OutStreamer.SwitchSection(getObjFileLowering().getDataSection()); |
Chris Lattner | f3231de | 2009-08-10 18:02:16 +0000 | [diff] [blame] | 404 | EmitAlignment(2); |
Bill Wendling | becd83e | 2010-03-09 00:40:17 +0000 | [diff] [blame] | 405 | for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { |
| 406 | // L_foo$stub: |
| 407 | OutStreamer.EmitLabel(Stubs[i].first); |
| 408 | // .long _foo |
Bill Wendling | cebae36 | 2010-03-10 22:34:10 +0000 | [diff] [blame] | 409 | OutStreamer.EmitValue(MCSymbolRefExpr:: |
| 410 | Create(Stubs[i].second.getPointer(), |
| 411 | OutContext), |
Bill Wendling | becd83e | 2010-03-09 00:40:17 +0000 | [diff] [blame] | 412 | 4/*size*/, 0/*addrspace*/); |
| 413 | } |
Bill Wendling | cf6f28d | 2010-03-09 00:43:34 +0000 | [diff] [blame] | 414 | |
| 415 | Stubs.clear(); |
| 416 | OutStreamer.AddBlankLine(); |
Evan Cheng | ae94e59 | 2008-12-05 01:06:39 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 419 | // Funny Darwin hack: This flag tells the linker that no global symbols |
| 420 | // contain code that falls through to other global symbols (e.g. the obvious |
| 421 | // implementation of multiple entry points). If this doesn't occur, the |
| 422 | // linker can safely perform dead code stripping. Since LLVM never |
| 423 | // generates code that does this, it is always safe to set. |
Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 424 | OutStreamer.EmitAssemblerFlag(MCAF_SubsectionsViaSymbols); |
Rafael Espindola | b01c4bb | 2006-07-27 11:38:51 +0000 | [diff] [blame] | 425 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 426 | } |
Anton Korobeynikov | 0bd8971 | 2008-08-17 13:55:10 +0000 | [diff] [blame] | 427 | |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 428 | //===----------------------------------------------------------------------===// |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 429 | // Helper routines for EmitStartOfAsmFile() and EmitEndOfAsmFile() |
| 430 | // FIXME: |
| 431 | // The following seem like one-off assembler flags, but they actually need |
Jim Grosbach | fa7fb64 | 2010-10-06 22:46:47 +0000 | [diff] [blame] | 432 | // to appear in the .ARM.attributes section in ELF. |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 433 | // Instead of subclassing the MCELFStreamer, we do the work here. |
| 434 | |
| 435 | void ARMAsmPrinter::emitAttributes() { |
Jim Grosbach | fa7fb64 | 2010-10-06 22:46:47 +0000 | [diff] [blame] | 436 | |
Jason W Kim | 17b443d | 2010-10-11 23:01:44 +0000 | [diff] [blame] | 437 | emitARMAttributeSection(); |
| 438 | |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 439 | AttributeEmitter *AttrEmitter; |
| 440 | if (OutStreamer.hasRawTextSupport()) |
| 441 | AttrEmitter = new AsmAttributeEmitter(OutStreamer); |
| 442 | else { |
| 443 | MCObjectStreamer &O = static_cast<MCObjectStreamer&>(OutStreamer); |
| 444 | AttrEmitter = new ObjectAttributeEmitter(O); |
| 445 | } |
| 446 | |
| 447 | AttrEmitter->MaybeSwitchVendor("aeabi"); |
| 448 | |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 449 | std::string CPUString = Subtarget->getCPUString(); |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 450 | if (OutStreamer.hasRawTextSupport()) { |
| 451 | if (CPUString != "generic") |
| 452 | OutStreamer.EmitRawText(StringRef("\t.cpu ") + CPUString); |
| 453 | } else { |
Dale Johannesen | 7179d1e | 2010-11-08 19:17:22 +0000 | [diff] [blame] | 454 | assert(CPUString == "generic" && "Unsupported .cpu attribute for ELF/.o"); |
| 455 | // FIXME: Why these defaults? |
| 456 | AttrEmitter->EmitAttribute(ARMBuildAttrs::CPU_arch, ARMBuildAttrs::v4T); |
| 457 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ARM_ISA_use, 1); |
| 458 | AttrEmitter->EmitAttribute(ARMBuildAttrs::THUMB_ISA_use, 1); |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 459 | } |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 460 | |
| 461 | // FIXME: Emit FPU type |
| 462 | if (Subtarget->hasVFP2()) |
Dale Johannesen | 7179d1e | 2010-11-08 19:17:22 +0000 | [diff] [blame] | 463 | AttrEmitter->EmitAttribute(ARMBuildAttrs::VFP_arch, 2); |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 464 | |
| 465 | // Signal various FP modes. |
| 466 | if (!UnsafeFPMath) { |
Dale Johannesen | 7179d1e | 2010-11-08 19:17:22 +0000 | [diff] [blame] | 467 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ABI_FP_denormal, 1); |
| 468 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ABI_FP_exceptions, 1); |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | if (NoInfsFPMath && NoNaNsFPMath) |
Dale Johannesen | 7179d1e | 2010-11-08 19:17:22 +0000 | [diff] [blame] | 472 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ABI_FP_number_model, 1); |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 473 | else |
Dale Johannesen | 7179d1e | 2010-11-08 19:17:22 +0000 | [diff] [blame] | 474 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ABI_FP_number_model, 3); |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 475 | |
| 476 | // 8-bytes alignment stuff. |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 477 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ABI_align8_needed, 1); |
| 478 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ABI_align8_preserved, 1); |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 479 | |
| 480 | // Hard float. Use both S and D registers and conform to AAPCS-VFP. |
| 481 | if (Subtarget->isAAPCS_ABI() && FloatABIType == FloatABI::Hard) { |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 482 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ABI_HardFP_use, 3); |
| 483 | AttrEmitter->EmitAttribute(ARMBuildAttrs::ABI_VFP_args, 1); |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 484 | } |
| 485 | // FIXME: Should we signal R9 usage? |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 486 | |
| 487 | AttrEmitter->EmitAttribute(ARMBuildAttrs::DIV_use, 1); |
| 488 | |
| 489 | AttrEmitter->Finish(); |
| 490 | delete AttrEmitter; |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Jason W Kim | 17b443d | 2010-10-11 23:01:44 +0000 | [diff] [blame] | 493 | void ARMAsmPrinter::emitARMAttributeSection() { |
| 494 | // <format-version> |
| 495 | // [ <section-length> "vendor-name" |
| 496 | // [ <file-tag> <size> <attribute>* |
| 497 | // | <section-tag> <size> <section-number>* 0 <attribute>* |
| 498 | // | <symbol-tag> <size> <symbol-number>* 0 <attribute>* |
| 499 | // ]+ |
| 500 | // ]* |
| 501 | |
| 502 | if (OutStreamer.hasRawTextSupport()) |
| 503 | return; |
| 504 | |
| 505 | const ARMElfTargetObjectFile &TLOFELF = |
| 506 | static_cast<const ARMElfTargetObjectFile &> |
| 507 | (getObjFileLowering()); |
| 508 | |
| 509 | OutStreamer.SwitchSection(TLOFELF.getAttributesSection()); |
Jason W Kim | 17b443d | 2010-10-11 23:01:44 +0000 | [diff] [blame] | 510 | |
Rafael Espindola | cecbc3d | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 511 | // Format version |
| 512 | OutStreamer.EmitIntValue(0x41, 1); |
Jason W Kim | 17b443d | 2010-10-11 23:01:44 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Jason W Kim | def9ac4 | 2010-10-06 22:36:46 +0000 | [diff] [blame] | 515 | //===----------------------------------------------------------------------===// |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 516 | |
Jim Grosbach | 988ce09 | 2010-09-18 00:05:05 +0000 | [diff] [blame] | 517 | static MCSymbol *getPICLabel(const char *Prefix, unsigned FunctionNumber, |
| 518 | unsigned LabelId, MCContext &Ctx) { |
| 519 | |
| 520 | MCSymbol *Label = Ctx.GetOrCreateSymbol(Twine(Prefix) |
| 521 | + "PC" + Twine(FunctionNumber) + "_" + Twine(LabelId)); |
| 522 | return Label; |
| 523 | } |
| 524 | |
Jim Grosbach | 2c4d512 | 2010-11-10 03:26:07 +0000 | [diff] [blame] | 525 | static MCSymbolRefExpr::VariantKind |
| 526 | getModifierVariantKind(ARMCP::ARMCPModifier Modifier) { |
| 527 | switch (Modifier) { |
| 528 | default: llvm_unreachable("Unknown modifier!"); |
| 529 | case ARMCP::no_modifier: return MCSymbolRefExpr::VK_None; |
| 530 | case ARMCP::TLSGD: return MCSymbolRefExpr::VK_ARM_TLSGD; |
| 531 | case ARMCP::TPOFF: return MCSymbolRefExpr::VK_ARM_TPOFF; |
| 532 | case ARMCP::GOTTPOFF: return MCSymbolRefExpr::VK_ARM_GOTTPOFF; |
| 533 | case ARMCP::GOT: return MCSymbolRefExpr::VK_ARM_GOT; |
| 534 | case ARMCP::GOTOFF: return MCSymbolRefExpr::VK_ARM_GOTOFF; |
| 535 | } |
| 536 | return MCSymbolRefExpr::VK_None; |
| 537 | } |
| 538 | |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 539 | void ARMAsmPrinter:: |
| 540 | EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) { |
| 541 | int Size = TM.getTargetData()->getTypeAllocSize(MCPV->getType()); |
| 542 | |
| 543 | ARMConstantPoolValue *ACPV = static_cast<ARMConstantPoolValue*>(MCPV); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 544 | |
Jim Grosbach | 7c7ddb2 | 2010-11-10 17:59:10 +0000 | [diff] [blame] | 545 | MCSymbol *MCSym; |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 546 | if (ACPV->isLSDA()) { |
Jim Grosbach | 7c7ddb2 | 2010-11-10 17:59:10 +0000 | [diff] [blame] | 547 | SmallString<128> Str; |
| 548 | raw_svector_ostream OS(Str); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 549 | OS << MAI->getPrivateGlobalPrefix() << "_LSDA_" << getFunctionNumber(); |
Jim Grosbach | 7c7ddb2 | 2010-11-10 17:59:10 +0000 | [diff] [blame] | 550 | MCSym = OutContext.GetOrCreateSymbol(OS.str()); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 551 | } else if (ACPV->isBlockAddress()) { |
Jim Grosbach | 7c7ddb2 | 2010-11-10 17:59:10 +0000 | [diff] [blame] | 552 | MCSym = GetBlockAddressSymbol(ACPV->getBlockAddress()); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 553 | } else if (ACPV->isGlobalValue()) { |
| 554 | const GlobalValue *GV = ACPV->getGV(); |
| 555 | bool isIndirect = Subtarget->isTargetDarwin() && |
| 556 | Subtarget->GVIsIndirectSymbol(GV, TM.getRelocationModel()); |
| 557 | if (!isIndirect) |
Jim Grosbach | 7c7ddb2 | 2010-11-10 17:59:10 +0000 | [diff] [blame] | 558 | MCSym = Mang->getSymbol(GV); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 559 | else { |
| 560 | // FIXME: Remove this when Darwin transition to @GOT like syntax. |
Jim Grosbach | 7c7ddb2 | 2010-11-10 17:59:10 +0000 | [diff] [blame] | 561 | MCSym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr"); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 562 | |
| 563 | MachineModuleInfoMachO &MMIMachO = |
| 564 | MMI->getObjFileInfo<MachineModuleInfoMachO>(); |
| 565 | MachineModuleInfoImpl::StubValueTy &StubSym = |
Jim Grosbach | 7c7ddb2 | 2010-11-10 17:59:10 +0000 | [diff] [blame] | 566 | GV->hasHiddenVisibility() ? MMIMachO.getHiddenGVStubEntry(MCSym) : |
| 567 | MMIMachO.getGVStubEntry(MCSym); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 568 | if (StubSym.getPointer() == 0) |
| 569 | StubSym = MachineModuleInfoImpl:: |
| 570 | StubValueTy(Mang->getSymbol(GV), !GV->hasInternalLinkage()); |
| 571 | } |
| 572 | } else { |
| 573 | assert(ACPV->isExtSymbol() && "unrecognized constant pool value"); |
Jim Grosbach | 7c7ddb2 | 2010-11-10 17:59:10 +0000 | [diff] [blame] | 574 | MCSym = GetExternalSymbolSymbol(ACPV->getSymbol()); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | // Create an MCSymbol for the reference. |
Jim Grosbach | 2c4d512 | 2010-11-10 03:26:07 +0000 | [diff] [blame] | 578 | const MCExpr *Expr = |
| 579 | MCSymbolRefExpr::Create(MCSym, getModifierVariantKind(ACPV->getModifier()), |
| 580 | OutContext); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 581 | |
Jim Grosbach | 2c4d512 | 2010-11-10 03:26:07 +0000 | [diff] [blame] | 582 | if (ACPV->getPCAdjustment()) { |
| 583 | MCSymbol *PCLabel = getPICLabel(MAI->getPrivateGlobalPrefix(), |
| 584 | getFunctionNumber(), |
| 585 | ACPV->getLabelId(), |
| 586 | OutContext); |
| 587 | const MCExpr *PCRelExpr = MCSymbolRefExpr::Create(PCLabel, OutContext); |
| 588 | PCRelExpr = |
| 589 | MCBinaryExpr::CreateAdd(PCRelExpr, |
| 590 | MCConstantExpr::Create(ACPV->getPCAdjustment(), |
| 591 | OutContext), |
| 592 | OutContext); |
| 593 | if (ACPV->mustAddCurrentAddress()) { |
| 594 | // We want "(<expr> - .)", but MC doesn't have a concept of the '.' |
| 595 | // label, so just emit a local label end reference that instead. |
| 596 | MCSymbol *DotSym = OutContext.CreateTempSymbol(); |
| 597 | OutStreamer.EmitLabel(DotSym); |
| 598 | const MCExpr *DotExpr = MCSymbolRefExpr::Create(DotSym, OutContext); |
| 599 | PCRelExpr = MCBinaryExpr::CreateSub(PCRelExpr, DotExpr, OutContext); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 600 | } |
Jim Grosbach | 2c4d512 | 2010-11-10 03:26:07 +0000 | [diff] [blame] | 601 | Expr = MCBinaryExpr::CreateSub(Expr, PCRelExpr, OutContext); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 602 | } |
Jim Grosbach | 2c4d512 | 2010-11-10 03:26:07 +0000 | [diff] [blame] | 603 | OutStreamer.EmitValue(Expr, Size); |
Jim Grosbach | 5df08d8 | 2010-11-09 18:45:04 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Jim Grosbach | a2244cb | 2010-09-22 17:39:48 +0000 | [diff] [blame] | 606 | void ARMAsmPrinter::EmitJumpTable(const MachineInstr *MI) { |
| 607 | unsigned Opcode = MI->getOpcode(); |
| 608 | int OpNum = 1; |
| 609 | if (Opcode == ARM::BR_JTadd) |
| 610 | OpNum = 2; |
| 611 | else if (Opcode == ARM::BR_JTm) |
| 612 | OpNum = 3; |
| 613 | |
| 614 | const MachineOperand &MO1 = MI->getOperand(OpNum); |
| 615 | const MachineOperand &MO2 = MI->getOperand(OpNum+1); // Unique Id |
| 616 | unsigned JTI = MO1.getIndex(); |
| 617 | |
| 618 | // Emit a label for the jump table. |
| 619 | MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel2(JTI, MO2.getImm()); |
| 620 | OutStreamer.EmitLabel(JTISymbol); |
| 621 | |
| 622 | // Emit each entry of the table. |
| 623 | const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo(); |
| 624 | const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables(); |
| 625 | const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs; |
| 626 | |
| 627 | for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) { |
| 628 | MachineBasicBlock *MBB = JTBBs[i]; |
| 629 | // Construct an MCExpr for the entry. We want a value of the form: |
| 630 | // (BasicBlockAddr - TableBeginAddr) |
| 631 | // |
| 632 | // For example, a table with entries jumping to basic blocks BB0 and BB1 |
| 633 | // would look like: |
| 634 | // LJTI_0_0: |
| 635 | // .word (LBB0 - LJTI_0_0) |
| 636 | // .word (LBB1 - LJTI_0_0) |
| 637 | const MCExpr *Expr = MCSymbolRefExpr::Create(MBB->getSymbol(), OutContext); |
| 638 | |
| 639 | if (TM.getRelocationModel() == Reloc::PIC_) |
| 640 | Expr = MCBinaryExpr::CreateSub(Expr, MCSymbolRefExpr::Create(JTISymbol, |
| 641 | OutContext), |
| 642 | OutContext); |
| 643 | OutStreamer.EmitValue(Expr, 4); |
| 644 | } |
| 645 | } |
| 646 | |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 647 | void ARMAsmPrinter::EmitJump2Table(const MachineInstr *MI) { |
| 648 | unsigned Opcode = MI->getOpcode(); |
| 649 | int OpNum = (Opcode == ARM::t2BR_JT) ? 2 : 1; |
| 650 | const MachineOperand &MO1 = MI->getOperand(OpNum); |
| 651 | const MachineOperand &MO2 = MI->getOperand(OpNum+1); // Unique Id |
| 652 | unsigned JTI = MO1.getIndex(); |
| 653 | |
| 654 | // Emit a label for the jump table. |
| 655 | MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel2(JTI, MO2.getImm()); |
| 656 | OutStreamer.EmitLabel(JTISymbol); |
| 657 | |
| 658 | // Emit each entry of the table. |
| 659 | const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo(); |
| 660 | const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables(); |
| 661 | const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs; |
Jim Grosbach | 205a5fa | 2010-09-22 17:15:35 +0000 | [diff] [blame] | 662 | unsigned OffsetWidth = 4; |
Jim Grosbach | d092a87 | 2010-11-29 21:28:32 +0000 | [diff] [blame] | 663 | if (MI->getOpcode() == ARM::t2TBB_JT) |
Jim Grosbach | 205a5fa | 2010-09-22 17:15:35 +0000 | [diff] [blame] | 664 | OffsetWidth = 1; |
Jim Grosbach | d092a87 | 2010-11-29 21:28:32 +0000 | [diff] [blame] | 665 | else if (MI->getOpcode() == ARM::t2TBH_JT) |
Jim Grosbach | 205a5fa | 2010-09-22 17:15:35 +0000 | [diff] [blame] | 666 | OffsetWidth = 2; |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 667 | |
| 668 | for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) { |
| 669 | MachineBasicBlock *MBB = JTBBs[i]; |
Jim Grosbach | 205a5fa | 2010-09-22 17:15:35 +0000 | [diff] [blame] | 670 | const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::Create(MBB->getSymbol(), |
| 671 | OutContext); |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 672 | // 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] | 673 | if (OffsetWidth == 4) { |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 674 | MCInst BrInst; |
| 675 | BrInst.setOpcode(ARM::t2B); |
Jim Grosbach | 205a5fa | 2010-09-22 17:15:35 +0000 | [diff] [blame] | 676 | BrInst.addOperand(MCOperand::CreateExpr(MBBSymbolExpr)); |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 677 | OutStreamer.EmitInstruction(BrInst); |
| 678 | continue; |
| 679 | } |
| 680 | // Otherwise it's an offset from the dispatch instruction. Construct an |
Jim Grosbach | 205a5fa | 2010-09-22 17:15:35 +0000 | [diff] [blame] | 681 | // MCExpr for the entry. We want a value of the form: |
| 682 | // (BasicBlockAddr - TableBeginAddr) / 2 |
| 683 | // |
| 684 | // For example, a TBB table with entries jumping to basic blocks BB0 and BB1 |
| 685 | // would look like: |
| 686 | // LJTI_0_0: |
| 687 | // .byte (LBB0 - LJTI_0_0) / 2 |
| 688 | // .byte (LBB1 - LJTI_0_0) / 2 |
| 689 | const MCExpr *Expr = |
| 690 | MCBinaryExpr::CreateSub(MBBSymbolExpr, |
| 691 | MCSymbolRefExpr::Create(JTISymbol, OutContext), |
| 692 | OutContext); |
| 693 | Expr = MCBinaryExpr::CreateDiv(Expr, MCConstantExpr::Create(2, OutContext), |
| 694 | OutContext); |
| 695 | OutStreamer.EmitValue(Expr, OffsetWidth); |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | |
Jim Grosbach | 2d0f53b | 2010-09-28 17:05:56 +0000 | [diff] [blame] | 699 | void ARMAsmPrinter::PrintDebugValueComment(const MachineInstr *MI, |
| 700 | raw_ostream &OS) { |
| 701 | unsigned NOps = MI->getNumOperands(); |
| 702 | assert(NOps==4); |
| 703 | OS << '\t' << MAI->getCommentString() << "DEBUG_VALUE: "; |
| 704 | // cast away const; DIetc do not take const operands for some reason. |
| 705 | DIVariable V(const_cast<MDNode *>(MI->getOperand(NOps-1).getMetadata())); |
| 706 | OS << V.getName(); |
| 707 | OS << " <- "; |
| 708 | // Frame address. Currently handles register +- offset only. |
| 709 | assert(MI->getOperand(0).isReg() && MI->getOperand(1).isImm()); |
| 710 | OS << '['; printOperand(MI, 0, OS); OS << '+'; printOperand(MI, 1, OS); |
| 711 | OS << ']'; |
| 712 | OS << "+"; |
| 713 | printOperand(MI, NOps-2, OS); |
| 714 | } |
| 715 | |
Jim Grosbach | 40edf73 | 2010-12-14 21:10:47 +0000 | [diff] [blame] | 716 | static void populateADROperands(MCInst &Inst, unsigned Dest, |
| 717 | const MCSymbol *Label, |
| 718 | unsigned pred, unsigned ccreg, |
| 719 | MCContext &Ctx) { |
| 720 | const MCExpr *SymbolExpr = MCSymbolRefExpr::Create(Label, Ctx); |
| 721 | Inst.addOperand(MCOperand::CreateReg(Dest)); |
| 722 | Inst.addOperand(MCOperand::CreateExpr(SymbolExpr)); |
| 723 | // Add predicate operands. |
| 724 | Inst.addOperand(MCOperand::CreateImm(pred)); |
| 725 | Inst.addOperand(MCOperand::CreateReg(ccreg)); |
| 726 | } |
| 727 | |
Jim Grosbach | b454cda | 2010-09-29 15:23:40 +0000 | [diff] [blame] | 728 | void ARMAsmPrinter::EmitInstruction(const MachineInstr *MI) { |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 729 | switch (MI->getOpcode()) { |
Chris Lattner | 4d15222 | 2009-10-19 22:23:04 +0000 | [diff] [blame] | 730 | default: break; |
Jim Grosbach | 9702e60 | 2010-12-09 01:22:19 +0000 | [diff] [blame] | 731 | case ARM::t2ADDrSPi: |
| 732 | case ARM::t2ADDrSPi12: |
| 733 | case ARM::t2SUBrSPi: |
| 734 | case ARM::t2SUBrSPi12: |
Jim Grosbach | 766a63d | 2010-12-09 01:23:51 +0000 | [diff] [blame] | 735 | assert ((MI->getOperand(1).getReg() == ARM::SP) && |
| 736 | "Unexpected source register!"); |
Jim Grosbach | 9702e60 | 2010-12-09 01:22:19 +0000 | [diff] [blame] | 737 | break; |
| 738 | |
Chris Lattner | 112f239 | 2010-11-14 20:31:06 +0000 | [diff] [blame] | 739 | case ARM::t2MOVi32imm: assert(0 && "Should be lowered by thumb2it pass"); |
Jim Grosbach | 2d0f53b | 2010-09-28 17:05:56 +0000 | [diff] [blame] | 740 | case ARM::DBG_VALUE: { |
| 741 | if (isVerbose() && OutStreamer.hasRawTextSupport()) { |
| 742 | SmallString<128> TmpStr; |
| 743 | raw_svector_ostream OS(TmpStr); |
| 744 | PrintDebugValueComment(MI, OS); |
| 745 | OutStreamer.EmitRawText(StringRef(OS.str())); |
| 746 | } |
| 747 | return; |
| 748 | } |
Jim Grosbach | 3efad8f | 2010-12-16 19:11:16 +0000 | [diff] [blame] | 749 | case ARM::tBfar: { |
| 750 | MCInst TmpInst; |
| 751 | TmpInst.setOpcode(ARM::tBL); |
| 752 | TmpInst.addOperand(MCOperand::CreateExpr(MCSymbolRefExpr::Create( |
| 753 | MI->getOperand(0).getMBB()->getSymbol(), OutContext))); |
| 754 | OutStreamer.EmitInstruction(TmpInst); |
| 755 | return; |
| 756 | } |
Jim Grosbach | 40edf73 | 2010-12-14 21:10:47 +0000 | [diff] [blame] | 757 | case ARM::LEApcrel: |
Jim Grosbach | d40963c | 2010-12-14 22:28:03 +0000 | [diff] [blame] | 758 | case ARM::tLEApcrel: |
Jim Grosbach | 40edf73 | 2010-12-14 21:10:47 +0000 | [diff] [blame] | 759 | case ARM::t2LEApcrel: { |
Jim Grosbach | dff84b0 | 2010-12-02 00:28:45 +0000 | [diff] [blame] | 760 | // FIXME: Need to also handle globals and externals |
Jim Grosbach | dff84b0 | 2010-12-02 00:28:45 +0000 | [diff] [blame] | 761 | MCInst TmpInst; |
Jim Grosbach | d40963c | 2010-12-14 22:28:03 +0000 | [diff] [blame] | 762 | TmpInst.setOpcode(MI->getOpcode() == ARM::t2LEApcrel ? ARM::t2ADR |
| 763 | : (MI->getOpcode() == ARM::tLEApcrel ? ARM::tADR |
| 764 | : ARM::ADR)); |
Jim Grosbach | 40edf73 | 2010-12-14 21:10:47 +0000 | [diff] [blame] | 765 | populateADROperands(TmpInst, MI->getOperand(0).getReg(), |
| 766 | GetCPISymbol(MI->getOperand(1).getIndex()), |
| 767 | MI->getOperand(2).getImm(), MI->getOperand(3).getReg(), |
| 768 | OutContext); |
Jim Grosbach | dff84b0 | 2010-12-02 00:28:45 +0000 | [diff] [blame] | 769 | OutStreamer.EmitInstruction(TmpInst); |
| 770 | return; |
| 771 | } |
Jim Grosbach | d40963c | 2010-12-14 22:28:03 +0000 | [diff] [blame] | 772 | case ARM::LEApcrelJT: |
| 773 | case ARM::tLEApcrelJT: |
| 774 | case ARM::t2LEApcrelJT: { |
Jim Grosbach | 5d14f9b | 2010-12-01 19:47:31 +0000 | [diff] [blame] | 775 | MCInst TmpInst; |
Jim Grosbach | d40963c | 2010-12-14 22:28:03 +0000 | [diff] [blame] | 776 | TmpInst.setOpcode(MI->getOpcode() == ARM::t2LEApcrelJT ? ARM::t2ADR |
| 777 | : (MI->getOpcode() == ARM::tLEApcrelJT ? ARM::tADR |
| 778 | : ARM::ADR)); |
Jim Grosbach | 40edf73 | 2010-12-14 21:10:47 +0000 | [diff] [blame] | 779 | populateADROperands(TmpInst, MI->getOperand(0).getReg(), |
| 780 | GetARMJTIPICJumpTableLabel2(MI->getOperand(1).getIndex(), |
| 781 | MI->getOperand(2).getImm()), |
| 782 | MI->getOperand(3).getImm(), MI->getOperand(4).getReg(), |
| 783 | OutContext); |
Jim Grosbach | 5d14f9b | 2010-12-01 19:47:31 +0000 | [diff] [blame] | 784 | OutStreamer.EmitInstruction(TmpInst); |
| 785 | return; |
| 786 | } |
Jim Grosbach | 2e812e1 | 2010-11-30 18:56:36 +0000 | [diff] [blame] | 787 | case ARM::MOVPCRX: { |
| 788 | MCInst TmpInst; |
| 789 | TmpInst.setOpcode(ARM::MOVr); |
| 790 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 791 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 792 | // Add predicate operands. |
| 793 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 794 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 795 | // Add 's' bit operand (always reg0 for this) |
| 796 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 797 | OutStreamer.EmitInstruction(TmpInst); |
| 798 | return; |
| 799 | } |
Jim Grosbach | a0d2c8a | 2010-11-30 18:30:19 +0000 | [diff] [blame] | 800 | case ARM::BXr9_CALL: |
| 801 | case ARM::BX_CALL: { |
| 802 | { |
| 803 | MCInst TmpInst; |
| 804 | TmpInst.setOpcode(ARM::MOVr); |
| 805 | TmpInst.addOperand(MCOperand::CreateReg(ARM::LR)); |
| 806 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 807 | // Add predicate operands. |
| 808 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 809 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 810 | // Add 's' bit operand (always reg0 for this) |
| 811 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 812 | OutStreamer.EmitInstruction(TmpInst); |
| 813 | } |
| 814 | { |
| 815 | MCInst TmpInst; |
| 816 | TmpInst.setOpcode(ARM::BX); |
| 817 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 818 | OutStreamer.EmitInstruction(TmpInst); |
| 819 | } |
| 820 | return; |
| 821 | } |
| 822 | case ARM::BMOVPCRXr9_CALL: |
| 823 | case ARM::BMOVPCRX_CALL: { |
| 824 | { |
| 825 | MCInst TmpInst; |
| 826 | TmpInst.setOpcode(ARM::MOVr); |
| 827 | TmpInst.addOperand(MCOperand::CreateReg(ARM::LR)); |
| 828 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 829 | // Add predicate operands. |
| 830 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 831 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 832 | // Add 's' bit operand (always reg0 for this) |
| 833 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 834 | OutStreamer.EmitInstruction(TmpInst); |
| 835 | } |
| 836 | { |
| 837 | MCInst TmpInst; |
| 838 | TmpInst.setOpcode(ARM::MOVr); |
| 839 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 840 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 841 | // Add predicate operands. |
| 842 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 843 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 844 | // Add 's' bit operand (always reg0 for this) |
| 845 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 846 | OutStreamer.EmitInstruction(TmpInst); |
| 847 | } |
| 848 | return; |
| 849 | } |
Jim Grosbach | fbd1873 | 2010-09-17 23:41:53 +0000 | [diff] [blame] | 850 | case ARM::tPICADD: { |
| 851 | // This is a pseudo op for a label + instruction sequence, which looks like: |
| 852 | // LPC0: |
| 853 | // add r0, pc |
| 854 | // This adds the address of LPC0 to r0. |
| 855 | |
| 856 | // Emit the label. |
Jim Grosbach | 988ce09 | 2010-09-18 00:05:05 +0000 | [diff] [blame] | 857 | OutStreamer.EmitLabel(getPICLabel(MAI->getPrivateGlobalPrefix(), |
| 858 | getFunctionNumber(), MI->getOperand(2).getImm(), |
| 859 | OutContext)); |
Jim Grosbach | fbd1873 | 2010-09-17 23:41:53 +0000 | [diff] [blame] | 860 | |
| 861 | // Form and emit the add. |
| 862 | MCInst AddInst; |
| 863 | AddInst.setOpcode(ARM::tADDhirr); |
| 864 | AddInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 865 | AddInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 866 | AddInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 867 | // Add predicate operands. |
| 868 | AddInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 869 | AddInst.addOperand(MCOperand::CreateReg(0)); |
| 870 | OutStreamer.EmitInstruction(AddInst); |
| 871 | return; |
| 872 | } |
Jim Grosbach | a3fbadf | 2010-09-30 19:53:58 +0000 | [diff] [blame] | 873 | case ARM::PICADD: { |
Chris Lattner | 4d15222 | 2009-10-19 22:23:04 +0000 | [diff] [blame] | 874 | // This is a pseudo op for a label + instruction sequence, which looks like: |
| 875 | // LPC0: |
| 876 | // add r0, pc, r0 |
| 877 | // This adds the address of LPC0 to r0. |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 878 | |
Chris Lattner | 4d15222 | 2009-10-19 22:23:04 +0000 | [diff] [blame] | 879 | // Emit the label. |
Jim Grosbach | 988ce09 | 2010-09-18 00:05:05 +0000 | [diff] [blame] | 880 | OutStreamer.EmitLabel(getPICLabel(MAI->getPrivateGlobalPrefix(), |
| 881 | getFunctionNumber(), MI->getOperand(2).getImm(), |
| 882 | OutContext)); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 883 | |
Jim Grosbach | f3f0952 | 2010-09-14 21:05:34 +0000 | [diff] [blame] | 884 | // Form and emit the add. |
Chris Lattner | 4d15222 | 2009-10-19 22:23:04 +0000 | [diff] [blame] | 885 | MCInst AddInst; |
| 886 | AddInst.setOpcode(ARM::ADDrr); |
| 887 | AddInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 888 | AddInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 889 | AddInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg())); |
Jim Grosbach | 5b46d62 | 2010-09-14 21:28:17 +0000 | [diff] [blame] | 890 | // Add predicate operands. |
| 891 | AddInst.addOperand(MCOperand::CreateImm(MI->getOperand(3).getImm())); |
| 892 | AddInst.addOperand(MCOperand::CreateReg(MI->getOperand(4).getReg())); |
| 893 | // Add 's' bit operand (always reg0 for this) |
| 894 | AddInst.addOperand(MCOperand::CreateReg(0)); |
Chris Lattner | 850d2e2 | 2010-02-03 01:16:28 +0000 | [diff] [blame] | 895 | OutStreamer.EmitInstruction(AddInst); |
Chris Lattner | 4d15222 | 2009-10-19 22:23:04 +0000 | [diff] [blame] | 896 | return; |
| 897 | } |
Jim Grosbach | a28abbe | 2010-09-17 16:25:52 +0000 | [diff] [blame] | 898 | case ARM::PICSTR: |
| 899 | case ARM::PICSTRB: |
| 900 | case ARM::PICSTRH: |
| 901 | case ARM::PICLDR: |
| 902 | case ARM::PICLDRB: |
| 903 | case ARM::PICLDRH: |
| 904 | case ARM::PICLDRSB: |
| 905 | case ARM::PICLDRSH: { |
Jim Grosbach | b74ca9d | 2010-09-16 17:43:25 +0000 | [diff] [blame] | 906 | // This is a pseudo op for a label + instruction sequence, which looks like: |
| 907 | // LPC0: |
Jim Grosbach | a28abbe | 2010-09-17 16:25:52 +0000 | [diff] [blame] | 908 | // OP r0, [pc, r0] |
Jim Grosbach | b74ca9d | 2010-09-16 17:43:25 +0000 | [diff] [blame] | 909 | // The LCP0 label is referenced by a constant pool entry in order to get |
| 910 | // a PC-relative address at the ldr instruction. |
| 911 | |
| 912 | // Emit the label. |
Jim Grosbach | 988ce09 | 2010-09-18 00:05:05 +0000 | [diff] [blame] | 913 | OutStreamer.EmitLabel(getPICLabel(MAI->getPrivateGlobalPrefix(), |
| 914 | getFunctionNumber(), MI->getOperand(2).getImm(), |
| 915 | OutContext)); |
Jim Grosbach | b74ca9d | 2010-09-16 17:43:25 +0000 | [diff] [blame] | 916 | |
| 917 | // Form and emit the load |
Jim Grosbach | a28abbe | 2010-09-17 16:25:52 +0000 | [diff] [blame] | 918 | unsigned Opcode; |
| 919 | switch (MI->getOpcode()) { |
| 920 | default: |
| 921 | llvm_unreachable("Unexpected opcode!"); |
Jim Grosbach | 7e3383c | 2010-10-27 23:12:14 +0000 | [diff] [blame] | 922 | case ARM::PICSTR: Opcode = ARM::STRrs; break; |
| 923 | case ARM::PICSTRB: Opcode = ARM::STRBrs; break; |
Jim Grosbach | a28abbe | 2010-09-17 16:25:52 +0000 | [diff] [blame] | 924 | case ARM::PICSTRH: Opcode = ARM::STRH; break; |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 925 | case ARM::PICLDR: Opcode = ARM::LDRrs; break; |
Jim Grosbach | c1d3021 | 2010-10-27 00:19:44 +0000 | [diff] [blame] | 926 | case ARM::PICLDRB: Opcode = ARM::LDRBrs; break; |
Jim Grosbach | a28abbe | 2010-09-17 16:25:52 +0000 | [diff] [blame] | 927 | case ARM::PICLDRH: Opcode = ARM::LDRH; break; |
| 928 | case ARM::PICLDRSB: Opcode = ARM::LDRSB; break; |
| 929 | case ARM::PICLDRSH: Opcode = ARM::LDRSH; break; |
| 930 | } |
| 931 | MCInst LdStInst; |
| 932 | LdStInst.setOpcode(Opcode); |
| 933 | LdStInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 934 | LdStInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 935 | LdStInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg())); |
| 936 | LdStInst.addOperand(MCOperand::CreateImm(0)); |
Jim Grosbach | b74ca9d | 2010-09-16 17:43:25 +0000 | [diff] [blame] | 937 | // Add predicate operands. |
Jim Grosbach | a28abbe | 2010-09-17 16:25:52 +0000 | [diff] [blame] | 938 | LdStInst.addOperand(MCOperand::CreateImm(MI->getOperand(3).getImm())); |
| 939 | LdStInst.addOperand(MCOperand::CreateReg(MI->getOperand(4).getReg())); |
| 940 | OutStreamer.EmitInstruction(LdStInst); |
Jim Grosbach | b74ca9d | 2010-09-16 17:43:25 +0000 | [diff] [blame] | 941 | |
| 942 | return; |
| 943 | } |
Jim Grosbach | a3fbadf | 2010-09-30 19:53:58 +0000 | [diff] [blame] | 944 | case ARM::CONSTPOOL_ENTRY: { |
Chris Lattner | a70e644 | 2009-10-19 22:33:05 +0000 | [diff] [blame] | 945 | /// CONSTPOOL_ENTRY - This instruction represents a floating constant pool |
| 946 | /// in the function. The first operand is the ID# for this instruction, the |
| 947 | /// second is the index into the MachineConstantPool that this is, the third |
| 948 | /// is the size in bytes of this constant pool entry. |
| 949 | unsigned LabelId = (unsigned)MI->getOperand(0).getImm(); |
| 950 | unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex(); |
| 951 | |
| 952 | EmitAlignment(2); |
Chris Lattner | 1b46f43 | 2010-01-23 07:00:21 +0000 | [diff] [blame] | 953 | OutStreamer.EmitLabel(GetCPISymbol(LabelId)); |
Chris Lattner | a70e644 | 2009-10-19 22:33:05 +0000 | [diff] [blame] | 954 | |
| 955 | const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx]; |
| 956 | if (MCPE.isMachineConstantPoolEntry()) |
| 957 | EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal); |
| 958 | else |
| 959 | EmitGlobalConstant(MCPE.Val.ConstVal); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 960 | |
Chris Lattner | a70e644 | 2009-10-19 22:33:05 +0000 | [diff] [blame] | 961 | return; |
| 962 | } |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 963 | case ARM::t2BR_JT: { |
| 964 | // Lower and emit the instruction itself, then the jump table following it. |
| 965 | MCInst TmpInst; |
Jim Grosbach | 5ca6669 | 2010-11-29 22:37:40 +0000 | [diff] [blame] | 966 | TmpInst.setOpcode(ARM::tMOVgpr2gpr); |
| 967 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 968 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 969 | // Add predicate operands. |
| 970 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 971 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 972 | OutStreamer.EmitInstruction(TmpInst); |
Jim Grosbach | 5ca6669 | 2010-11-29 22:37:40 +0000 | [diff] [blame] | 973 | // Output the data for the jump table itself |
| 974 | EmitJump2Table(MI); |
| 975 | return; |
| 976 | } |
| 977 | case ARM::t2TBB_JT: { |
| 978 | // Lower and emit the instruction itself, then the jump table following it. |
| 979 | MCInst TmpInst; |
| 980 | |
| 981 | TmpInst.setOpcode(ARM::t2TBB); |
| 982 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 983 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 984 | // Add predicate operands. |
| 985 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 986 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 987 | OutStreamer.EmitInstruction(TmpInst); |
| 988 | // Output the data for the jump table itself |
| 989 | EmitJump2Table(MI); |
| 990 | // Make sure the next instruction is 2-byte aligned. |
| 991 | EmitAlignment(1); |
| 992 | return; |
| 993 | } |
| 994 | case ARM::t2TBH_JT: { |
| 995 | // Lower and emit the instruction itself, then the jump table following it. |
| 996 | MCInst TmpInst; |
| 997 | |
| 998 | TmpInst.setOpcode(ARM::t2TBH); |
| 999 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1000 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1001 | // Add predicate operands. |
| 1002 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1003 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1004 | OutStreamer.EmitInstruction(TmpInst); |
| 1005 | // Output the data for the jump table itself |
Jim Grosbach | 882ef2b | 2010-09-21 23:28:16 +0000 | [diff] [blame] | 1006 | EmitJump2Table(MI); |
| 1007 | return; |
| 1008 | } |
Jim Grosbach | f1aa47d | 2010-11-29 19:32:47 +0000 | [diff] [blame] | 1009 | case ARM::tBR_JTr: |
Jim Grosbach | 2dc7768 | 2010-11-29 18:37:44 +0000 | [diff] [blame] | 1010 | case ARM::BR_JTr: { |
| 1011 | // Lower and emit the instruction itself, then the jump table following it. |
| 1012 | // mov pc, target |
| 1013 | MCInst TmpInst; |
Jim Grosbach | 5ca6669 | 2010-11-29 22:37:40 +0000 | [diff] [blame] | 1014 | unsigned Opc = MI->getOpcode() == ARM::BR_JTr ? |
| 1015 | ARM::MOVr : ARM::tMOVgpr2gpr; |
Jim Grosbach | f1aa47d | 2010-11-29 19:32:47 +0000 | [diff] [blame] | 1016 | TmpInst.setOpcode(Opc); |
Jim Grosbach | 2dc7768 | 2010-11-29 18:37:44 +0000 | [diff] [blame] | 1017 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1018 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1019 | // Add predicate operands. |
| 1020 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1021 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
Jim Grosbach | a0d2c8a | 2010-11-30 18:30:19 +0000 | [diff] [blame] | 1022 | // Add 's' bit operand (always reg0 for this) |
| 1023 | if (Opc == ARM::MOVr) |
| 1024 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
Jim Grosbach | 2dc7768 | 2010-11-29 18:37:44 +0000 | [diff] [blame] | 1025 | OutStreamer.EmitInstruction(TmpInst); |
| 1026 | |
Jim Grosbach | f1aa47d | 2010-11-29 19:32:47 +0000 | [diff] [blame] | 1027 | // Make sure the Thumb jump table is 4-byte aligned. |
| 1028 | if (Opc == ARM::tMOVr) |
| 1029 | EmitAlignment(2); |
| 1030 | |
Jim Grosbach | 2dc7768 | 2010-11-29 18:37:44 +0000 | [diff] [blame] | 1031 | // Output the data for the jump table itself |
| 1032 | EmitJumpTable(MI); |
| 1033 | return; |
| 1034 | } |
| 1035 | case ARM::BR_JTm: { |
| 1036 | // Lower and emit the instruction itself, then the jump table following it. |
| 1037 | // ldr pc, target |
| 1038 | MCInst TmpInst; |
| 1039 | if (MI->getOperand(1).getReg() == 0) { |
| 1040 | // literal offset |
| 1041 | TmpInst.setOpcode(ARM::LDRi12); |
| 1042 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1043 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1044 | TmpInst.addOperand(MCOperand::CreateImm(MI->getOperand(2).getImm())); |
| 1045 | } else { |
| 1046 | TmpInst.setOpcode(ARM::LDRrs); |
| 1047 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1048 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1049 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg())); |
| 1050 | TmpInst.addOperand(MCOperand::CreateImm(0)); |
| 1051 | } |
| 1052 | // Add predicate operands. |
| 1053 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1054 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1055 | OutStreamer.EmitInstruction(TmpInst); |
| 1056 | |
| 1057 | // Output the data for the jump table itself |
Jim Grosbach | a2244cb | 2010-09-22 17:39:48 +0000 | [diff] [blame] | 1058 | EmitJumpTable(MI); |
| 1059 | return; |
| 1060 | } |
Jim Grosbach | f8dabac | 2010-11-17 21:05:55 +0000 | [diff] [blame] | 1061 | case ARM::BR_JTadd: { |
| 1062 | // Lower and emit the instruction itself, then the jump table following it. |
| 1063 | // add pc, target, idx |
Jim Grosbach | 2dc7768 | 2010-11-29 18:37:44 +0000 | [diff] [blame] | 1064 | MCInst TmpInst; |
| 1065 | TmpInst.setOpcode(ARM::ADDrr); |
| 1066 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1067 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1068 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg())); |
Jim Grosbach | f8dabac | 2010-11-17 21:05:55 +0000 | [diff] [blame] | 1069 | // Add predicate operands. |
Jim Grosbach | 2dc7768 | 2010-11-29 18:37:44 +0000 | [diff] [blame] | 1070 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1071 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
Jim Grosbach | f8dabac | 2010-11-17 21:05:55 +0000 | [diff] [blame] | 1072 | // Add 's' bit operand (always reg0 for this) |
Jim Grosbach | 2dc7768 | 2010-11-29 18:37:44 +0000 | [diff] [blame] | 1073 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1074 | OutStreamer.EmitInstruction(TmpInst); |
Jim Grosbach | f8dabac | 2010-11-17 21:05:55 +0000 | [diff] [blame] | 1075 | |
| 1076 | // Output the data for the jump table itself |
| 1077 | EmitJumpTable(MI); |
| 1078 | return; |
| 1079 | } |
Jim Grosbach | 2e6ae13 | 2010-09-23 18:05:37 +0000 | [diff] [blame] | 1080 | case ARM::TRAP: { |
| 1081 | // Non-Darwin binutils don't yet support the "trap" mnemonic. |
| 1082 | // FIXME: Remove this special case when they do. |
| 1083 | if (!Subtarget->isTargetDarwin()) { |
Jim Grosbach | 78890f4 | 2010-10-01 23:21:38 +0000 | [diff] [blame] | 1084 | //.long 0xe7ffdefe @ trap |
Jim Grosbach | b2dda4b | 2010-09-23 19:42:17 +0000 | [diff] [blame] | 1085 | uint32_t Val = 0xe7ffdefeUL; |
Jim Grosbach | 2e6ae13 | 2010-09-23 18:05:37 +0000 | [diff] [blame] | 1086 | OutStreamer.AddComment("trap"); |
| 1087 | OutStreamer.EmitIntValue(Val, 4); |
| 1088 | return; |
| 1089 | } |
| 1090 | break; |
| 1091 | } |
| 1092 | case ARM::tTRAP: { |
| 1093 | // Non-Darwin binutils don't yet support the "trap" mnemonic. |
| 1094 | // FIXME: Remove this special case when they do. |
| 1095 | if (!Subtarget->isTargetDarwin()) { |
Jim Grosbach | 78890f4 | 2010-10-01 23:21:38 +0000 | [diff] [blame] | 1096 | //.short 57086 @ trap |
Benjamin Kramer | c8ab9eb | 2010-09-23 18:57:26 +0000 | [diff] [blame] | 1097 | uint16_t Val = 0xdefe; |
Jim Grosbach | 2e6ae13 | 2010-09-23 18:05:37 +0000 | [diff] [blame] | 1098 | OutStreamer.AddComment("trap"); |
| 1099 | OutStreamer.EmitIntValue(Val, 2); |
| 1100 | return; |
| 1101 | } |
| 1102 | break; |
| 1103 | } |
Jim Grosbach | 433a578 | 2010-09-24 20:47:58 +0000 | [diff] [blame] | 1104 | case ARM::t2Int_eh_sjlj_setjmp: |
| 1105 | case ARM::t2Int_eh_sjlj_setjmp_nofp: |
Jim Grosbach | a3fbadf | 2010-09-30 19:53:58 +0000 | [diff] [blame] | 1106 | case ARM::tInt_eh_sjlj_setjmp: { |
Jim Grosbach | 433a578 | 2010-09-24 20:47:58 +0000 | [diff] [blame] | 1107 | // Two incoming args: GPR:$src, GPR:$val |
| 1108 | // mov $val, pc |
| 1109 | // adds $val, #7 |
| 1110 | // str $val, [$src, #4] |
| 1111 | // movs r0, #0 |
| 1112 | // b 1f |
| 1113 | // movs r0, #1 |
| 1114 | // 1: |
| 1115 | unsigned SrcReg = MI->getOperand(0).getReg(); |
| 1116 | unsigned ValReg = MI->getOperand(1).getReg(); |
| 1117 | MCSymbol *Label = GetARMSJLJEHLabel(); |
| 1118 | { |
| 1119 | MCInst TmpInst; |
| 1120 | TmpInst.setOpcode(ARM::tMOVgpr2tgpr); |
| 1121 | TmpInst.addOperand(MCOperand::CreateReg(ValReg)); |
| 1122 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1123 | // 's' bit operand |
| 1124 | TmpInst.addOperand(MCOperand::CreateReg(ARM::CPSR)); |
| 1125 | OutStreamer.AddComment("eh_setjmp begin"); |
| 1126 | OutStreamer.EmitInstruction(TmpInst); |
| 1127 | } |
| 1128 | { |
| 1129 | MCInst TmpInst; |
| 1130 | TmpInst.setOpcode(ARM::tADDi3); |
| 1131 | TmpInst.addOperand(MCOperand::CreateReg(ValReg)); |
| 1132 | // 's' bit operand |
| 1133 | TmpInst.addOperand(MCOperand::CreateReg(ARM::CPSR)); |
| 1134 | TmpInst.addOperand(MCOperand::CreateReg(ValReg)); |
| 1135 | TmpInst.addOperand(MCOperand::CreateImm(7)); |
| 1136 | // Predicate. |
| 1137 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1138 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1139 | OutStreamer.EmitInstruction(TmpInst); |
| 1140 | } |
| 1141 | { |
| 1142 | MCInst TmpInst; |
Bill Wendling | f4caf69 | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 1143 | TmpInst.setOpcode(ARM::tSTRi); |
Jim Grosbach | 433a578 | 2010-09-24 20:47:58 +0000 | [diff] [blame] | 1144 | TmpInst.addOperand(MCOperand::CreateReg(ValReg)); |
| 1145 | TmpInst.addOperand(MCOperand::CreateReg(SrcReg)); |
| 1146 | // The offset immediate is #4. The operand value is scaled by 4 for the |
| 1147 | // tSTR instruction. |
| 1148 | TmpInst.addOperand(MCOperand::CreateImm(1)); |
Jim Grosbach | 433a578 | 2010-09-24 20:47:58 +0000 | [diff] [blame] | 1149 | // Predicate. |
| 1150 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1151 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1152 | OutStreamer.EmitInstruction(TmpInst); |
| 1153 | } |
| 1154 | { |
| 1155 | MCInst TmpInst; |
| 1156 | TmpInst.setOpcode(ARM::tMOVi8); |
| 1157 | TmpInst.addOperand(MCOperand::CreateReg(ARM::R0)); |
| 1158 | TmpInst.addOperand(MCOperand::CreateReg(ARM::CPSR)); |
| 1159 | TmpInst.addOperand(MCOperand::CreateImm(0)); |
| 1160 | // Predicate. |
| 1161 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1162 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1163 | OutStreamer.EmitInstruction(TmpInst); |
| 1164 | } |
| 1165 | { |
| 1166 | const MCExpr *SymbolExpr = MCSymbolRefExpr::Create(Label, OutContext); |
| 1167 | MCInst TmpInst; |
| 1168 | TmpInst.setOpcode(ARM::tB); |
| 1169 | TmpInst.addOperand(MCOperand::CreateExpr(SymbolExpr)); |
| 1170 | OutStreamer.EmitInstruction(TmpInst); |
| 1171 | } |
| 1172 | { |
| 1173 | MCInst TmpInst; |
| 1174 | TmpInst.setOpcode(ARM::tMOVi8); |
| 1175 | TmpInst.addOperand(MCOperand::CreateReg(ARM::R0)); |
| 1176 | TmpInst.addOperand(MCOperand::CreateReg(ARM::CPSR)); |
| 1177 | TmpInst.addOperand(MCOperand::CreateImm(1)); |
| 1178 | // Predicate. |
| 1179 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1180 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1181 | OutStreamer.AddComment("eh_setjmp end"); |
| 1182 | OutStreamer.EmitInstruction(TmpInst); |
| 1183 | } |
| 1184 | OutStreamer.EmitLabel(Label); |
| 1185 | return; |
| 1186 | } |
| 1187 | |
Jim Grosbach | 4539008 | 2010-09-23 23:33:56 +0000 | [diff] [blame] | 1188 | case ARM::Int_eh_sjlj_setjmp_nofp: |
Jim Grosbach | a3fbadf | 2010-09-30 19:53:58 +0000 | [diff] [blame] | 1189 | case ARM::Int_eh_sjlj_setjmp: { |
Jim Grosbach | 4539008 | 2010-09-23 23:33:56 +0000 | [diff] [blame] | 1190 | // Two incoming args: GPR:$src, GPR:$val |
| 1191 | // add $val, pc, #8 |
| 1192 | // str $val, [$src, #+4] |
| 1193 | // mov r0, #0 |
| 1194 | // add pc, pc, #0 |
| 1195 | // mov r0, #1 |
| 1196 | unsigned SrcReg = MI->getOperand(0).getReg(); |
| 1197 | unsigned ValReg = MI->getOperand(1).getReg(); |
| 1198 | |
| 1199 | { |
| 1200 | MCInst TmpInst; |
| 1201 | TmpInst.setOpcode(ARM::ADDri); |
| 1202 | TmpInst.addOperand(MCOperand::CreateReg(ValReg)); |
| 1203 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1204 | TmpInst.addOperand(MCOperand::CreateImm(8)); |
| 1205 | // Predicate. |
| 1206 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1207 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1208 | // 's' bit operand (always reg0 for this). |
| 1209 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1210 | OutStreamer.AddComment("eh_setjmp begin"); |
| 1211 | OutStreamer.EmitInstruction(TmpInst); |
| 1212 | } |
| 1213 | { |
| 1214 | MCInst TmpInst; |
Jim Grosbach | 7e3383c | 2010-10-27 23:12:14 +0000 | [diff] [blame] | 1215 | TmpInst.setOpcode(ARM::STRi12); |
Jim Grosbach | 4539008 | 2010-09-23 23:33:56 +0000 | [diff] [blame] | 1216 | TmpInst.addOperand(MCOperand::CreateReg(ValReg)); |
| 1217 | TmpInst.addOperand(MCOperand::CreateReg(SrcReg)); |
Jim Grosbach | 4539008 | 2010-09-23 23:33:56 +0000 | [diff] [blame] | 1218 | TmpInst.addOperand(MCOperand::CreateImm(4)); |
| 1219 | // Predicate. |
| 1220 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1221 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1222 | OutStreamer.EmitInstruction(TmpInst); |
| 1223 | } |
| 1224 | { |
| 1225 | MCInst TmpInst; |
| 1226 | TmpInst.setOpcode(ARM::MOVi); |
| 1227 | TmpInst.addOperand(MCOperand::CreateReg(ARM::R0)); |
| 1228 | TmpInst.addOperand(MCOperand::CreateImm(0)); |
| 1229 | // Predicate. |
| 1230 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1231 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1232 | // 's' bit operand (always reg0 for this). |
| 1233 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1234 | OutStreamer.EmitInstruction(TmpInst); |
| 1235 | } |
| 1236 | { |
| 1237 | MCInst TmpInst; |
| 1238 | TmpInst.setOpcode(ARM::ADDri); |
| 1239 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1240 | TmpInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1241 | TmpInst.addOperand(MCOperand::CreateImm(0)); |
| 1242 | // Predicate. |
| 1243 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1244 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1245 | // 's' bit operand (always reg0 for this). |
| 1246 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1247 | OutStreamer.EmitInstruction(TmpInst); |
| 1248 | } |
| 1249 | { |
| 1250 | MCInst TmpInst; |
| 1251 | TmpInst.setOpcode(ARM::MOVi); |
| 1252 | TmpInst.addOperand(MCOperand::CreateReg(ARM::R0)); |
| 1253 | TmpInst.addOperand(MCOperand::CreateImm(1)); |
| 1254 | // Predicate. |
| 1255 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1256 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1257 | // 's' bit operand (always reg0 for this). |
| 1258 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1259 | OutStreamer.AddComment("eh_setjmp end"); |
| 1260 | OutStreamer.EmitInstruction(TmpInst); |
| 1261 | } |
| 1262 | return; |
| 1263 | } |
Jim Grosbach | 5acb3de | 2010-09-27 21:47:04 +0000 | [diff] [blame] | 1264 | case ARM::Int_eh_sjlj_longjmp: { |
| 1265 | // ldr sp, [$src, #8] |
| 1266 | // ldr $scratch, [$src, #4] |
| 1267 | // ldr r7, [$src] |
| 1268 | // bx $scratch |
| 1269 | unsigned SrcReg = MI->getOperand(0).getReg(); |
| 1270 | unsigned ScratchReg = MI->getOperand(1).getReg(); |
| 1271 | { |
| 1272 | MCInst TmpInst; |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 1273 | TmpInst.setOpcode(ARM::LDRi12); |
Jim Grosbach | 5acb3de | 2010-09-27 21:47:04 +0000 | [diff] [blame] | 1274 | TmpInst.addOperand(MCOperand::CreateReg(ARM::SP)); |
| 1275 | TmpInst.addOperand(MCOperand::CreateReg(SrcReg)); |
Jim Grosbach | 5acb3de | 2010-09-27 21:47:04 +0000 | [diff] [blame] | 1276 | TmpInst.addOperand(MCOperand::CreateImm(8)); |
| 1277 | // Predicate. |
| 1278 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1279 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1280 | OutStreamer.EmitInstruction(TmpInst); |
| 1281 | } |
| 1282 | { |
| 1283 | MCInst TmpInst; |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 1284 | TmpInst.setOpcode(ARM::LDRi12); |
Jim Grosbach | 5acb3de | 2010-09-27 21:47:04 +0000 | [diff] [blame] | 1285 | TmpInst.addOperand(MCOperand::CreateReg(ScratchReg)); |
| 1286 | TmpInst.addOperand(MCOperand::CreateReg(SrcReg)); |
Jim Grosbach | 5acb3de | 2010-09-27 21:47:04 +0000 | [diff] [blame] | 1287 | TmpInst.addOperand(MCOperand::CreateImm(4)); |
| 1288 | // Predicate. |
| 1289 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1290 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1291 | OutStreamer.EmitInstruction(TmpInst); |
| 1292 | } |
| 1293 | { |
| 1294 | MCInst TmpInst; |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 1295 | TmpInst.setOpcode(ARM::LDRi12); |
Jim Grosbach | 5acb3de | 2010-09-27 21:47:04 +0000 | [diff] [blame] | 1296 | TmpInst.addOperand(MCOperand::CreateReg(ARM::R7)); |
| 1297 | TmpInst.addOperand(MCOperand::CreateReg(SrcReg)); |
Jim Grosbach | 5acb3de | 2010-09-27 21:47:04 +0000 | [diff] [blame] | 1298 | TmpInst.addOperand(MCOperand::CreateImm(0)); |
| 1299 | // Predicate. |
| 1300 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1301 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1302 | OutStreamer.EmitInstruction(TmpInst); |
| 1303 | } |
| 1304 | { |
| 1305 | MCInst TmpInst; |
Bill Wendling | 6e46d84 | 2010-11-30 00:48:15 +0000 | [diff] [blame] | 1306 | TmpInst.setOpcode(ARM::BX); |
Jim Grosbach | 5acb3de | 2010-09-27 21:47:04 +0000 | [diff] [blame] | 1307 | TmpInst.addOperand(MCOperand::CreateReg(ScratchReg)); |
| 1308 | // Predicate. |
| 1309 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1310 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1311 | OutStreamer.EmitInstruction(TmpInst); |
| 1312 | } |
| 1313 | return; |
| 1314 | } |
Jim Grosbach | 385cc5e | 2010-09-27 22:28:11 +0000 | [diff] [blame] | 1315 | case ARM::tInt_eh_sjlj_longjmp: { |
| 1316 | // ldr $scratch, [$src, #8] |
| 1317 | // mov sp, $scratch |
| 1318 | // ldr $scratch, [$src, #4] |
| 1319 | // ldr r7, [$src] |
| 1320 | // bx $scratch |
| 1321 | unsigned SrcReg = MI->getOperand(0).getReg(); |
| 1322 | unsigned ScratchReg = MI->getOperand(1).getReg(); |
| 1323 | { |
| 1324 | MCInst TmpInst; |
Bill Wendling | f4caf69 | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 1325 | TmpInst.setOpcode(ARM::tLDRi); |
Jim Grosbach | 385cc5e | 2010-09-27 22:28:11 +0000 | [diff] [blame] | 1326 | TmpInst.addOperand(MCOperand::CreateReg(ScratchReg)); |
| 1327 | TmpInst.addOperand(MCOperand::CreateReg(SrcReg)); |
| 1328 | // 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] | 1329 | // tLDR instruction. |
Jim Grosbach | 385cc5e | 2010-09-27 22:28:11 +0000 | [diff] [blame] | 1330 | TmpInst.addOperand(MCOperand::CreateImm(2)); |
Jim Grosbach | 385cc5e | 2010-09-27 22:28:11 +0000 | [diff] [blame] | 1331 | // Predicate. |
| 1332 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1333 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1334 | OutStreamer.EmitInstruction(TmpInst); |
| 1335 | } |
| 1336 | { |
| 1337 | MCInst TmpInst; |
| 1338 | TmpInst.setOpcode(ARM::tMOVtgpr2gpr); |
| 1339 | TmpInst.addOperand(MCOperand::CreateReg(ARM::SP)); |
| 1340 | TmpInst.addOperand(MCOperand::CreateReg(ScratchReg)); |
| 1341 | // Predicate. |
| 1342 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1343 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1344 | OutStreamer.EmitInstruction(TmpInst); |
| 1345 | } |
| 1346 | { |
| 1347 | MCInst TmpInst; |
Bill Wendling | f4caf69 | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 1348 | TmpInst.setOpcode(ARM::tLDRi); |
Jim Grosbach | 385cc5e | 2010-09-27 22:28:11 +0000 | [diff] [blame] | 1349 | TmpInst.addOperand(MCOperand::CreateReg(ScratchReg)); |
| 1350 | TmpInst.addOperand(MCOperand::CreateReg(SrcReg)); |
| 1351 | TmpInst.addOperand(MCOperand::CreateImm(1)); |
Jim Grosbach | 385cc5e | 2010-09-27 22:28:11 +0000 | [diff] [blame] | 1352 | // Predicate. |
| 1353 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1354 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1355 | OutStreamer.EmitInstruction(TmpInst); |
| 1356 | } |
| 1357 | { |
| 1358 | MCInst TmpInst; |
Bill Wendling | f4caf69 | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 1359 | TmpInst.setOpcode(ARM::tLDRr); |
Jim Grosbach | 385cc5e | 2010-09-27 22:28:11 +0000 | [diff] [blame] | 1360 | TmpInst.addOperand(MCOperand::CreateReg(ARM::R7)); |
| 1361 | TmpInst.addOperand(MCOperand::CreateReg(SrcReg)); |
Jim Grosbach | 385cc5e | 2010-09-27 22:28:11 +0000 | [diff] [blame] | 1362 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1363 | // Predicate. |
| 1364 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1365 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1366 | OutStreamer.EmitInstruction(TmpInst); |
| 1367 | } |
| 1368 | { |
| 1369 | MCInst TmpInst; |
| 1370 | TmpInst.setOpcode(ARM::tBX_RET_vararg); |
| 1371 | TmpInst.addOperand(MCOperand::CreateReg(ScratchReg)); |
| 1372 | // Predicate. |
| 1373 | TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1374 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 1375 | OutStreamer.EmitInstruction(TmpInst); |
| 1376 | } |
| 1377 | return; |
| 1378 | } |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 1379 | } |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1380 | |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 1381 | MCInst TmpInst; |
Chris Lattner | 30e2cc2 | 2010-11-14 21:00:02 +0000 | [diff] [blame] | 1382 | LowerARMMachineInstrToMCInst(MI, TmpInst, *this); |
Chris Lattner | 850d2e2 | 2010-02-03 01:16:28 +0000 | [diff] [blame] | 1383 | OutStreamer.EmitInstruction(TmpInst); |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 1384 | } |
Daniel Dunbar | 2685a29 | 2009-10-20 05:15:36 +0000 | [diff] [blame] | 1385 | |
| 1386 | //===----------------------------------------------------------------------===// |
| 1387 | // Target Registry Stuff |
| 1388 | //===----------------------------------------------------------------------===// |
| 1389 | |
| 1390 | static MCInstPrinter *createARMMCInstPrinter(const Target &T, |
| 1391 | unsigned SyntaxVariant, |
Chris Lattner | d374087 | 2010-04-04 05:04:31 +0000 | [diff] [blame] | 1392 | const MCAsmInfo &MAI) { |
Daniel Dunbar | 2685a29 | 2009-10-20 05:15:36 +0000 | [diff] [blame] | 1393 | if (SyntaxVariant == 0) |
Jim Grosbach | 74d7e6c | 2010-09-17 21:33:25 +0000 | [diff] [blame] | 1394 | return new ARMInstPrinter(MAI); |
Daniel Dunbar | 2685a29 | 2009-10-20 05:15:36 +0000 | [diff] [blame] | 1395 | return 0; |
| 1396 | } |
| 1397 | |
| 1398 | // Force static initialization. |
| 1399 | extern "C" void LLVMInitializeARMAsmPrinter() { |
| 1400 | RegisterAsmPrinter<ARMAsmPrinter> X(TheARMTarget); |
| 1401 | RegisterAsmPrinter<ARMAsmPrinter> Y(TheThumbTarget); |
| 1402 | |
| 1403 | TargetRegistry::RegisterMCInstPrinter(TheARMTarget, createARMMCInstPrinter); |
| 1404 | TargetRegistry::RegisterMCInstPrinter(TheThumbTarget, createARMMCInstPrinter); |
| 1405 | } |
| 1406 | |