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