Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 1 | //===- HexagonAsmPrinter.cpp - Print machine instrs to Hexagon assembly ---===// |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2 | // |
| 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 Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Jyotsna Verma | 7503a62 | 2013-02-20 16:13:27 +0000 | [diff] [blame] | 16 | #include "HexagonAsmPrinter.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 17 | #include "Hexagon.h" |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 18 | #include "HexagonInstrInfo.h" |
| 19 | #include "HexagonRegisterInfo.h" |
Jyotsna Verma | 7503a62 | 2013-02-20 16:13:27 +0000 | [diff] [blame] | 20 | #include "HexagonSubtarget.h" |
Colin LeMahieu | ff06261 | 2014-11-20 21:56:35 +0000 | [diff] [blame] | 21 | #include "MCTargetDesc/HexagonInstPrinter.h" |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 22 | #include "MCTargetDesc/HexagonMCExpr.h" |
Colin LeMahieu | 1174fea | 2015-02-19 21:10:50 +0000 | [diff] [blame] | 23 | #include "MCTargetDesc/HexagonMCInstrInfo.h" |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 24 | #include "MCTargetDesc/HexagonMCTargetDesc.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/StringExtras.h" |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/StringRef.h" |
| 27 | #include "llvm/ADT/Twine.h" |
Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 28 | #include "llvm/BinaryFormat/ELF.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/AsmPrinter.h" |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 31 | #include "llvm/CodeGen/MachineFunction.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/MachineInstr.h" |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/MachineOperand.h" |
David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/TargetRegisterInfo.h" |
| 35 | #include "llvm/CodeGen/TargetSubtargetInfo.h" |
Evandro Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 36 | #include "llvm/MC/MCContext.h" |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 37 | #include "llvm/MC/MCDirectives.h" |
Evandro Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 38 | #include "llvm/MC/MCExpr.h" |
| 39 | #include "llvm/MC/MCInst.h" |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 40 | #include "llvm/MC/MCRegisterInfo.h" |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 41 | #include "llvm/MC/MCSectionELF.h" |
Evandro Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 42 | #include "llvm/MC/MCStreamer.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 43 | #include "llvm/MC/MCSymbol.h" |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 44 | #include "llvm/Support/Casting.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 45 | #include "llvm/Support/CommandLine.h" |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 46 | #include "llvm/Support/ErrorHandling.h" |
Craig Topper | b25fda9 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 47 | #include "llvm/Support/TargetRegistry.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 48 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 49 | #include <algorithm> |
| 50 | #include <cassert> |
| 51 | #include <cstdint> |
| 52 | #include <string> |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 53 | |
| 54 | using namespace llvm; |
| 55 | |
Krzysztof Parzyszek | 8d8b229 | 2015-12-02 23:08:29 +0000 | [diff] [blame] | 56 | namespace llvm { |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 57 | |
| 58 | void HexagonLowerToMC(const MCInstrInfo &MCII, const MachineInstr *MI, |
| 59 | MCInst &MCB, HexagonAsmPrinter &AP); |
| 60 | |
| 61 | } // end namespace llvm |
Krzysztof Parzyszek | 8d8b229 | 2015-12-02 23:08:29 +0000 | [diff] [blame] | 62 | |
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 63 | #define DEBUG_TYPE "asm-printer" |
| 64 | |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 65 | // Given a scalar register return its pair. |
| 66 | inline 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 Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 75 | void HexagonAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, |
Krzysztof Parzyszek | 29c567a | 2016-07-26 17:31:02 +0000 | [diff] [blame] | 76 | raw_ostream &O) { |
Evandro Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 77 | const MachineOperand &MO = MI->getOperand(OpNo); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 78 | |
Evandro Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 79 | switch (MO.getType()) { |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 80 | default: |
| 81 | llvm_unreachable ("<unknown operand type>"); |
Evandro Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 82 | case MachineOperand::MO_Register: |
| 83 | O << HexagonInstPrinter::getRegisterName(MO.getReg()); |
| 84 | return; |
| 85 | case MachineOperand::MO_Immediate: |
| 86 | O << MO.getImm(); |
| 87 | return; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 88 | case MachineOperand::MO_MachineBasicBlock: |
Matt Arsenault | 8b64355 | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 89 | MO.getMBB()->getSymbol()->print(O, MAI); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 90 | return; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 91 | case MachineOperand::MO_ConstantPoolIndex: |
Matt Arsenault | 8b64355 | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 92 | GetCPISymbol(MO.getIndex())->print(O, MAI); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 93 | return; |
Evandro Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 94 | case MachineOperand::MO_GlobalAddress: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 95 | // Computing the address of a global symbol, not calling it. |
Matt Arsenault | 8b64355 | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 96 | getSymbol(MO.getGlobal())->print(O, MAI); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 97 | printOffset(MO.getOffset(), O); |
| 98 | return; |
| 99 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 102 | // 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 Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 108 | bool HexagonAsmPrinter::isBlockOnlyReachableByFallthrough( |
| 109 | const MachineBasicBlock *MBB) const { |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 110 | if (MBB->hasAddressTaken()) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 111 | return false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 112 | return AsmPrinter::isBlockOnlyReachableByFallthrough(MBB); |
| 113 | } |
| 114 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 115 | /// PrintAsmOperand - Print out an operand for an inline asm expression. |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 116 | bool HexagonAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
| 117 | unsigned AsmVariant, |
| 118 | const char *ExtraCode, |
Evandro Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 119 | raw_ostream &OS) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 120 | // Does this asm operand have a single letter operand modifier? |
| 121 | if (ExtraCode && ExtraCode[0]) { |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 122 | if (ExtraCode[1] != 0) |
| 123 | return true; // Unknown modifier. |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 124 | |
| 125 | switch (ExtraCode[0]) { |
Jack Carter | 5e69cff | 2012-06-26 13:49:27 +0000 | [diff] [blame] | 126 | default: |
| 127 | // See if this is a generic print operand |
| 128 | return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, OS); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 129 | 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 Parzyszek | 29c567a | 2016-07-26 17:31:02 +0000 | [diff] [blame] | 133 | 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 Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 139 | return true; |
Krzysztof Parzyszek | 29c567a | 2016-07-26 17:31:02 +0000 | [diff] [blame] | 140 | 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 Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 144 | Hexagon::isub_lo : |
| 145 | Hexagon::isub_hi); |
Krzysztof Parzyszek | 29c567a | 2016-07-26 17:31:02 +0000 | [diff] [blame] | 146 | OS << HexagonInstPrinter::getRegisterName(RegNumber); |
| 147 | return false; |
| 148 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 149 | 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 | |
| 162 | bool HexagonAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 163 | unsigned OpNo, |
| 164 | unsigned AsmVariant, |
Krzysztof Parzyszek | 067debe | 2016-08-19 14:12:51 +0000 | [diff] [blame] | 165 | const char *ExtraCode, |
| 166 | raw_ostream &O) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 167 | 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 Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 176 | llvm_unreachable("Unimplemented"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 177 | |
| 178 | if (Offset.isImm()) { |
| 179 | if (Offset.getImm()) |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 180 | O << "+#" << Offset.getImm(); |
| 181 | } else { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 182 | llvm_unreachable("Unimplemented"); |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 183 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 184 | |
| 185 | return false; |
| 186 | } |
| 187 | |
Benjamin Kramer | ab8cc02 | 2016-01-12 14:58:49 +0000 | [diff] [blame] | 188 | static MCSymbol *smallData(AsmPrinter &AP, const MachineInstr &MI, |
| 189 | MCStreamer &OutStreamer, const MCOperand &Imm, |
| 190 | int AlignSize) { |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 191 | 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 Parzyszek | 058abf1a | 2017-04-06 17:28:21 +0000 | [diff] [blame] | 254 | static 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 Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 273 | void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst, |
| 274 | const MachineInstr &MI) { |
| 275 | MCInst &MappedInst = static_cast <MCInst &>(Inst); |
| 276 | const MCRegisterInfo *RI = OutStreamer->getContext().getRegisterInfo(); |
Krzysztof Parzyszek | 058abf1a | 2017-04-06 17:28:21 +0000 | [diff] [blame] | 277 | const MachineFunction &MF = *MI.getParent()->getParent(); |
Krzysztof Parzyszek | 5577297 | 2017-09-15 15:46:05 +0000 | [diff] [blame] | 278 | auto &HRI = *MF.getSubtarget<HexagonSubtarget>().getRegisterInfo(); |
| 279 | unsigned VectorSize = HRI.getRegSizeInBits(Hexagon::HvxVRRegClass) / 8; |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 280 | |
| 281 | switch (Inst.getOpcode()) { |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 282 | default: |
| 283 | return; |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 284 | |
Colin LeMahieu | ecef1d9 | 2016-02-16 20:38:17 +0000 | [diff] [blame] | 285 | 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 Parzyszek | 57a8bb43 | 2017-05-02 18:19:11 +0000 | [diff] [blame] | 290 | HexagonMCInstrInfo::setS27_2_reloc(*S16.getExpr()); |
Colin LeMahieu | ecef1d9 | 2016-02-16 20:38:17 +0000 | [diff] [blame] | 291 | Inst.clear(); |
| 292 | Inst.addOperand(Reg); |
| 293 | Inst.addOperand(MCOperand::createReg(Hexagon::R0)); |
| 294 | Inst.addOperand(S16); |
| 295 | break; |
| 296 | } |
| 297 | |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 298 | case Hexagon::A2_tfrf: { |
| 299 | const MCConstantExpr *Zero = MCConstantExpr::create(0, OutContext); |
Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 300 | Inst.setOpcode(Hexagon::A2_paddif); |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 301 | Inst.addOperand(MCOperand::createExpr(Zero)); |
Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 302 | break; |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 303 | } |
Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 304 | |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 305 | case Hexagon::A2_tfrt: { |
| 306 | const MCConstantExpr *Zero = MCConstantExpr::create(0, OutContext); |
Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 307 | Inst.setOpcode(Hexagon::A2_paddit); |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 308 | Inst.addOperand(MCOperand::createExpr(Zero)); |
Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 309 | break; |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 310 | } |
Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 311 | |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 312 | case Hexagon::A2_tfrfnew: { |
| 313 | const MCConstantExpr *Zero = MCConstantExpr::create(0, OutContext); |
Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 314 | Inst.setOpcode(Hexagon::A2_paddifnew); |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 315 | Inst.addOperand(MCOperand::createExpr(Zero)); |
Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 316 | break; |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 317 | } |
Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 318 | |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 319 | case Hexagon::A2_tfrtnew: { |
| 320 | const MCConstantExpr *Zero = MCConstantExpr::create(0, OutContext); |
Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 321 | Inst.setOpcode(Hexagon::A2_padditnew); |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 322 | Inst.addOperand(MCOperand::createExpr(Zero)); |
Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 323 | break; |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 324 | } |
Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 325 | |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 326 | case Hexagon::A2_zxtb: { |
| 327 | const MCConstantExpr *C255 = MCConstantExpr::create(255, OutContext); |
Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 328 | Inst.setOpcode(Hexagon::A2_andir); |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 329 | Inst.addOperand(MCOperand::createExpr(C255)); |
Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 330 | break; |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 331 | } |
Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 332 | |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 333 | // "$dst = CONST64(#$src1)", |
Krzysztof Parzyszek | a338650 | 2016-08-10 16:46:36 +0000 | [diff] [blame] | 334 | case Hexagon::CONST64: |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 335 | 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 Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 353 | 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 LeMahieu | c7b2124 | 2016-02-15 18:47:55 +0000 | [diff] [blame] | 362 | TmpInst.addOperand(MCOperand::createExpr(HexagonMCExpr::create( |
Colin LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 363 | MCSymbolRefExpr::create(Sym, OutContext), OutContext))); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 364 | 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 Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 383 | assert(Rt.isReg() && "Expected register and none was found"); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 384 | 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 Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 394 | assert(Rt.isReg() && "Expected register and none was found"); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 395 | 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 Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 406 | assert(Rt.isReg() && "Expected register and none was found"); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 407 | 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 Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 418 | assert(Rs.isReg() && "Expected register and none was found"); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 419 | 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 Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 427 | |
Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 428 | case Hexagon::PS_call_nr: |
| 429 | Inst.setOpcode(Hexagon::J2_call); |
| 430 | break; |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 431 | |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 432 | 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 Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 437 | assert(Success && "Expected immediate and none was found"); |
Colin LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 438 | (void)Success; |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 439 | 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 LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 452 | TmpInst.addOperand( |
Colin LeMahieu | c7b2124 | 2016-02-15 18:47:55 +0000 | [diff] [blame] | 453 | MCOperand::createExpr(HexagonMCExpr::create(Sub, OutContext))); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 454 | MappedInst = TmpInst; |
| 455 | return; |
| 456 | } |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 457 | |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 458 | 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 Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 464 | assert(Success && "Expected immediate and none was found"); |
Colin LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 465 | (void)Success; |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 466 | 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 Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 471 | unsigned High = RI->getSubReg(MO1.getReg(), Hexagon::isub_hi); |
| 472 | unsigned Low = RI->getSubReg(MO1.getReg(), Hexagon::isub_lo); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 473 | // 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 LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 488 | TmpInst.addOperand( |
Colin LeMahieu | c7b2124 | 2016-02-15 18:47:55 +0000 | [diff] [blame] | 489 | MCOperand::createExpr(HexagonMCExpr::create(Sub, OutContext))); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 490 | MappedInst = TmpInst; |
| 491 | return; |
| 492 | } |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 493 | |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 494 | // 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 Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 500 | assert(Success && "Expected immediate and none was found"); |
Colin LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 501 | (void)Success; |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 502 | 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 LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 515 | TmpInst.addOperand( |
Colin LeMahieu | c7b2124 | 2016-02-15 18:47:55 +0000 | [diff] [blame] | 516 | MCOperand::createExpr(HexagonMCExpr::create(Sub, OutContext))); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 517 | MappedInst = TmpInst; |
| 518 | return; |
| 519 | } |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 520 | |
| 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 Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 533 | const HexagonMCExpr *E = HexagonMCExpr::create(MOne, OutContext); |
| 534 | TmpInst.addOperand(MCOperand::createExpr(E)); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 535 | } else { |
| 536 | const MCExpr *Zero = MCConstantExpr::create(0, OutContext); |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 537 | const HexagonMCExpr *E = HexagonMCExpr::create(Zero, OutContext); |
| 538 | TmpInst.addOperand(MCOperand::createExpr(E)); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 539 | } |
| 540 | TmpInst.addOperand(MO); |
| 541 | MappedInst = TmpInst; |
| 542 | return; |
| 543 | } |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 544 | |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 545 | // Translate a "$Rdd = $Rss" to "$Rdd = combine($Rs, $Rt)" |
| 546 | case Hexagon::A2_tfrp: { |
| 547 | MCOperand &MO = MappedInst.getOperand(1); |
Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 548 | unsigned High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi); |
| 549 | unsigned Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 550 | 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 Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 560 | unsigned High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi); |
| 561 | unsigned Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 562 | 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 Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 570 | |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 571 | case Hexagon::A2_tfrptnew: |
| 572 | case Hexagon::A2_tfrpfnew: { |
| 573 | MCOperand &MO = MappedInst.getOperand(2); |
Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 574 | unsigned High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi); |
| 575 | unsigned Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 576 | MO.setReg(High); |
| 577 | // Add a new operand for the second register in the pair. |
| 578 | MappedInst.addOperand(MCOperand::createReg(Low)); |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 579 | MappedInst.setOpcode(Inst.getOpcode() == Hexagon::A2_tfrptnew |
| 580 | ? Hexagon::C2_ccombinewnewt |
| 581 | : Hexagon::C2_ccombinewnewf); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 582 | 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 LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 590 | assert(Success); |
| 591 | (void)Success; |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 592 | if (Value < 0 && Value > -256) { |
| 593 | MappedInst.setOpcode(Hexagon::M2_mpysin); |
Colin LeMahieu | c7b2124 | 2016-02-15 18:47:55 +0000 | [diff] [blame] | 594 | Imm.setExpr(HexagonMCExpr::create( |
Colin LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 595 | MCUnaryExpr::createMinus(Expr, OutContext), OutContext)); |
| 596 | } else |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 597 | MappedInst.setOpcode(Hexagon::M2_mpysip); |
| 598 | return; |
| 599 | } |
| 600 | |
| 601 | case Hexagon::A2_addsp: { |
| 602 | MCOperand &Rt = Inst.getOperand(1); |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 603 | assert(Rt.isReg() && "Expected register and none was found"); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 604 | 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 Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 612 | |
Krzysztof Parzyszek | 5577297 | 2017-09-15 15:46:05 +0000 | [diff] [blame] | 613 | case Hexagon::V6_vd0: { |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 614 | MCInst TmpInst; |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 615 | assert(Inst.getOperand(0).isReg() && |
| 616 | "Expected register and none was found"); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 617 | |
| 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 Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 625 | |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 626 | case Hexagon::V6_vdd0: { |
| 627 | MCInst TmpInst; |
| 628 | assert (Inst.getOperand(0).isReg() && |
| 629 | "Expected register and none was found"); |
Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 630 | |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 631 | 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 Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 638 | |
Krzysztof Parzyszek | 058abf1a | 2017-04-06 17:28:21 +0000 | [diff] [blame] | 639 | 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 Parzyszek | 058abf1a | 2017-04-06 17:28:21 +0000 | [diff] [blame] | 646 | 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 Parzyszek | 058abf1a | 2017-04-06 17:28:21 +0000 | [diff] [blame] | 656 | 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 Parzyszek | 058abf1a | 2017-04-06 17:28:21 +0000 | [diff] [blame] | 664 | 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 Parzyszek | 058abf1a | 2017-04-06 17:28:21 +0000 | [diff] [blame] | 672 | 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 Parzyszek | 058abf1a | 2017-04-06 17:28:21 +0000 | [diff] [blame] | 687 | 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 Parzyszek | 058abf1a | 2017-04-06 17:28:21 +0000 | [diff] [blame] | 702 | 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 Parzyszek | 058abf1a | 2017-04-06 17:28:21 +0000 | [diff] [blame] | 719 | 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 Parzyszek | 058abf1a | 2017-04-06 17:28:21 +0000 | [diff] [blame] | 736 | MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext); |
| 737 | return; |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 738 | |
| 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 Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 750 | /// Print out a single Hexagon MI to the current output stream. |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 751 | void HexagonAsmPrinter::EmitInstruction(const MachineInstr *MI) { |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 752 | MCInst MCB; |
| 753 | MCB.setOpcode(Hexagon::BUNDLE); |
| 754 | MCB.addOperand(MCOperand::createImm(0)); |
Krzysztof Parzyszek | 8d8b229 | 2015-12-02 23:08:29 +0000 | [diff] [blame] | 755 | const MCInstrInfo &MCII = *Subtarget->getInstrInfo(); |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 756 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 757 | if (MI->isBundle()) { |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 758 | const MachineBasicBlock* MBB = MI->getParent(); |
Duncan P. N. Exon Smith | c5b668d | 2016-02-22 20:49:58 +0000 | [diff] [blame] | 759 | MachineBasicBlock::const_instr_iterator MII = MI->getIterator(); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 760 | |
Colin LeMahieu | 7c572b2 | 2015-12-03 16:37:21 +0000 | [diff] [blame] | 761 | for (++MII; MII != MBB->instr_end() && MII->isInsideBundle(); ++MII) |
Shiva Chen | 801bf7e | 2018-05-09 02:42:00 +0000 | [diff] [blame] | 762 | if (!MII->isDebugInstr() && !MII->isImplicitDef()) |
Krzysztof Parzyszek | 8d8b229 | 2015-12-02 23:08:29 +0000 | [diff] [blame] | 763 | HexagonLowerToMC(MCII, &*MII, MCB, *this); |
Krzysztof Parzyszek | 46abcb2 | 2018-03-30 15:09:05 +0000 | [diff] [blame] | 764 | } else { |
Krzysztof Parzyszek | 8d8b229 | 2015-12-02 23:08:29 +0000 | [diff] [blame] | 765 | HexagonLowerToMC(MCII, MI, MCB, *this); |
Krzysztof Parzyszek | 46abcb2 | 2018-03-30 15:09:05 +0000 | [diff] [blame] | 766 | } |
| 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 LeMahieu | 7c572b2 | 2015-12-03 16:37:21 +0000 | [diff] [blame] | 772 | |
Krzysztof Parzyszek | 0831f57 | 2018-04-02 15:06:55 +0000 | [diff] [blame] | 773 | 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 LeMahieu | 7c572b2 | 2015-12-03 16:37:21 +0000 | [diff] [blame] | 778 | return; |
| 779 | OutStreamer->EmitInstruction(MCB, getSubtargetInfo()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 780 | } |
| 781 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 782 | extern "C" void LLVMInitializeHexagonAsmPrinter() { |
Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 783 | RegisterAsmPrinter<HexagonAsmPrinter> X(getTheHexagonTarget()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 784 | } |