blob: 6cb0dcd98d82a739a5b0b3255fa78a873a23f208 [file] [log] [blame]
Chris Lattner71eb0772009-10-19 20:20:46 +00001//===-- ARMAsmPrinter.cpp - Print machine code to an ARM .s file ----------===//
2//
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00006// 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
Jim Grosbachd0d13292010-12-01 03:45:07 +000015#include "ARMAsmPrinter.h"
Craig Topper188ed9d2012-03-17 07:33:42 +000016#include "ARM.h"
Evan Chenge45d6852011-01-11 21:46:47 +000017#include "ARMConstantPoolValue.h"
Chris Lattner71eb0772009-10-19 20:20:46 +000018#include "ARMMachineFunctionInfo.h"
Chris Lattner71eb0772009-10-19 20:20:46 +000019#include "ARMTargetMachine.h"
Jason W Kim109ff292010-10-11 23:01:44 +000020#include "ARMTargetObjectFile.h"
Evan Chenge45d6852011-01-11 21:46:47 +000021#include "InstPrinter/ARMInstPrinter.h"
Evan Chenga20cde32011-07-20 23:34:39 +000022#include "MCTargetDesc/ARMAddressingModes.h"
23#include "MCTargetDesc/ARMMCExpr.h"
Jim Grosbach330840f2012-10-04 21:33:24 +000024#include "llvm/ADT/SetVector.h"
25#include "llvm/ADT/SmallString.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000026#include "llvm/CodeGen/MachineFunctionPass.h"
Evan Cheng10043e22007-01-19 07:51:42 +000027#include "llvm/CodeGen/MachineJumpTableInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000028#include "llvm/CodeGen/MachineModuleInfoImpls.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000029#include "llvm/IR/Constants.h"
30#include "llvm/IR/DataLayout.h"
Chandler Carruth9a4c9e52014-03-06 00:46:21 +000031#include "llvm/IR/DebugInfo.h"
Rafael Espindola894843c2014-01-07 21:19:40 +000032#include "llvm/IR/Mangler.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000033#include "llvm/IR/Module.h"
34#include "llvm/IR/Type.h"
Chris Lattner6462adc2009-10-19 18:38:33 +000035#include "llvm/MC/MCAsmInfo.h"
Rafael Espindola0ed15432010-10-25 17:50:35 +000036#include "llvm/MC/MCAssembler.h"
Chris Lattner6462adc2009-10-19 18:38:33 +000037#include "llvm/MC/MCContext.h"
Jack Carter718da0b2013-01-30 02:24:33 +000038#include "llvm/MC/MCELFStreamer.h"
Chris Lattner71eb0772009-10-19 20:20:46 +000039#include "llvm/MC/MCInst.h"
Benjamin Kramer4e629f72012-11-26 13:34:22 +000040#include "llvm/MC/MCInstBuilder.h"
Rafael Espindola0ed15432010-10-25 17:50:35 +000041#include "llvm/MC/MCObjectStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000042#include "llvm/MC/MCSectionMachO.h"
Chris Lattner4b7dadb2009-08-19 05:49:37 +000043#include "llvm/MC/MCStreamer.h"
Chris Lattner4cd44982009-09-13 17:14:04 +000044#include "llvm/MC/MCSymbol.h"
Saleem Abdulrasool278a9f42014-01-19 08:25:27 +000045#include "llvm/Support/ARMBuildAttributes.h"
Renato Golinf5f373f2015-05-08 21:04:27 +000046#include "llvm/Support/TargetParser.h"
Saleem Abdulrasool0aca1c32014-04-30 06:14:25 +000047#include "llvm/Support/COFF.h"
Chris Lattner71eb0772009-10-19 20:20:46 +000048#include "llvm/Support/CommandLine.h"
Devang Patela52ddc42010-08-04 22:39:39 +000049#include "llvm/Support/Debug.h"
Jack Carter718da0b2013-01-30 02:24:33 +000050#include "llvm/Support/ELF.h"
Torok Edwinf8d479c2009-07-08 20:55:50 +000051#include "llvm/Support/ErrorHandling.h"
Evan Cheng2bb40352011-08-24 18:08:43 +000052#include "llvm/Support/TargetRegistry.h"
Chris Lattnerd20699b2010-04-04 08:18:47 +000053#include "llvm/Support/raw_ostream.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000054#include "llvm/Target/TargetMachine.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000055#include <cctype>
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000056using namespace llvm;
57
Chandler Carruth84e68b22014-04-22 02:41:26 +000058#define DEBUG_TYPE "asm-printer"
59
David Blaikie94598322015-01-18 20:29:04 +000060ARMAsmPrinter::ARMAsmPrinter(TargetMachine &TM,
61 std::unique_ptr<MCStreamer> Streamer)
62 : AsmPrinter(TM, std::move(Streamer)), AFI(nullptr), MCP(nullptr),
Eric Christophera49d68e2015-02-17 20:02:32 +000063 InConstantPool(false) {}
David Blaikie94598322015-01-18 20:29:04 +000064
Jim Grosbach4b63d2a2012-05-18 19:12:01 +000065void ARMAsmPrinter::EmitFunctionBodyEnd() {
66 // Make sure to terminate any constant pools that were at the end
67 // of the function.
68 if (!InConstantPool)
69 return;
70 InConstantPool = false;
Lang Hames9ff69c82015-04-24 19:11:51 +000071 OutStreamer->EmitDataRegion(MCDR_DataRegionEnd);
Jim Grosbach4b63d2a2012-05-18 19:12:01 +000072}
Owen Anderson0ca562e2011-10-04 23:26:17 +000073
Jim Grosbach4b63d2a2012-05-18 19:12:01 +000074void ARMAsmPrinter::EmitFunctionEntryLabel() {
Chris Lattner56db8c32010-01-27 23:58:11 +000075 if (AFI->isThumbFunction()) {
Lang Hames9ff69c82015-04-24 19:11:51 +000076 OutStreamer->EmitAssemblerFlag(MCAF_Code16);
77 OutStreamer->EmitThumbFunc(CurrentFnSym);
Chris Lattner56db8c32010-01-27 23:58:11 +000078 }
Jim Grosbach8ee5cd92010-09-02 01:02:06 +000079
Lang Hames9ff69c82015-04-24 19:11:51 +000080 OutStreamer->EmitLabel(CurrentFnSym);
Chris Lattner56db8c32010-01-27 23:58:11 +000081}
82
James Molloy6685c082012-01-26 09:25:43 +000083void ARMAsmPrinter::EmitXXStructor(const Constant *CV) {
Eric Christopher8b770652015-01-26 19:03:15 +000084 uint64_t Size = TM.getDataLayout()->getTypeAllocSize(CV->getType());
James Molloy6685c082012-01-26 09:25:43 +000085 assert(Size && "C++ constructor pointer had zero size!");
86
Bill Wendlingdfb45f42012-02-15 09:14:08 +000087 const GlobalValue *GV = dyn_cast<GlobalValue>(CV->stripPointerCasts());
James Molloy6685c082012-01-26 09:25:43 +000088 assert(GV && "C++ constructor pointer was not a GlobalValue!");
89
Saleem Abdulrasool1eb4a282014-07-07 05:18:22 +000090 const MCExpr *E = MCSymbolRefExpr::Create(GetARMGVSymbol(GV,
91 ARMII::MO_NO_FLAG),
Tim Northoverd6a729b2014-01-06 14:28:05 +000092 (Subtarget->isTargetELF()
93 ? MCSymbolRefExpr::VK_ARM_TARGET1
94 : MCSymbolRefExpr::VK_None),
James Molloy6685c082012-01-26 09:25:43 +000095 OutContext);
Jim Grosbach1a597112014-04-03 23:43:18 +000096
Lang Hames9ff69c82015-04-24 19:11:51 +000097 OutStreamer->EmitValue(E, Size);
James Molloy6685c082012-01-26 09:25:43 +000098}
99
Jim Grosbach080fdf42010-09-30 01:57:53 +0000100/// runOnMachineFunction - This uses the EmitInstruction()
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000101/// method to print assembly for each instruction.
102///
103bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Evan Cheng10043e22007-01-19 07:51:42 +0000104 AFI = MF.getInfo<ARMFunctionInfo>();
Evan Cheng5e3ac182008-09-18 07:27:23 +0000105 MCP = MF.getConstantPool();
Eric Christophera49d68e2015-02-17 20:02:32 +0000106 Subtarget = &MF.getSubtarget<ARMSubtarget>();
Rafael Espindola27f8bdc2006-05-23 02:48:20 +0000107
Saleem Abdulrasool0aca1c32014-04-30 06:14:25 +0000108 SetupMachineFunction(MF);
109
110 if (Subtarget->isTargetCOFF()) {
111 bool Internal = MF.getFunction()->hasInternalLinkage();
112 COFF::SymbolStorageClass Scl = Internal ? COFF::IMAGE_SYM_CLASS_STATIC
113 : COFF::IMAGE_SYM_CLASS_EXTERNAL;
114 int Type = COFF::IMAGE_SYM_DTYPE_FUNCTION << COFF::SCT_COMPLEX_TYPE_SHIFT;
115
Lang Hames9ff69c82015-04-24 19:11:51 +0000116 OutStreamer->BeginCOFFSymbolDef(CurrentFnSym);
117 OutStreamer->EmitCOFFSymbolStorageClass(Scl);
118 OutStreamer->EmitCOFFSymbolType(Type);
119 OutStreamer->EndCOFFSymbolDef();
Saleem Abdulrasool0aca1c32014-04-30 06:14:25 +0000120 }
121
Saleem Abdulrasool0aca1c32014-04-30 06:14:25 +0000122 // Emit the rest of the function body.
123 EmitFunctionBody();
124
Jonathan Roelofs300d8ff2014-12-04 19:34:50 +0000125 // If we need V4T thumb mode Register Indirect Jump pads, emit them.
126 // These are created per function, rather than per TU, since it's
127 // relatively easy to exceed the thumb branch range within a TU.
128 if (! ThumbIndirectPads.empty()) {
Lang Hames9ff69c82015-04-24 19:11:51 +0000129 OutStreamer->EmitAssemblerFlag(MCAF_Code16);
Jonathan Roelofs300d8ff2014-12-04 19:34:50 +0000130 EmitAlignment(1);
131 for (unsigned i = 0, e = ThumbIndirectPads.size(); i < e; i++) {
Lang Hames9ff69c82015-04-24 19:11:51 +0000132 OutStreamer->EmitLabel(ThumbIndirectPads[i].second);
133 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tBX)
Jonathan Roelofs300d8ff2014-12-04 19:34:50 +0000134 .addReg(ThumbIndirectPads[i].first)
135 // Add predicate operands.
136 .addImm(ARMCC::AL)
137 .addReg(0));
138 }
139 ThumbIndirectPads.clear();
140 }
141
Saleem Abdulrasool0aca1c32014-04-30 06:14:25 +0000142 // We didn't modify anything.
143 return false;
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000144}
145
Evan Chengb23b50d2009-06-29 07:51:04 +0000146void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
Tim Northoverb4c61f82015-05-13 20:28:41 +0000147 raw_ostream &O) {
Evan Chengb23b50d2009-06-29 07:51:04 +0000148 const MachineOperand &MO = MI->getOperand(OpNum);
Anton Korobeynikov25229082009-11-24 00:44:37 +0000149 unsigned TF = MO.getTargetFlags();
150
Rafael Espindola91df1ef2006-05-25 12:57:06 +0000151 switch (MO.getType()) {
Craig Toppere55c5562012-02-07 02:50:20 +0000152 default: llvm_unreachable("<unknown operand type>");
Bob Wilson2e076c42009-06-22 23:27:02 +0000153 case MachineOperand::MO_Register: {
154 unsigned Reg = MO.getReg();
Chris Lattner93e3ef62009-10-19 20:59:55 +0000155 assert(TargetRegisterInfo::isPhysicalRegister(Reg));
Jim Grosbach2c950272010-10-06 21:22:32 +0000156 assert(!MO.getSubReg() && "Subregs should be eliminated!");
Weiming Zhaoc5987002013-02-14 18:10:21 +0000157 if(ARM::GPRPairRegClass.contains(Reg)) {
158 const MachineFunction &MF = *MI->getParent()->getParent();
Eric Christopherfc6de422014-08-05 02:39:49 +0000159 const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
Weiming Zhaoc5987002013-02-14 18:10:21 +0000160 Reg = TRI->getSubReg(Reg, ARM::gsub_0);
161 }
Jim Grosbach2c950272010-10-06 21:22:32 +0000162 O << ARMInstPrinter::getRegisterName(Reg);
Rafael Espindola91df1ef2006-05-25 12:57:06 +0000163 break;
Bob Wilson2e076c42009-06-22 23:27:02 +0000164 }
Evan Cheng10043e22007-01-19 07:51:42 +0000165 case MachineOperand::MO_Immediate: {
Evan Cheng83e0d482009-09-28 09:14:39 +0000166 int64_t Imm = MO.getImm();
Anton Korobeynikov222b86c2009-10-08 20:43:22 +0000167 O << '#';
Tim Northoverb4c61f82015-05-13 20:28:41 +0000168 if (TF == ARMII::MO_LO16)
Anton Korobeynikov25229082009-11-24 00:44:37 +0000169 O << ":lower16:";
Tim Northoverb4c61f82015-05-13 20:28:41 +0000170 else if (TF == ARMII::MO_HI16)
Anton Korobeynikov25229082009-11-24 00:44:37 +0000171 O << ":upper16:";
Anton Korobeynikov222b86c2009-10-08 20:43:22 +0000172 O << Imm;
Rafael Espindola91df1ef2006-05-25 12:57:06 +0000173 break;
Evan Cheng10043e22007-01-19 07:51:42 +0000174 }
Rafael Espindola91df1ef2006-05-25 12:57:06 +0000175 case MachineOperand::MO_MachineBasicBlock:
Chris Lattner29bdac42010-03-13 21:04:28 +0000176 O << *MO.getMBB()->getSymbol();
Rafael Espindola91df1ef2006-05-25 12:57:06 +0000177 return;
Rafael Espindola75269be2006-07-16 01:02:57 +0000178 case MachineOperand::MO_GlobalAddress: {
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000179 const GlobalValue *GV = MO.getGlobal();
Tim Northoverb4c61f82015-05-13 20:28:41 +0000180 if (TF & ARMII::MO_LO16)
Anton Korobeynikov25229082009-11-24 00:44:37 +0000181 O << ":lower16:";
Tim Northoverb4c61f82015-05-13 20:28:41 +0000182 else if (TF & ARMII::MO_HI16)
Anton Korobeynikov25229082009-11-24 00:44:37 +0000183 O << ":upper16:";
Saleem Abdulrasool1eb4a282014-07-07 05:18:22 +0000184 O << *GetARMGVSymbol(GV, TF);
Anton Korobeynikovbff4b372008-11-22 16:15:34 +0000185
Chris Lattnerf33c7fc2010-04-03 22:28:33 +0000186 printOffset(MO.getOffset(), O);
Jim Grosbachf49540c2010-10-06 21:36:43 +0000187 if (TF == ARMII::MO_PLT)
Lauro Ramos Venancioee2d1642007-04-22 00:04:12 +0000188 O << "(PLT)";
Evan Cheng10043e22007-01-19 07:51:42 +0000189 break;
Rafael Espindola75269be2006-07-16 01:02:57 +0000190 }
Rafael Espindola91df1ef2006-05-25 12:57:06 +0000191 case MachineOperand::MO_ConstantPoolIndex:
Chris Lattnerc55ea3f2010-01-23 07:00:21 +0000192 O << *GetCPISymbol(MO.getIndex());
Rafael Espindola91df1ef2006-05-25 12:57:06 +0000193 break;
Rafael Espindola91df1ef2006-05-25 12:57:06 +0000194 }
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000195}
196
Evan Chengb23b50d2009-06-29 07:51:04 +0000197//===--------------------------------------------------------------------===//
198
Chris Lattner68d64aa2010-01-25 19:51:38 +0000199MCSymbol *ARMAsmPrinter::
Tim Northover4998a472015-05-13 20:28:38 +0000200GetARMJTIPICJumpTableLabel(unsigned uid) const {
Eric Christopher8b770652015-01-26 19:03:15 +0000201 const DataLayout *DL = TM.getDataLayout();
Chris Lattner68d64aa2010-01-25 19:51:38 +0000202 SmallString<60> Name;
Rafael Espindola58873562014-01-03 19:21:54 +0000203 raw_svector_ostream(Name) << DL->getPrivateGlobalPrefix() << "JTI"
Tim Northover4998a472015-05-13 20:28:38 +0000204 << getFunctionNumber() << '_' << uid;
Yaron Keren075759a2015-03-30 15:42:36 +0000205 return OutContext.GetOrCreateSymbol(Name);
Chris Lattner6330d532010-01-25 19:39:52 +0000206}
207
Jim Grosbach4a6ab132010-09-24 20:47:58 +0000208
Dmitri Gribenko0011bbf2012-11-15 16:51:49 +0000209MCSymbol *ARMAsmPrinter::GetARMSJLJEHLabel() const {
Eric Christopher8b770652015-01-26 19:03:15 +0000210 const DataLayout *DL = TM.getDataLayout();
Jim Grosbach4a6ab132010-09-24 20:47:58 +0000211 SmallString<60> Name;
Rafael Espindola58873562014-01-03 19:21:54 +0000212 raw_svector_ostream(Name) << DL->getPrivateGlobalPrefix() << "SJLJEH"
Jim Grosbach4a6ab132010-09-24 20:47:58 +0000213 << getFunctionNumber();
Yaron Keren075759a2015-03-30 15:42:36 +0000214 return OutContext.GetOrCreateSymbol(Name);
Jim Grosbach4a6ab132010-09-24 20:47:58 +0000215}
216
Evan Chengb23b50d2009-06-29 07:51:04 +0000217bool ARMAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
Chris Lattner3bb09762010-04-04 05:29:35 +0000218 unsigned AsmVariant, const char *ExtraCode,
219 raw_ostream &O) {
Evan Cheng10043e22007-01-19 07:51:42 +0000220 // Does this asm operand have a single letter operand modifier?
221 if (ExtraCode && ExtraCode[0]) {
222 if (ExtraCode[1] != 0) return true; // Unknown modifier.
Anton Korobeynikovcfed3002009-08-08 23:10:41 +0000223
Evan Cheng10043e22007-01-19 07:51:42 +0000224 switch (ExtraCode[0]) {
Jack Carter5e69cff2012-06-26 13:49:27 +0000225 default:
226 // See if this is a generic print operand
227 return AsmPrinter::PrintAsmOperand(MI, OpNum, AsmVariant, ExtraCode, O);
Bob Wilson9ce44e22009-07-09 23:54:51 +0000228 case 'a': // Print as a memory address.
229 if (MI->getOperand(OpNum).isReg()) {
Jim Grosbach136ed512010-09-30 15:25:22 +0000230 O << "["
231 << ARMInstPrinter::getRegisterName(MI->getOperand(OpNum).getReg())
232 << "]";
Bob Wilson9ce44e22009-07-09 23:54:51 +0000233 return false;
234 }
235 // Fallthrough
236 case 'c': // Don't print "#" before an immediate operand.
Bob Wilsonceffeb62009-08-21 21:58:55 +0000237 if (!MI->getOperand(OpNum).isImm())
238 return true;
Jim Grosbach080fdf42010-09-30 01:57:53 +0000239 O << MI->getOperand(OpNum).getImm();
Bob Wilson0669f6d2009-04-06 21:46:51 +0000240 return false;
Evan Cheng1e150de2007-04-04 00:13:29 +0000241 case 'P': // Print a VFP double precision register.
Evan Cheng0c2544f2009-12-08 23:06:22 +0000242 case 'q': // Print a NEON quad precision register.
Chris Lattner76c564b2010-04-04 04:47:45 +0000243 printOperand(MI, OpNum, O);
Evan Chengea28fc52007-03-08 22:42:46 +0000244 return false;
Eric Christopher76178832011-05-24 22:10:34 +0000245 case 'y': // Print a VFP single precision register as indexed double.
Eric Christopher76178832011-05-24 22:10:34 +0000246 if (MI->getOperand(OpNum).isReg()) {
247 unsigned Reg = MI->getOperand(OpNum).getReg();
Eric Christopherfc6de422014-08-05 02:39:49 +0000248 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
Jakob Stoklund Olesen5541f602012-05-30 23:00:43 +0000249 // Find the 'd' register that has this 's' register as a sub-register,
250 // and determine the lane number.
251 for (MCSuperRegIterator SR(Reg, TRI); SR.isValid(); ++SR) {
252 if (!ARM::DPRRegClass.contains(*SR))
253 continue;
254 bool Lane0 = TRI->getSubReg(*SR, ARM::ssub_0) == Reg;
255 O << ARMInstPrinter::getRegisterName(*SR) << (Lane0 ? "[0]" : "[1]");
256 return false;
257 }
Eric Christopher76178832011-05-24 22:10:34 +0000258 }
Eric Christopher1b724942011-05-24 23:27:13 +0000259 return true;
Eric Christopherd4562562011-05-24 22:27:43 +0000260 case 'B': // Bitwise inverse of integer or symbol without a preceding #.
Eric Christopherb1dda562011-05-24 23:15:43 +0000261 if (!MI->getOperand(OpNum).isImm())
262 return true;
263 O << ~(MI->getOperand(OpNum).getImm());
264 return false;
Eric Christopherd4562562011-05-24 22:27:43 +0000265 case 'L': // The low 16 bits of an immediate constant.
Eric Christopher1b724942011-05-24 23:27:13 +0000266 if (!MI->getOperand(OpNum).isImm())
267 return true;
268 O << (MI->getOperand(OpNum).getImm() & 0xffff);
269 return false;
Eric Christopherd00e8ad2011-05-28 01:40:44 +0000270 case 'M': { // A register range suitable for LDM/STM.
271 if (!MI->getOperand(OpNum).isReg())
272 return true;
273 const MachineOperand &MO = MI->getOperand(OpNum);
274 unsigned RegBegin = MO.getReg();
275 // This takes advantage of the 2 operand-ness of ldm/stm and that we've
276 // already got the operands in registers that are operands to the
277 // inline asm statement.
Weiming Zhaoa3d87a12013-06-28 17:26:02 +0000278 O << "{";
279 if (ARM::GPRPairRegClass.contains(RegBegin)) {
Eric Christopherfc6de422014-08-05 02:39:49 +0000280 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
Weiming Zhaoa3d87a12013-06-28 17:26:02 +0000281 unsigned Reg0 = TRI->getSubReg(RegBegin, ARM::gsub_0);
Alp Toker98444342014-04-19 23:56:35 +0000282 O << ARMInstPrinter::getRegisterName(Reg0) << ", ";
Weiming Zhaoa3d87a12013-06-28 17:26:02 +0000283 RegBegin = TRI->getSubReg(RegBegin, ARM::gsub_1);
284 }
285 O << ARMInstPrinter::getRegisterName(RegBegin);
Jim Grosbach05dec8b12011-09-02 18:46:15 +0000286
Eric Christopherd00e8ad2011-05-28 01:40:44 +0000287 // FIXME: The register allocator not only may not have given us the
288 // registers in sequence, but may not be in ascending registers. This
289 // will require changes in the register allocator that'll need to be
290 // propagated down here if the operands change.
291 unsigned RegOps = OpNum + 1;
292 while (MI->getOperand(RegOps).isReg()) {
Jim Grosbach05dec8b12011-09-02 18:46:15 +0000293 O << ", "
Eric Christopherd00e8ad2011-05-28 01:40:44 +0000294 << ARMInstPrinter::getRegisterName(MI->getOperand(RegOps).getReg());
295 RegOps++;
296 }
297
298 O << "}";
299
300 return false;
301 }
Rafael Espindola36a3abc2011-08-10 16:26:42 +0000302 case 'R': // The most significant register of a pair.
303 case 'Q': { // The least significant register of a pair.
304 if (OpNum == 0)
305 return true;
306 const MachineOperand &FlagsOP = MI->getOperand(OpNum - 1);
307 if (!FlagsOP.isImm())
308 return true;
309 unsigned Flags = FlagsOP.getImm();
Tim Northover2ddeeed2013-08-22 06:51:04 +0000310
311 // This operand may not be the one that actually provides the register. If
312 // it's tied to a previous one then we should refer instead to that one
313 // for registers and their classes.
314 unsigned TiedIdx;
315 if (InlineAsm::isUseOperandTiedToDef(Flags, TiedIdx)) {
316 for (OpNum = InlineAsm::MIOp_FirstOperand; TiedIdx; --TiedIdx) {
317 unsigned OpFlags = MI->getOperand(OpNum).getImm();
318 OpNum += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
319 }
320 Flags = MI->getOperand(OpNum).getImm();
321
322 // Later code expects OpNum to be pointing at the register rather than
323 // the flags.
324 OpNum += 1;
325 }
326
Rafael Espindola36a3abc2011-08-10 16:26:42 +0000327 unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags);
Weiming Zhaoa3d87a12013-06-28 17:26:02 +0000328 unsigned RC;
329 InlineAsm::hasRegClassConstraint(Flags, RC);
330 if (RC == ARM::GPRPairRegClassID) {
331 if (NumVals != 1)
332 return true;
333 const MachineOperand &MO = MI->getOperand(OpNum);
334 if (!MO.isReg())
335 return true;
Eric Christopherfc6de422014-08-05 02:39:49 +0000336 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
Weiming Zhaoa3d87a12013-06-28 17:26:02 +0000337 unsigned Reg = TRI->getSubReg(MO.getReg(), ExtraCode[0] == 'Q' ?
338 ARM::gsub_0 : ARM::gsub_1);
339 O << ARMInstPrinter::getRegisterName(Reg);
340 return false;
341 }
Rafael Espindola36a3abc2011-08-10 16:26:42 +0000342 if (NumVals != 2)
343 return true;
344 unsigned RegOp = ExtraCode[0] == 'Q' ? OpNum : OpNum + 1;
345 if (RegOp >= MI->getNumOperands())
346 return true;
347 const MachineOperand &MO = MI->getOperand(RegOp);
348 if (!MO.isReg())
349 return true;
350 unsigned Reg = MO.getReg();
351 O << ARMInstPrinter::getRegisterName(Reg);
352 return false;
353 }
354
Eric Christopherd4562562011-05-24 22:27:43 +0000355 case 'e': // The low doubleword register of a NEON quad register.
Bob Wilsonfadc2c82011-12-12 21:45:15 +0000356 case 'f': { // The high doubleword register of a NEON quad register.
357 if (!MI->getOperand(OpNum).isReg())
358 return true;
359 unsigned Reg = MI->getOperand(OpNum).getReg();
360 if (!ARM::QPRRegClass.contains(Reg))
361 return true;
Eric Christopherfc6de422014-08-05 02:39:49 +0000362 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
Bob Wilsonfadc2c82011-12-12 21:45:15 +0000363 unsigned SubReg = TRI->getSubReg(Reg, ExtraCode[0] == 'e' ?
364 ARM::dsub_0 : ARM::dsub_1);
365 O << ARMInstPrinter::getRegisterName(SubReg);
366 return false;
367 }
368
Eric Christopher7d8b53c2012-08-13 18:18:52 +0000369 // This modifier is not yet supported.
Eric Christopherd4562562011-05-24 22:27:43 +0000370 case 'h': // A range of VFP/NEON registers suitable for VLD1/VST1.
Bob Wilson40e62df2010-05-27 20:23:42 +0000371 return true;
Eric Christopher5f61a742012-08-14 23:32:15 +0000372 case 'H': { // The highest-numbered register of a pair.
Eric Christopher7d8b53c2012-08-13 18:18:52 +0000373 const MachineOperand &MO = MI->getOperand(OpNum);
374 if (!MO.isReg())
375 return true;
Eric Christopher7d8b53c2012-08-13 18:18:52 +0000376 const MachineFunction &MF = *MI->getParent()->getParent();
Eric Christopherfc6de422014-08-05 02:39:49 +0000377 const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
Weiming Zhaoc5987002013-02-14 18:10:21 +0000378 unsigned Reg = MO.getReg();
379 if(!ARM::GPRPairRegClass.contains(Reg))
380 return false;
381 Reg = TRI->getSubReg(Reg, ARM::gsub_1);
Eric Christopher7d8b53c2012-08-13 18:18:52 +0000382 O << ARMInstPrinter::getRegisterName(Reg);
383 return false;
Evan Cheng3d3ee872010-05-27 22:08:38 +0000384 }
Eric Christopher5f61a742012-08-14 23:32:15 +0000385 }
Evan Cheng10043e22007-01-19 07:51:42 +0000386 }
Jim Grosbach1eaa90b2009-09-04 01:38:51 +0000387
Chris Lattner76c564b2010-04-04 04:47:45 +0000388 printOperand(MI, OpNum, O);
Evan Cheng10043e22007-01-19 07:51:42 +0000389 return false;
390}
391
Bob Wilsona2c462b2009-05-19 05:53:42 +0000392bool ARMAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
Evan Chengb23b50d2009-06-29 07:51:04 +0000393 unsigned OpNum, unsigned AsmVariant,
Chris Lattner3bb09762010-04-04 05:29:35 +0000394 const char *ExtraCode,
395 raw_ostream &O) {
Eric Christopher8c5e4192011-05-25 20:51:58 +0000396 // Does this asm operand have a single letter operand modifier?
397 if (ExtraCode && ExtraCode[0]) {
398 if (ExtraCode[1] != 0) return true; // Unknown modifier.
Jim Grosbach05dec8b12011-09-02 18:46:15 +0000399
Eric Christopher8c5e4192011-05-25 20:51:58 +0000400 switch (ExtraCode[0]) {
Eric Christopher33a73c72011-05-26 18:22:26 +0000401 case 'A': // A memory operand for a VLD1/VST1 instruction.
Eric Christopher8c5e4192011-05-25 20:51:58 +0000402 default: return true; // Unknown modifier.
403 case 'm': // The base register of a memory operand.
404 if (!MI->getOperand(OpNum).isReg())
405 return true;
406 O << ARMInstPrinter::getRegisterName(MI->getOperand(OpNum).getReg());
407 return false;
408 }
409 }
Jim Grosbach05dec8b12011-09-02 18:46:15 +0000410
Bob Wilson3b515602009-10-13 20:50:28 +0000411 const MachineOperand &MO = MI->getOperand(OpNum);
412 assert(MO.isReg() && "unexpected inline asm memory operand");
Jim Grosbach080fdf42010-09-30 01:57:53 +0000413 O << "[" << ARMInstPrinter::getRegisterName(MO.getReg()) << "]";
Bob Wilsona2c462b2009-05-19 05:53:42 +0000414 return false;
415}
416
Rafael Espindola65fd0a82014-01-24 15:47:54 +0000417static bool isThumb(const MCSubtargetInfo& STI) {
Michael Kupersteinc3434b32015-05-13 10:28:46 +0000418 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Rafael Espindola65fd0a82014-01-24 15:47:54 +0000419}
420
421void ARMAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
David Peixottoea2bcb92014-02-06 18:19:40 +0000422 const MCSubtargetInfo *EndInfo) const {
Rafael Espindola65fd0a82014-01-24 15:47:54 +0000423 // If either end mode is unknown (EndInfo == NULL) or different than
424 // the start mode, then restore the start mode.
425 const bool WasThumb = isThumb(StartInfo);
Craig Topper062a2ba2014-04-25 05:30:21 +0000426 if (!EndInfo || WasThumb != isThumb(*EndInfo)) {
Lang Hames9ff69c82015-04-24 19:11:51 +0000427 OutStreamer->EmitAssemblerFlag(WasThumb ? MCAF_Code16 : MCAF_Code32);
Rafael Espindola65fd0a82014-01-24 15:47:54 +0000428 }
429}
430
Bob Wilsonb633d7a2009-09-30 22:06:26 +0000431void ARMAsmPrinter::EmitStartOfAsmFile(Module &M) {
Eric Christophera49d68e2015-02-17 20:02:32 +0000432 Triple TT(TM.getTargetTriple());
Jim Grosbachd7cf55c2009-11-09 00:11:35 +0000433 // Use unified assembler syntax.
Lang Hames9ff69c82015-04-24 19:11:51 +0000434 OutStreamer->EmitAssemblerFlag(MCAF_SyntaxUnified);
Anton Korobeynikovf687a822009-06-17 23:43:18 +0000435
Anton Korobeynikovfa6f1ee2009-05-23 19:51:20 +0000436 // Emit ARM Build Attributes
Eric Christophera49d68e2015-02-17 20:02:32 +0000437 if (TT.isOSBinFormatELF())
Jason W Kimbff84d42010-10-06 22:36:46 +0000438 emitAttributes();
Akira Hatanaka16e47ff2014-07-25 05:12:49 +0000439
Eric Christophera49d68e2015-02-17 20:02:32 +0000440 // Use the triple's architecture and subarchitecture to determine
441 // if we're thumb for the purposes of the top level code16 assembler
442 // flag.
443 bool isThumb = TT.getArch() == Triple::thumb ||
444 TT.getArch() == Triple::thumbeb ||
445 TT.getSubArch() == Triple::ARMSubArch_v7m ||
446 TT.getSubArch() == Triple::ARMSubArch_v6m;
447 if (!M.getModuleInlineAsm().empty() && isThumb)
Lang Hames9ff69c82015-04-24 19:11:51 +0000448 OutStreamer->EmitAssemblerFlag(MCAF_Code16);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000449}
450
Tim Northover23723012014-04-29 10:06:05 +0000451static void
452emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel,
453 MachineModuleInfoImpl::StubValueTy &MCSym) {
454 // L_foo$stub:
455 OutStreamer.EmitLabel(StubLabel);
456 // .indirect_symbol _foo
457 OutStreamer.EmitSymbolAttribute(MCSym.getPointer(), MCSA_IndirectSymbol);
458
459 if (MCSym.getInt())
460 // External to current translation unit.
461 OutStreamer.EmitIntValue(0, 4/*size*/);
462 else
463 // Internal to current translation unit.
464 //
465 // When we place the LSDA into the TEXT section, the type info
466 // pointers need to be indirect and pc-rel. We accomplish this by
467 // using NLPs; however, sometimes the types are local to the file.
468 // We need to fill in the value for the NLP in those cases.
469 OutStreamer.EmitValue(
470 MCSymbolRefExpr::Create(MCSym.getPointer(), OutStreamer.getContext()),
471 4 /*size*/);
472}
473
Anton Korobeynikov04083522008-08-07 09:54:23 +0000474
Chris Lattneree9399a2009-10-19 17:59:19 +0000475void ARMAsmPrinter::EmitEndOfAsmFile(Module &M) {
Eric Christophera49d68e2015-02-17 20:02:32 +0000476 Triple TT(TM.getTargetTriple());
477 if (TT.isOSBinFormatMachO()) {
Chris Lattner73ebe432009-08-03 22:18:15 +0000478 // All darwin targets use mach-o.
Dan Gohman53d4a082010-04-17 16:44:48 +0000479 const TargetLoweringObjectFileMachO &TLOFMacho =
480 static_cast<const TargetLoweringObjectFileMachO &>(getObjFileLowering());
Chris Lattner6462adc2009-10-19 18:38:33 +0000481 MachineModuleInfoMachO &MMIMacho =
482 MMI->getObjFileInfo<MachineModuleInfoMachO>();
Jim Grosbach1eaa90b2009-09-04 01:38:51 +0000483
Evan Cheng10043e22007-01-19 07:51:42 +0000484 // Output non-lazy-pointers for external and common global variables.
Chris Lattner6462adc2009-10-19 18:38:33 +0000485 MachineModuleInfoMachO::SymbolListTy Stubs = MMIMacho.GetGVStubList();
Bill Wendlinga810bdf2010-03-10 22:34:10 +0000486
Chris Lattner6462adc2009-10-19 18:38:33 +0000487 if (!Stubs.empty()) {
Chris Lattnercb307a272009-08-10 01:39:42 +0000488 // Switch with ".non_lazy_symbol_pointer" directive.
Lang Hames9ff69c82015-04-24 19:11:51 +0000489 OutStreamer->SwitchSection(TLOFMacho.getNonLazySymbolPointerSection());
Chris Lattner292472d2009-08-10 18:01:34 +0000490 EmitAlignment(2);
Bill Wendlingffba5fa2010-03-09 00:43:34 +0000491
Tim Northover23723012014-04-29 10:06:05 +0000492 for (auto &Stub : Stubs)
Lang Hames9ff69c82015-04-24 19:11:51 +0000493 emitNonLazySymbolPointer(*OutStreamer, Stub.first, Stub.second);
Bill Wendlingf1eae222010-03-09 00:40:17 +0000494
495 Stubs.clear();
Lang Hames9ff69c82015-04-24 19:11:51 +0000496 OutStreamer->AddBlankLine();
Evan Cheng10043e22007-01-19 07:51:42 +0000497 }
498
Chris Lattner3334deb2009-10-19 18:44:38 +0000499 Stubs = MMIMacho.GetHiddenGVStubList();
500 if (!Stubs.empty()) {
Lang Hames9ff69c82015-04-24 19:11:51 +0000501 OutStreamer->SwitchSection(TLOFMacho.getNonLazySymbolPointerSection());
Chris Lattnerfbcafd42009-08-10 18:02:16 +0000502 EmitAlignment(2);
Tim Northover23723012014-04-29 10:06:05 +0000503
504 for (auto &Stub : Stubs)
Lang Hames9ff69c82015-04-24 19:11:51 +0000505 emitNonLazySymbolPointer(*OutStreamer, Stub.first, Stub.second);
Bill Wendlingffba5fa2010-03-09 00:43:34 +0000506
507 Stubs.clear();
Lang Hames9ff69c82015-04-24 19:11:51 +0000508 OutStreamer->AddBlankLine();
Evan Cheng2a03c7e2008-12-05 01:06:39 +0000509 }
510
Evan Cheng10043e22007-01-19 07:51:42 +0000511 // Funny Darwin hack: This flag tells the linker that no global symbols
512 // contain code that falls through to other global symbols (e.g. the obvious
513 // implementation of multiple entry points). If this doesn't occur, the
514 // linker can safely perform dead code stripping. Since LLVM never
515 // generates code that does this, it is always safe to set.
Lang Hames9ff69c82015-04-24 19:11:51 +0000516 OutStreamer->EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
Rafael Espindola89e5cbd2006-07-27 11:38:51 +0000517 }
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000518}
Anton Korobeynikov17d28de2008-08-17 13:55:10 +0000519
Chris Lattner71eb0772009-10-19 20:20:46 +0000520//===----------------------------------------------------------------------===//
Jason W Kimbff84d42010-10-06 22:36:46 +0000521// Helper routines for EmitStartOfAsmFile() and EmitEndOfAsmFile()
522// FIXME:
523// The following seem like one-off assembler flags, but they actually need
Jim Grosbach25cd3bf2010-10-06 22:46:47 +0000524// to appear in the .ARM.attributes section in ELF.
Jason W Kimbff84d42010-10-06 22:36:46 +0000525// Instead of subclassing the MCELFStreamer, we do the work here.
526
Amara Emerson5035ee02013-10-07 16:55:23 +0000527static ARMBuildAttrs::CPUArch getArchForCPU(StringRef CPU,
528 const ARMSubtarget *Subtarget) {
529 if (CPU == "xscale")
530 return ARMBuildAttrs::v5TEJ;
531
532 if (Subtarget->hasV8Ops())
533 return ARMBuildAttrs::v8;
534 else if (Subtarget->hasV7Ops()) {
535 if (Subtarget->isMClass() && Subtarget->hasThumb2DSP())
536 return ARMBuildAttrs::v7E_M;
537 return ARMBuildAttrs::v7;
538 } else if (Subtarget->hasV6T2Ops())
539 return ARMBuildAttrs::v6T2;
540 else if (Subtarget->hasV6MOps())
541 return ARMBuildAttrs::v6S_M;
542 else if (Subtarget->hasV6Ops())
543 return ARMBuildAttrs::v6;
544 else if (Subtarget->hasV5TEOps())
545 return ARMBuildAttrs::v5TE;
546 else if (Subtarget->hasV5TOps())
547 return ARMBuildAttrs::v5T;
548 else if (Subtarget->hasV4TOps())
549 return ARMBuildAttrs::v4T;
550 else
551 return ARMBuildAttrs::v4;
552}
553
Jason W Kimbff84d42010-10-06 22:36:46 +0000554void ARMAsmPrinter::emitAttributes() {
Lang Hames9ff69c82015-04-24 19:11:51 +0000555 MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
Logan Chien8cbb80d2013-10-28 17:51:12 +0000556 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
Jim Grosbach25cd3bf2010-10-06 22:46:47 +0000557
Charlie Turner8b2caa42015-01-05 13:12:17 +0000558 ATS.emitTextAttribute(ARMBuildAttrs::conformance, "2.09");
559
Logan Chien8cbb80d2013-10-28 17:51:12 +0000560 ATS.switchVendor("aeabi");
Rafael Espindola0ed15432010-10-25 17:50:35 +0000561
Eric Christophera49d68e2015-02-17 20:02:32 +0000562 // Compute ARM ELF Attributes based on the default subtarget that
563 // we'd have constructed. The existing ARM behavior isn't LTO clean
564 // anyhow.
565 // FIXME: For ifunc related functions we could iterate over and look
566 // for a feature string that doesn't match the default one.
567 StringRef TT = TM.getTargetTriple();
568 StringRef CPU = TM.getTargetCPU();
569 StringRef FS = TM.getTargetFeatureString();
570 std::string ArchFS = ARM_MC::ParseARMTriple(TT, CPU);
571 if (!FS.empty()) {
572 if (!ArchFS.empty())
Yaron Keren075759a2015-03-30 15:42:36 +0000573 ArchFS = (Twine(ArchFS) + "," + FS).str();
Eric Christophera49d68e2015-02-17 20:02:32 +0000574 else
575 ArchFS = FS;
576 }
577 const ARMBaseTargetMachine &ATM =
578 static_cast<const ARMBaseTargetMachine &>(TM);
579 const ARMSubtarget STI(TT, CPU, ArchFS, ATM, ATM.isLittleEndian());
580
581 std::string CPUString = STI.getCPUString();
Jason W Kim85b0af12011-02-07 00:49:53 +0000582
Vladimir Sukharevc632cda2015-03-26 17:05:54 +0000583 if (CPUString.find("generic") != 0) { //CPUString doesn't start with "generic"
Sumanth Gundapaneni28a3b862015-02-26 18:08:41 +0000584 // FIXME: remove krait check when GNU tools support krait cpu
585 if (STI.isKrait()) {
586 ATS.emitTextAttribute(ARMBuildAttrs::CPU_name, "cortex-a9");
587 // We consider krait as a "cortex-a9" + hwdiv CPU
588 // Enable hwdiv through ".arch_extension idiv"
589 if (STI.hasDivide() || STI.hasDivideInARMMode())
Renato Golin35de35d2015-05-12 10:33:58 +0000590 ATS.emitArchExtension(ARM::AEK_HWDIV);
Sumanth Gundapaneni28a3b862015-02-26 18:08:41 +0000591 } else
592 ATS.emitTextAttribute(ARMBuildAttrs::CPU_name, CPUString);
593 }
Amara Emerson5035ee02013-10-07 16:55:23 +0000594
Eric Christophera49d68e2015-02-17 20:02:32 +0000595 ATS.emitAttribute(ARMBuildAttrs::CPU_arch, getArchForCPU(CPUString, &STI));
Amara Emerson5035ee02013-10-07 16:55:23 +0000596
Artyom Skrobov4d91d942014-01-10 16:42:55 +0000597 // Tag_CPU_arch_profile must have the default value of 0 when "Architecture
Jim Grosbach1a597112014-04-03 23:43:18 +0000598 // profile is not applicable (e.g. pre v7, or cross-profile code)".
Eric Christophera49d68e2015-02-17 20:02:32 +0000599 if (STI.hasV7Ops()) {
600 if (STI.isAClass()) {
Artyom Skrobov4d91d942014-01-10 16:42:55 +0000601 ATS.emitAttribute(ARMBuildAttrs::CPU_arch_profile,
602 ARMBuildAttrs::ApplicationProfile);
Eric Christophera49d68e2015-02-17 20:02:32 +0000603 } else if (STI.isRClass()) {
Artyom Skrobov4d91d942014-01-10 16:42:55 +0000604 ATS.emitAttribute(ARMBuildAttrs::CPU_arch_profile,
605 ARMBuildAttrs::RealTimeProfile);
Eric Christophera49d68e2015-02-17 20:02:32 +0000606 } else if (STI.isMClass()) {
Artyom Skrobov4d91d942014-01-10 16:42:55 +0000607 ATS.emitAttribute(ARMBuildAttrs::CPU_arch_profile,
608 ARMBuildAttrs::MicroControllerProfile);
609 }
Amara Emerson5035ee02013-10-07 16:55:23 +0000610 }
Jason W Kim85b0af12011-02-07 00:49:53 +0000611
Eric Christophera49d68e2015-02-17 20:02:32 +0000612 ATS.emitAttribute(ARMBuildAttrs::ARM_ISA_use,
613 STI.hasARMOps() ? ARMBuildAttrs::Allowed
614 : ARMBuildAttrs::Not_Allowed);
615 if (STI.isThumb1Only()) {
616 ATS.emitAttribute(ARMBuildAttrs::THUMB_ISA_use, ARMBuildAttrs::Allowed);
617 } else if (STI.hasThumb2()) {
Logan Chien8cbb80d2013-10-28 17:51:12 +0000618 ATS.emitAttribute(ARMBuildAttrs::THUMB_ISA_use,
619 ARMBuildAttrs::AllowThumb32);
Amara Emerson5035ee02013-10-07 16:55:23 +0000620 }
Jason W Kimbff84d42010-10-06 22:36:46 +0000621
Eric Christophera49d68e2015-02-17 20:02:32 +0000622 if (STI.hasNEON()) {
Renato Golinec0fc7d2011-02-28 22:04:27 +0000623 /* NEON is not exactly a VFP architecture, but GAS emit one of
Joey Gouly3c0e5562013-09-13 11:51:52 +0000624 * neon/neon-fp-armv8/neon-vfpv4/vfpv3/vfpv2 for .fpu parameters */
Eric Christophera49d68e2015-02-17 20:02:32 +0000625 if (STI.hasFPARMv8()) {
626 if (STI.hasCrypto())
Renato Golin35de35d2015-05-12 10:33:58 +0000627 ATS.emitFPU(ARM::FK_CRYPTO_NEON_FP_ARMV8);
Amara Emerson5035ee02013-10-07 16:55:23 +0000628 else
Renato Golin35de35d2015-05-12 10:33:58 +0000629 ATS.emitFPU(ARM::FK_NEON_FP_ARMV8);
Eric Christophera49d68e2015-02-17 20:02:32 +0000630 } else if (STI.hasVFP4())
Renato Golin35de35d2015-05-12 10:33:58 +0000631 ATS.emitFPU(ARM::FK_NEON_VFPV4);
Anton Korobeynikov5482b9f2012-01-22 12:07:33 +0000632 else
Renato Golin35de35d2015-05-12 10:33:58 +0000633 ATS.emitFPU(ARM::FK_NEON);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000634 // Emit Tag_Advanced_SIMD_arch for ARMv8 architecture
Eric Christophera49d68e2015-02-17 20:02:32 +0000635 if (STI.hasV8Ops())
Logan Chien8cbb80d2013-10-28 17:51:12 +0000636 ATS.emitAttribute(ARMBuildAttrs::Advanced_SIMD_arch,
Vladimir Sukharev2afdb322015-04-01 14:54:56 +0000637 STI.hasV8_1aOps() ? ARMBuildAttrs::AllowNeonARMv8_1a:
638 ARMBuildAttrs::AllowNeonARMv8);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000639 } else {
Eric Christophera49d68e2015-02-17 20:02:32 +0000640 if (STI.hasFPARMv8())
Oliver Stannard37e4daa2014-10-01 09:02:17 +0000641 // FPv5 and FP-ARMv8 have the same instructions, so are modeled as one
642 // FPU, but there are two different names for it depending on the CPU.
Renato Golin35de35d2015-05-12 10:33:58 +0000643 ATS.emitFPU(STI.hasD16() ? ARM::FK_FPV5_D16 : ARM::FK_FP_ARMV8);
Eric Christophera49d68e2015-02-17 20:02:32 +0000644 else if (STI.hasVFP4())
Renato Golin35de35d2015-05-12 10:33:58 +0000645 ATS.emitFPU(STI.hasD16() ? ARM::FK_VFPV4_D16 : ARM::FK_VFPV4);
Eric Christophera49d68e2015-02-17 20:02:32 +0000646 else if (STI.hasVFP3())
Renato Golin35de35d2015-05-12 10:33:58 +0000647 ATS.emitFPU(STI.hasD16() ? ARM::FK_VFPV3_D16 : ARM::FK_VFPV3);
Eric Christophera49d68e2015-02-17 20:02:32 +0000648 else if (STI.hasVFP2())
Renato Golin35de35d2015-05-12 10:33:58 +0000649 ATS.emitFPU(ARM::FK_VFPV2);
Renato Golinec0fc7d2011-02-28 22:04:27 +0000650 }
Jason W Kimbff84d42010-10-06 22:36:46 +0000651
Amara Emersonceeb1c42014-05-27 13:30:21 +0000652 if (TM.getRelocationModel() == Reloc::PIC_) {
653 // PIC specific attributes.
654 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RW_data,
655 ARMBuildAttrs::AddressRWPCRel);
656 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RO_data,
657 ARMBuildAttrs::AddressROPCRel);
658 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_GOT_use,
659 ARMBuildAttrs::AddressGOT);
660 } else {
661 // Allow direct addressing of imported data for all other relocation models.
662 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_GOT_use,
663 ARMBuildAttrs::AddressDirect);
664 }
665
Jason W Kimbff84d42010-10-06 22:36:46 +0000666 // Signal various FP modes.
Amara Emersonac695082013-10-11 16:03:43 +0000667 if (!TM.Options.UnsafeFPMath) {
Charlie Turner15f91c52014-12-02 08:22:29 +0000668 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
669 ARMBuildAttrs::IEEEDenormals);
Eric Christophera49d68e2015-02-17 20:02:32 +0000670 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions, ARMBuildAttrs::Allowed);
Charlie Turnerf02c9242014-12-03 08:12:26 +0000671
672 // If the user has permitted this code to choose the IEEE 754
673 // rounding at run-time, emit the rounding attribute.
674 if (TM.Options.HonorSignDependentRoundingFPMathOption)
Eric Christophera49d68e2015-02-17 20:02:32 +0000675 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_rounding, ARMBuildAttrs::Allowed);
Charlie Turner15f91c52014-12-02 08:22:29 +0000676 } else {
Eric Christophera49d68e2015-02-17 20:02:32 +0000677 if (!STI.hasVFP2()) {
Charlie Turner15f91c52014-12-02 08:22:29 +0000678 // When the target doesn't have an FPU (by design or
679 // intention), the assumptions made on the software support
680 // mirror that of the equivalent hardware support *if it
681 // existed*. For v7 and better we indicate that denormals are
682 // flushed preserving sign, and for V6 we indicate that
683 // denormals are flushed to positive zero.
Eric Christophera49d68e2015-02-17 20:02:32 +0000684 if (STI.hasV7Ops())
Charlie Turner15f91c52014-12-02 08:22:29 +0000685 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
686 ARMBuildAttrs::PreserveFPSign);
Eric Christophera49d68e2015-02-17 20:02:32 +0000687 } else if (STI.hasVFP3()) {
Charlie Turner15f91c52014-12-02 08:22:29 +0000688 // In VFPv4, VFPv4U, VFPv3, or VFPv3U, it is preserved. That is,
689 // the sign bit of the zero matches the sign bit of the input or
690 // result that is being flushed to zero.
691 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
692 ARMBuildAttrs::PreserveFPSign);
693 }
694 // For VFPv2 implementations it is implementation defined as
695 // to whether denormals are flushed to positive zero or to
696 // whatever the sign of zero is (ARM v7AR ARM 2.7.5). Historically
697 // LLVM has chosen to flush this to positive zero (most likely for
698 // GCC compatibility), so that's the chosen value here (the
699 // absence of its emission implies zero).
Amara Emerson5035ee02013-10-07 16:55:23 +0000700 }
Jason W Kimbff84d42010-10-06 22:36:46 +0000701
Charlie Turnerc96e95c2014-12-05 08:22:47 +0000702 // TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath is the
703 // equivalent of GCC's -ffinite-math-only flag.
Amara Emersonac695082013-10-11 16:03:43 +0000704 if (TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath)
Logan Chien8cbb80d2013-10-28 17:51:12 +0000705 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model,
706 ARMBuildAttrs::Allowed);
Amara Emersonac695082013-10-11 16:03:43 +0000707 else
Logan Chien8cbb80d2013-10-28 17:51:12 +0000708 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model,
709 ARMBuildAttrs::AllowIEE754);
Amara Emersonac695082013-10-11 16:03:43 +0000710
Eric Christophera49d68e2015-02-17 20:02:32 +0000711 if (STI.allowsUnalignedMem())
Renato Golin0595a262014-10-08 12:26:22 +0000712 ATS.emitAttribute(ARMBuildAttrs::CPU_unaligned_access,
713 ARMBuildAttrs::Allowed);
714 else
715 ATS.emitAttribute(ARMBuildAttrs::CPU_unaligned_access,
716 ARMBuildAttrs::Not_Allowed);
717
Saleem Abdulrasool278a9f42014-01-19 08:25:27 +0000718 // FIXME: add more flags to ARMBuildAttributes.h
Jason W Kimbff84d42010-10-06 22:36:46 +0000719 // 8-bytes alignment stuff.
Saleem Abdulrasool196c3212014-01-19 08:25:35 +0000720 ATS.emitAttribute(ARMBuildAttrs::ABI_align_needed, 1);
721 ATS.emitAttribute(ARMBuildAttrs::ABI_align_preserved, 1);
Jason W Kimbff84d42010-10-06 22:36:46 +0000722
Bradley Smithc848beb2013-11-01 11:21:16 +0000723 // ABI_HardFP_use attribute to indicate single precision FP.
Eric Christophera49d68e2015-02-17 20:02:32 +0000724 if (STI.isFPOnlySP())
Bradley Smithc848beb2013-11-01 11:21:16 +0000725 ATS.emitAttribute(ARMBuildAttrs::ABI_HardFP_use,
726 ARMBuildAttrs::HardFPSinglePrecision);
727
Jason W Kimbff84d42010-10-06 22:36:46 +0000728 // Hard float. Use both S and D registers and conform to AAPCS-VFP.
Eric Christophera49d68e2015-02-17 20:02:32 +0000729 if (STI.isAAPCS_ABI() && TM.Options.FloatABIType == FloatABI::Hard)
Bradley Smithc848beb2013-11-01 11:21:16 +0000730 ATS.emitAttribute(ARMBuildAttrs::ABI_VFP_args, ARMBuildAttrs::HardFPAAPCS);
731
Jason W Kimbff84d42010-10-06 22:36:46 +0000732 // FIXME: Should we signal R9 usage?
Rafael Espindola0ed15432010-10-25 17:50:35 +0000733
Eric Christophera49d68e2015-02-17 20:02:32 +0000734 if (STI.hasFP16())
735 ATS.emitAttribute(ARMBuildAttrs::FP_HP_extension, ARMBuildAttrs::AllowHPFP);
Bradley Smith9aa8ac92013-11-12 10:38:05 +0000736
Charlie Turner1a539962014-12-12 11:59:18 +0000737 // FIXME: To support emitting this build attribute as GCC does, the
738 // -mfp16-format option and associated plumbing must be
739 // supported. For now the __fp16 type is exposed by default, so this
740 // attribute should be emitted with value 1.
741 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_16bit_format,
742 ARMBuildAttrs::FP16FormatIEEE);
743
Eric Christophera49d68e2015-02-17 20:02:32 +0000744 if (STI.hasMPExtension())
745 ATS.emitAttribute(ARMBuildAttrs::MPextension_use, ARMBuildAttrs::AllowMP);
Bradley Smith25219752013-11-01 13:27:35 +0000746
Artyom Skrobov10e76a42014-01-20 10:18:42 +0000747 // Hardware divide in ARM mode is part of base arch, starting from ARMv8.
748 // If only Thumb hwdiv is present, it must also be in base arch (ARMv7-R/M).
749 // It is not possible to produce DisallowDIV: if hwdiv is present in the base
750 // arch, supplying -hwdiv downgrades the effective arch, via ClearImpliedBits.
751 // AllowDIVExt is only emitted if hwdiv isn't available in the base arch;
752 // otherwise, the default value (AllowDIVIfExists) applies.
Eric Christophera49d68e2015-02-17 20:02:32 +0000753 if (STI.hasDivideInARMMode() && !STI.hasV8Ops())
754 ATS.emitAttribute(ARMBuildAttrs::DIV_use, ARMBuildAttrs::AllowDIVExt);
Rafael Espindola0ed15432010-10-25 17:50:35 +0000755
Oliver Stannard5dc29342014-06-20 10:08:11 +0000756 if (MMI) {
757 if (const Module *SourceModule = MMI->getModule()) {
758 // ABI_PCS_wchar_t to indicate wchar_t width
759 // FIXME: There is no way to emit value 0 (wchar_t prohibited).
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000760 if (auto WCharWidthValue = mdconst::extract_or_null<ConstantInt>(
Oliver Stannard5dc29342014-06-20 10:08:11 +0000761 SourceModule->getModuleFlag("wchar_size"))) {
762 int WCharWidth = WCharWidthValue->getZExtValue();
763 assert((WCharWidth == 2 || WCharWidth == 4) &&
764 "wchar_t width must be 2 or 4 bytes");
765 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_wchar_t, WCharWidth);
766 }
767
768 // ABI_enum_size to indicate enum width
769 // FIXME: There is no way to emit value 0 (enums prohibited) or value 3
770 // (all enums contain a value needing 32 bits to encode).
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000771 if (auto EnumWidthValue = mdconst::extract_or_null<ConstantInt>(
Oliver Stannard5dc29342014-06-20 10:08:11 +0000772 SourceModule->getModuleFlag("min_enum_size"))) {
773 int EnumWidth = EnumWidthValue->getZExtValue();
774 assert((EnumWidth == 1 || EnumWidth == 4) &&
775 "Minimum enum width must be 1 or 4 bytes");
776 int EnumBuildAttr = EnumWidth == 1 ? 1 : 2;
777 ATS.emitAttribute(ARMBuildAttrs::ABI_enum_size, EnumBuildAttr);
778 }
779 }
780 }
781
Amara Emerson115d2df2014-07-25 14:03:14 +0000782 // TODO: We currently only support either reserving the register, or treating
783 // it as another callee-saved register, but not as SB or a TLS pointer; It
784 // would instead be nicer to push this from the frontend as metadata, as we do
785 // for the wchar and enum size tags
Eric Christophera49d68e2015-02-17 20:02:32 +0000786 if (STI.isR9Reserved())
787 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use, ARMBuildAttrs::R9Reserved);
Amara Emerson115d2df2014-07-25 14:03:14 +0000788 else
Eric Christophera49d68e2015-02-17 20:02:32 +0000789 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use, ARMBuildAttrs::R9IsGPR);
Amara Emerson115d2df2014-07-25 14:03:14 +0000790
Eric Christophera49d68e2015-02-17 20:02:32 +0000791 if (STI.hasTrustZone() && STI.hasVirtualization())
792 ATS.emitAttribute(ARMBuildAttrs::Virtualization_use,
793 ARMBuildAttrs::AllowTZVirtualization);
794 else if (STI.hasTrustZone())
795 ATS.emitAttribute(ARMBuildAttrs::Virtualization_use,
796 ARMBuildAttrs::AllowTZ);
797 else if (STI.hasVirtualization())
798 ATS.emitAttribute(ARMBuildAttrs::Virtualization_use,
799 ARMBuildAttrs::AllowVirtualization);
Bradley Smith25219752013-11-01 13:27:35 +0000800
Logan Chien8cbb80d2013-10-28 17:51:12 +0000801 ATS.finishAttributeSection();
Jason W Kimbff84d42010-10-06 22:36:46 +0000802}
803
Jason W Kimbff84d42010-10-06 22:36:46 +0000804//===----------------------------------------------------------------------===//
Chris Lattner71eb0772009-10-19 20:20:46 +0000805
Jim Grosbachaf5d6352010-09-18 00:05:05 +0000806static MCSymbol *getPICLabel(const char *Prefix, unsigned FunctionNumber,
807 unsigned LabelId, MCContext &Ctx) {
808
809 MCSymbol *Label = Ctx.GetOrCreateSymbol(Twine(Prefix)
810 + "PC" + Twine(FunctionNumber) + "_" + Twine(LabelId));
811 return Label;
812}
813
Jim Grosbachf23b2d92010-11-10 03:26:07 +0000814static MCSymbolRefExpr::VariantKind
815getModifierVariantKind(ARMCP::ARMCPModifier Modifier) {
816 switch (Modifier) {
Jim Grosbachf23b2d92010-11-10 03:26:07 +0000817 case ARMCP::no_modifier: return MCSymbolRefExpr::VK_None;
David Peixotto8ad70b32013-12-04 22:43:20 +0000818 case ARMCP::TLSGD: return MCSymbolRefExpr::VK_TLSGD;
819 case ARMCP::TPOFF: return MCSymbolRefExpr::VK_TPOFF;
820 case ARMCP::GOTTPOFF: return MCSymbolRefExpr::VK_GOTTPOFF;
821 case ARMCP::GOT: return MCSymbolRefExpr::VK_GOT;
822 case ARMCP::GOTOFF: return MCSymbolRefExpr::VK_GOTOFF;
Jim Grosbachf23b2d92010-11-10 03:26:07 +0000823 }
David Blaikie46a9f012012-01-20 21:51:11 +0000824 llvm_unreachable("Invalid ARMCPModifier!");
Jim Grosbachf23b2d92010-11-10 03:26:07 +0000825}
826
Tim Northoverdb962e2c2013-11-25 16:24:52 +0000827MCSymbol *ARMAsmPrinter::GetARMGVSymbol(const GlobalValue *GV,
828 unsigned char TargetFlags) {
Saleem Abdulrasool220a0442014-07-07 05:18:30 +0000829 if (Subtarget->isTargetMachO()) {
830 bool IsIndirect = (TargetFlags & ARMII::MO_NONLAZY) &&
831 Subtarget->GVIsIndirectSymbol(GV, TM.getRelocationModel());
Evan Chengdfce83c2011-01-17 08:03:18 +0000832
Saleem Abdulrasool220a0442014-07-07 05:18:30 +0000833 if (!IsIndirect)
834 return getSymbol(GV);
835
836 // FIXME: Remove this when Darwin transition to @GOT like syntax.
837 MCSymbol *MCSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
838 MachineModuleInfoMachO &MMIMachO =
839 MMI->getObjFileInfo<MachineModuleInfoMachO>();
840 MachineModuleInfoImpl::StubValueTy &StubSym =
841 GV->hasHiddenVisibility() ? MMIMachO.getHiddenGVStubEntry(MCSym)
842 : MMIMachO.getGVStubEntry(MCSym);
843 if (!StubSym.getPointer())
844 StubSym = MachineModuleInfoImpl::StubValueTy(getSymbol(GV),
845 !GV->hasInternalLinkage());
846 return MCSym;
847 } else if (Subtarget->isTargetCOFF()) {
848 assert(Subtarget->isTargetWindows() &&
849 "Windows is the only supported COFF target");
850
851 bool IsIndirect = (TargetFlags & ARMII::MO_DLLIMPORT);
852 if (!IsIndirect)
853 return getSymbol(GV);
854
855 SmallString<128> Name;
856 Name = "__imp_";
857 getNameWithPrefix(Name, GV);
858
859 return OutContext.GetOrCreateSymbol(Name);
860 } else if (Subtarget->isTargetELF()) {
861 return getSymbol(GV);
862 }
863 llvm_unreachable("unexpected target");
Evan Chengdfce83c2011-01-17 08:03:18 +0000864}
865
Jim Grosbach38f8e762010-11-09 18:45:04 +0000866void ARMAsmPrinter::
867EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
Eric Christopher8b770652015-01-26 19:03:15 +0000868 const DataLayout *DL = TM.getDataLayout();
869 int Size = TM.getDataLayout()->getTypeAllocSize(MCPV->getType());
Jim Grosbach38f8e762010-11-09 18:45:04 +0000870
871 ARMConstantPoolValue *ACPV = static_cast<ARMConstantPoolValue*>(MCPV);
Jim Grosbach38f8e762010-11-09 18:45:04 +0000872
Jim Grosbachca21cd72010-11-10 17:59:10 +0000873 MCSymbol *MCSym;
Jim Grosbach38f8e762010-11-09 18:45:04 +0000874 if (ACPV->isLSDA()) {
Rafael Espindoladc4263c2015-03-17 13:57:48 +0000875 MCSym = getCurExceptionSym();
Jim Grosbach38f8e762010-11-09 18:45:04 +0000876 } else if (ACPV->isBlockAddress()) {
Bill Wendling7753d662011-10-01 08:00:54 +0000877 const BlockAddress *BA =
878 cast<ARMConstantPoolConstant>(ACPV)->getBlockAddress();
879 MCSym = GetBlockAddressSymbol(BA);
Jim Grosbach38f8e762010-11-09 18:45:04 +0000880 } else if (ACPV->isGlobalValue()) {
Bill Wendling7753d662011-10-01 08:00:54 +0000881 const GlobalValue *GV = cast<ARMConstantPoolConstant>(ACPV)->getGV();
Tim Northoverdb962e2c2013-11-25 16:24:52 +0000882
883 // On Darwin, const-pool entries may get the "FOO$non_lazy_ptr" mangling, so
884 // flag the global as MO_NONLAZY.
Tim Northoverd6a729b2014-01-06 14:28:05 +0000885 unsigned char TF = Subtarget->isTargetMachO() ? ARMII::MO_NONLAZY : 0;
Tim Northoverd34094e2013-11-25 17:04:35 +0000886 MCSym = GetARMGVSymbol(GV, TF);
Bill Wendling69bc3de2011-09-29 23:50:42 +0000887 } else if (ACPV->isMachineBasicBlock()) {
Bill Wendling4a4772f2011-10-01 09:30:42 +0000888 const MachineBasicBlock *MBB = cast<ARMConstantPoolMBB>(ACPV)->getMBB();
Bill Wendling69bc3de2011-09-29 23:50:42 +0000889 MCSym = MBB->getSymbol();
Jim Grosbach38f8e762010-11-09 18:45:04 +0000890 } else {
891 assert(ACPV->isExtSymbol() && "unrecognized constant pool value");
Bill Wendlingc214cb02011-10-01 08:58:29 +0000892 const char *Sym = cast<ARMConstantPoolSymbol>(ACPV)->getSymbol();
893 MCSym = GetExternalSymbolSymbol(Sym);
Jim Grosbach38f8e762010-11-09 18:45:04 +0000894 }
895
896 // Create an MCSymbol for the reference.
Jim Grosbachf23b2d92010-11-10 03:26:07 +0000897 const MCExpr *Expr =
898 MCSymbolRefExpr::Create(MCSym, getModifierVariantKind(ACPV->getModifier()),
899 OutContext);
Jim Grosbach38f8e762010-11-09 18:45:04 +0000900
Jim Grosbachf23b2d92010-11-10 03:26:07 +0000901 if (ACPV->getPCAdjustment()) {
Rafael Espindola58873562014-01-03 19:21:54 +0000902 MCSymbol *PCLabel = getPICLabel(DL->getPrivateGlobalPrefix(),
Jim Grosbachf23b2d92010-11-10 03:26:07 +0000903 getFunctionNumber(),
904 ACPV->getLabelId(),
905 OutContext);
906 const MCExpr *PCRelExpr = MCSymbolRefExpr::Create(PCLabel, OutContext);
907 PCRelExpr =
908 MCBinaryExpr::CreateAdd(PCRelExpr,
909 MCConstantExpr::Create(ACPV->getPCAdjustment(),
910 OutContext),
911 OutContext);
912 if (ACPV->mustAddCurrentAddress()) {
913 // We want "(<expr> - .)", but MC doesn't have a concept of the '.'
914 // label, so just emit a local label end reference that instead.
915 MCSymbol *DotSym = OutContext.CreateTempSymbol();
Lang Hames9ff69c82015-04-24 19:11:51 +0000916 OutStreamer->EmitLabel(DotSym);
Jim Grosbachf23b2d92010-11-10 03:26:07 +0000917 const MCExpr *DotExpr = MCSymbolRefExpr::Create(DotSym, OutContext);
918 PCRelExpr = MCBinaryExpr::CreateSub(PCRelExpr, DotExpr, OutContext);
Jim Grosbach38f8e762010-11-09 18:45:04 +0000919 }
Jim Grosbachf23b2d92010-11-10 03:26:07 +0000920 Expr = MCBinaryExpr::CreateSub(Expr, PCRelExpr, OutContext);
Jim Grosbach38f8e762010-11-09 18:45:04 +0000921 }
Lang Hames9ff69c82015-04-24 19:11:51 +0000922 OutStreamer->EmitValue(Expr, Size);
Jim Grosbach38f8e762010-11-09 18:45:04 +0000923}
924
Tim Northover12c41af2015-05-18 17:10:40 +0000925void ARMAsmPrinter::EmitJumpTableAddrs(const MachineInstr *MI) {
926 const MachineOperand &MO1 = MI->getOperand(1);
Jim Grosbach284eebc2010-09-22 17:39:48 +0000927 unsigned JTI = MO1.getIndex();
928
Tim Northover12c41af2015-05-18 17:10:40 +0000929 // Make sure the Thumb jump table is 4-byte aligned. This will be a nop for
930 // ARM mode tables.
931 EmitAlignment(2);
932
Jim Grosbach284eebc2010-09-22 17:39:48 +0000933 // Emit a label for the jump table.
Tim Northover4998a472015-05-13 20:28:38 +0000934 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);
Lang Hames9ff69c82015-04-24 19:11:51 +0000935 OutStreamer->EmitLabel(JTISymbol);
Jim Grosbach284eebc2010-09-22 17:39:48 +0000936
Jim Grosbach4b63d2a2012-05-18 19:12:01 +0000937 // Mark the jump table as data-in-code.
Lang Hames9ff69c82015-04-24 19:11:51 +0000938 OutStreamer->EmitDataRegion(MCDR_DataRegionJT32);
Jim Grosbach4b63d2a2012-05-18 19:12:01 +0000939
Jim Grosbach284eebc2010-09-22 17:39:48 +0000940 // Emit each entry of the table.
941 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
942 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
943 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
944
945 for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) {
946 MachineBasicBlock *MBB = JTBBs[i];
947 // Construct an MCExpr for the entry. We want a value of the form:
948 // (BasicBlockAddr - TableBeginAddr)
949 //
950 // For example, a table with entries jumping to basic blocks BB0 and BB1
951 // would look like:
952 // LJTI_0_0:
953 // .word (LBB0 - LJTI_0_0)
954 // .word (LBB1 - LJTI_0_0)
955 const MCExpr *Expr = MCSymbolRefExpr::Create(MBB->getSymbol(), OutContext);
956
957 if (TM.getRelocationModel() == Reloc::PIC_)
958 Expr = MCBinaryExpr::CreateSub(Expr, MCSymbolRefExpr::Create(JTISymbol,
959 OutContext),
960 OutContext);
Jim Grosbache1995f22011-08-31 22:23:09 +0000961 // If we're generating a table of Thumb addresses in static relocation
962 // model, we need to add one to keep interworking correctly.
963 else if (AFI->isThumbFunction())
964 Expr = MCBinaryExpr::CreateAdd(Expr, MCConstantExpr::Create(1,OutContext),
965 OutContext);
Lang Hames9ff69c82015-04-24 19:11:51 +0000966 OutStreamer->EmitValue(Expr, 4);
Jim Grosbach284eebc2010-09-22 17:39:48 +0000967 }
Jim Grosbach4b63d2a2012-05-18 19:12:01 +0000968 // Mark the end of jump table data-in-code region.
Lang Hames9ff69c82015-04-24 19:11:51 +0000969 OutStreamer->EmitDataRegion(MCDR_DataRegionEnd);
Jim Grosbach284eebc2010-09-22 17:39:48 +0000970}
971
Tim Northover12c41af2015-05-18 17:10:40 +0000972void ARMAsmPrinter::EmitJumpTableInsts(const MachineInstr *MI) {
973 const MachineOperand &MO1 = MI->getOperand(1);
Jim Grosbachd64f9b82010-09-21 23:28:16 +0000974 unsigned JTI = MO1.getIndex();
975
Tim Northover4998a472015-05-13 20:28:38 +0000976 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);
Lang Hames9ff69c82015-04-24 19:11:51 +0000977 OutStreamer->EmitLabel(JTISymbol);
Jim Grosbachd64f9b82010-09-21 23:28:16 +0000978
979 // Emit each entry of the table.
980 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
981 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
982 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
Jim Grosbachd64f9b82010-09-21 23:28:16 +0000983
984 for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) {
985 MachineBasicBlock *MBB = JTBBs[i];
Jim Grosbach1573b292010-09-22 17:15:35 +0000986 const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::Create(MBB->getSymbol(),
Saleem Abdulrasool1eb4a282014-07-07 05:18:22 +0000987 OutContext);
Jim Grosbachd64f9b82010-09-21 23:28:16 +0000988 // If this isn't a TBB or TBH, the entries are direct branch instructions.
Tim Northover12c41af2015-05-18 17:10:40 +0000989 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::t2B)
Benjamin Kramer4e629f72012-11-26 13:34:22 +0000990 .addExpr(MBBSymbolExpr)
991 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +0000992 .addReg(0));
Tim Northover12c41af2015-05-18 17:10:40 +0000993 }
994}
995
996void ARMAsmPrinter::EmitJumpTableTBInst(const MachineInstr *MI,
997 unsigned OffsetWidth) {
998 assert((OffsetWidth == 1 || OffsetWidth == 2) && "invalid tbb/tbh width");
999 const MachineOperand &MO1 = MI->getOperand(1);
1000 unsigned JTI = MO1.getIndex();
1001
1002 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);
1003 OutStreamer->EmitLabel(JTISymbol);
1004
1005 // Emit each entry of the table.
1006 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
1007 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
1008 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
1009
1010 // Mark the jump table as data-in-code.
1011 OutStreamer->EmitDataRegion(OffsetWidth == 1 ? MCDR_DataRegionJT8
1012 : MCDR_DataRegionJT16);
1013
1014 for (auto MBB : JTBBs) {
1015 const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::Create(MBB->getSymbol(),
1016 OutContext);
Jim Grosbachd64f9b82010-09-21 23:28:16 +00001017 // Otherwise it's an offset from the dispatch instruction. Construct an
Jim Grosbach1573b292010-09-22 17:15:35 +00001018 // MCExpr for the entry. We want a value of the form:
Tim Northover12c41af2015-05-18 17:10:40 +00001019 // (BasicBlockAddr - TBBInstAddr + 4) / 2
Jim Grosbach1573b292010-09-22 17:15:35 +00001020 //
1021 // For example, a TBB table with entries jumping to basic blocks BB0 and BB1
1022 // would look like:
1023 // LJTI_0_0:
Tim Northover12c41af2015-05-18 17:10:40 +00001024 // .byte (LBB0 - (LCPI0_0 + 4)) / 2
1025 // .byte (LBB1 - (LCPI0_0 + 4)) / 2
1026 // where LCPI0_0 is a label defined just before the TBB instruction using
1027 // this table.
1028 MCSymbol *TBInstPC = GetCPISymbol(MI->getOperand(0).getImm());
1029 const MCExpr *Expr = MCBinaryExpr::CreateAdd(
1030 MCSymbolRefExpr::Create(TBInstPC, OutContext),
1031 MCConstantExpr::Create(4, OutContext), OutContext);
1032 Expr = MCBinaryExpr::CreateSub(MBBSymbolExpr, Expr, OutContext);
Jim Grosbach1573b292010-09-22 17:15:35 +00001033 Expr = MCBinaryExpr::CreateDiv(Expr, MCConstantExpr::Create(2, OutContext),
1034 OutContext);
Lang Hames9ff69c82015-04-24 19:11:51 +00001035 OutStreamer->EmitValue(Expr, OffsetWidth);
Jim Grosbachd64f9b82010-09-21 23:28:16 +00001036 }
Jim Grosbach2597f832012-05-21 23:34:42 +00001037 // Mark the end of jump table data-in-code region. 32-bit offsets use
1038 // actual branch instructions here, so we don't mark those as a data-region
1039 // at all.
Tim Northover12c41af2015-05-18 17:10:40 +00001040 OutStreamer->EmitDataRegion(MCDR_DataRegionEnd);
1041
1042 // Make sure the next instruction is 2-byte aligned.
1043 EmitAlignment(1);
Jim Grosbachd64f9b82010-09-21 23:28:16 +00001044}
1045
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001046void ARMAsmPrinter::EmitUnwindingInstruction(const MachineInstr *MI) {
1047 assert(MI->getFlag(MachineInstr::FrameSetup) &&
1048 "Only instruction which are involved into frame setup code are allowed");
1049
Lang Hames9ff69c82015-04-24 19:11:51 +00001050 MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001051 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001052 const MachineFunction &MF = *MI->getParent()->getParent();
Eric Christopherfc6de422014-08-05 02:39:49 +00001053 const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
Anton Korobeynikov9e66cbb2011-03-05 18:43:55 +00001054 const ARMFunctionInfo &AFI = *MF.getInfo<ARMFunctionInfo>();
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001055
1056 unsigned FramePtr = RegInfo->getFrameRegister(MF);
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001057 unsigned Opc = MI->getOpcode();
Anton Korobeynikov51537f12011-03-05 18:43:43 +00001058 unsigned SrcReg, DstReg;
1059
Anton Korobeynikova8d177b2011-03-05 18:43:50 +00001060 if (Opc == ARM::tPUSH || Opc == ARM::tLDRpci) {
1061 // Two special cases:
1062 // 1) tPUSH does not have src/dst regs.
1063 // 2) for Thumb1 code we sometimes materialize the constant via constpool
1064 // load. Yes, this is pretty fragile, but for now I don't see better
1065 // way... :(
Anton Korobeynikov51537f12011-03-05 18:43:43 +00001066 SrcReg = DstReg = ARM::SP;
1067 } else {
Anton Korobeynikova8d177b2011-03-05 18:43:50 +00001068 SrcReg = MI->getOperand(1).getReg();
Anton Korobeynikov51537f12011-03-05 18:43:43 +00001069 DstReg = MI->getOperand(0).getReg();
1070 }
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001071
1072 // Try to figure out the unwinding opcode out of src / dst regs.
Evan Cheng7f8e5632011-12-07 07:15:52 +00001073 if (MI->mayStore()) {
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001074 // Register saves.
1075 assert(DstReg == ARM::SP &&
1076 "Only stack pointer as a destination reg is supported");
1077
1078 SmallVector<unsigned, 4> RegList;
Anton Korobeynikov51537f12011-03-05 18:43:43 +00001079 // Skip src & dst reg, and pred ops.
1080 unsigned StartOp = 2 + 2;
1081 // Use all the operands.
1082 unsigned NumOffset = 0;
1083
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001084 switch (Opc) {
1085 default:
1086 MI->dump();
Craig Toppere55c5562012-02-07 02:50:20 +00001087 llvm_unreachable("Unsupported opcode for unwinding information");
Anton Korobeynikov51537f12011-03-05 18:43:43 +00001088 case ARM::tPUSH:
1089 // Special case here: no src & dst reg, but two extra imp ops.
1090 StartOp = 2; NumOffset = 2;
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001091 case ARM::STMDB_UPD:
Anton Korobeynikov51537f12011-03-05 18:43:43 +00001092 case ARM::t2STMDB_UPD:
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001093 case ARM::VSTMDDB_UPD:
1094 assert(SrcReg == ARM::SP &&
1095 "Only stack pointer as a source reg is supported");
Anton Korobeynikov51537f12011-03-05 18:43:43 +00001096 for (unsigned i = StartOp, NumOps = MI->getNumOperands() - NumOffset;
Anton Korobeynikovef731ed2012-08-04 13:25:58 +00001097 i != NumOps; ++i) {
1098 const MachineOperand &MO = MI->getOperand(i);
1099 // Actually, there should never be any impdef stuff here. Skip it
1100 // temporary to workaround PR11902.
1101 if (MO.isImplicit())
1102 continue;
1103 RegList.push_back(MO.getReg());
1104 }
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001105 break;
Owen Anderson2aedba62011-07-26 20:54:26 +00001106 case ARM::STR_PRE_IMM:
1107 case ARM::STR_PRE_REG:
Evgeniy Stepanov4c7eb472012-01-19 12:53:06 +00001108 case ARM::t2STR_PRE:
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001109 assert(MI->getOperand(2).getReg() == ARM::SP &&
1110 "Only stack pointer as a source reg is supported");
1111 RegList.push_back(SrcReg);
1112 break;
1113 }
Joerg Sonnenberger3c108172014-04-30 22:43:13 +00001114 if (MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
1115 ATS.emitRegSave(RegList, Opc == ARM::VSTMDDB_UPD);
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001116 } else {
1117 // Changes of stack / frame pointer.
1118 if (SrcReg == ARM::SP) {
1119 int64_t Offset = 0;
1120 switch (Opc) {
1121 default:
1122 MI->dump();
Craig Toppere55c5562012-02-07 02:50:20 +00001123 llvm_unreachable("Unsupported opcode for unwinding information");
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001124 case ARM::MOVr:
Evgeniy Stepanov4c7eb472012-01-19 12:53:06 +00001125 case ARM::tMOVr:
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001126 Offset = 0;
1127 break;
1128 case ARM::ADDri:
1129 Offset = -MI->getOperand(2).getImm();
1130 break;
1131 case ARM::SUBri:
Evgeniy Stepanov4c7eb472012-01-19 12:53:06 +00001132 case ARM::t2SUBri:
Jim Grosbacha8a80672011-06-29 23:25:04 +00001133 Offset = MI->getOperand(2).getImm();
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001134 break;
Anton Korobeynikov51537f12011-03-05 18:43:43 +00001135 case ARM::tSUBspi:
Jim Grosbacha8a80672011-06-29 23:25:04 +00001136 Offset = MI->getOperand(2).getImm()*4;
Anton Korobeynikov51537f12011-03-05 18:43:43 +00001137 break;
1138 case ARM::tADDspi:
1139 case ARM::tADDrSPi:
1140 Offset = -MI->getOperand(2).getImm()*4;
1141 break;
Anton Korobeynikov9e66cbb2011-03-05 18:43:55 +00001142 case ARM::tLDRpci: {
1143 // Grab the constpool index and check, whether it corresponds to
1144 // original or cloned constpool entry.
1145 unsigned CPI = MI->getOperand(1).getIndex();
1146 const MachineConstantPool *MCP = MF.getConstantPool();
1147 if (CPI >= MCP->getConstants().size())
1148 CPI = AFI.getOriginalCPIdx(CPI);
1149 assert(CPI != -1U && "Invalid constpool index");
1150
1151 // Derive the actual offset.
1152 const MachineConstantPoolEntry &CPE = MCP->getConstants()[CPI];
1153 assert(!CPE.isMachineConstantPoolEntry() && "Invalid constpool entry");
1154 // FIXME: Check for user, it should be "add" instruction!
1155 Offset = -cast<ConstantInt>(CPE.Val.ConstVal)->getSExtValue();
Anton Korobeynikova8d177b2011-03-05 18:43:50 +00001156 break;
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001157 }
Anton Korobeynikov9e66cbb2011-03-05 18:43:55 +00001158 }
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001159
Joerg Sonnenberger3c108172014-04-30 22:43:13 +00001160 if (MAI->getExceptionHandlingType() == ExceptionHandling::ARM) {
1161 if (DstReg == FramePtr && FramePtr != ARM::SP)
1162 // Set-up of the frame pointer. Positive values correspond to "add"
1163 // instruction.
1164 ATS.emitSetFP(FramePtr, ARM::SP, -Offset);
1165 else if (DstReg == ARM::SP) {
1166 // Change of SP by an offset. Positive values correspond to "sub"
1167 // instruction.
1168 ATS.emitPad(Offset);
1169 } else {
1170 // Move of SP to a register. Positive values correspond to an "add"
1171 // instruction.
1172 ATS.emitMovSP(DstReg, -Offset);
1173 }
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001174 }
1175 } else if (DstReg == ARM::SP) {
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001176 MI->dump();
Craig Toppere55c5562012-02-07 02:50:20 +00001177 llvm_unreachable("Unsupported opcode for unwinding information");
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001178 }
1179 else {
1180 MI->dump();
Craig Toppere55c5562012-02-07 02:50:20 +00001181 llvm_unreachable("Unsupported opcode for unwinding information");
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001182 }
1183 }
1184}
1185
Jim Grosbach95dee402011-07-08 17:40:42 +00001186// Simple pseudo-instructions have their lowering (with expansion to real
1187// instructions) auto-generated.
1188#include "ARMGenMCPseudoLowering.inc"
1189
Jim Grosbach05eccf02010-09-29 15:23:40 +00001190void ARMAsmPrinter::EmitInstruction(const MachineInstr *MI) {
Eric Christopher8b770652015-01-26 19:03:15 +00001191 const DataLayout *DL = TM.getDataLayout();
Rafael Espindola58873562014-01-03 19:21:54 +00001192
Jim Grosbach4b63d2a2012-05-18 19:12:01 +00001193 // If we just ended a constant pool, mark it as such.
1194 if (InConstantPool && MI->getOpcode() != ARM::CONSTPOOL_ENTRY) {
Lang Hames9ff69c82015-04-24 19:11:51 +00001195 OutStreamer->EmitDataRegion(MCDR_DataRegionEnd);
Jim Grosbach4b63d2a2012-05-18 19:12:01 +00001196 InConstantPool = false;
1197 }
Owen Anderson0ca562e2011-10-04 23:26:17 +00001198
Jim Grosbach51b55422011-08-23 21:32:34 +00001199 // Emit unwinding stuff for frame-related instructions
Renato Golin78a6eba2014-02-07 20:12:49 +00001200 if (Subtarget->isTargetEHABICompatible() &&
Renato Golin8cea6e82014-01-29 11:50:56 +00001201 MI->getFlag(MachineInstr::FrameSetup))
Jim Grosbach51b55422011-08-23 21:32:34 +00001202 EmitUnwindingInstruction(MI);
1203
Jim Grosbach95dee402011-07-08 17:40:42 +00001204 // Do any auto-generated pseudo lowerings.
Lang Hames9ff69c82015-04-24 19:11:51 +00001205 if (emitPseudoExpansionLowering(*OutStreamer, MI))
Jim Grosbach95dee402011-07-08 17:40:42 +00001206 return;
1207
Andrew Trick924123a2011-09-21 02:20:46 +00001208 assert(!convertAddSubFlagsOpcode(MI->getOpcode()) &&
1209 "Pseudo flag setting opcode should be expanded early");
1210
Jim Grosbach95dee402011-07-08 17:40:42 +00001211 // Check for manual lowerings.
Evan Chengdfce83c2011-01-17 08:03:18 +00001212 unsigned Opc = MI->getOpcode();
1213 switch (Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00001214 case ARM::t2MOVi32imm: llvm_unreachable("Should be lowered by thumb2it pass");
David Blaikieb735b4d2013-06-16 20:34:27 +00001215 case ARM::DBG_VALUE: llvm_unreachable("Should be handled by generic printing");
Jim Grosbach8c1fabe2010-12-14 21:10:47 +00001216 case ARM::LEApcrel:
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001217 case ARM::tLEApcrel:
Jim Grosbach8c1fabe2010-12-14 21:10:47 +00001218 case ARM::t2LEApcrel: {
Jim Grosbachce2bd8d2010-12-02 00:28:45 +00001219 // FIXME: Need to also handle globals and externals
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001220 MCSymbol *CPISymbol = GetCPISymbol(MI->getOperand(1).getIndex());
Lang Hames9ff69c82015-04-24 19:11:51 +00001221 EmitToStreamer(*OutStreamer, MCInstBuilder(MI->getOpcode() ==
1222 ARM::t2LEApcrel ? ARM::t2ADR
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001223 : (MI->getOpcode() == ARM::tLEApcrel ? ARM::tADR
1224 : ARM::ADR))
1225 .addReg(MI->getOperand(0).getReg())
1226 .addExpr(MCSymbolRefExpr::Create(CPISymbol, OutContext))
1227 // Add predicate operands.
1228 .addImm(MI->getOperand(2).getImm())
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001229 .addReg(MI->getOperand(3).getReg()));
Jim Grosbachce2bd8d2010-12-02 00:28:45 +00001230 return;
1231 }
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001232 case ARM::LEApcrelJT:
1233 case ARM::tLEApcrelJT:
1234 case ARM::t2LEApcrelJT: {
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001235 MCSymbol *JTIPICSymbol =
Tim Northover4998a472015-05-13 20:28:38 +00001236 GetARMJTIPICJumpTableLabel(MI->getOperand(1).getIndex());
Lang Hames9ff69c82015-04-24 19:11:51 +00001237 EmitToStreamer(*OutStreamer, MCInstBuilder(MI->getOpcode() ==
1238 ARM::t2LEApcrelJT ? ARM::t2ADR
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001239 : (MI->getOpcode() == ARM::tLEApcrelJT ? ARM::tADR
1240 : ARM::ADR))
1241 .addReg(MI->getOperand(0).getReg())
1242 .addExpr(MCSymbolRefExpr::Create(JTIPICSymbol, OutContext))
1243 // Add predicate operands.
Tim Northover4998a472015-05-13 20:28:38 +00001244 .addImm(MI->getOperand(2).getImm())
1245 .addReg(MI->getOperand(3).getReg()));
Jim Grosbachdc35e062010-12-01 19:47:31 +00001246 return;
1247 }
Jim Grosbach3f2096e2011-03-12 00:45:26 +00001248 // Darwin call instructions are just normal call instructions with different
1249 // clobber semantics (they clobber R9).
Jim Grosbachcd5e30f2010-11-30 18:30:19 +00001250 case ARM::BX_CALL: {
Lang Hames9ff69c82015-04-24 19:11:51 +00001251 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001252 .addReg(ARM::LR)
1253 .addReg(ARM::PC)
Jim Grosbachcd5e30f2010-11-30 18:30:19 +00001254 // Add predicate operands.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001255 .addImm(ARMCC::AL)
1256 .addReg(0)
Jim Grosbachcd5e30f2010-11-30 18:30:19 +00001257 // Add 's' bit operand (always reg0 for this)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001258 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001259
Lang Hames9ff69c82015-04-24 19:11:51 +00001260 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::BX)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001261 .addReg(MI->getOperand(0).getReg()));
Jim Grosbachcd5e30f2010-11-30 18:30:19 +00001262 return;
1263 }
Cameron Zwaricha946f472011-05-25 21:53:50 +00001264 case ARM::tBX_CALL: {
Jonathan Roelofs300d8ff2014-12-04 19:34:50 +00001265 if (Subtarget->hasV5TOps())
1266 llvm_unreachable("Expected BLX to be selected for v5t+");
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001267
Jonathan Roelofs300d8ff2014-12-04 19:34:50 +00001268 // On ARM v4t, when doing a call from thumb mode, we need to ensure
1269 // that the saved lr has its LSB set correctly (the arch doesn't
1270 // have blx).
1271 // So here we generate a bl to a small jump pad that does bx rN.
1272 // The jump pads are emitted after the function body.
1273
1274 unsigned TReg = MI->getOperand(0).getReg();
1275 MCSymbol *TRegSym = nullptr;
1276 for (unsigned i = 0, e = ThumbIndirectPads.size(); i < e; i++) {
1277 if (ThumbIndirectPads[i].first == TReg) {
1278 TRegSym = ThumbIndirectPads[i].second;
1279 break;
1280 }
1281 }
1282
1283 if (!TRegSym) {
1284 TRegSym = OutContext.CreateTempSymbol();
1285 ThumbIndirectPads.push_back(std::make_pair(TReg, TRegSym));
1286 }
1287
1288 // Create a link-saving branch to the Reg Indirect Jump Pad.
Lang Hames9ff69c82015-04-24 19:11:51 +00001289 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tBL)
Jonathan Roelofs300d8ff2014-12-04 19:34:50 +00001290 // Predicate comes first here.
1291 .addImm(ARMCC::AL).addReg(0)
1292 .addExpr(MCSymbolRefExpr::Create(TRegSym, OutContext)));
Cameron Zwaricha946f472011-05-25 21:53:50 +00001293 return;
1294 }
Jim Grosbachcd5e30f2010-11-30 18:30:19 +00001295 case ARM::BMOVPCRX_CALL: {
Lang Hames9ff69c82015-04-24 19:11:51 +00001296 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001297 .addReg(ARM::LR)
1298 .addReg(ARM::PC)
Jim Grosbachcd5e30f2010-11-30 18:30:19 +00001299 // Add predicate operands.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001300 .addImm(ARMCC::AL)
1301 .addReg(0)
Jim Grosbachcd5e30f2010-11-30 18:30:19 +00001302 // Add 's' bit operand (always reg0 for this)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001303 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001304
Lang Hames9ff69c82015-04-24 19:11:51 +00001305 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001306 .addReg(ARM::PC)
Benjamin Kramer2f545712013-03-15 17:27:39 +00001307 .addReg(MI->getOperand(0).getReg())
Jim Grosbachcd5e30f2010-11-30 18:30:19 +00001308 // Add predicate operands.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001309 .addImm(ARMCC::AL)
1310 .addReg(0)
Jim Grosbachcd5e30f2010-11-30 18:30:19 +00001311 // Add 's' bit operand (always reg0 for this)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001312 .addReg(0));
Jim Grosbachcd5e30f2010-11-30 18:30:19 +00001313 return;
1314 }
Evan Cheng65f9d192012-02-28 18:51:51 +00001315 case ARM::BMOVPCB_CALL: {
Lang Hames9ff69c82015-04-24 19:11:51 +00001316 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001317 .addReg(ARM::LR)
1318 .addReg(ARM::PC)
Evan Cheng65f9d192012-02-28 18:51:51 +00001319 // Add predicate operands.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001320 .addImm(ARMCC::AL)
1321 .addReg(0)
Evan Cheng65f9d192012-02-28 18:51:51 +00001322 // Add 's' bit operand (always reg0 for this)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001323 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001324
Saleem Abdulrasool1eb4a282014-07-07 05:18:22 +00001325 const MachineOperand &Op = MI->getOperand(0);
1326 const GlobalValue *GV = Op.getGlobal();
1327 const unsigned TF = Op.getTargetFlags();
1328 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001329 const MCExpr *GVSymExpr = MCSymbolRefExpr::Create(GVSym, OutContext);
Lang Hames9ff69c82015-04-24 19:11:51 +00001330 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::Bcc)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001331 .addExpr(GVSymExpr)
Evan Cheng65f9d192012-02-28 18:51:51 +00001332 // Add predicate operands.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001333 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001334 .addReg(0));
Evan Cheng65f9d192012-02-28 18:51:51 +00001335 return;
1336 }
Evan Cheng2f2435d2011-01-21 18:55:51 +00001337 case ARM::MOVi16_ga_pcrel:
1338 case ARM::t2MOVi16_ga_pcrel: {
Evan Chengdfce83c2011-01-17 08:03:18 +00001339 MCInst TmpInst;
Evan Cheng2f2435d2011-01-21 18:55:51 +00001340 TmpInst.setOpcode(Opc == ARM::MOVi16_ga_pcrel? ARM::MOVi16 : ARM::t2MOVi16);
Jim Grosbache9119e42015-05-13 18:37:00 +00001341 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
Evan Chengdfce83c2011-01-17 08:03:18 +00001342
Evan Cheng2f2435d2011-01-21 18:55:51 +00001343 unsigned TF = MI->getOperand(1).getTargetFlags();
Evan Chengdfce83c2011-01-17 08:03:18 +00001344 const GlobalValue *GV = MI->getOperand(1).getGlobal();
Tim Northoverdb962e2c2013-11-25 16:24:52 +00001345 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
Evan Chengdfce83c2011-01-17 08:03:18 +00001346 const MCExpr *GVSymExpr = MCSymbolRefExpr::Create(GVSym, OutContext);
Tim Northoverdb962e2c2013-11-25 16:24:52 +00001347
Rafael Espindola58873562014-01-03 19:21:54 +00001348 MCSymbol *LabelSym = getPICLabel(DL->getPrivateGlobalPrefix(),
Tim Northoverdb962e2c2013-11-25 16:24:52 +00001349 getFunctionNumber(),
1350 MI->getOperand(2).getImm(), OutContext);
1351 const MCExpr *LabelSymExpr= MCSymbolRefExpr::Create(LabelSym, OutContext);
1352 unsigned PCAdj = (Opc == ARM::MOVi16_ga_pcrel) ? 8 : 4;
1353 const MCExpr *PCRelExpr =
1354 ARMMCExpr::CreateLower16(MCBinaryExpr::CreateSub(GVSymExpr,
1355 MCBinaryExpr::CreateAdd(LabelSymExpr,
Evan Cheng2f2435d2011-01-21 18:55:51 +00001356 MCConstantExpr::Create(PCAdj, OutContext),
Tim Northoverdb962e2c2013-11-25 16:24:52 +00001357 OutContext), OutContext), OutContext);
Jim Grosbache9119e42015-05-13 18:37:00 +00001358 TmpInst.addOperand(MCOperand::createExpr(PCRelExpr));
Evan Cheng2f2435d2011-01-21 18:55:51 +00001359
Evan Chengdfce83c2011-01-17 08:03:18 +00001360 // Add predicate operands.
Jim Grosbache9119e42015-05-13 18:37:00 +00001361 TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
1362 TmpInst.addOperand(MCOperand::createReg(0));
Evan Chengdfce83c2011-01-17 08:03:18 +00001363 // Add 's' bit operand (always reg0 for this)
Jim Grosbache9119e42015-05-13 18:37:00 +00001364 TmpInst.addOperand(MCOperand::createReg(0));
Lang Hames9ff69c82015-04-24 19:11:51 +00001365 EmitToStreamer(*OutStreamer, TmpInst);
Evan Chengdfce83c2011-01-17 08:03:18 +00001366 return;
1367 }
Evan Cheng2f2435d2011-01-21 18:55:51 +00001368 case ARM::MOVTi16_ga_pcrel:
1369 case ARM::t2MOVTi16_ga_pcrel: {
Evan Chengdfce83c2011-01-17 08:03:18 +00001370 MCInst TmpInst;
Evan Cheng2f2435d2011-01-21 18:55:51 +00001371 TmpInst.setOpcode(Opc == ARM::MOVTi16_ga_pcrel
1372 ? ARM::MOVTi16 : ARM::t2MOVTi16);
Jim Grosbache9119e42015-05-13 18:37:00 +00001373 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1374 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(1).getReg()));
Evan Chengdfce83c2011-01-17 08:03:18 +00001375
Evan Cheng2f2435d2011-01-21 18:55:51 +00001376 unsigned TF = MI->getOperand(2).getTargetFlags();
Evan Chengdfce83c2011-01-17 08:03:18 +00001377 const GlobalValue *GV = MI->getOperand(2).getGlobal();
Tim Northoverdb962e2c2013-11-25 16:24:52 +00001378 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
Evan Chengdfce83c2011-01-17 08:03:18 +00001379 const MCExpr *GVSymExpr = MCSymbolRefExpr::Create(GVSym, OutContext);
Tim Northoverdb962e2c2013-11-25 16:24:52 +00001380
Rafael Espindola58873562014-01-03 19:21:54 +00001381 MCSymbol *LabelSym = getPICLabel(DL->getPrivateGlobalPrefix(),
Tim Northoverdb962e2c2013-11-25 16:24:52 +00001382 getFunctionNumber(),
1383 MI->getOperand(3).getImm(), OutContext);
1384 const MCExpr *LabelSymExpr= MCSymbolRefExpr::Create(LabelSym, OutContext);
1385 unsigned PCAdj = (Opc == ARM::MOVTi16_ga_pcrel) ? 8 : 4;
1386 const MCExpr *PCRelExpr =
Evan Cheng2f2435d2011-01-21 18:55:51 +00001387 ARMMCExpr::CreateUpper16(MCBinaryExpr::CreateSub(GVSymExpr,
1388 MCBinaryExpr::CreateAdd(LabelSymExpr,
1389 MCConstantExpr::Create(PCAdj, OutContext),
Evan Chengdfce83c2011-01-17 08:03:18 +00001390 OutContext), OutContext), OutContext);
Jim Grosbache9119e42015-05-13 18:37:00 +00001391 TmpInst.addOperand(MCOperand::createExpr(PCRelExpr));
Evan Chengdfce83c2011-01-17 08:03:18 +00001392 // Add predicate operands.
Jim Grosbache9119e42015-05-13 18:37:00 +00001393 TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
1394 TmpInst.addOperand(MCOperand::createReg(0));
Evan Chengdfce83c2011-01-17 08:03:18 +00001395 // Add 's' bit operand (always reg0 for this)
Jim Grosbache9119e42015-05-13 18:37:00 +00001396 TmpInst.addOperand(MCOperand::createReg(0));
Lang Hames9ff69c82015-04-24 19:11:51 +00001397 EmitToStreamer(*OutStreamer, TmpInst);
Evan Chengdfce83c2011-01-17 08:03:18 +00001398 return;
1399 }
Jim Grosbach3d979202010-09-17 23:41:53 +00001400 case ARM::tPICADD: {
1401 // This is a pseudo op for a label + instruction sequence, which looks like:
1402 // LPC0:
1403 // add r0, pc
1404 // This adds the address of LPC0 to r0.
1405
1406 // Emit the label.
Lang Hames9ff69c82015-04-24 19:11:51 +00001407 OutStreamer->EmitLabel(getPICLabel(DL->getPrivateGlobalPrefix(),
1408 getFunctionNumber(),
1409 MI->getOperand(2).getImm(),
1410 OutContext));
Jim Grosbach3d979202010-09-17 23:41:53 +00001411
1412 // Form and emit the add.
Lang Hames9ff69c82015-04-24 19:11:51 +00001413 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDhirr)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001414 .addReg(MI->getOperand(0).getReg())
1415 .addReg(MI->getOperand(0).getReg())
1416 .addReg(ARM::PC)
1417 // Add predicate operands.
1418 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001419 .addReg(0));
Jim Grosbach3d979202010-09-17 23:41:53 +00001420 return;
1421 }
Jim Grosbachc8e2e9d2010-09-30 19:53:58 +00001422 case ARM::PICADD: {
Chris Lattneradd57492009-10-19 22:23:04 +00001423 // This is a pseudo op for a label + instruction sequence, which looks like:
1424 // LPC0:
1425 // add r0, pc, r0
1426 // This adds the address of LPC0 to r0.
Jim Grosbach8ee5cd92010-09-02 01:02:06 +00001427
Chris Lattneradd57492009-10-19 22:23:04 +00001428 // Emit the label.
Lang Hames9ff69c82015-04-24 19:11:51 +00001429 OutStreamer->EmitLabel(getPICLabel(DL->getPrivateGlobalPrefix(),
1430 getFunctionNumber(),
1431 MI->getOperand(2).getImm(),
1432 OutContext));
Jim Grosbach8ee5cd92010-09-02 01:02:06 +00001433
Jim Grosbach7ae94222010-09-14 21:05:34 +00001434 // Form and emit the add.
Lang Hames9ff69c82015-04-24 19:11:51 +00001435 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDrr)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001436 .addReg(MI->getOperand(0).getReg())
1437 .addReg(ARM::PC)
1438 .addReg(MI->getOperand(1).getReg())
1439 // Add predicate operands.
1440 .addImm(MI->getOperand(3).getImm())
1441 .addReg(MI->getOperand(4).getReg())
1442 // Add 's' bit operand (always reg0 for this)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001443 .addReg(0));
Chris Lattneradd57492009-10-19 22:23:04 +00001444 return;
1445 }
Jim Grosbacha7d430b2010-09-17 16:25:52 +00001446 case ARM::PICSTR:
1447 case ARM::PICSTRB:
1448 case ARM::PICSTRH:
1449 case ARM::PICLDR:
1450 case ARM::PICLDRB:
1451 case ARM::PICLDRH:
1452 case ARM::PICLDRSB:
1453 case ARM::PICLDRSH: {
Jim Grosbach218e22d2010-09-16 17:43:25 +00001454 // This is a pseudo op for a label + instruction sequence, which looks like:
1455 // LPC0:
Jim Grosbacha7d430b2010-09-17 16:25:52 +00001456 // OP r0, [pc, r0]
Jim Grosbach218e22d2010-09-16 17:43:25 +00001457 // The LCP0 label is referenced by a constant pool entry in order to get
1458 // a PC-relative address at the ldr instruction.
1459
1460 // Emit the label.
Lang Hames9ff69c82015-04-24 19:11:51 +00001461 OutStreamer->EmitLabel(getPICLabel(DL->getPrivateGlobalPrefix(),
1462 getFunctionNumber(),
1463 MI->getOperand(2).getImm(),
1464 OutContext));
Jim Grosbach218e22d2010-09-16 17:43:25 +00001465
1466 // Form and emit the load
Jim Grosbacha7d430b2010-09-17 16:25:52 +00001467 unsigned Opcode;
1468 switch (MI->getOpcode()) {
1469 default:
1470 llvm_unreachable("Unexpected opcode!");
Jim Grosbach338de3e2010-10-27 23:12:14 +00001471 case ARM::PICSTR: Opcode = ARM::STRrs; break;
1472 case ARM::PICSTRB: Opcode = ARM::STRBrs; break;
Jim Grosbacha7d430b2010-09-17 16:25:52 +00001473 case ARM::PICSTRH: Opcode = ARM::STRH; break;
Jim Grosbach1e4d9a12010-10-26 22:37:02 +00001474 case ARM::PICLDR: Opcode = ARM::LDRrs; break;
Jim Grosbach5a7c7152010-10-27 00:19:44 +00001475 case ARM::PICLDRB: Opcode = ARM::LDRBrs; break;
Jim Grosbacha7d430b2010-09-17 16:25:52 +00001476 case ARM::PICLDRH: Opcode = ARM::LDRH; break;
1477 case ARM::PICLDRSB: Opcode = ARM::LDRSB; break;
1478 case ARM::PICLDRSH: Opcode = ARM::LDRSH; break;
1479 }
Lang Hames9ff69c82015-04-24 19:11:51 +00001480 EmitToStreamer(*OutStreamer, MCInstBuilder(Opcode)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001481 .addReg(MI->getOperand(0).getReg())
1482 .addReg(ARM::PC)
1483 .addReg(MI->getOperand(1).getReg())
1484 .addImm(0)
1485 // Add predicate operands.
1486 .addImm(MI->getOperand(3).getImm())
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001487 .addReg(MI->getOperand(4).getReg()));
Jim Grosbach218e22d2010-09-16 17:43:25 +00001488
1489 return;
1490 }
Jim Grosbachc8e2e9d2010-09-30 19:53:58 +00001491 case ARM::CONSTPOOL_ENTRY: {
Chris Lattner186c6b02009-10-19 22:33:05 +00001492 /// CONSTPOOL_ENTRY - This instruction represents a floating constant pool
1493 /// in the function. The first operand is the ID# for this instruction, the
1494 /// second is the index into the MachineConstantPool that this is, the third
1495 /// is the size in bytes of this constant pool entry.
Jakob Stoklund Olesen2e05db22011-12-06 01:43:02 +00001496 /// The required alignment is specified on the basic block holding this MI.
Chris Lattner186c6b02009-10-19 22:33:05 +00001497 unsigned LabelId = (unsigned)MI->getOperand(0).getImm();
1498 unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex();
1499
Jim Grosbach4b63d2a2012-05-18 19:12:01 +00001500 // If this is the first entry of the pool, mark it.
1501 if (!InConstantPool) {
Lang Hames9ff69c82015-04-24 19:11:51 +00001502 OutStreamer->EmitDataRegion(MCDR_DataRegion);
Jim Grosbach4b63d2a2012-05-18 19:12:01 +00001503 InConstantPool = true;
1504 }
1505
Lang Hames9ff69c82015-04-24 19:11:51 +00001506 OutStreamer->EmitLabel(GetCPISymbol(LabelId));
Chris Lattner186c6b02009-10-19 22:33:05 +00001507
1508 const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx];
1509 if (MCPE.isMachineConstantPoolEntry())
1510 EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal);
1511 else
1512 EmitGlobalConstant(MCPE.Val.ConstVal);
Chris Lattner186c6b02009-10-19 22:33:05 +00001513 return;
1514 }
Tim Northover12c41af2015-05-18 17:10:40 +00001515 case ARM::JUMPTABLE_ADDRS:
1516 EmitJumpTableAddrs(MI);
1517 return;
1518 case ARM::JUMPTABLE_INSTS:
1519 EmitJumpTableInsts(MI);
1520 return;
1521 case ARM::JUMPTABLE_TBB:
1522 case ARM::JUMPTABLE_TBH:
1523 EmitJumpTableTBInst(MI, MI->getOpcode() == ARM::JUMPTABLE_TBB ? 1 : 2);
1524 return;
Jim Grosbachd64f9b82010-09-21 23:28:16 +00001525 case ARM::t2BR_JT: {
1526 // Lower and emit the instruction itself, then the jump table following it.
Lang Hames9ff69c82015-04-24 19:11:51 +00001527 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001528 .addReg(ARM::PC)
1529 .addReg(MI->getOperand(0).getReg())
1530 // Add predicate operands.
1531 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001532 .addReg(0));
Jim Grosbach7ec3d342010-11-29 22:37:40 +00001533 return;
1534 }
Tim Northover12c41af2015-05-18 17:10:40 +00001535 case ARM::t2TBB_JT:
Jim Grosbach7ec3d342010-11-29 22:37:40 +00001536 case ARM::t2TBH_JT: {
Tim Northover12c41af2015-05-18 17:10:40 +00001537 unsigned Opc = MI->getOpcode() == ARM::t2TBB_JT ? ARM::t2TBB : ARM::t2TBH;
1538 // Lower and emit the PC label, then the instruction itself.
1539 OutStreamer->EmitLabel(GetCPISymbol(MI->getOperand(3).getImm()));
1540 EmitToStreamer(*OutStreamer, MCInstBuilder(Opc)
1541 .addReg(MI->getOperand(0).getReg())
1542 .addReg(MI->getOperand(1).getReg())
1543 // Add predicate operands.
1544 .addImm(ARMCC::AL)
1545 .addReg(0));
Jim Grosbachd64f9b82010-09-21 23:28:16 +00001546 return;
1547 }
Jim Grosbach58bc36a2010-11-29 19:32:47 +00001548 case ARM::tBR_JTr:
Jim Grosbach150b1ad2010-11-29 18:37:44 +00001549 case ARM::BR_JTr: {
1550 // Lower and emit the instruction itself, then the jump table following it.
1551 // mov pc, target
1552 MCInst TmpInst;
Jim Grosbach7ec3d342010-11-29 22:37:40 +00001553 unsigned Opc = MI->getOpcode() == ARM::BR_JTr ?
Jim Grosbache9cc9012011-06-30 23:38:17 +00001554 ARM::MOVr : ARM::tMOVr;
Jim Grosbach58bc36a2010-11-29 19:32:47 +00001555 TmpInst.setOpcode(Opc);
Jim Grosbache9119e42015-05-13 18:37:00 +00001556 TmpInst.addOperand(MCOperand::createReg(ARM::PC));
1557 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
Jim Grosbach150b1ad2010-11-29 18:37:44 +00001558 // Add predicate operands.
Jim Grosbache9119e42015-05-13 18:37:00 +00001559 TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
1560 TmpInst.addOperand(MCOperand::createReg(0));
Jim Grosbachcd5e30f2010-11-30 18:30:19 +00001561 // Add 's' bit operand (always reg0 for this)
1562 if (Opc == ARM::MOVr)
Jim Grosbache9119e42015-05-13 18:37:00 +00001563 TmpInst.addOperand(MCOperand::createReg(0));
Lang Hames9ff69c82015-04-24 19:11:51 +00001564 EmitToStreamer(*OutStreamer, TmpInst);
Jim Grosbach150b1ad2010-11-29 18:37:44 +00001565 return;
1566 }
1567 case ARM::BR_JTm: {
1568 // Lower and emit the instruction itself, then the jump table following it.
1569 // ldr pc, target
1570 MCInst TmpInst;
1571 if (MI->getOperand(1).getReg() == 0) {
1572 // literal offset
1573 TmpInst.setOpcode(ARM::LDRi12);
Jim Grosbache9119e42015-05-13 18:37:00 +00001574 TmpInst.addOperand(MCOperand::createReg(ARM::PC));
1575 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1576 TmpInst.addOperand(MCOperand::createImm(MI->getOperand(2).getImm()));
Jim Grosbach150b1ad2010-11-29 18:37:44 +00001577 } else {
1578 TmpInst.setOpcode(ARM::LDRrs);
Jim Grosbache9119e42015-05-13 18:37:00 +00001579 TmpInst.addOperand(MCOperand::createReg(ARM::PC));
1580 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1581 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(1).getReg()));
1582 TmpInst.addOperand(MCOperand::createImm(0));
Jim Grosbach150b1ad2010-11-29 18:37:44 +00001583 }
1584 // Add predicate operands.
Jim Grosbache9119e42015-05-13 18:37:00 +00001585 TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
1586 TmpInst.addOperand(MCOperand::createReg(0));
Lang Hames9ff69c82015-04-24 19:11:51 +00001587 EmitToStreamer(*OutStreamer, TmpInst);
Jim Grosbach284eebc2010-09-22 17:39:48 +00001588 return;
1589 }
Jim Grosbach08c562b2010-11-17 21:05:55 +00001590 case ARM::BR_JTadd: {
1591 // Lower and emit the instruction itself, then the jump table following it.
1592 // add pc, target, idx
Lang Hames9ff69c82015-04-24 19:11:51 +00001593 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDrr)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001594 .addReg(ARM::PC)
1595 .addReg(MI->getOperand(0).getReg())
1596 .addReg(MI->getOperand(1).getReg())
1597 // Add predicate operands.
1598 .addImm(ARMCC::AL)
1599 .addReg(0)
1600 // Add 's' bit operand (always reg0 for this)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001601 .addReg(0));
Jim Grosbach08c562b2010-11-17 21:05:55 +00001602 return;
1603 }
Tim Northover650b0ee52014-11-13 17:58:48 +00001604 case ARM::SPACE:
Lang Hames9ff69c82015-04-24 19:11:51 +00001605 OutStreamer->EmitZeros(MI->getOperand(1).getImm());
Tim Northover650b0ee52014-11-13 17:58:48 +00001606 return;
Jim Grosbach85030542010-09-23 18:05:37 +00001607 case ARM::TRAP: {
1608 // Non-Darwin binutils don't yet support the "trap" mnemonic.
1609 // FIXME: Remove this special case when they do.
Tim Northoverd6a729b2014-01-06 14:28:05 +00001610 if (!Subtarget->isTargetMachO()) {
Jim Grosbachfae83052010-10-01 23:21:38 +00001611 //.long 0xe7ffdefe @ trap
Jim Grosbach7d348372010-09-23 19:42:17 +00001612 uint32_t Val = 0xe7ffdefeUL;
Lang Hames9ff69c82015-04-24 19:11:51 +00001613 OutStreamer->AddComment("trap");
1614 OutStreamer->EmitIntValue(Val, 4);
Jim Grosbach85030542010-09-23 18:05:37 +00001615 return;
1616 }
1617 break;
1618 }
Eli Bendersky2e2ce492013-01-30 16:30:19 +00001619 case ARM::TRAPNaCl: {
1620 //.long 0xe7fedef0 @ trap
1621 uint32_t Val = 0xe7fedef0UL;
Lang Hames9ff69c82015-04-24 19:11:51 +00001622 OutStreamer->AddComment("trap");
1623 OutStreamer->EmitIntValue(Val, 4);
Eli Bendersky2e2ce492013-01-30 16:30:19 +00001624 return;
1625 }
Jim Grosbach85030542010-09-23 18:05:37 +00001626 case ARM::tTRAP: {
1627 // Non-Darwin binutils don't yet support the "trap" mnemonic.
1628 // FIXME: Remove this special case when they do.
Tim Northoverd6a729b2014-01-06 14:28:05 +00001629 if (!Subtarget->isTargetMachO()) {
Jim Grosbachfae83052010-10-01 23:21:38 +00001630 //.short 57086 @ trap
Benjamin Kramere38495d2010-09-23 18:57:26 +00001631 uint16_t Val = 0xdefe;
Lang Hames9ff69c82015-04-24 19:11:51 +00001632 OutStreamer->AddComment("trap");
1633 OutStreamer->EmitIntValue(Val, 2);
Jim Grosbach85030542010-09-23 18:05:37 +00001634 return;
1635 }
1636 break;
1637 }
Jim Grosbach4a6ab132010-09-24 20:47:58 +00001638 case ARM::t2Int_eh_sjlj_setjmp:
1639 case ARM::t2Int_eh_sjlj_setjmp_nofp:
Jim Grosbachc8e2e9d2010-09-30 19:53:58 +00001640 case ARM::tInt_eh_sjlj_setjmp: {
Jim Grosbach4a6ab132010-09-24 20:47:58 +00001641 // Two incoming args: GPR:$src, GPR:$val
1642 // mov $val, pc
1643 // adds $val, #7
1644 // str $val, [$src, #4]
1645 // movs r0, #0
1646 // b 1f
1647 // movs r0, #1
1648 // 1:
1649 unsigned SrcReg = MI->getOperand(0).getReg();
1650 unsigned ValReg = MI->getOperand(1).getReg();
1651 MCSymbol *Label = GetARMSJLJEHLabel();
Lang Hames9ff69c82015-04-24 19:11:51 +00001652 OutStreamer->AddComment("eh_setjmp begin");
1653 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001654 .addReg(ValReg)
1655 .addReg(ARM::PC)
Jim Grosbachb98ab912011-06-30 22:10:46 +00001656 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001657 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001658 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001659
Lang Hames9ff69c82015-04-24 19:11:51 +00001660 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDi3)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001661 .addReg(ValReg)
Jim Grosbach4a6ab132010-09-24 20:47:58 +00001662 // 's' bit operand
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001663 .addReg(ARM::CPSR)
1664 .addReg(ValReg)
1665 .addImm(7)
Jim Grosbach4a6ab132010-09-24 20:47:58 +00001666 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001667 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001668 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001669
Lang Hames9ff69c82015-04-24 19:11:51 +00001670 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tSTRi)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001671 .addReg(ValReg)
1672 .addReg(SrcReg)
Jim Grosbach4a6ab132010-09-24 20:47:58 +00001673 // The offset immediate is #4. The operand value is scaled by 4 for the
1674 // tSTR instruction.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001675 .addImm(1)
Jim Grosbach4a6ab132010-09-24 20:47:58 +00001676 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001677 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001678 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001679
Lang Hames9ff69c82015-04-24 19:11:51 +00001680 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVi8)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001681 .addReg(ARM::R0)
1682 .addReg(ARM::CPSR)
1683 .addImm(0)
Jim Grosbach4a6ab132010-09-24 20:47:58 +00001684 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001685 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001686 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001687
1688 const MCExpr *SymbolExpr = MCSymbolRefExpr::Create(Label, OutContext);
Lang Hames9ff69c82015-04-24 19:11:51 +00001689 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tB)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001690 .addExpr(SymbolExpr)
1691 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001692 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001693
Lang Hames9ff69c82015-04-24 19:11:51 +00001694 OutStreamer->AddComment("eh_setjmp end");
1695 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVi8)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001696 .addReg(ARM::R0)
1697 .addReg(ARM::CPSR)
1698 .addImm(1)
Jim Grosbach4a6ab132010-09-24 20:47:58 +00001699 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001700 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001701 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001702
Lang Hames9ff69c82015-04-24 19:11:51 +00001703 OutStreamer->EmitLabel(Label);
Jim Grosbach4a6ab132010-09-24 20:47:58 +00001704 return;
1705 }
1706
Jim Grosbachc0aed712010-09-23 23:33:56 +00001707 case ARM::Int_eh_sjlj_setjmp_nofp:
Jim Grosbachc8e2e9d2010-09-30 19:53:58 +00001708 case ARM::Int_eh_sjlj_setjmp: {
Jim Grosbachc0aed712010-09-23 23:33:56 +00001709 // Two incoming args: GPR:$src, GPR:$val
1710 // add $val, pc, #8
1711 // str $val, [$src, #+4]
1712 // mov r0, #0
1713 // add pc, pc, #0
1714 // mov r0, #1
1715 unsigned SrcReg = MI->getOperand(0).getReg();
1716 unsigned ValReg = MI->getOperand(1).getReg();
1717
Lang Hames9ff69c82015-04-24 19:11:51 +00001718 OutStreamer->AddComment("eh_setjmp begin");
1719 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDri)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001720 .addReg(ValReg)
1721 .addReg(ARM::PC)
1722 .addImm(8)
Jim Grosbachc0aed712010-09-23 23:33:56 +00001723 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001724 .addImm(ARMCC::AL)
1725 .addReg(0)
Jim Grosbachc0aed712010-09-23 23:33:56 +00001726 // 's' bit operand (always reg0 for this).
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001727 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001728
Lang Hames9ff69c82015-04-24 19:11:51 +00001729 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::STRi12)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001730 .addReg(ValReg)
1731 .addReg(SrcReg)
1732 .addImm(4)
Jim Grosbachc0aed712010-09-23 23:33:56 +00001733 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001734 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001735 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001736
Lang Hames9ff69c82015-04-24 19:11:51 +00001737 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVi)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001738 .addReg(ARM::R0)
1739 .addImm(0)
Jim Grosbachc0aed712010-09-23 23:33:56 +00001740 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001741 .addImm(ARMCC::AL)
1742 .addReg(0)
Jim Grosbachc0aed712010-09-23 23:33:56 +00001743 // 's' bit operand (always reg0 for this).
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001744 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001745
Lang Hames9ff69c82015-04-24 19:11:51 +00001746 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDri)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001747 .addReg(ARM::PC)
1748 .addReg(ARM::PC)
1749 .addImm(0)
Jim Grosbachc0aed712010-09-23 23:33:56 +00001750 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001751 .addImm(ARMCC::AL)
1752 .addReg(0)
Jim Grosbachc0aed712010-09-23 23:33:56 +00001753 // 's' bit operand (always reg0 for this).
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001754 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001755
Lang Hames9ff69c82015-04-24 19:11:51 +00001756 OutStreamer->AddComment("eh_setjmp end");
1757 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVi)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001758 .addReg(ARM::R0)
1759 .addImm(1)
Jim Grosbachc0aed712010-09-23 23:33:56 +00001760 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001761 .addImm(ARMCC::AL)
1762 .addReg(0)
Jim Grosbachc0aed712010-09-23 23:33:56 +00001763 // 's' bit operand (always reg0 for this).
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001764 .addReg(0));
Jim Grosbachc0aed712010-09-23 23:33:56 +00001765 return;
1766 }
Jim Grosbach9e9ed982010-09-27 21:47:04 +00001767 case ARM::Int_eh_sjlj_longjmp: {
1768 // ldr sp, [$src, #8]
1769 // ldr $scratch, [$src, #4]
1770 // ldr r7, [$src]
1771 // bx $scratch
1772 unsigned SrcReg = MI->getOperand(0).getReg();
1773 unsigned ScratchReg = MI->getOperand(1).getReg();
Lang Hames9ff69c82015-04-24 19:11:51 +00001774 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001775 .addReg(ARM::SP)
1776 .addReg(SrcReg)
1777 .addImm(8)
Jim Grosbach9e9ed982010-09-27 21:47:04 +00001778 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001779 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001780 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001781
Lang Hames9ff69c82015-04-24 19:11:51 +00001782 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001783 .addReg(ScratchReg)
1784 .addReg(SrcReg)
1785 .addImm(4)
Jim Grosbach9e9ed982010-09-27 21:47:04 +00001786 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001787 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001788 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001789
Lang Hames9ff69c82015-04-24 19:11:51 +00001790 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001791 .addReg(ARM::R7)
1792 .addReg(SrcReg)
1793 .addImm(0)
Jim Grosbach9e9ed982010-09-27 21:47:04 +00001794 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001795 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001796 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001797
Lang Hames9ff69c82015-04-24 19:11:51 +00001798 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::BX)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001799 .addReg(ScratchReg)
Jim Grosbach9e9ed982010-09-27 21:47:04 +00001800 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001801 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001802 .addReg(0));
Jim Grosbach9e9ed982010-09-27 21:47:04 +00001803 return;
1804 }
Jim Grosbach175d6412010-09-27 22:28:11 +00001805 case ARM::tInt_eh_sjlj_longjmp: {
1806 // ldr $scratch, [$src, #8]
1807 // mov sp, $scratch
1808 // ldr $scratch, [$src, #4]
1809 // ldr r7, [$src]
1810 // bx $scratch
1811 unsigned SrcReg = MI->getOperand(0).getReg();
1812 unsigned ScratchReg = MI->getOperand(1).getReg();
Lang Hames9ff69c82015-04-24 19:11:51 +00001813 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001814 .addReg(ScratchReg)
1815 .addReg(SrcReg)
Jim Grosbach175d6412010-09-27 22:28:11 +00001816 // The offset immediate is #8. The operand value is scaled by 4 for the
Bill Wendling092a7bd2010-12-14 03:36:38 +00001817 // tLDR instruction.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001818 .addImm(2)
Jim Grosbach175d6412010-09-27 22:28:11 +00001819 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001820 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001821 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001822
Lang Hames9ff69c82015-04-24 19:11:51 +00001823 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001824 .addReg(ARM::SP)
1825 .addReg(ScratchReg)
Jim Grosbach175d6412010-09-27 22:28:11 +00001826 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001827 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001828 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001829
Lang Hames9ff69c82015-04-24 19:11:51 +00001830 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001831 .addReg(ScratchReg)
1832 .addReg(SrcReg)
1833 .addImm(1)
Jim Grosbach175d6412010-09-27 22:28:11 +00001834 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001835 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001836 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001837
Lang Hames9ff69c82015-04-24 19:11:51 +00001838 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001839 .addReg(ARM::R7)
1840 .addReg(SrcReg)
1841 .addImm(0)
Jim Grosbach175d6412010-09-27 22:28:11 +00001842 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001843 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001844 .addReg(0));
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001845
Lang Hames9ff69c82015-04-24 19:11:51 +00001846 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tBX)
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001847 .addReg(ScratchReg)
Jim Grosbach175d6412010-09-27 22:28:11 +00001848 // Predicate.
Benjamin Kramer4e629f72012-11-26 13:34:22 +00001849 .addImm(ARMCC::AL)
Benjamin Kramerebf576d2012-11-26 18:05:52 +00001850 .addReg(0));
Jim Grosbach175d6412010-09-27 22:28:11 +00001851 return;
1852 }
Chris Lattner71eb0772009-10-19 20:20:46 +00001853 }
Jim Grosbach8ee5cd92010-09-02 01:02:06 +00001854
Chris Lattner71eb0772009-10-19 20:20:46 +00001855 MCInst TmpInst;
Chris Lattnerde16ca82010-11-14 21:00:02 +00001856 LowerARMMachineInstrToMCInst(MI, TmpInst, *this);
Anton Korobeynikove7410dd2011-03-05 18:43:32 +00001857
Lang Hames9ff69c82015-04-24 19:11:51 +00001858 EmitToStreamer(*OutStreamer, TmpInst);
Chris Lattner71eb0772009-10-19 20:20:46 +00001859}
Daniel Dunbarf0b3d152009-10-20 05:15:36 +00001860
1861//===----------------------------------------------------------------------===//
1862// Target Registry Stuff
1863//===----------------------------------------------------------------------===//
1864
Daniel Dunbarf0b3d152009-10-20 05:15:36 +00001865// Force static initialization.
1866extern "C" void LLVMInitializeARMAsmPrinter() {
Christian Pirkerdc9ff752014-04-01 15:19:30 +00001867 RegisterAsmPrinter<ARMAsmPrinter> X(TheARMLETarget);
1868 RegisterAsmPrinter<ARMAsmPrinter> Y(TheARMBETarget);
1869 RegisterAsmPrinter<ARMAsmPrinter> A(TheThumbLETarget);
1870 RegisterAsmPrinter<ARMAsmPrinter> B(TheThumbBETarget);
Daniel Dunbarf0b3d152009-10-20 05:15:36 +00001871}