blob: f44fb16e2d8e0381785559dbab55acc75bf07445 [file] [log] [blame]
Eugene Zelenko52889212017-08-01 21:20:10 +00001//===- HexagonAsmPrinter.cpp - Print machine instrs to Hexagon assembly ---===//
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains a printer that converts from our internal representation
11// of machine-dependent LLVM code to Hexagon assembly language. This printer is
12// the output mechanism used by `llc'.
13//
Tony Linthicum1213a7a2011-12-12 21:14:40 +000014//===----------------------------------------------------------------------===//
15
Jyotsna Verma7503a622013-02-20 16:13:27 +000016#include "HexagonAsmPrinter.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000017#include "Hexagon.h"
Eugene Zelenko52889212017-08-01 21:20:10 +000018#include "HexagonInstrInfo.h"
19#include "HexagonRegisterInfo.h"
Jyotsna Verma7503a622013-02-20 16:13:27 +000020#include "HexagonSubtarget.h"
Colin LeMahieuff062612014-11-20 21:56:35 +000021#include "MCTargetDesc/HexagonInstPrinter.h"
Eugene Zelenko52889212017-08-01 21:20:10 +000022#include "MCTargetDesc/HexagonMCExpr.h"
Colin LeMahieu1174fea2015-02-19 21:10:50 +000023#include "MCTargetDesc/HexagonMCInstrInfo.h"
Eugene Zelenko52889212017-08-01 21:20:10 +000024#include "MCTargetDesc/HexagonMCTargetDesc.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000025#include "llvm/ADT/StringExtras.h"
Eugene Zelenko52889212017-08-01 21:20:10 +000026#include "llvm/ADT/StringRef.h"
27#include "llvm/ADT/Twine.h"
Zachary Turner264b5d92017-06-07 03:48:56 +000028#include "llvm/BinaryFormat/ELF.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000029#include "llvm/CodeGen/AsmPrinter.h"
Eugene Zelenko52889212017-08-01 21:20:10 +000030#include "llvm/CodeGen/MachineBasicBlock.h"
31#include "llvm/CodeGen/MachineFunction.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000032#include "llvm/CodeGen/MachineInstr.h"
Eugene Zelenko52889212017-08-01 21:20:10 +000033#include "llvm/CodeGen/MachineOperand.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000034#include "llvm/CodeGen/TargetRegisterInfo.h"
35#include "llvm/CodeGen/TargetSubtargetInfo.h"
Evandro Menezes5cee6212012-04-12 17:55:53 +000036#include "llvm/MC/MCContext.h"
Eugene Zelenko52889212017-08-01 21:20:10 +000037#include "llvm/MC/MCDirectives.h"
Evandro Menezes5cee6212012-04-12 17:55:53 +000038#include "llvm/MC/MCExpr.h"
39#include "llvm/MC/MCInst.h"
Eugene Zelenko52889212017-08-01 21:20:10 +000040#include "llvm/MC/MCRegisterInfo.h"
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +000041#include "llvm/MC/MCSectionELF.h"
Evandro Menezes5cee6212012-04-12 17:55:53 +000042#include "llvm/MC/MCStreamer.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000043#include "llvm/MC/MCSymbol.h"
Eugene Zelenko52889212017-08-01 21:20:10 +000044#include "llvm/Support/Casting.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000045#include "llvm/Support/CommandLine.h"
Eugene Zelenko52889212017-08-01 21:20:10 +000046#include "llvm/Support/ErrorHandling.h"
Craig Topperb25fda92012-03-17 18:46:09 +000047#include "llvm/Support/TargetRegistry.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000048#include "llvm/Support/raw_ostream.h"
Eugene Zelenko52889212017-08-01 21:20:10 +000049#include <algorithm>
50#include <cassert>
51#include <cstdint>
52#include <string>
Tony Linthicum1213a7a2011-12-12 21:14:40 +000053
54using namespace llvm;
55
Krzysztof Parzyszek8d8b2292015-12-02 23:08:29 +000056namespace llvm {
Eugene Zelenko52889212017-08-01 21:20:10 +000057
58void HexagonLowerToMC(const MCInstrInfo &MCII, const MachineInstr *MI,
59 MCInst &MCB, HexagonAsmPrinter &AP);
60
61} // end namespace llvm
Krzysztof Parzyszek8d8b2292015-12-02 23:08:29 +000062
Chandler Carruth84e68b22014-04-22 02:41:26 +000063#define DEBUG_TYPE "asm-printer"
64
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +000065// Given a scalar register return its pair.
66inline static unsigned getHexagonRegisterPair(unsigned Reg,
67 const MCRegisterInfo *RI) {
68 assert(Hexagon::IntRegsRegClass.contains(Reg));
69 MCSuperRegIterator SR(Reg, RI, false);
70 unsigned Pair = *SR;
71 assert(Hexagon::DoubleRegsRegClass.contains(Pair));
72 return Pair;
73}
74
Evandro Menezes5cee6212012-04-12 17:55:53 +000075void HexagonAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
Krzysztof Parzyszek29c567a2016-07-26 17:31:02 +000076 raw_ostream &O) {
Evandro Menezes5cee6212012-04-12 17:55:53 +000077 const MachineOperand &MO = MI->getOperand(OpNo);
Tony Linthicum1213a7a2011-12-12 21:14:40 +000078
Evandro Menezes5cee6212012-04-12 17:55:53 +000079 switch (MO.getType()) {
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +000080 default:
81 llvm_unreachable ("<unknown operand type>");
Evandro Menezes5cee6212012-04-12 17:55:53 +000082 case MachineOperand::MO_Register:
83 O << HexagonInstPrinter::getRegisterName(MO.getReg());
84 return;
85 case MachineOperand::MO_Immediate:
86 O << MO.getImm();
87 return;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000088 case MachineOperand::MO_MachineBasicBlock:
Matt Arsenault8b643552015-06-09 00:31:39 +000089 MO.getMBB()->getSymbol()->print(O, MAI);
Tony Linthicum1213a7a2011-12-12 21:14:40 +000090 return;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000091 case MachineOperand::MO_ConstantPoolIndex:
Matt Arsenault8b643552015-06-09 00:31:39 +000092 GetCPISymbol(MO.getIndex())->print(O, MAI);
Tony Linthicum1213a7a2011-12-12 21:14:40 +000093 return;
Evandro Menezes5cee6212012-04-12 17:55:53 +000094 case MachineOperand::MO_GlobalAddress:
Tony Linthicum1213a7a2011-12-12 21:14:40 +000095 // Computing the address of a global symbol, not calling it.
Matt Arsenault8b643552015-06-09 00:31:39 +000096 getSymbol(MO.getGlobal())->print(O, MAI);
Tony Linthicum1213a7a2011-12-12 21:14:40 +000097 printOffset(MO.getOffset(), O);
98 return;
99 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000100}
101
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000102// isBlockOnlyReachableByFallthrough - We need to override this since the
103// default AsmPrinter does not print labels for any basic block that
104// is only reachable by a fall through. That works for all cases except
105// for the case in which the basic block is reachable by a fall through but
106// through an indirect from a jump table. In this case, the jump table
107// will contain a label not defined by AsmPrinter.
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000108bool HexagonAsmPrinter::isBlockOnlyReachableByFallthrough(
109 const MachineBasicBlock *MBB) const {
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000110 if (MBB->hasAddressTaken())
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000111 return false;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000112 return AsmPrinter::isBlockOnlyReachableByFallthrough(MBB);
113}
114
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000115/// PrintAsmOperand - Print out an operand for an inline asm expression.
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000116bool HexagonAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
117 unsigned AsmVariant,
118 const char *ExtraCode,
Evandro Menezes5cee6212012-04-12 17:55:53 +0000119 raw_ostream &OS) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000120 // Does this asm operand have a single letter operand modifier?
121 if (ExtraCode && ExtraCode[0]) {
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000122 if (ExtraCode[1] != 0)
123 return true; // Unknown modifier.
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000124
125 switch (ExtraCode[0]) {
Jack Carter5e69cff2012-06-26 13:49:27 +0000126 default:
127 // See if this is a generic print operand
128 return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, OS);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000129 case 'c': // Don't print "$" before a global var name or constant.
130 // Hexagon never has a prefix.
131 printOperand(MI, OpNo, OS);
132 return false;
Krzysztof Parzyszek29c567a2016-07-26 17:31:02 +0000133 case 'L':
134 case 'H': { // The highest-numbered register of a pair.
135 const MachineOperand &MO = MI->getOperand(OpNo);
136 const MachineFunction &MF = *MI->getParent()->getParent();
137 const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
138 if (!MO.isReg())
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000139 return true;
Krzysztof Parzyszek29c567a2016-07-26 17:31:02 +0000140 unsigned RegNumber = MO.getReg();
141 // This should be an assert in the frontend.
142 if (Hexagon::DoubleRegsRegClass.contains(RegNumber))
143 RegNumber = TRI->getSubReg(RegNumber, ExtraCode[0] == 'L' ?
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +0000144 Hexagon::isub_lo :
145 Hexagon::isub_hi);
Krzysztof Parzyszek29c567a2016-07-26 17:31:02 +0000146 OS << HexagonInstPrinter::getRegisterName(RegNumber);
147 return false;
148 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000149 case 'I':
150 // Write 'i' if an integer constant, otherwise nothing. Used to print
151 // addi vs add, etc.
152 if (MI->getOperand(OpNo).isImm())
153 OS << "i";
154 return false;
155 }
156 }
157
158 printOperand(MI, OpNo, OS);
159 return false;
160}
161
162bool HexagonAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000163 unsigned OpNo,
164 unsigned AsmVariant,
Krzysztof Parzyszek067debe2016-08-19 14:12:51 +0000165 const char *ExtraCode,
166 raw_ostream &O) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000167 if (ExtraCode && ExtraCode[0])
168 return true; // Unknown modifier.
169
170 const MachineOperand &Base = MI->getOperand(OpNo);
171 const MachineOperand &Offset = MI->getOperand(OpNo+1);
172
173 if (Base.isReg())
174 printOperand(MI, OpNo, O);
175 else
Craig Toppere55c5562012-02-07 02:50:20 +0000176 llvm_unreachable("Unimplemented");
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000177
178 if (Offset.isImm()) {
179 if (Offset.getImm())
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000180 O << "+#" << Offset.getImm();
181 } else {
Craig Toppere55c5562012-02-07 02:50:20 +0000182 llvm_unreachable("Unimplemented");
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000183 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000184
185 return false;
186}
187
Benjamin Kramerab8cc022016-01-12 14:58:49 +0000188static MCSymbol *smallData(AsmPrinter &AP, const MachineInstr &MI,
189 MCStreamer &OutStreamer, const MCOperand &Imm,
190 int AlignSize) {
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000191 MCSymbol *Sym;
192 int64_t Value;
193 if (Imm.getExpr()->evaluateAsAbsolute(Value)) {
194 StringRef sectionPrefix;
195 std::string ImmString;
196 StringRef Name;
197 if (AlignSize == 8) {
198 Name = ".CONST_0000000000000000";
199 sectionPrefix = ".gnu.linkonce.l8";
200 ImmString = utohexstr(Value);
201 } else {
202 Name = ".CONST_00000000";
203 sectionPrefix = ".gnu.linkonce.l4";
204 ImmString = utohexstr(static_cast<uint32_t>(Value));
205 }
206
207 std::string symbolName = // Yes, leading zeros are kept.
208 Name.drop_back(ImmString.size()).str() + ImmString;
209 std::string sectionName = sectionPrefix.str() + symbolName;
210
211 MCSectionELF *Section = OutStreamer.getContext().getELFSection(
212 sectionName, ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
213 OutStreamer.SwitchSection(Section);
214
215 Sym = AP.OutContext.getOrCreateSymbol(Twine(symbolName));
216 if (Sym->isUndefined()) {
217 OutStreamer.EmitLabel(Sym);
218 OutStreamer.EmitSymbolAttribute(Sym, MCSA_Global);
219 OutStreamer.EmitIntValue(Value, AlignSize);
220 OutStreamer.EmitCodeAlignment(AlignSize);
221 }
222 } else {
223 assert(Imm.isExpr() && "Expected expression and found none");
224 const MachineOperand &MO = MI.getOperand(1);
225 assert(MO.isGlobal() || MO.isCPI() || MO.isJTI());
226 MCSymbol *MOSymbol = nullptr;
227 if (MO.isGlobal())
228 MOSymbol = AP.getSymbol(MO.getGlobal());
229 else if (MO.isCPI())
230 MOSymbol = AP.GetCPISymbol(MO.getIndex());
231 else if (MO.isJTI())
232 MOSymbol = AP.GetJTISymbol(MO.getIndex());
233 else
234 llvm_unreachable("Unknown operand type!");
235
236 StringRef SymbolName = MOSymbol->getName();
237 std::string LitaName = ".CONST_" + SymbolName.str();
238
239 MCSectionELF *Section = OutStreamer.getContext().getELFSection(
240 ".lita", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
241
242 OutStreamer.SwitchSection(Section);
243 Sym = AP.OutContext.getOrCreateSymbol(Twine(LitaName));
244 if (Sym->isUndefined()) {
245 OutStreamer.EmitLabel(Sym);
246 OutStreamer.EmitSymbolAttribute(Sym, MCSA_Local);
247 OutStreamer.EmitValue(Imm.getExpr(), AlignSize);
248 OutStreamer.EmitCodeAlignment(AlignSize);
249 }
250 }
251 return Sym;
252}
253
Krzysztof Parzyszek058abf1a2017-04-06 17:28:21 +0000254static MCInst ScaleVectorOffset(MCInst &Inst, unsigned OpNo,
255 unsigned VectorSize, MCContext &Ctx) {
256 MCInst T;
257 T.setOpcode(Inst.getOpcode());
258 for (unsigned i = 0, n = Inst.getNumOperands(); i != n; ++i) {
259 if (i != OpNo) {
260 T.addOperand(Inst.getOperand(i));
261 continue;
262 }
263 MCOperand &ImmOp = Inst.getOperand(i);
264 const auto *HE = static_cast<const HexagonMCExpr*>(ImmOp.getExpr());
265 int32_t V = cast<MCConstantExpr>(HE->getExpr())->getValue();
266 auto *NewCE = MCConstantExpr::create(V / int32_t(VectorSize), Ctx);
267 auto *NewHE = HexagonMCExpr::create(NewCE, Ctx);
268 T.addOperand(MCOperand::createExpr(NewHE));
269 }
270 return T;
271}
272
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000273void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
274 const MachineInstr &MI) {
275 MCInst &MappedInst = static_cast <MCInst &>(Inst);
276 const MCRegisterInfo *RI = OutStreamer->getContext().getRegisterInfo();
Krzysztof Parzyszek058abf1a2017-04-06 17:28:21 +0000277 const MachineFunction &MF = *MI.getParent()->getParent();
Krzysztof Parzyszek55772972017-09-15 15:46:05 +0000278 auto &HRI = *MF.getSubtarget<HexagonSubtarget>().getRegisterInfo();
279 unsigned VectorSize = HRI.getRegSizeInBits(Hexagon::HvxVRRegClass) / 8;
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000280
281 switch (Inst.getOpcode()) {
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000282 default:
283 return;
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000284
Colin LeMahieuecef1d92016-02-16 20:38:17 +0000285 case Hexagon::A2_iconst: {
286 Inst.setOpcode(Hexagon::A2_addi);
287 MCOperand Reg = Inst.getOperand(0);
288 MCOperand S16 = Inst.getOperand(1);
289 HexagonMCInstrInfo::setMustNotExtend(*S16.getExpr());
Krzysztof Parzyszek57a8bb432017-05-02 18:19:11 +0000290 HexagonMCInstrInfo::setS27_2_reloc(*S16.getExpr());
Colin LeMahieuecef1d92016-02-16 20:38:17 +0000291 Inst.clear();
292 Inst.addOperand(Reg);
293 Inst.addOperand(MCOperand::createReg(Hexagon::R0));
294 Inst.addOperand(S16);
295 break;
296 }
297
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000298 case Hexagon::A2_tfrf: {
299 const MCConstantExpr *Zero = MCConstantExpr::create(0, OutContext);
Krzysztof Parzyszekc8d676e2017-02-07 17:42:11 +0000300 Inst.setOpcode(Hexagon::A2_paddif);
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000301 Inst.addOperand(MCOperand::createExpr(Zero));
Krzysztof Parzyszekc8d676e2017-02-07 17:42:11 +0000302 break;
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000303 }
Krzysztof Parzyszekc8d676e2017-02-07 17:42:11 +0000304
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000305 case Hexagon::A2_tfrt: {
306 const MCConstantExpr *Zero = MCConstantExpr::create(0, OutContext);
Krzysztof Parzyszekc8d676e2017-02-07 17:42:11 +0000307 Inst.setOpcode(Hexagon::A2_paddit);
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000308 Inst.addOperand(MCOperand::createExpr(Zero));
Krzysztof Parzyszekc8d676e2017-02-07 17:42:11 +0000309 break;
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000310 }
Krzysztof Parzyszekc8d676e2017-02-07 17:42:11 +0000311
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000312 case Hexagon::A2_tfrfnew: {
313 const MCConstantExpr *Zero = MCConstantExpr::create(0, OutContext);
Krzysztof Parzyszekc8d676e2017-02-07 17:42:11 +0000314 Inst.setOpcode(Hexagon::A2_paddifnew);
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000315 Inst.addOperand(MCOperand::createExpr(Zero));
Krzysztof Parzyszekc8d676e2017-02-07 17:42:11 +0000316 break;
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000317 }
Krzysztof Parzyszekc8d676e2017-02-07 17:42:11 +0000318
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000319 case Hexagon::A2_tfrtnew: {
320 const MCConstantExpr *Zero = MCConstantExpr::create(0, OutContext);
Krzysztof Parzyszekc8d676e2017-02-07 17:42:11 +0000321 Inst.setOpcode(Hexagon::A2_padditnew);
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000322 Inst.addOperand(MCOperand::createExpr(Zero));
Krzysztof Parzyszekc8d676e2017-02-07 17:42:11 +0000323 break;
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000324 }
Krzysztof Parzyszekc8d676e2017-02-07 17:42:11 +0000325
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000326 case Hexagon::A2_zxtb: {
327 const MCConstantExpr *C255 = MCConstantExpr::create(255, OutContext);
Krzysztof Parzyszekc8d676e2017-02-07 17:42:11 +0000328 Inst.setOpcode(Hexagon::A2_andir);
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000329 Inst.addOperand(MCOperand::createExpr(C255));
Krzysztof Parzyszekc8d676e2017-02-07 17:42:11 +0000330 break;
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000331 }
Krzysztof Parzyszekc8d676e2017-02-07 17:42:11 +0000332
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000333 // "$dst = CONST64(#$src1)",
Krzysztof Parzyszeka3386502016-08-10 16:46:36 +0000334 case Hexagon::CONST64:
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000335 if (!OutStreamer->hasRawTextSupport()) {
336 const MCOperand &Imm = MappedInst.getOperand(1);
337 MCSectionSubPair Current = OutStreamer->getCurrentSection();
338
339 MCSymbol *Sym = smallData(*this, MI, *OutStreamer, Imm, 8);
340
341 OutStreamer->SwitchSection(Current.first, Current.second);
342 MCInst TmpInst;
343 MCOperand &Reg = MappedInst.getOperand(0);
344 TmpInst.setOpcode(Hexagon::L2_loadrdgp);
345 TmpInst.addOperand(Reg);
346 TmpInst.addOperand(MCOperand::createExpr(
347 MCSymbolRefExpr::create(Sym, OutContext)));
348 MappedInst = TmpInst;
349
350 }
351 break;
352 case Hexagon::CONST32:
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000353 if (!OutStreamer->hasRawTextSupport()) {
354 MCOperand &Imm = MappedInst.getOperand(1);
355 MCSectionSubPair Current = OutStreamer->getCurrentSection();
356 MCSymbol *Sym = smallData(*this, MI, *OutStreamer, Imm, 4);
357 OutStreamer->SwitchSection(Current.first, Current.second);
358 MCInst TmpInst;
359 MCOperand &Reg = MappedInst.getOperand(0);
360 TmpInst.setOpcode(Hexagon::L2_loadrigp);
361 TmpInst.addOperand(Reg);
Colin LeMahieuc7b21242016-02-15 18:47:55 +0000362 TmpInst.addOperand(MCOperand::createExpr(HexagonMCExpr::create(
Colin LeMahieu98c8e072016-02-15 18:42:07 +0000363 MCSymbolRefExpr::create(Sym, OutContext), OutContext)));
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000364 MappedInst = TmpInst;
365 }
366 break;
367
368 // C2_pxfer_map maps to C2_or instruction. Though, it's possible to use
369 // C2_or during instruction selection itself but it results
370 // into suboptimal code.
371 case Hexagon::C2_pxfer_map: {
372 MCOperand &Ps = Inst.getOperand(1);
373 MappedInst.setOpcode(Hexagon::C2_or);
374 MappedInst.addOperand(Ps);
375 return;
376 }
377
378 // Vector reduce complex multiply by scalar, Rt & 1 map to :hi else :lo
379 // The insn is mapped from the 4 operand to the 3 operand raw form taking
380 // 3 register pairs.
381 case Hexagon::M2_vrcmpys_acc_s1: {
382 MCOperand &Rt = Inst.getOperand(3);
Eugene Zelenko52889212017-08-01 21:20:10 +0000383 assert(Rt.isReg() && "Expected register and none was found");
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000384 unsigned Reg = RI->getEncodingValue(Rt.getReg());
385 if (Reg & 1)
386 MappedInst.setOpcode(Hexagon::M2_vrcmpys_acc_s1_h);
387 else
388 MappedInst.setOpcode(Hexagon::M2_vrcmpys_acc_s1_l);
389 Rt.setReg(getHexagonRegisterPair(Rt.getReg(), RI));
390 return;
391 }
392 case Hexagon::M2_vrcmpys_s1: {
393 MCOperand &Rt = Inst.getOperand(2);
Eugene Zelenko52889212017-08-01 21:20:10 +0000394 assert(Rt.isReg() && "Expected register and none was found");
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000395 unsigned Reg = RI->getEncodingValue(Rt.getReg());
396 if (Reg & 1)
397 MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1_h);
398 else
399 MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1_l);
400 Rt.setReg(getHexagonRegisterPair(Rt.getReg(), RI));
401 return;
402 }
403
404 case Hexagon::M2_vrcmpys_s1rp: {
405 MCOperand &Rt = Inst.getOperand(2);
Eugene Zelenko52889212017-08-01 21:20:10 +0000406 assert(Rt.isReg() && "Expected register and none was found");
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000407 unsigned Reg = RI->getEncodingValue(Rt.getReg());
408 if (Reg & 1)
409 MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1rp_h);
410 else
411 MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1rp_l);
412 Rt.setReg(getHexagonRegisterPair(Rt.getReg(), RI));
413 return;
414 }
415
416 case Hexagon::A4_boundscheck: {
417 MCOperand &Rs = Inst.getOperand(1);
Eugene Zelenko52889212017-08-01 21:20:10 +0000418 assert(Rs.isReg() && "Expected register and none was found");
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000419 unsigned Reg = RI->getEncodingValue(Rs.getReg());
420 if (Reg & 1) // Odd mapped to raw:hi, regpair is rodd:odd-1, like r3:2
421 MappedInst.setOpcode(Hexagon::A4_boundscheck_hi);
422 else // raw:lo
423 MappedInst.setOpcode(Hexagon::A4_boundscheck_lo);
424 Rs.setReg(getHexagonRegisterPair(Rs.getReg(), RI));
425 return;
426 }
Eugene Zelenko52889212017-08-01 21:20:10 +0000427
Krzysztof Parzyszekc8d676e2017-02-07 17:42:11 +0000428 case Hexagon::PS_call_nr:
429 Inst.setOpcode(Hexagon::J2_call);
430 break;
Eugene Zelenko52889212017-08-01 21:20:10 +0000431
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000432 case Hexagon::S5_asrhub_rnd_sat_goodsyntax: {
433 MCOperand &MO = MappedInst.getOperand(2);
434 int64_t Imm;
435 MCExpr const *Expr = MO.getExpr();
436 bool Success = Expr->evaluateAsAbsolute(Imm);
Eugene Zelenko52889212017-08-01 21:20:10 +0000437 assert(Success && "Expected immediate and none was found");
Colin LeMahieu98c8e072016-02-15 18:42:07 +0000438 (void)Success;
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000439 MCInst TmpInst;
440 if (Imm == 0) {
441 TmpInst.setOpcode(Hexagon::S2_vsathub);
442 TmpInst.addOperand(MappedInst.getOperand(0));
443 TmpInst.addOperand(MappedInst.getOperand(1));
444 MappedInst = TmpInst;
445 return;
446 }
447 TmpInst.setOpcode(Hexagon::S5_asrhub_rnd_sat);
448 TmpInst.addOperand(MappedInst.getOperand(0));
449 TmpInst.addOperand(MappedInst.getOperand(1));
450 const MCExpr *One = MCConstantExpr::create(1, OutContext);
451 const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
Colin LeMahieu98c8e072016-02-15 18:42:07 +0000452 TmpInst.addOperand(
Colin LeMahieuc7b21242016-02-15 18:47:55 +0000453 MCOperand::createExpr(HexagonMCExpr::create(Sub, OutContext)));
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000454 MappedInst = TmpInst;
455 return;
456 }
Eugene Zelenko52889212017-08-01 21:20:10 +0000457
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000458 case Hexagon::S5_vasrhrnd_goodsyntax:
459 case Hexagon::S2_asr_i_p_rnd_goodsyntax: {
460 MCOperand &MO2 = MappedInst.getOperand(2);
461 MCExpr const *Expr = MO2.getExpr();
462 int64_t Imm;
463 bool Success = Expr->evaluateAsAbsolute(Imm);
Eugene Zelenko52889212017-08-01 21:20:10 +0000464 assert(Success && "Expected immediate and none was found");
Colin LeMahieu98c8e072016-02-15 18:42:07 +0000465 (void)Success;
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000466 MCInst TmpInst;
467 if (Imm == 0) {
468 TmpInst.setOpcode(Hexagon::A2_combinew);
469 TmpInst.addOperand(MappedInst.getOperand(0));
470 MCOperand &MO1 = MappedInst.getOperand(1);
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +0000471 unsigned High = RI->getSubReg(MO1.getReg(), Hexagon::isub_hi);
472 unsigned Low = RI->getSubReg(MO1.getReg(), Hexagon::isub_lo);
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000473 // Add a new operand for the second register in the pair.
474 TmpInst.addOperand(MCOperand::createReg(High));
475 TmpInst.addOperand(MCOperand::createReg(Low));
476 MappedInst = TmpInst;
477 return;
478 }
479
480 if (Inst.getOpcode() == Hexagon::S2_asr_i_p_rnd_goodsyntax)
481 TmpInst.setOpcode(Hexagon::S2_asr_i_p_rnd);
482 else
483 TmpInst.setOpcode(Hexagon::S5_vasrhrnd);
484 TmpInst.addOperand(MappedInst.getOperand(0));
485 TmpInst.addOperand(MappedInst.getOperand(1));
486 const MCExpr *One = MCConstantExpr::create(1, OutContext);
487 const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
Colin LeMahieu98c8e072016-02-15 18:42:07 +0000488 TmpInst.addOperand(
Colin LeMahieuc7b21242016-02-15 18:47:55 +0000489 MCOperand::createExpr(HexagonMCExpr::create(Sub, OutContext)));
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000490 MappedInst = TmpInst;
491 return;
492 }
Eugene Zelenko52889212017-08-01 21:20:10 +0000493
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000494 // if ("#u5==0") Assembler mapped to: "Rd=Rs"; else Rd=asr(Rs,#u5-1):rnd
495 case Hexagon::S2_asr_i_r_rnd_goodsyntax: {
496 MCOperand &MO = Inst.getOperand(2);
497 MCExpr const *Expr = MO.getExpr();
498 int64_t Imm;
499 bool Success = Expr->evaluateAsAbsolute(Imm);
Eugene Zelenko52889212017-08-01 21:20:10 +0000500 assert(Success && "Expected immediate and none was found");
Colin LeMahieu98c8e072016-02-15 18:42:07 +0000501 (void)Success;
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000502 MCInst TmpInst;
503 if (Imm == 0) {
504 TmpInst.setOpcode(Hexagon::A2_tfr);
505 TmpInst.addOperand(MappedInst.getOperand(0));
506 TmpInst.addOperand(MappedInst.getOperand(1));
507 MappedInst = TmpInst;
508 return;
509 }
510 TmpInst.setOpcode(Hexagon::S2_asr_i_r_rnd);
511 TmpInst.addOperand(MappedInst.getOperand(0));
512 TmpInst.addOperand(MappedInst.getOperand(1));
513 const MCExpr *One = MCConstantExpr::create(1, OutContext);
514 const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
Colin LeMahieu98c8e072016-02-15 18:42:07 +0000515 TmpInst.addOperand(
Colin LeMahieuc7b21242016-02-15 18:47:55 +0000516 MCOperand::createExpr(HexagonMCExpr::create(Sub, OutContext)));
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000517 MappedInst = TmpInst;
518 return;
519 }
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000520
521 // Translate a "$Rdd = #imm" to "$Rdd = combine(#[-1,0], #imm)"
522 case Hexagon::A2_tfrpi: {
523 MCInst TmpInst;
524 MCOperand &Rdd = MappedInst.getOperand(0);
525 MCOperand &MO = MappedInst.getOperand(1);
526
527 TmpInst.setOpcode(Hexagon::A2_combineii);
528 TmpInst.addOperand(Rdd);
529 int64_t Imm;
530 bool Success = MO.getExpr()->evaluateAsAbsolute(Imm);
531 if (Success && Imm < 0) {
532 const MCExpr *MOne = MCConstantExpr::create(-1, OutContext);
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000533 const HexagonMCExpr *E = HexagonMCExpr::create(MOne, OutContext);
534 TmpInst.addOperand(MCOperand::createExpr(E));
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000535 } else {
536 const MCExpr *Zero = MCConstantExpr::create(0, OutContext);
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000537 const HexagonMCExpr *E = HexagonMCExpr::create(Zero, OutContext);
538 TmpInst.addOperand(MCOperand::createExpr(E));
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000539 }
540 TmpInst.addOperand(MO);
541 MappedInst = TmpInst;
542 return;
543 }
Eugene Zelenko52889212017-08-01 21:20:10 +0000544
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000545 // Translate a "$Rdd = $Rss" to "$Rdd = combine($Rs, $Rt)"
546 case Hexagon::A2_tfrp: {
547 MCOperand &MO = MappedInst.getOperand(1);
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +0000548 unsigned High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi);
549 unsigned Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo);
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000550 MO.setReg(High);
551 // Add a new operand for the second register in the pair.
552 MappedInst.addOperand(MCOperand::createReg(Low));
553 MappedInst.setOpcode(Hexagon::A2_combinew);
554 return;
555 }
556
557 case Hexagon::A2_tfrpt:
558 case Hexagon::A2_tfrpf: {
559 MCOperand &MO = MappedInst.getOperand(2);
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +0000560 unsigned High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi);
561 unsigned Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo);
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000562 MO.setReg(High);
563 // Add a new operand for the second register in the pair.
564 MappedInst.addOperand(MCOperand::createReg(Low));
565 MappedInst.setOpcode((Inst.getOpcode() == Hexagon::A2_tfrpt)
566 ? Hexagon::C2_ccombinewt
567 : Hexagon::C2_ccombinewf);
568 return;
569 }
Eugene Zelenko52889212017-08-01 21:20:10 +0000570
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000571 case Hexagon::A2_tfrptnew:
572 case Hexagon::A2_tfrpfnew: {
573 MCOperand &MO = MappedInst.getOperand(2);
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +0000574 unsigned High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi);
575 unsigned Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo);
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000576 MO.setReg(High);
577 // Add a new operand for the second register in the pair.
578 MappedInst.addOperand(MCOperand::createReg(Low));
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000579 MappedInst.setOpcode(Inst.getOpcode() == Hexagon::A2_tfrptnew
580 ? Hexagon::C2_ccombinewnewt
581 : Hexagon::C2_ccombinewnewf);
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000582 return;
583 }
584
585 case Hexagon::M2_mpysmi: {
586 MCOperand &Imm = MappedInst.getOperand(2);
587 MCExpr const *Expr = Imm.getExpr();
588 int64_t Value;
589 bool Success = Expr->evaluateAsAbsolute(Value);
Colin LeMahieu98c8e072016-02-15 18:42:07 +0000590 assert(Success);
591 (void)Success;
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000592 if (Value < 0 && Value > -256) {
593 MappedInst.setOpcode(Hexagon::M2_mpysin);
Colin LeMahieuc7b21242016-02-15 18:47:55 +0000594 Imm.setExpr(HexagonMCExpr::create(
Colin LeMahieu98c8e072016-02-15 18:42:07 +0000595 MCUnaryExpr::createMinus(Expr, OutContext), OutContext));
596 } else
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000597 MappedInst.setOpcode(Hexagon::M2_mpysip);
598 return;
599 }
600
601 case Hexagon::A2_addsp: {
602 MCOperand &Rt = Inst.getOperand(1);
Eugene Zelenko52889212017-08-01 21:20:10 +0000603 assert(Rt.isReg() && "Expected register and none was found");
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000604 unsigned Reg = RI->getEncodingValue(Rt.getReg());
605 if (Reg & 1)
606 MappedInst.setOpcode(Hexagon::A2_addsph);
607 else
608 MappedInst.setOpcode(Hexagon::A2_addspl);
609 Rt.setReg(getHexagonRegisterPair(Rt.getReg(), RI));
610 return;
611 }
Eugene Zelenko52889212017-08-01 21:20:10 +0000612
Krzysztof Parzyszek55772972017-09-15 15:46:05 +0000613 case Hexagon::V6_vd0: {
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000614 MCInst TmpInst;
Eugene Zelenko52889212017-08-01 21:20:10 +0000615 assert(Inst.getOperand(0).isReg() &&
616 "Expected register and none was found");
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000617
618 TmpInst.setOpcode(Hexagon::V6_vxor);
619 TmpInst.addOperand(Inst.getOperand(0));
620 TmpInst.addOperand(Inst.getOperand(0));
621 TmpInst.addOperand(Inst.getOperand(0));
622 MappedInst = TmpInst;
623 return;
624 }
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000625
Krzysztof Parzyszeka8ab1b72017-12-11 18:57:54 +0000626 case Hexagon::V6_vdd0: {
627 MCInst TmpInst;
628 assert (Inst.getOperand(0).isReg() &&
629 "Expected register and none was found");
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000630
Krzysztof Parzyszeka8ab1b72017-12-11 18:57:54 +0000631 TmpInst.setOpcode(Hexagon::V6_vsubw_dv);
632 TmpInst.addOperand(Inst.getOperand(0));
633 TmpInst.addOperand(Inst.getOperand(0));
634 TmpInst.addOperand(Inst.getOperand(0));
635 MappedInst = TmpInst;
636 return;
637 }
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000638
Krzysztof Parzyszek058abf1a2017-04-06 17:28:21 +0000639 case Hexagon::V6_vL32Ub_pi:
640 case Hexagon::V6_vL32b_cur_pi:
641 case Hexagon::V6_vL32b_nt_cur_pi:
642 case Hexagon::V6_vL32b_pi:
643 case Hexagon::V6_vL32b_nt_pi:
644 case Hexagon::V6_vL32b_nt_tmp_pi:
645 case Hexagon::V6_vL32b_tmp_pi:
Krzysztof Parzyszek058abf1a2017-04-06 17:28:21 +0000646 MappedInst = ScaleVectorOffset(Inst, 3, VectorSize, OutContext);
647 return;
648
649 case Hexagon::V6_vL32Ub_ai:
650 case Hexagon::V6_vL32b_ai:
651 case Hexagon::V6_vL32b_cur_ai:
652 case Hexagon::V6_vL32b_nt_ai:
653 case Hexagon::V6_vL32b_nt_cur_ai:
654 case Hexagon::V6_vL32b_nt_tmp_ai:
655 case Hexagon::V6_vL32b_tmp_ai:
Krzysztof Parzyszek058abf1a2017-04-06 17:28:21 +0000656 MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext);
657 return;
658
659 case Hexagon::V6_vS32Ub_pi:
660 case Hexagon::V6_vS32b_new_pi:
661 case Hexagon::V6_vS32b_nt_new_pi:
662 case Hexagon::V6_vS32b_nt_pi:
663 case Hexagon::V6_vS32b_pi:
Krzysztof Parzyszek058abf1a2017-04-06 17:28:21 +0000664 MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext);
665 return;
666
667 case Hexagon::V6_vS32Ub_ai:
668 case Hexagon::V6_vS32b_ai:
669 case Hexagon::V6_vS32b_new_ai:
670 case Hexagon::V6_vS32b_nt_ai:
671 case Hexagon::V6_vS32b_nt_new_ai:
Krzysztof Parzyszek058abf1a2017-04-06 17:28:21 +0000672 MappedInst = ScaleVectorOffset(Inst, 1, VectorSize, OutContext);
673 return;
674
675 case Hexagon::V6_vL32b_cur_npred_pi:
676 case Hexagon::V6_vL32b_cur_pred_pi:
677 case Hexagon::V6_vL32b_npred_pi:
678 case Hexagon::V6_vL32b_nt_cur_npred_pi:
679 case Hexagon::V6_vL32b_nt_cur_pred_pi:
680 case Hexagon::V6_vL32b_nt_npred_pi:
681 case Hexagon::V6_vL32b_nt_pred_pi:
682 case Hexagon::V6_vL32b_nt_tmp_npred_pi:
683 case Hexagon::V6_vL32b_nt_tmp_pred_pi:
684 case Hexagon::V6_vL32b_pred_pi:
685 case Hexagon::V6_vL32b_tmp_npred_pi:
686 case Hexagon::V6_vL32b_tmp_pred_pi:
Krzysztof Parzyszek058abf1a2017-04-06 17:28:21 +0000687 MappedInst = ScaleVectorOffset(Inst, 4, VectorSize, OutContext);
688 return;
689
690 case Hexagon::V6_vL32b_cur_npred_ai:
691 case Hexagon::V6_vL32b_cur_pred_ai:
692 case Hexagon::V6_vL32b_npred_ai:
693 case Hexagon::V6_vL32b_nt_cur_npred_ai:
694 case Hexagon::V6_vL32b_nt_cur_pred_ai:
695 case Hexagon::V6_vL32b_nt_npred_ai:
696 case Hexagon::V6_vL32b_nt_pred_ai:
697 case Hexagon::V6_vL32b_nt_tmp_npred_ai:
698 case Hexagon::V6_vL32b_nt_tmp_pred_ai:
699 case Hexagon::V6_vL32b_pred_ai:
700 case Hexagon::V6_vL32b_tmp_npred_ai:
701 case Hexagon::V6_vL32b_tmp_pred_ai:
Krzysztof Parzyszek058abf1a2017-04-06 17:28:21 +0000702 MappedInst = ScaleVectorOffset(Inst, 3, VectorSize, OutContext);
703 return;
704
705 case Hexagon::V6_vS32Ub_npred_pi:
706 case Hexagon::V6_vS32Ub_pred_pi:
707 case Hexagon::V6_vS32b_new_npred_pi:
708 case Hexagon::V6_vS32b_new_pred_pi:
709 case Hexagon::V6_vS32b_npred_pi:
710 case Hexagon::V6_vS32b_nqpred_pi:
711 case Hexagon::V6_vS32b_nt_new_npred_pi:
712 case Hexagon::V6_vS32b_nt_new_pred_pi:
713 case Hexagon::V6_vS32b_nt_npred_pi:
714 case Hexagon::V6_vS32b_nt_nqpred_pi:
715 case Hexagon::V6_vS32b_nt_pred_pi:
716 case Hexagon::V6_vS32b_nt_qpred_pi:
717 case Hexagon::V6_vS32b_pred_pi:
718 case Hexagon::V6_vS32b_qpred_pi:
Krzysztof Parzyszek058abf1a2017-04-06 17:28:21 +0000719 MappedInst = ScaleVectorOffset(Inst, 3, VectorSize, OutContext);
720 return;
721
722 case Hexagon::V6_vS32Ub_npred_ai:
723 case Hexagon::V6_vS32Ub_pred_ai:
724 case Hexagon::V6_vS32b_new_npred_ai:
725 case Hexagon::V6_vS32b_new_pred_ai:
726 case Hexagon::V6_vS32b_npred_ai:
727 case Hexagon::V6_vS32b_nqpred_ai:
728 case Hexagon::V6_vS32b_nt_new_npred_ai:
729 case Hexagon::V6_vS32b_nt_new_pred_ai:
730 case Hexagon::V6_vS32b_nt_npred_ai:
731 case Hexagon::V6_vS32b_nt_nqpred_ai:
732 case Hexagon::V6_vS32b_nt_pred_ai:
733 case Hexagon::V6_vS32b_nt_qpred_ai:
734 case Hexagon::V6_vS32b_pred_ai:
735 case Hexagon::V6_vS32b_qpred_ai:
Krzysztof Parzyszek058abf1a2017-04-06 17:28:21 +0000736 MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext);
737 return;
Krzysztof Parzyszeka8ab1b72017-12-11 18:57:54 +0000738
739 // V65+
740 case Hexagon::V6_vS32b_srls_ai:
741 MappedInst = ScaleVectorOffset(Inst, 1, VectorSize, OutContext);
742 return;
743
744 case Hexagon::V6_vS32b_srls_pi:
745 MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext);
746 return;
Krzysztof Parzyszek372bd802015-12-15 17:05:45 +0000747 }
748}
749
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000750/// Print out a single Hexagon MI to the current output stream.
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000751void HexagonAsmPrinter::EmitInstruction(const MachineInstr *MI) {
Krzysztof Parzyszeka8ab1b72017-12-11 18:57:54 +0000752 MCInst MCB;
753 MCB.setOpcode(Hexagon::BUNDLE);
754 MCB.addOperand(MCOperand::createImm(0));
Krzysztof Parzyszek8d8b2292015-12-02 23:08:29 +0000755 const MCInstrInfo &MCII = *Subtarget->getInstrInfo();
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000756
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000757 if (MI->isBundle()) {
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000758 const MachineBasicBlock* MBB = MI->getParent();
Duncan P. N. Exon Smithc5b668d2016-02-22 20:49:58 +0000759 MachineBasicBlock::const_instr_iterator MII = MI->getIterator();
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000760
Colin LeMahieu7c572b22015-12-03 16:37:21 +0000761 for (++MII; MII != MBB->instr_end() && MII->isInsideBundle(); ++MII)
Shiva Chen801bf7e2018-05-09 02:42:00 +0000762 if (!MII->isDebugInstr() && !MII->isImplicitDef())
Krzysztof Parzyszek8d8b2292015-12-02 23:08:29 +0000763 HexagonLowerToMC(MCII, &*MII, MCB, *this);
Krzysztof Parzyszek46abcb22018-03-30 15:09:05 +0000764 } else {
Krzysztof Parzyszek8d8b2292015-12-02 23:08:29 +0000765 HexagonLowerToMC(MCII, MI, MCB, *this);
Krzysztof Parzyszek46abcb22018-03-30 15:09:05 +0000766 }
767
768 const MachineFunction &MF = *MI->getParent()->getParent();
769 const auto &HII = *MF.getSubtarget<HexagonSubtarget>().getInstrInfo();
770 if (MI->isBundle() && HII.getBundleNoShuf(*MI))
771 HexagonMCInstrInfo::setMemReorderDisabled(MCB);
Colin LeMahieu7c572b22015-12-03 16:37:21 +0000772
Krzysztof Parzyszek0831f572018-04-02 15:06:55 +0000773 MCContext &Ctx = OutStreamer->getContext();
774 bool Ok = HexagonMCInstrInfo::canonicalizePacket(MCII, *Subtarget, Ctx,
775 MCB, nullptr);
776 assert(Ok); (void)Ok;
777 if (HexagonMCInstrInfo::bundleSize(MCB) == 0)
Colin LeMahieu7c572b22015-12-03 16:37:21 +0000778 return;
779 OutStreamer->EmitInstruction(MCB, getSubtargetInfo());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000780}
781
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000782extern "C" void LLVMInitializeHexagonAsmPrinter() {
Mehdi Aminif42454b2016-10-09 23:00:34 +0000783 RegisterAsmPrinter<HexagonAsmPrinter> X(getTheHexagonTarget());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000784}