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