| 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" |
| Evandro Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 34 | #include "llvm/MC/MCContext.h" |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 35 | #include "llvm/MC/MCDirectives.h" |
| Evandro Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 36 | #include "llvm/MC/MCExpr.h" |
| 37 | #include "llvm/MC/MCInst.h" |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 38 | #include "llvm/MC/MCRegisterInfo.h" |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 39 | #include "llvm/MC/MCSectionELF.h" |
| Evandro Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 40 | #include "llvm/MC/MCStreamer.h" |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 41 | #include "llvm/MC/MCSymbol.h" |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 42 | #include "llvm/Support/Casting.h" |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 43 | #include "llvm/Support/CommandLine.h" |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 44 | #include "llvm/Support/ErrorHandling.h" |
| Craig Topper | b25fda9 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 45 | #include "llvm/Support/TargetRegistry.h" |
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 46 | #include "llvm/Support/raw_ostream.h" |
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 47 | #include "llvm/Target/TargetRegisterInfo.h" |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 48 | #include "llvm/Target/TargetSubtargetInfo.h" |
| 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 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 65 | static cl::opt<bool> AlignCalls( |
| 66 | "hexagon-align-calls", cl::Hidden, cl::init(true), |
| 67 | cl::desc("Insert falign after call instruction for Hexagon target")); |
| 68 | |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 69 | // Given a scalar register return its pair. |
| 70 | inline static unsigned getHexagonRegisterPair(unsigned Reg, |
| 71 | const MCRegisterInfo *RI) { |
| 72 | assert(Hexagon::IntRegsRegClass.contains(Reg)); |
| 73 | MCSuperRegIterator SR(Reg, RI, false); |
| 74 | unsigned Pair = *SR; |
| 75 | assert(Hexagon::DoubleRegsRegClass.contains(Pair)); |
| 76 | return Pair; |
| 77 | } |
| 78 | |
| David Blaikie | 9459832 | 2015-01-18 20:29:04 +0000 | [diff] [blame] | 79 | HexagonAsmPrinter::HexagonAsmPrinter(TargetMachine &TM, |
| 80 | std::unique_ptr<MCStreamer> Streamer) |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 81 | : AsmPrinter(TM, std::move(Streamer)) {} |
| David Blaikie | 9459832 | 2015-01-18 20:29:04 +0000 | [diff] [blame] | 82 | |
| Evandro Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 83 | void HexagonAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, |
| Krzysztof Parzyszek | 29c567a | 2016-07-26 17:31:02 +0000 | [diff] [blame] | 84 | raw_ostream &O) { |
| Evandro Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 85 | const MachineOperand &MO = MI->getOperand(OpNo); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 86 | |
| Evandro Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 87 | switch (MO.getType()) { |
| Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 88 | default: llvm_unreachable ("<unknown operand type>"); |
| Evandro Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 89 | case MachineOperand::MO_Register: |
| 90 | O << HexagonInstPrinter::getRegisterName(MO.getReg()); |
| 91 | return; |
| 92 | case MachineOperand::MO_Immediate: |
| 93 | O << MO.getImm(); |
| 94 | return; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 95 | case MachineOperand::MO_MachineBasicBlock: |
| Matt Arsenault | 8b64355 | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 96 | MO.getMBB()->getSymbol()->print(O, MAI); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 97 | return; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 98 | case MachineOperand::MO_ConstantPoolIndex: |
| Matt Arsenault | 8b64355 | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 99 | GetCPISymbol(MO.getIndex())->print(O, MAI); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 100 | return; |
| Evandro Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 101 | case MachineOperand::MO_GlobalAddress: |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 102 | // Computing the address of a global symbol, not calling it. |
| Matt Arsenault | 8b64355 | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 103 | getSymbol(MO.getGlobal())->print(O, MAI); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 104 | printOffset(MO.getOffset(), O); |
| 105 | return; |
| 106 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 109 | // isBlockOnlyReachableByFallthrough - We need to override this since the |
| 110 | // default AsmPrinter does not print labels for any basic block that |
| 111 | // is only reachable by a fall through. That works for all cases except |
| 112 | // for the case in which the basic block is reachable by a fall through but |
| 113 | // through an indirect from a jump table. In this case, the jump table |
| 114 | // will contain a label not defined by AsmPrinter. |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 115 | bool HexagonAsmPrinter:: |
| 116 | isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const { |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 117 | if (MBB->hasAddressTaken()) |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 118 | return false; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 119 | return AsmPrinter::isBlockOnlyReachableByFallthrough(MBB); |
| 120 | } |
| 121 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 122 | /// PrintAsmOperand - Print out an operand for an inline asm expression. |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 123 | bool HexagonAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
| 124 | unsigned AsmVariant, |
| 125 | const char *ExtraCode, |
| Evandro Menezes | 5cee621 | 2012-04-12 17:55:53 +0000 | [diff] [blame] | 126 | raw_ostream &OS) { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 127 | // Does this asm operand have a single letter operand modifier? |
| 128 | if (ExtraCode && ExtraCode[0]) { |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 129 | if (ExtraCode[1] != 0) |
| 130 | return true; // Unknown modifier. |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 131 | |
| 132 | switch (ExtraCode[0]) { |
| Jack Carter | 5e69cff | 2012-06-26 13:49:27 +0000 | [diff] [blame] | 133 | default: |
| 134 | // See if this is a generic print operand |
| 135 | return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, OS); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 136 | case 'c': // Don't print "$" before a global var name or constant. |
| 137 | // Hexagon never has a prefix. |
| 138 | printOperand(MI, OpNo, OS); |
| 139 | return false; |
| Krzysztof Parzyszek | 29c567a | 2016-07-26 17:31:02 +0000 | [diff] [blame] | 140 | case 'L': |
| 141 | case 'H': { // The highest-numbered register of a pair. |
| 142 | const MachineOperand &MO = MI->getOperand(OpNo); |
| 143 | const MachineFunction &MF = *MI->getParent()->getParent(); |
| 144 | const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo(); |
| 145 | if (!MO.isReg()) |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 146 | return true; |
| Krzysztof Parzyszek | 29c567a | 2016-07-26 17:31:02 +0000 | [diff] [blame] | 147 | unsigned RegNumber = MO.getReg(); |
| 148 | // This should be an assert in the frontend. |
| 149 | if (Hexagon::DoubleRegsRegClass.contains(RegNumber)) |
| 150 | RegNumber = TRI->getSubReg(RegNumber, ExtraCode[0] == 'L' ? |
| Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 151 | Hexagon::isub_lo : |
| 152 | Hexagon::isub_hi); |
| Krzysztof Parzyszek | 29c567a | 2016-07-26 17:31:02 +0000 | [diff] [blame] | 153 | OS << HexagonInstPrinter::getRegisterName(RegNumber); |
| 154 | return false; |
| 155 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 156 | case 'I': |
| 157 | // Write 'i' if an integer constant, otherwise nothing. Used to print |
| 158 | // addi vs add, etc. |
| 159 | if (MI->getOperand(OpNo).isImm()) |
| 160 | OS << "i"; |
| 161 | return false; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | printOperand(MI, OpNo, OS); |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | bool HexagonAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, |
| Krzysztof Parzyszek | 067debe | 2016-08-19 14:12:51 +0000 | [diff] [blame] | 170 | unsigned OpNo, unsigned AsmVariant, |
| 171 | const char *ExtraCode, |
| 172 | raw_ostream &O) { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 173 | if (ExtraCode && ExtraCode[0]) |
| 174 | return true; // Unknown modifier. |
| 175 | |
| 176 | const MachineOperand &Base = MI->getOperand(OpNo); |
| 177 | const MachineOperand &Offset = MI->getOperand(OpNo+1); |
| 178 | |
| 179 | if (Base.isReg()) |
| 180 | printOperand(MI, OpNo, O); |
| 181 | else |
| Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 182 | llvm_unreachable("Unimplemented"); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 183 | |
| 184 | if (Offset.isImm()) { |
| 185 | if (Offset.getImm()) |
| 186 | O << " + #" << Offset.getImm(); |
| 187 | } |
| 188 | else |
| Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 189 | llvm_unreachable("Unimplemented"); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 190 | |
| 191 | return false; |
| 192 | } |
| 193 | |
| Benjamin Kramer | ab8cc02 | 2016-01-12 14:58:49 +0000 | [diff] [blame] | 194 | static MCSymbol *smallData(AsmPrinter &AP, const MachineInstr &MI, |
| 195 | MCStreamer &OutStreamer, const MCOperand &Imm, |
| 196 | int AlignSize) { |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 197 | MCSymbol *Sym; |
| 198 | int64_t Value; |
| 199 | if (Imm.getExpr()->evaluateAsAbsolute(Value)) { |
| 200 | StringRef sectionPrefix; |
| 201 | std::string ImmString; |
| 202 | StringRef Name; |
| 203 | if (AlignSize == 8) { |
| 204 | Name = ".CONST_0000000000000000"; |
| 205 | sectionPrefix = ".gnu.linkonce.l8"; |
| 206 | ImmString = utohexstr(Value); |
| 207 | } else { |
| 208 | Name = ".CONST_00000000"; |
| 209 | sectionPrefix = ".gnu.linkonce.l4"; |
| 210 | ImmString = utohexstr(static_cast<uint32_t>(Value)); |
| 211 | } |
| 212 | |
| 213 | std::string symbolName = // Yes, leading zeros are kept. |
| 214 | Name.drop_back(ImmString.size()).str() + ImmString; |
| 215 | std::string sectionName = sectionPrefix.str() + symbolName; |
| 216 | |
| 217 | MCSectionELF *Section = OutStreamer.getContext().getELFSection( |
| 218 | sectionName, ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC); |
| 219 | OutStreamer.SwitchSection(Section); |
| 220 | |
| 221 | Sym = AP.OutContext.getOrCreateSymbol(Twine(symbolName)); |
| 222 | if (Sym->isUndefined()) { |
| 223 | OutStreamer.EmitLabel(Sym); |
| 224 | OutStreamer.EmitSymbolAttribute(Sym, MCSA_Global); |
| 225 | OutStreamer.EmitIntValue(Value, AlignSize); |
| 226 | OutStreamer.EmitCodeAlignment(AlignSize); |
| 227 | } |
| 228 | } else { |
| 229 | assert(Imm.isExpr() && "Expected expression and found none"); |
| 230 | const MachineOperand &MO = MI.getOperand(1); |
| 231 | assert(MO.isGlobal() || MO.isCPI() || MO.isJTI()); |
| 232 | MCSymbol *MOSymbol = nullptr; |
| 233 | if (MO.isGlobal()) |
| 234 | MOSymbol = AP.getSymbol(MO.getGlobal()); |
| 235 | else if (MO.isCPI()) |
| 236 | MOSymbol = AP.GetCPISymbol(MO.getIndex()); |
| 237 | else if (MO.isJTI()) |
| 238 | MOSymbol = AP.GetJTISymbol(MO.getIndex()); |
| 239 | else |
| 240 | llvm_unreachable("Unknown operand type!"); |
| 241 | |
| 242 | StringRef SymbolName = MOSymbol->getName(); |
| 243 | std::string LitaName = ".CONST_" + SymbolName.str(); |
| 244 | |
| 245 | MCSectionELF *Section = OutStreamer.getContext().getELFSection( |
| 246 | ".lita", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC); |
| 247 | |
| 248 | OutStreamer.SwitchSection(Section); |
| 249 | Sym = AP.OutContext.getOrCreateSymbol(Twine(LitaName)); |
| 250 | if (Sym->isUndefined()) { |
| 251 | OutStreamer.EmitLabel(Sym); |
| 252 | OutStreamer.EmitSymbolAttribute(Sym, MCSA_Local); |
| 253 | OutStreamer.EmitValue(Imm.getExpr(), AlignSize); |
| 254 | OutStreamer.EmitCodeAlignment(AlignSize); |
| 255 | } |
| 256 | } |
| 257 | return Sym; |
| 258 | } |
| 259 | |
| Krzysztof Parzyszek | 058abf1a | 2017-04-06 17:28:21 +0000 | [diff] [blame] | 260 | static MCInst ScaleVectorOffset(MCInst &Inst, unsigned OpNo, |
| 261 | unsigned VectorSize, MCContext &Ctx) { |
| 262 | MCInst T; |
| 263 | T.setOpcode(Inst.getOpcode()); |
| 264 | for (unsigned i = 0, n = Inst.getNumOperands(); i != n; ++i) { |
| 265 | if (i != OpNo) { |
| 266 | T.addOperand(Inst.getOperand(i)); |
| 267 | continue; |
| 268 | } |
| 269 | MCOperand &ImmOp = Inst.getOperand(i); |
| 270 | const auto *HE = static_cast<const HexagonMCExpr*>(ImmOp.getExpr()); |
| 271 | int32_t V = cast<MCConstantExpr>(HE->getExpr())->getValue(); |
| 272 | auto *NewCE = MCConstantExpr::create(V / int32_t(VectorSize), Ctx); |
| 273 | auto *NewHE = HexagonMCExpr::create(NewCE, Ctx); |
| 274 | T.addOperand(MCOperand::createExpr(NewHE)); |
| 275 | } |
| 276 | return T; |
| 277 | } |
| 278 | |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 279 | void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst, |
| 280 | const MachineInstr &MI) { |
| 281 | MCInst &MappedInst = static_cast <MCInst &>(Inst); |
| 282 | const MCRegisterInfo *RI = OutStreamer->getContext().getRegisterInfo(); |
| Krzysztof Parzyszek | 058abf1a | 2017-04-06 17:28:21 +0000 | [diff] [blame] | 283 | const MachineFunction &MF = *MI.getParent()->getParent(); |
| 284 | const auto &HST = MF.getSubtarget<HexagonSubtarget>(); |
| Krzysztof Parzyszek | 44e25f3 | 2017-04-24 18:55:33 +0000 | [diff] [blame] | 285 | const auto &VecRC = HST.useHVXSglOps() ? Hexagon::VectorRegsRegClass |
| 286 | : Hexagon::VectorRegs128BRegClass; |
| 287 | unsigned VectorSize = HST.getRegisterInfo()->getSpillSize(VecRC); |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 288 | |
| 289 | switch (Inst.getOpcode()) { |
| 290 | default: return; |
| 291 | |
| Colin LeMahieu | ecef1d9 | 2016-02-16 20:38:17 +0000 | [diff] [blame] | 292 | case Hexagon::A2_iconst: { |
| 293 | Inst.setOpcode(Hexagon::A2_addi); |
| 294 | MCOperand Reg = Inst.getOperand(0); |
| 295 | MCOperand S16 = Inst.getOperand(1); |
| 296 | HexagonMCInstrInfo::setMustNotExtend(*S16.getExpr()); |
| Krzysztof Parzyszek | 57a8bb43 | 2017-05-02 18:19:11 +0000 | [diff] [blame] | 297 | HexagonMCInstrInfo::setS27_2_reloc(*S16.getExpr()); |
| Colin LeMahieu | ecef1d9 | 2016-02-16 20:38:17 +0000 | [diff] [blame] | 298 | Inst.clear(); |
| 299 | Inst.addOperand(Reg); |
| 300 | Inst.addOperand(MCOperand::createReg(Hexagon::R0)); |
| 301 | Inst.addOperand(S16); |
| 302 | break; |
| 303 | } |
| 304 | |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 305 | case Hexagon::A2_tfrf: |
| Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 306 | Inst.setOpcode(Hexagon::A2_paddif); |
| 307 | Inst.addOperand(MCOperand::createExpr(MCConstantExpr::create(0, OutContext))); |
| 308 | break; |
| Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 309 | |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 310 | case Hexagon::A2_tfrt: |
| Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 311 | Inst.setOpcode(Hexagon::A2_paddit); |
| 312 | Inst.addOperand(MCOperand::createExpr(MCConstantExpr::create(0, OutContext))); |
| 313 | break; |
| Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 314 | |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 315 | case Hexagon::A2_tfrfnew: |
| Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 316 | Inst.setOpcode(Hexagon::A2_paddifnew); |
| 317 | Inst.addOperand(MCOperand::createExpr(MCConstantExpr::create(0, OutContext))); |
| 318 | break; |
| Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 319 | |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 320 | case Hexagon::A2_tfrtnew: |
| Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 321 | Inst.setOpcode(Hexagon::A2_padditnew); |
| 322 | Inst.addOperand(MCOperand::createExpr(MCConstantExpr::create(0, OutContext))); |
| 323 | break; |
| Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 324 | |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 325 | case Hexagon::A2_zxtb: |
| Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 326 | Inst.setOpcode(Hexagon::A2_andir); |
| 327 | Inst.addOperand(MCOperand::createExpr(MCConstantExpr::create(255, OutContext))); |
| 328 | break; |
| Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 329 | |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 330 | // "$dst = CONST64(#$src1)", |
| Krzysztof Parzyszek | a338650 | 2016-08-10 16:46:36 +0000 | [diff] [blame] | 331 | case Hexagon::CONST64: |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 332 | if (!OutStreamer->hasRawTextSupport()) { |
| 333 | const MCOperand &Imm = MappedInst.getOperand(1); |
| 334 | MCSectionSubPair Current = OutStreamer->getCurrentSection(); |
| 335 | |
| 336 | MCSymbol *Sym = smallData(*this, MI, *OutStreamer, Imm, 8); |
| 337 | |
| 338 | OutStreamer->SwitchSection(Current.first, Current.second); |
| 339 | MCInst TmpInst; |
| 340 | MCOperand &Reg = MappedInst.getOperand(0); |
| 341 | TmpInst.setOpcode(Hexagon::L2_loadrdgp); |
| 342 | TmpInst.addOperand(Reg); |
| 343 | TmpInst.addOperand(MCOperand::createExpr( |
| 344 | MCSymbolRefExpr::create(Sym, OutContext))); |
| 345 | MappedInst = TmpInst; |
| 346 | |
| 347 | } |
| 348 | break; |
| 349 | case Hexagon::CONST32: |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 350 | if (!OutStreamer->hasRawTextSupport()) { |
| 351 | MCOperand &Imm = MappedInst.getOperand(1); |
| 352 | MCSectionSubPair Current = OutStreamer->getCurrentSection(); |
| 353 | MCSymbol *Sym = smallData(*this, MI, *OutStreamer, Imm, 4); |
| 354 | OutStreamer->SwitchSection(Current.first, Current.second); |
| 355 | MCInst TmpInst; |
| 356 | MCOperand &Reg = MappedInst.getOperand(0); |
| 357 | TmpInst.setOpcode(Hexagon::L2_loadrigp); |
| 358 | TmpInst.addOperand(Reg); |
| Colin LeMahieu | c7b2124 | 2016-02-15 18:47:55 +0000 | [diff] [blame] | 359 | TmpInst.addOperand(MCOperand::createExpr(HexagonMCExpr::create( |
| Colin LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 360 | MCSymbolRefExpr::create(Sym, OutContext), OutContext))); |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 361 | MappedInst = TmpInst; |
| 362 | } |
| 363 | break; |
| 364 | |
| 365 | // C2_pxfer_map maps to C2_or instruction. Though, it's possible to use |
| 366 | // C2_or during instruction selection itself but it results |
| 367 | // into suboptimal code. |
| 368 | case Hexagon::C2_pxfer_map: { |
| 369 | MCOperand &Ps = Inst.getOperand(1); |
| 370 | MappedInst.setOpcode(Hexagon::C2_or); |
| 371 | MappedInst.addOperand(Ps); |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | // Vector reduce complex multiply by scalar, Rt & 1 map to :hi else :lo |
| 376 | // The insn is mapped from the 4 operand to the 3 operand raw form taking |
| 377 | // 3 register pairs. |
| 378 | case Hexagon::M2_vrcmpys_acc_s1: { |
| 379 | MCOperand &Rt = Inst.getOperand(3); |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 380 | assert(Rt.isReg() && "Expected register and none was found"); |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 381 | unsigned Reg = RI->getEncodingValue(Rt.getReg()); |
| 382 | if (Reg & 1) |
| 383 | MappedInst.setOpcode(Hexagon::M2_vrcmpys_acc_s1_h); |
| 384 | else |
| 385 | MappedInst.setOpcode(Hexagon::M2_vrcmpys_acc_s1_l); |
| 386 | Rt.setReg(getHexagonRegisterPair(Rt.getReg(), RI)); |
| 387 | return; |
| 388 | } |
| 389 | case Hexagon::M2_vrcmpys_s1: { |
| 390 | MCOperand &Rt = Inst.getOperand(2); |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 391 | assert(Rt.isReg() && "Expected register and none was found"); |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 392 | unsigned Reg = RI->getEncodingValue(Rt.getReg()); |
| 393 | if (Reg & 1) |
| 394 | MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1_h); |
| 395 | else |
| 396 | MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1_l); |
| 397 | Rt.setReg(getHexagonRegisterPair(Rt.getReg(), RI)); |
| 398 | return; |
| 399 | } |
| 400 | |
| 401 | case Hexagon::M2_vrcmpys_s1rp: { |
| 402 | MCOperand &Rt = Inst.getOperand(2); |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 403 | assert(Rt.isReg() && "Expected register and none was found"); |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 404 | unsigned Reg = RI->getEncodingValue(Rt.getReg()); |
| 405 | if (Reg & 1) |
| 406 | MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1rp_h); |
| 407 | else |
| 408 | MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1rp_l); |
| 409 | Rt.setReg(getHexagonRegisterPair(Rt.getReg(), RI)); |
| 410 | return; |
| 411 | } |
| 412 | |
| 413 | case Hexagon::A4_boundscheck: { |
| 414 | MCOperand &Rs = Inst.getOperand(1); |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 415 | assert(Rs.isReg() && "Expected register and none was found"); |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 416 | unsigned Reg = RI->getEncodingValue(Rs.getReg()); |
| 417 | if (Reg & 1) // Odd mapped to raw:hi, regpair is rodd:odd-1, like r3:2 |
| 418 | MappedInst.setOpcode(Hexagon::A4_boundscheck_hi); |
| 419 | else // raw:lo |
| 420 | MappedInst.setOpcode(Hexagon::A4_boundscheck_lo); |
| 421 | Rs.setReg(getHexagonRegisterPair(Rs.getReg(), RI)); |
| 422 | return; |
| 423 | } |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 424 | |
| Krzysztof Parzyszek | c8d676e | 2017-02-07 17:42:11 +0000 | [diff] [blame] | 425 | case Hexagon::PS_call_nr: |
| 426 | Inst.setOpcode(Hexagon::J2_call); |
| 427 | break; |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 428 | |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 429 | case Hexagon::S5_asrhub_rnd_sat_goodsyntax: { |
| 430 | MCOperand &MO = MappedInst.getOperand(2); |
| 431 | int64_t Imm; |
| 432 | MCExpr const *Expr = MO.getExpr(); |
| 433 | bool Success = Expr->evaluateAsAbsolute(Imm); |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 434 | assert(Success && "Expected immediate and none was found"); |
| Colin LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 435 | (void)Success; |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 436 | MCInst TmpInst; |
| 437 | if (Imm == 0) { |
| 438 | TmpInst.setOpcode(Hexagon::S2_vsathub); |
| 439 | TmpInst.addOperand(MappedInst.getOperand(0)); |
| 440 | TmpInst.addOperand(MappedInst.getOperand(1)); |
| 441 | MappedInst = TmpInst; |
| 442 | return; |
| 443 | } |
| 444 | TmpInst.setOpcode(Hexagon::S5_asrhub_rnd_sat); |
| 445 | TmpInst.addOperand(MappedInst.getOperand(0)); |
| 446 | TmpInst.addOperand(MappedInst.getOperand(1)); |
| 447 | const MCExpr *One = MCConstantExpr::create(1, OutContext); |
| 448 | const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext); |
| Colin LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 449 | TmpInst.addOperand( |
| Colin LeMahieu | c7b2124 | 2016-02-15 18:47:55 +0000 | [diff] [blame] | 450 | MCOperand::createExpr(HexagonMCExpr::create(Sub, OutContext))); |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 451 | MappedInst = TmpInst; |
| 452 | return; |
| 453 | } |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 454 | |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 455 | case Hexagon::S5_vasrhrnd_goodsyntax: |
| 456 | case Hexagon::S2_asr_i_p_rnd_goodsyntax: { |
| 457 | MCOperand &MO2 = MappedInst.getOperand(2); |
| 458 | MCExpr const *Expr = MO2.getExpr(); |
| 459 | int64_t Imm; |
| 460 | bool Success = Expr->evaluateAsAbsolute(Imm); |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 461 | assert(Success && "Expected immediate and none was found"); |
| Colin LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 462 | (void)Success; |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 463 | MCInst TmpInst; |
| 464 | if (Imm == 0) { |
| 465 | TmpInst.setOpcode(Hexagon::A2_combinew); |
| 466 | TmpInst.addOperand(MappedInst.getOperand(0)); |
| 467 | MCOperand &MO1 = MappedInst.getOperand(1); |
| Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 468 | unsigned High = RI->getSubReg(MO1.getReg(), Hexagon::isub_hi); |
| 469 | unsigned Low = RI->getSubReg(MO1.getReg(), Hexagon::isub_lo); |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 470 | // Add a new operand for the second register in the pair. |
| 471 | TmpInst.addOperand(MCOperand::createReg(High)); |
| 472 | TmpInst.addOperand(MCOperand::createReg(Low)); |
| 473 | MappedInst = TmpInst; |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | if (Inst.getOpcode() == Hexagon::S2_asr_i_p_rnd_goodsyntax) |
| 478 | TmpInst.setOpcode(Hexagon::S2_asr_i_p_rnd); |
| 479 | else |
| 480 | TmpInst.setOpcode(Hexagon::S5_vasrhrnd); |
| 481 | TmpInst.addOperand(MappedInst.getOperand(0)); |
| 482 | TmpInst.addOperand(MappedInst.getOperand(1)); |
| 483 | const MCExpr *One = MCConstantExpr::create(1, OutContext); |
| 484 | const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext); |
| Colin LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 485 | TmpInst.addOperand( |
| Colin LeMahieu | c7b2124 | 2016-02-15 18:47:55 +0000 | [diff] [blame] | 486 | MCOperand::createExpr(HexagonMCExpr::create(Sub, OutContext))); |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 487 | MappedInst = TmpInst; |
| 488 | return; |
| 489 | } |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 490 | |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 491 | // if ("#u5==0") Assembler mapped to: "Rd=Rs"; else Rd=asr(Rs,#u5-1):rnd |
| 492 | case Hexagon::S2_asr_i_r_rnd_goodsyntax: { |
| 493 | MCOperand &MO = Inst.getOperand(2); |
| 494 | MCExpr const *Expr = MO.getExpr(); |
| 495 | int64_t Imm; |
| 496 | bool Success = Expr->evaluateAsAbsolute(Imm); |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 497 | assert(Success && "Expected immediate and none was found"); |
| Colin LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 498 | (void)Success; |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 499 | MCInst TmpInst; |
| 500 | if (Imm == 0) { |
| 501 | TmpInst.setOpcode(Hexagon::A2_tfr); |
| 502 | TmpInst.addOperand(MappedInst.getOperand(0)); |
| 503 | TmpInst.addOperand(MappedInst.getOperand(1)); |
| 504 | MappedInst = TmpInst; |
| 505 | return; |
| 506 | } |
| 507 | TmpInst.setOpcode(Hexagon::S2_asr_i_r_rnd); |
| 508 | TmpInst.addOperand(MappedInst.getOperand(0)); |
| 509 | TmpInst.addOperand(MappedInst.getOperand(1)); |
| 510 | const MCExpr *One = MCConstantExpr::create(1, OutContext); |
| 511 | const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext); |
| Colin LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 512 | TmpInst.addOperand( |
| Colin LeMahieu | c7b2124 | 2016-02-15 18:47:55 +0000 | [diff] [blame] | 513 | MCOperand::createExpr(HexagonMCExpr::create(Sub, OutContext))); |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 514 | MappedInst = TmpInst; |
| 515 | return; |
| 516 | } |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 517 | |
| 518 | // Translate a "$Rdd = #imm" to "$Rdd = combine(#[-1,0], #imm)" |
| 519 | case Hexagon::A2_tfrpi: { |
| 520 | MCInst TmpInst; |
| 521 | MCOperand &Rdd = MappedInst.getOperand(0); |
| 522 | MCOperand &MO = MappedInst.getOperand(1); |
| 523 | |
| 524 | TmpInst.setOpcode(Hexagon::A2_combineii); |
| 525 | TmpInst.addOperand(Rdd); |
| 526 | int64_t Imm; |
| 527 | bool Success = MO.getExpr()->evaluateAsAbsolute(Imm); |
| 528 | if (Success && Imm < 0) { |
| 529 | const MCExpr *MOne = MCConstantExpr::create(-1, OutContext); |
| Colin LeMahieu | c7b2124 | 2016-02-15 18:47:55 +0000 | [diff] [blame] | 530 | TmpInst.addOperand(MCOperand::createExpr(HexagonMCExpr::create(MOne, OutContext))); |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 531 | } else { |
| 532 | const MCExpr *Zero = MCConstantExpr::create(0, OutContext); |
| Colin LeMahieu | c7b2124 | 2016-02-15 18:47:55 +0000 | [diff] [blame] | 533 | TmpInst.addOperand(MCOperand::createExpr(HexagonMCExpr::create(Zero, OutContext))); |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 534 | } |
| 535 | TmpInst.addOperand(MO); |
| 536 | MappedInst = TmpInst; |
| 537 | return; |
| 538 | } |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 539 | |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 540 | // Translate a "$Rdd = $Rss" to "$Rdd = combine($Rs, $Rt)" |
| 541 | case Hexagon::A2_tfrp: { |
| 542 | MCOperand &MO = MappedInst.getOperand(1); |
| Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 543 | unsigned High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi); |
| 544 | unsigned Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo); |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 545 | MO.setReg(High); |
| 546 | // Add a new operand for the second register in the pair. |
| 547 | MappedInst.addOperand(MCOperand::createReg(Low)); |
| 548 | MappedInst.setOpcode(Hexagon::A2_combinew); |
| 549 | return; |
| 550 | } |
| 551 | |
| 552 | case Hexagon::A2_tfrpt: |
| 553 | case Hexagon::A2_tfrpf: { |
| 554 | MCOperand &MO = MappedInst.getOperand(2); |
| Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 555 | unsigned High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi); |
| 556 | unsigned Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo); |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 557 | MO.setReg(High); |
| 558 | // Add a new operand for the second register in the pair. |
| 559 | MappedInst.addOperand(MCOperand::createReg(Low)); |
| 560 | MappedInst.setOpcode((Inst.getOpcode() == Hexagon::A2_tfrpt) |
| 561 | ? Hexagon::C2_ccombinewt |
| 562 | : Hexagon::C2_ccombinewf); |
| 563 | return; |
| 564 | } |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 565 | |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 566 | case Hexagon::A2_tfrptnew: |
| 567 | case Hexagon::A2_tfrpfnew: { |
| 568 | MCOperand &MO = MappedInst.getOperand(2); |
| Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 569 | unsigned High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi); |
| 570 | unsigned Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo); |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 571 | MO.setReg(High); |
| 572 | // Add a new operand for the second register in the pair. |
| 573 | MappedInst.addOperand(MCOperand::createReg(Low)); |
| 574 | MappedInst.setOpcode((Inst.getOpcode() == Hexagon::A2_tfrptnew) |
| 575 | ? Hexagon::C2_ccombinewnewt |
| 576 | : Hexagon::C2_ccombinewnewf); |
| 577 | return; |
| 578 | } |
| 579 | |
| 580 | case Hexagon::M2_mpysmi: { |
| 581 | MCOperand &Imm = MappedInst.getOperand(2); |
| 582 | MCExpr const *Expr = Imm.getExpr(); |
| 583 | int64_t Value; |
| 584 | bool Success = Expr->evaluateAsAbsolute(Value); |
| Colin LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 585 | assert(Success); |
| 586 | (void)Success; |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 587 | if (Value < 0 && Value > -256) { |
| 588 | MappedInst.setOpcode(Hexagon::M2_mpysin); |
| Colin LeMahieu | c7b2124 | 2016-02-15 18:47:55 +0000 | [diff] [blame] | 589 | Imm.setExpr(HexagonMCExpr::create( |
| Colin LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 590 | MCUnaryExpr::createMinus(Expr, OutContext), OutContext)); |
| 591 | } else |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 592 | MappedInst.setOpcode(Hexagon::M2_mpysip); |
| 593 | return; |
| 594 | } |
| 595 | |
| 596 | case Hexagon::A2_addsp: { |
| 597 | MCOperand &Rt = Inst.getOperand(1); |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 598 | assert(Rt.isReg() && "Expected register and none was found"); |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 599 | unsigned Reg = RI->getEncodingValue(Rt.getReg()); |
| 600 | if (Reg & 1) |
| 601 | MappedInst.setOpcode(Hexagon::A2_addsph); |
| 602 | else |
| 603 | MappedInst.setOpcode(Hexagon::A2_addspl); |
| 604 | Rt.setReg(getHexagonRegisterPair(Rt.getReg(), RI)); |
| 605 | return; |
| 606 | } |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 607 | |
| Krzysztof Parzyszek | eabc0d0 | 2016-08-16 17:14:44 +0000 | [diff] [blame] | 608 | case Hexagon::V6_vd0: |
| 609 | case Hexagon::V6_vd0_128B: { |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 610 | MCInst TmpInst; |
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame^] | 611 | assert(Inst.getOperand(0).isReg() && |
| 612 | "Expected register and none was found"); |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 613 | |
| 614 | TmpInst.setOpcode(Hexagon::V6_vxor); |
| 615 | TmpInst.addOperand(Inst.getOperand(0)); |
| 616 | TmpInst.addOperand(Inst.getOperand(0)); |
| 617 | TmpInst.addOperand(Inst.getOperand(0)); |
| 618 | MappedInst = TmpInst; |
| 619 | return; |
| 620 | } |
| 621 | |
| Krzysztof Parzyszek | 058abf1a | 2017-04-06 17:28:21 +0000 | [diff] [blame] | 622 | case Hexagon::V6_vL32Ub_pi: |
| 623 | case Hexagon::V6_vL32b_cur_pi: |
| 624 | case Hexagon::V6_vL32b_nt_cur_pi: |
| 625 | case Hexagon::V6_vL32b_pi: |
| 626 | case Hexagon::V6_vL32b_nt_pi: |
| 627 | case Hexagon::V6_vL32b_nt_tmp_pi: |
| 628 | case Hexagon::V6_vL32b_tmp_pi: |
| 629 | case Hexagon::V6_vL32Ub_pi_128B: |
| 630 | case Hexagon::V6_vL32b_cur_pi_128B: |
| 631 | case Hexagon::V6_vL32b_nt_cur_pi_128B: |
| 632 | case Hexagon::V6_vL32b_pi_128B: |
| 633 | case Hexagon::V6_vL32b_nt_pi_128B: |
| 634 | case Hexagon::V6_vL32b_nt_tmp_pi_128B: |
| 635 | case Hexagon::V6_vL32b_tmp_pi_128B: |
| 636 | MappedInst = ScaleVectorOffset(Inst, 3, VectorSize, OutContext); |
| 637 | return; |
| 638 | |
| 639 | case Hexagon::V6_vL32Ub_ai: |
| 640 | case Hexagon::V6_vL32b_ai: |
| 641 | case Hexagon::V6_vL32b_cur_ai: |
| 642 | case Hexagon::V6_vL32b_nt_ai: |
| 643 | case Hexagon::V6_vL32b_nt_cur_ai: |
| 644 | case Hexagon::V6_vL32b_nt_tmp_ai: |
| 645 | case Hexagon::V6_vL32b_tmp_ai: |
| 646 | case Hexagon::V6_vL32Ub_ai_128B: |
| 647 | case Hexagon::V6_vL32b_ai_128B: |
| 648 | case Hexagon::V6_vL32b_cur_ai_128B: |
| 649 | case Hexagon::V6_vL32b_nt_ai_128B: |
| 650 | case Hexagon::V6_vL32b_nt_cur_ai_128B: |
| 651 | case Hexagon::V6_vL32b_nt_tmp_ai_128B: |
| 652 | case Hexagon::V6_vL32b_tmp_ai_128B: |
| 653 | MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext); |
| 654 | return; |
| 655 | |
| 656 | case Hexagon::V6_vS32Ub_pi: |
| 657 | case Hexagon::V6_vS32b_new_pi: |
| 658 | case Hexagon::V6_vS32b_nt_new_pi: |
| 659 | case Hexagon::V6_vS32b_nt_pi: |
| 660 | case Hexagon::V6_vS32b_pi: |
| 661 | case Hexagon::V6_vS32Ub_pi_128B: |
| 662 | case Hexagon::V6_vS32b_new_pi_128B: |
| 663 | case Hexagon::V6_vS32b_nt_new_pi_128B: |
| 664 | case Hexagon::V6_vS32b_nt_pi_128B: |
| 665 | case Hexagon::V6_vS32b_pi_128B: |
| 666 | MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext); |
| 667 | return; |
| 668 | |
| 669 | case Hexagon::V6_vS32Ub_ai: |
| 670 | case Hexagon::V6_vS32b_ai: |
| 671 | case Hexagon::V6_vS32b_new_ai: |
| 672 | case Hexagon::V6_vS32b_nt_ai: |
| 673 | case Hexagon::V6_vS32b_nt_new_ai: |
| 674 | case Hexagon::V6_vS32Ub_ai_128B: |
| 675 | case Hexagon::V6_vS32b_ai_128B: |
| 676 | case Hexagon::V6_vS32b_new_ai_128B: |
| 677 | case Hexagon::V6_vS32b_nt_ai_128B: |
| 678 | case Hexagon::V6_vS32b_nt_new_ai_128B: |
| 679 | MappedInst = ScaleVectorOffset(Inst, 1, VectorSize, OutContext); |
| 680 | return; |
| 681 | |
| 682 | case Hexagon::V6_vL32b_cur_npred_pi: |
| 683 | case Hexagon::V6_vL32b_cur_pred_pi: |
| 684 | case Hexagon::V6_vL32b_npred_pi: |
| 685 | case Hexagon::V6_vL32b_nt_cur_npred_pi: |
| 686 | case Hexagon::V6_vL32b_nt_cur_pred_pi: |
| 687 | case Hexagon::V6_vL32b_nt_npred_pi: |
| 688 | case Hexagon::V6_vL32b_nt_pred_pi: |
| 689 | case Hexagon::V6_vL32b_nt_tmp_npred_pi: |
| 690 | case Hexagon::V6_vL32b_nt_tmp_pred_pi: |
| 691 | case Hexagon::V6_vL32b_pred_pi: |
| 692 | case Hexagon::V6_vL32b_tmp_npred_pi: |
| 693 | case Hexagon::V6_vL32b_tmp_pred_pi: |
| 694 | case Hexagon::V6_vL32b_cur_npred_pi_128B: |
| 695 | case Hexagon::V6_vL32b_cur_pred_pi_128B: |
| 696 | case Hexagon::V6_vL32b_npred_pi_128B: |
| 697 | case Hexagon::V6_vL32b_nt_cur_npred_pi_128B: |
| 698 | case Hexagon::V6_vL32b_nt_cur_pred_pi_128B: |
| 699 | case Hexagon::V6_vL32b_nt_npred_pi_128B: |
| 700 | case Hexagon::V6_vL32b_nt_pred_pi_128B: |
| 701 | case Hexagon::V6_vL32b_nt_tmp_npred_pi_128B: |
| 702 | case Hexagon::V6_vL32b_nt_tmp_pred_pi_128B: |
| 703 | case Hexagon::V6_vL32b_pred_pi_128B: |
| 704 | case Hexagon::V6_vL32b_tmp_npred_pi_128B: |
| 705 | case Hexagon::V6_vL32b_tmp_pred_pi_128B: |
| 706 | MappedInst = ScaleVectorOffset(Inst, 4, VectorSize, OutContext); |
| 707 | return; |
| 708 | |
| 709 | case Hexagon::V6_vL32b_cur_npred_ai: |
| 710 | case Hexagon::V6_vL32b_cur_pred_ai: |
| 711 | case Hexagon::V6_vL32b_npred_ai: |
| 712 | case Hexagon::V6_vL32b_nt_cur_npred_ai: |
| 713 | case Hexagon::V6_vL32b_nt_cur_pred_ai: |
| 714 | case Hexagon::V6_vL32b_nt_npred_ai: |
| 715 | case Hexagon::V6_vL32b_nt_pred_ai: |
| 716 | case Hexagon::V6_vL32b_nt_tmp_npred_ai: |
| 717 | case Hexagon::V6_vL32b_nt_tmp_pred_ai: |
| 718 | case Hexagon::V6_vL32b_pred_ai: |
| 719 | case Hexagon::V6_vL32b_tmp_npred_ai: |
| 720 | case Hexagon::V6_vL32b_tmp_pred_ai: |
| 721 | case Hexagon::V6_vL32b_cur_npred_ai_128B: |
| 722 | case Hexagon::V6_vL32b_cur_pred_ai_128B: |
| 723 | case Hexagon::V6_vL32b_npred_ai_128B: |
| 724 | case Hexagon::V6_vL32b_nt_cur_npred_ai_128B: |
| 725 | case Hexagon::V6_vL32b_nt_cur_pred_ai_128B: |
| 726 | case Hexagon::V6_vL32b_nt_npred_ai_128B: |
| 727 | case Hexagon::V6_vL32b_nt_pred_ai_128B: |
| 728 | case Hexagon::V6_vL32b_nt_tmp_npred_ai_128B: |
| 729 | case Hexagon::V6_vL32b_nt_tmp_pred_ai_128B: |
| 730 | case Hexagon::V6_vL32b_pred_ai_128B: |
| 731 | case Hexagon::V6_vL32b_tmp_npred_ai_128B: |
| 732 | case Hexagon::V6_vL32b_tmp_pred_ai_128B: |
| 733 | MappedInst = ScaleVectorOffset(Inst, 3, VectorSize, OutContext); |
| 734 | return; |
| 735 | |
| 736 | case Hexagon::V6_vS32Ub_npred_pi: |
| 737 | case Hexagon::V6_vS32Ub_pred_pi: |
| 738 | case Hexagon::V6_vS32b_new_npred_pi: |
| 739 | case Hexagon::V6_vS32b_new_pred_pi: |
| 740 | case Hexagon::V6_vS32b_npred_pi: |
| 741 | case Hexagon::V6_vS32b_nqpred_pi: |
| 742 | case Hexagon::V6_vS32b_nt_new_npred_pi: |
| 743 | case Hexagon::V6_vS32b_nt_new_pred_pi: |
| 744 | case Hexagon::V6_vS32b_nt_npred_pi: |
| 745 | case Hexagon::V6_vS32b_nt_nqpred_pi: |
| 746 | case Hexagon::V6_vS32b_nt_pred_pi: |
| 747 | case Hexagon::V6_vS32b_nt_qpred_pi: |
| 748 | case Hexagon::V6_vS32b_pred_pi: |
| 749 | case Hexagon::V6_vS32b_qpred_pi: |
| 750 | case Hexagon::V6_vS32Ub_npred_pi_128B: |
| 751 | case Hexagon::V6_vS32Ub_pred_pi_128B: |
| 752 | case Hexagon::V6_vS32b_new_npred_pi_128B: |
| 753 | case Hexagon::V6_vS32b_new_pred_pi_128B: |
| 754 | case Hexagon::V6_vS32b_npred_pi_128B: |
| 755 | case Hexagon::V6_vS32b_nqpred_pi_128B: |
| 756 | case Hexagon::V6_vS32b_nt_new_npred_pi_128B: |
| 757 | case Hexagon::V6_vS32b_nt_new_pred_pi_128B: |
| 758 | case Hexagon::V6_vS32b_nt_npred_pi_128B: |
| 759 | case Hexagon::V6_vS32b_nt_nqpred_pi_128B: |
| 760 | case Hexagon::V6_vS32b_nt_pred_pi_128B: |
| 761 | case Hexagon::V6_vS32b_nt_qpred_pi_128B: |
| 762 | case Hexagon::V6_vS32b_pred_pi_128B: |
| 763 | case Hexagon::V6_vS32b_qpred_pi_128B: |
| 764 | MappedInst = ScaleVectorOffset(Inst, 3, VectorSize, OutContext); |
| 765 | return; |
| 766 | |
| 767 | case Hexagon::V6_vS32Ub_npred_ai: |
| 768 | case Hexagon::V6_vS32Ub_pred_ai: |
| 769 | case Hexagon::V6_vS32b_new_npred_ai: |
| 770 | case Hexagon::V6_vS32b_new_pred_ai: |
| 771 | case Hexagon::V6_vS32b_npred_ai: |
| 772 | case Hexagon::V6_vS32b_nqpred_ai: |
| 773 | case Hexagon::V6_vS32b_nt_new_npred_ai: |
| 774 | case Hexagon::V6_vS32b_nt_new_pred_ai: |
| 775 | case Hexagon::V6_vS32b_nt_npred_ai: |
| 776 | case Hexagon::V6_vS32b_nt_nqpred_ai: |
| 777 | case Hexagon::V6_vS32b_nt_pred_ai: |
| 778 | case Hexagon::V6_vS32b_nt_qpred_ai: |
| 779 | case Hexagon::V6_vS32b_pred_ai: |
| 780 | case Hexagon::V6_vS32b_qpred_ai: |
| 781 | case Hexagon::V6_vS32Ub_npred_ai_128B: |
| 782 | case Hexagon::V6_vS32Ub_pred_ai_128B: |
| 783 | case Hexagon::V6_vS32b_new_npred_ai_128B: |
| 784 | case Hexagon::V6_vS32b_new_pred_ai_128B: |
| 785 | case Hexagon::V6_vS32b_npred_ai_128B: |
| 786 | case Hexagon::V6_vS32b_nqpred_ai_128B: |
| 787 | case Hexagon::V6_vS32b_nt_new_npred_ai_128B: |
| 788 | case Hexagon::V6_vS32b_nt_new_pred_ai_128B: |
| 789 | case Hexagon::V6_vS32b_nt_npred_ai_128B: |
| 790 | case Hexagon::V6_vS32b_nt_nqpred_ai_128B: |
| 791 | case Hexagon::V6_vS32b_nt_pred_ai_128B: |
| 792 | case Hexagon::V6_vS32b_nt_qpred_ai_128B: |
| 793 | case Hexagon::V6_vS32b_pred_ai_128B: |
| 794 | case Hexagon::V6_vS32b_qpred_ai_128B: |
| 795 | MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext); |
| 796 | return; |
| Krzysztof Parzyszek | 372bd80 | 2015-12-15 17:05:45 +0000 | [diff] [blame] | 797 | } |
| 798 | } |
| 799 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 800 | /// printMachineInstruction -- Print out a single Hexagon MI in Darwin syntax to |
| 801 | /// the current output stream. |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 802 | void HexagonAsmPrinter::EmitInstruction(const MachineInstr *MI) { |
| Colin LeMahieu | f0af6e5 | 2015-11-13 17:42:46 +0000 | [diff] [blame] | 803 | MCInst MCB = HexagonMCInstrInfo::createBundle(); |
| Krzysztof Parzyszek | 8d8b229 | 2015-12-02 23:08:29 +0000 | [diff] [blame] | 804 | const MCInstrInfo &MCII = *Subtarget->getInstrInfo(); |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 805 | |
| Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 806 | if (MI->isBundle()) { |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 807 | const MachineBasicBlock* MBB = MI->getParent(); |
| Duncan P. N. Exon Smith | c5b668d | 2016-02-22 20:49:58 +0000 | [diff] [blame] | 808 | MachineBasicBlock::const_instr_iterator MII = MI->getIterator(); |
| Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 809 | |
| Colin LeMahieu | 7c572b2 | 2015-12-03 16:37:21 +0000 | [diff] [blame] | 810 | for (++MII; MII != MBB->instr_end() && MII->isInsideBundle(); ++MII) |
| Krzysztof Parzyszek | d04c9b9 | 2017-03-31 21:03:59 +0000 | [diff] [blame] | 811 | if (!MII->isDebugValue() && !MII->isImplicitDef()) |
| Krzysztof Parzyszek | 8d8b229 | 2015-12-02 23:08:29 +0000 | [diff] [blame] | 812 | HexagonLowerToMC(MCII, &*MII, MCB, *this); |
| Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 813 | } |
| Colin LeMahieu | 7c572b2 | 2015-12-03 16:37:21 +0000 | [diff] [blame] | 814 | else |
| Krzysztof Parzyszek | 8d8b229 | 2015-12-02 23:08:29 +0000 | [diff] [blame] | 815 | HexagonLowerToMC(MCII, MI, MCB, *this); |
| Colin LeMahieu | 7c572b2 | 2015-12-03 16:37:21 +0000 | [diff] [blame] | 816 | |
| 817 | bool Ok = HexagonMCInstrInfo::canonicalizePacket( |
| 818 | MCII, *Subtarget, OutStreamer->getContext(), MCB, nullptr); |
| 819 | assert(Ok); |
| 820 | (void)Ok; |
| 821 | if(HexagonMCInstrInfo::bundleSize(MCB) == 0) |
| 822 | return; |
| 823 | OutStreamer->EmitInstruction(MCB, getSubtargetInfo()); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 824 | } |
| 825 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 826 | extern "C" void LLVMInitializeHexagonAsmPrinter() { |
| Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 827 | RegisterAsmPrinter<HexagonAsmPrinter> X(getTheHexagonTarget()); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 828 | } |