Colin LeMahieu | af304e5 | 2015-02-19 19:00:00 +0000 | [diff] [blame] | 1 | //===- HexagonMCInstrInfo.cpp - Hexagon sub-class of MCInst ---------------===// |
| 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 class extends MCInstrInfo to allow Hexagon specific MCInstr queries |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Colin LeMahieu | b23c47b | 2015-05-31 21:57:09 +0000 | [diff] [blame] | 14 | #include "HexagonMCInstrInfo.h" |
| 15 | |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 16 | #include "Hexagon.h" |
Colin LeMahieu | af304e5 | 2015-02-19 19:00:00 +0000 | [diff] [blame] | 17 | #include "HexagonBaseInfo.h" |
Colin LeMahieu | b23c47b | 2015-05-31 21:57:09 +0000 | [diff] [blame] | 18 | |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame^] | 19 | #include "llvm/MC/MCContext.h" |
| 20 | #include "llvm/MC/MCInstrInfo.h" |
Colin LeMahieu | b23c47b | 2015-05-31 21:57:09 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCSubtargetInfo.h" |
Colin LeMahieu | af304e5 | 2015-02-19 19:00:00 +0000 | [diff] [blame] | 22 | |
| 23 | namespace llvm { |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 24 | iterator_range<MCInst::const_iterator> |
| 25 | HexagonMCInstrInfo::bundleInstructions(MCInst const &MCI) { |
| 26 | assert(isBundle(MCI)); |
| 27 | return iterator_range<MCInst::const_iterator>( |
| 28 | MCI.begin() + bundleInstructionsOffset, MCI.end()); |
| 29 | } |
| 30 | |
| 31 | size_t HexagonMCInstrInfo::bundleSize(MCInst const &MCI) { |
| 32 | if (HexagonMCInstrInfo::isBundle(MCI)) |
| 33 | return (MCI.size() - bundleInstructionsOffset); |
| 34 | else |
| 35 | return (1); |
Colin LeMahieu | 1174fea | 2015-02-19 21:10:50 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame^] | 38 | MCInst *HexagonMCInstrInfo::deriveDuplex(MCContext &Context, unsigned iClass, |
| 39 | MCInst const &inst0, |
| 40 | MCInst const &inst1) { |
| 41 | assert((iClass <= 0xf) && "iClass must have range of 0 to 0xf"); |
| 42 | MCInst *duplexInst = new (Context) MCInst; |
| 43 | duplexInst->setOpcode(Hexagon::DuplexIClass0 + iClass); |
| 44 | |
| 45 | MCInst *SubInst0 = new (Context) MCInst(deriveSubInst(inst0)); |
| 46 | MCInst *SubInst1 = new (Context) MCInst(deriveSubInst(inst1)); |
| 47 | duplexInst->addOperand(MCOperand::createInst(SubInst0)); |
| 48 | duplexInst->addOperand(MCOperand::createInst(SubInst1)); |
| 49 | return duplexInst; |
| 50 | } |
| 51 | |
| 52 | MCInst const *HexagonMCInstrInfo::extenderForIndex(MCInst const &MCB, |
| 53 | size_t Index) { |
| 54 | assert(Index <= bundleSize(MCB)); |
| 55 | if (Index == 0) |
| 56 | return nullptr; |
| 57 | MCInst const *Inst = |
| 58 | MCB.getOperand(Index + bundleInstructionsOffset - 1).getInst(); |
| 59 | if (isImmext(*Inst)) |
| 60 | return Inst; |
| 61 | return nullptr; |
| 62 | } |
| 63 | |
Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 64 | HexagonII::MemAccessSize |
| 65 | HexagonMCInstrInfo::getAccessSize(MCInstrInfo const &MCII, MCInst const &MCI) { |
| 66 | const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 67 | |
| 68 | return (HexagonII::MemAccessSize((F >> HexagonII::MemAccessSizePos) & |
| 69 | HexagonII::MemAccesSizeMask)); |
| 70 | } |
| 71 | |
Colin LeMahieu | 745c471 | 2015-02-19 19:49:27 +0000 | [diff] [blame] | 72 | unsigned HexagonMCInstrInfo::getBitCount(MCInstrInfo const &MCII, |
| 73 | MCInst const &MCI) { |
| 74 | uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 75 | return ((F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask); |
| 76 | } |
| 77 | |
Colin LeMahieu | 745c471 | 2015-02-19 19:49:27 +0000 | [diff] [blame] | 78 | // Return constant extended operand number. |
| 79 | unsigned short HexagonMCInstrInfo::getCExtOpNum(MCInstrInfo const &MCII, |
| 80 | MCInst const &MCI) { |
| 81 | const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 82 | return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask); |
| 83 | } |
| 84 | |
Colin LeMahieu | 1174fea | 2015-02-19 21:10:50 +0000 | [diff] [blame] | 85 | MCInstrDesc const &HexagonMCInstrInfo::getDesc(MCInstrInfo const &MCII, |
| 86 | MCInst const &MCI) { |
| 87 | return (MCII.get(MCI.getOpcode())); |
| 88 | } |
| 89 | |
Colin LeMahieu | 86f218e | 2015-05-30 18:55:47 +0000 | [diff] [blame] | 90 | unsigned short HexagonMCInstrInfo::getExtendableOp(MCInstrInfo const &MCII, |
| 91 | MCInst const &MCI) { |
| 92 | const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 93 | return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask); |
| 94 | } |
| 95 | |
| 96 | MCOperand const & |
| 97 | HexagonMCInstrInfo::getExtendableOperand(MCInstrInfo const &MCII, |
| 98 | MCInst const &MCI) { |
| 99 | unsigned O = HexagonMCInstrInfo::getExtendableOp(MCII, MCI); |
| 100 | MCOperand const &MO = MCI.getOperand(O); |
| 101 | |
| 102 | assert((HexagonMCInstrInfo::isExtendable(MCII, MCI) || |
| 103 | HexagonMCInstrInfo::isExtended(MCII, MCI)) && |
| 104 | (MO.isImm() || MO.isExpr())); |
| 105 | return (MO); |
| 106 | } |
| 107 | |
Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 108 | unsigned HexagonMCInstrInfo::getExtentAlignment(MCInstrInfo const &MCII, |
| 109 | MCInst const &MCI) { |
| 110 | const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 111 | return ((F >> HexagonII::ExtentAlignPos) & HexagonII::ExtentAlignMask); |
| 112 | } |
| 113 | |
| 114 | unsigned HexagonMCInstrInfo::getExtentBits(MCInstrInfo const &MCII, |
| 115 | MCInst const &MCI) { |
| 116 | const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 117 | return ((F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask); |
| 118 | } |
| 119 | |
Colin LeMahieu | af304e5 | 2015-02-19 19:00:00 +0000 | [diff] [blame] | 120 | // Return the max value that a constant extendable operand can have |
| 121 | // without being extended. |
| 122 | int HexagonMCInstrInfo::getMaxValue(MCInstrInfo const &MCII, |
| 123 | MCInst const &MCI) { |
Colin LeMahieu | 745c471 | 2015-02-19 19:49:27 +0000 | [diff] [blame] | 124 | uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
Colin LeMahieu | af304e5 | 2015-02-19 19:00:00 +0000 | [diff] [blame] | 125 | unsigned isSigned = |
| 126 | (F >> HexagonII::ExtentSignedPos) & HexagonII::ExtentSignedMask; |
| 127 | unsigned bits = (F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask; |
| 128 | |
| 129 | if (isSigned) // if value is signed |
| 130 | return ~(-1U << (bits - 1)); |
| 131 | else |
| 132 | return ~(-1U << bits); |
| 133 | } |
Colin LeMahieu | 745c471 | 2015-02-19 19:49:27 +0000 | [diff] [blame] | 134 | |
| 135 | // Return the min value that a constant extendable operand can have |
| 136 | // without being extended. |
| 137 | int HexagonMCInstrInfo::getMinValue(MCInstrInfo const &MCII, |
| 138 | MCInst const &MCI) { |
| 139 | uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 140 | unsigned isSigned = |
| 141 | (F >> HexagonII::ExtentSignedPos) & HexagonII::ExtentSignedMask; |
| 142 | unsigned bits = (F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask; |
| 143 | |
| 144 | if (isSigned) // if value is signed |
| 145 | return -1U << (bits - 1); |
| 146 | else |
| 147 | return 0; |
| 148 | } |
| 149 | |
Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 150 | char const *HexagonMCInstrInfo::getName(MCInstrInfo const &MCII, |
| 151 | MCInst const &MCI) { |
| 152 | return MCII.getName(MCI.getOpcode()); |
| 153 | } |
| 154 | |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 155 | unsigned short HexagonMCInstrInfo::getNewValueOp(MCInstrInfo const &MCII, |
Colin LeMahieu | 745c471 | 2015-02-19 19:49:27 +0000 | [diff] [blame] | 156 | MCInst const &MCI) { |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 157 | const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 158 | return ((F >> HexagonII::NewValueOpPos) & HexagonII::NewValueOpMask); |
| 159 | } |
| 160 | |
| 161 | MCOperand const &HexagonMCInstrInfo::getNewValueOperand(MCInstrInfo const &MCII, |
| 162 | MCInst const &MCI) { |
Colin LeMahieu | 745c471 | 2015-02-19 19:49:27 +0000 | [diff] [blame] | 163 | uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 164 | unsigned const O = |
| 165 | (F >> HexagonII::NewValueOpPos) & HexagonII::NewValueOpMask; |
| 166 | MCOperand const &MCO = MCI.getOperand(O); |
| 167 | |
| 168 | assert((HexagonMCInstrInfo::isNewValue(MCII, MCI) || |
| 169 | HexagonMCInstrInfo::hasNewValue(MCII, MCI)) && |
| 170 | MCO.isReg()); |
| 171 | return (MCO); |
| 172 | } |
| 173 | |
Colin LeMahieu | b23c47b | 2015-05-31 21:57:09 +0000 | [diff] [blame] | 174 | int HexagonMCInstrInfo::getSubTarget(MCInstrInfo const &MCII, |
| 175 | MCInst const &MCI) { |
| 176 | const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 177 | |
| 178 | HexagonII::SubTarget Target = static_cast<HexagonII::SubTarget>( |
| 179 | (F >> HexagonII::validSubTargetPos) & HexagonII::validSubTargetMask); |
| 180 | |
| 181 | switch (Target) { |
| 182 | default: |
| 183 | return Hexagon::ArchV4; |
| 184 | case HexagonII::HasV5SubT: |
| 185 | return Hexagon::ArchV5; |
| 186 | } |
| 187 | } |
| 188 | |
Colin LeMahieu | 745c471 | 2015-02-19 19:49:27 +0000 | [diff] [blame] | 189 | // Return the Hexagon ISA class for the insn. |
| 190 | unsigned HexagonMCInstrInfo::getType(MCInstrInfo const &MCII, |
| 191 | MCInst const &MCI) { |
| 192 | const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 193 | |
| 194 | return ((F >> HexagonII::TypePos) & HexagonII::TypeMask); |
| 195 | } |
| 196 | |
Colin LeMahieu | b23c47b | 2015-05-31 21:57:09 +0000 | [diff] [blame] | 197 | unsigned HexagonMCInstrInfo::getUnits(MCInstrInfo const &MCII, |
| 198 | MCSubtargetInfo const &STI, |
| 199 | MCInst const &MCI) { |
| 200 | |
| 201 | const InstrItinerary *II = STI.getSchedModel().InstrItineraries; |
| 202 | int SchedClass = HexagonMCInstrInfo::getDesc(MCII, MCI).getSchedClass(); |
| 203 | return ((II[SchedClass].FirstStage + HexagonStages)->getUnits()); |
| 204 | } |
| 205 | |
| 206 | bool HexagonMCInstrInfo::hasImmExt(MCInst const &MCI) { |
| 207 | if (!HexagonMCInstrInfo::isBundle(MCI)) |
| 208 | return false; |
| 209 | |
| 210 | for (const auto &I : HexagonMCInstrInfo::bundleInstructions(MCI)) { |
| 211 | auto MI = I.getInst(); |
| 212 | if (isImmext(*MI)) |
| 213 | return true; |
| 214 | } |
| 215 | |
| 216 | return false; |
| 217 | } |
| 218 | |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame^] | 219 | bool HexagonMCInstrInfo::hasExtenderForIndex(MCInst const &MCB, size_t Index) { |
| 220 | return extenderForIndex(MCB, Index) != nullptr; |
| 221 | } |
| 222 | |
Colin LeMahieu | 745c471 | 2015-02-19 19:49:27 +0000 | [diff] [blame] | 223 | // Return whether the instruction is a legal new-value producer. |
| 224 | bool HexagonMCInstrInfo::hasNewValue(MCInstrInfo const &MCII, |
| 225 | MCInst const &MCI) { |
| 226 | const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 227 | return ((F >> HexagonII::hasNewValuePos) & HexagonII::hasNewValueMask); |
| 228 | } |
| 229 | |
Colin LeMahieu | 86f218e | 2015-05-30 18:55:47 +0000 | [diff] [blame] | 230 | MCInst const &HexagonMCInstrInfo::instruction(MCInst const &MCB, size_t Index) { |
| 231 | assert(isBundle(MCB)); |
| 232 | assert(Index < HEXAGON_PACKET_SIZE); |
| 233 | return *MCB.getOperand(bundleInstructionsOffset + Index).getInst(); |
| 234 | } |
| 235 | |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 236 | bool HexagonMCInstrInfo::isBundle(MCInst const &MCI) { |
| 237 | auto Result = Hexagon::BUNDLE == MCI.getOpcode(); |
| 238 | assert(!Result || (MCI.size() > 0 && MCI.getOperand(0).isImm())); |
| 239 | return Result; |
| 240 | } |
| 241 | |
Colin LeMahieu | 745c471 | 2015-02-19 19:49:27 +0000 | [diff] [blame] | 242 | // Return whether the insn is an actual insn. |
| 243 | bool HexagonMCInstrInfo::isCanon(MCInstrInfo const &MCII, MCInst const &MCI) { |
| 244 | return (!HexagonMCInstrInfo::getDesc(MCII, MCI).isPseudo() && |
| 245 | !HexagonMCInstrInfo::isPrefix(MCII, MCI) && |
| 246 | HexagonMCInstrInfo::getType(MCII, MCI) != HexagonII::TypeENDLOOP); |
| 247 | } |
| 248 | |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame^] | 249 | bool HexagonMCInstrInfo::isDblRegForSubInst(unsigned Reg) { |
| 250 | return ((Reg >= Hexagon::D0 && Reg <= Hexagon::D3) || |
| 251 | (Reg >= Hexagon::D8 && Reg <= Hexagon::D11)); |
| 252 | } |
| 253 | |
| 254 | bool HexagonMCInstrInfo::isDuplex(MCInstrInfo const &MCII, MCInst const &MCI) { |
| 255 | return HexagonII::TypeDUPLEX == HexagonMCInstrInfo::getType(MCII, MCI); |
| 256 | } |
| 257 | |
Colin LeMahieu | 745c471 | 2015-02-19 19:49:27 +0000 | [diff] [blame] | 258 | // Return whether the instruction needs to be constant extended. |
| 259 | // 1) Always return true if the instruction has 'isExtended' flag set. |
| 260 | // |
| 261 | // isExtendable: |
| 262 | // 2) For immediate extended operands, return true only if the value is |
| 263 | // out-of-range. |
| 264 | // 3) For global address, always return true. |
| 265 | |
| 266 | bool HexagonMCInstrInfo::isConstExtended(MCInstrInfo const &MCII, |
| 267 | MCInst const &MCI) { |
| 268 | if (HexagonMCInstrInfo::isExtended(MCII, MCI)) |
| 269 | return true; |
| 270 | |
| 271 | if (!HexagonMCInstrInfo::isExtendable(MCII, MCI)) |
| 272 | return false; |
| 273 | |
| 274 | short ExtOpNum = HexagonMCInstrInfo::getCExtOpNum(MCII, MCI); |
| 275 | int MinValue = HexagonMCInstrInfo::getMinValue(MCII, MCI); |
| 276 | int MaxValue = HexagonMCInstrInfo::getMaxValue(MCII, MCI); |
| 277 | MCOperand const &MO = MCI.getOperand(ExtOpNum); |
| 278 | |
| 279 | // We could be using an instruction with an extendable immediate and shoehorn |
| 280 | // a global address into it. If it is a global address it will be constant |
| 281 | // extended. We do this for COMBINE. |
| 282 | // We currently only handle isGlobal() because it is the only kind of |
| 283 | // object we are going to end up with here for now. |
| 284 | // In the future we probably should add isSymbol(), etc. |
| 285 | if (MO.isExpr()) |
| 286 | return true; |
| 287 | |
| 288 | // If the extendable operand is not 'Immediate' type, the instruction should |
| 289 | // have 'isExtended' flag set. |
| 290 | assert(MO.isImm() && "Extendable operand must be Immediate type"); |
| 291 | |
| 292 | int ImmValue = MO.getImm(); |
| 293 | return (ImmValue < MinValue || ImmValue > MaxValue); |
| 294 | } |
| 295 | |
Colin LeMahieu | 745c471 | 2015-02-19 19:49:27 +0000 | [diff] [blame] | 296 | bool HexagonMCInstrInfo::isExtendable(MCInstrInfo const &MCII, |
| 297 | MCInst const &MCI) { |
| 298 | uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 299 | return (F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask; |
| 300 | } |
| 301 | |
Colin LeMahieu | 745c471 | 2015-02-19 19:49:27 +0000 | [diff] [blame] | 302 | bool HexagonMCInstrInfo::isExtended(MCInstrInfo const &MCII, |
| 303 | MCInst const &MCI) { |
| 304 | uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 305 | return (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask; |
| 306 | } |
| 307 | |
Colin LeMahieu | b23c47b | 2015-05-31 21:57:09 +0000 | [diff] [blame] | 308 | bool HexagonMCInstrInfo::isFloat(MCInstrInfo const &MCII, MCInst const &MCI) { |
| 309 | const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 310 | return ((F >> HexagonII::FPPos) & HexagonII::FPMask); |
| 311 | } |
| 312 | |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 313 | bool HexagonMCInstrInfo::isImmext(MCInst const &MCI) { |
| 314 | auto Op = MCI.getOpcode(); |
| 315 | return (Op == Hexagon::A4_ext_b || Op == Hexagon::A4_ext_c || |
| 316 | Op == Hexagon::A4_ext_g || Op == Hexagon::A4_ext); |
| 317 | } |
| 318 | |
| 319 | bool HexagonMCInstrInfo::isInnerLoop(MCInst const &MCI) { |
| 320 | assert(isBundle(MCI)); |
| 321 | int64_t Flags = MCI.getOperand(0).getImm(); |
| 322 | return (Flags & innerLoopMask) != 0; |
| 323 | } |
| 324 | |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame^] | 325 | bool HexagonMCInstrInfo::isIntReg(unsigned Reg) { |
| 326 | return (Reg >= Hexagon::R0 && Reg <= Hexagon::R31); |
| 327 | } |
| 328 | |
| 329 | bool HexagonMCInstrInfo::isIntRegForSubInst(unsigned Reg) { |
| 330 | return ((Reg >= Hexagon::R0 && Reg <= Hexagon::R7) || |
| 331 | (Reg >= Hexagon::R16 && Reg <= Hexagon::R23)); |
| 332 | } |
| 333 | |
Colin LeMahieu | 745c471 | 2015-02-19 19:49:27 +0000 | [diff] [blame] | 334 | // Return whether the insn is a new-value consumer. |
| 335 | bool HexagonMCInstrInfo::isNewValue(MCInstrInfo const &MCII, |
| 336 | MCInst const &MCI) { |
| 337 | const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 338 | return ((F >> HexagonII::NewValuePos) & HexagonII::NewValueMask); |
| 339 | } |
| 340 | |
| 341 | // Return whether the operand can be constant extended. |
| 342 | bool HexagonMCInstrInfo::isOperandExtended(MCInstrInfo const &MCII, |
| 343 | MCInst const &MCI, |
| 344 | unsigned short OperandNum) { |
| 345 | uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 346 | return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask) == |
| 347 | OperandNum; |
| 348 | } |
| 349 | |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 350 | bool HexagonMCInstrInfo::isOuterLoop(MCInst const &MCI) { |
| 351 | assert(isBundle(MCI)); |
| 352 | int64_t Flags = MCI.getOperand(0).getImm(); |
| 353 | return (Flags & outerLoopMask) != 0; |
Colin LeMahieu | 1174fea | 2015-02-19 21:10:50 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 356 | bool HexagonMCInstrInfo::isPredicated(MCInstrInfo const &MCII, |
| 357 | MCInst const &MCI) { |
| 358 | const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 359 | return ((F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask); |
| 360 | } |
| 361 | |
| 362 | bool HexagonMCInstrInfo::isPredicatedTrue(MCInstrInfo const &MCII, |
| 363 | MCInst const &MCI) { |
| 364 | const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 365 | return ( |
| 366 | !((F >> HexagonII::PredicatedFalsePos) & HexagonII::PredicatedFalseMask)); |
Colin LeMahieu | 1174fea | 2015-02-19 21:10:50 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame^] | 369 | bool HexagonMCInstrInfo::isPredReg(unsigned Reg) { |
| 370 | return (Reg >= Hexagon::P0 && Reg <= Hexagon::P3_0); |
| 371 | } |
| 372 | |
Colin LeMahieu | 745c471 | 2015-02-19 19:49:27 +0000 | [diff] [blame] | 373 | bool HexagonMCInstrInfo::isPrefix(MCInstrInfo const &MCII, MCInst const &MCI) { |
| 374 | return (HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypePREFIX); |
| 375 | } |
| 376 | |
Colin LeMahieu | 745c471 | 2015-02-19 19:49:27 +0000 | [diff] [blame] | 377 | bool HexagonMCInstrInfo::isSolo(MCInstrInfo const &MCII, MCInst const &MCI) { |
| 378 | const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 379 | return ((F >> HexagonII::SoloPos) & HexagonII::SoloMask); |
| 380 | } |
Colin LeMahieu | 1174fea | 2015-02-19 21:10:50 +0000 | [diff] [blame] | 381 | |
Colin LeMahieu | b23c47b | 2015-05-31 21:57:09 +0000 | [diff] [blame] | 382 | bool HexagonMCInstrInfo::isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI) { |
| 383 | const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 384 | return ((F >> HexagonII::SoloAXPos) & HexagonII::SoloAXMask); |
| 385 | } |
| 386 | |
| 387 | bool HexagonMCInstrInfo::isSoloAin1(MCInstrInfo const &MCII, |
| 388 | MCInst const &MCI) { |
| 389 | const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; |
| 390 | return ((F >> HexagonII::SoloAin1Pos) & HexagonII::SoloAin1Mask); |
| 391 | } |
| 392 | |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 393 | void HexagonMCInstrInfo::padEndloop(MCInst &MCB) { |
| 394 | MCInst Nop; |
| 395 | Nop.setOpcode(Hexagon::A2_nop); |
| 396 | assert(isBundle(MCB)); |
| 397 | while ((HexagonMCInstrInfo::isInnerLoop(MCB) && |
| 398 | (HexagonMCInstrInfo::bundleSize(MCB) < HEXAGON_PACKET_INNER_SIZE)) || |
| 399 | ((HexagonMCInstrInfo::isOuterLoop(MCB) && |
| 400 | (HexagonMCInstrInfo::bundleSize(MCB) < HEXAGON_PACKET_OUTER_SIZE)))) |
| 401 | MCB.addOperand(MCOperand::createInst(new MCInst(Nop))); |
Colin LeMahieu | 1174fea | 2015-02-19 21:10:50 +0000 | [diff] [blame] | 402 | } |
| 403 | |
Colin LeMahieu | b23c47b | 2015-05-31 21:57:09 +0000 | [diff] [blame] | 404 | bool HexagonMCInstrInfo::prefersSlot3(MCInstrInfo const &MCII, |
| 405 | MCInst const &MCI) { |
| 406 | if (HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeCR) |
| 407 | return false; |
| 408 | |
| 409 | unsigned SchedClass = HexagonMCInstrInfo::getDesc(MCII, MCI).getSchedClass(); |
| 410 | switch (SchedClass) { |
| 411 | case Hexagon::Sched::ALU32_3op_tc_2_SLOT0123: |
| 412 | case Hexagon::Sched::ALU64_tc_2_SLOT23: |
| 413 | case Hexagon::Sched::ALU64_tc_3x_SLOT23: |
| 414 | case Hexagon::Sched::M_tc_2_SLOT23: |
| 415 | case Hexagon::Sched::M_tc_3x_SLOT23: |
| 416 | case Hexagon::Sched::S_2op_tc_2_SLOT23: |
| 417 | case Hexagon::Sched::S_3op_tc_2_SLOT23: |
| 418 | case Hexagon::Sched::S_3op_tc_3x_SLOT23: |
| 419 | return true; |
| 420 | } |
| 421 | return false; |
| 422 | } |
| 423 | |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame^] | 424 | void HexagonMCInstrInfo::replaceDuplex(MCContext &Context, MCInst &MCB, |
| 425 | DuplexCandidate Candidate) { |
| 426 | assert(Candidate.packetIndexI < MCB.size()); |
| 427 | assert(Candidate.packetIndexJ < MCB.size()); |
| 428 | assert(isBundle(MCB)); |
| 429 | MCInst *Duplex = |
| 430 | deriveDuplex(Context, Candidate.iClass, |
| 431 | *MCB.getOperand(Candidate.packetIndexJ).getInst(), |
| 432 | *MCB.getOperand(Candidate.packetIndexI).getInst()); |
| 433 | assert(Duplex != nullptr); |
| 434 | MCB.getOperand(Candidate.packetIndexI).setInst(Duplex); |
| 435 | MCB.erase(MCB.begin() + Candidate.packetIndexJ); |
| 436 | } |
| 437 | |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 438 | void HexagonMCInstrInfo::setInnerLoop(MCInst &MCI) { |
| 439 | assert(isBundle(MCI)); |
| 440 | MCOperand &Operand = MCI.getOperand(0); |
| 441 | Operand.setImm(Operand.getImm() | innerLoopMask); |
Colin LeMahieu | 1174fea | 2015-02-19 21:10:50 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 444 | void HexagonMCInstrInfo::setOuterLoop(MCInst &MCI) { |
| 445 | assert(isBundle(MCI)); |
| 446 | MCOperand &Operand = MCI.getOperand(0); |
| 447 | Operand.setImm(Operand.getImm() | outerLoopMask); |
Colin LeMahieu | 1174fea | 2015-02-19 21:10:50 +0000 | [diff] [blame] | 448 | } |
Colin LeMahieu | af304e5 | 2015-02-19 19:00:00 +0000 | [diff] [blame] | 449 | } |