Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 1 | //===--- HexagonBitTracker.cpp --------------------------------------------===// |
| 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 | |
Eugene Zelenko | b2ca1b3 | 2017-01-04 02:02:05 +0000 | [diff] [blame] | 10 | #include "HexagonBitTracker.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 11 | #include "Hexagon.h" |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 12 | #include "HexagonInstrInfo.h" |
| 13 | #include "HexagonRegisterInfo.h" |
| 14 | #include "HexagonTargetMachine.h" |
Eugene Zelenko | b2ca1b3 | 2017-01-04 02:02:05 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/MachineFunction.h" |
| 16 | #include "llvm/CodeGen/MachineInstr.h" |
| 17 | #include "llvm/CodeGen/MachineOperand.h" |
| 18 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 19 | #include "llvm/IR/Argument.h" |
| 20 | #include "llvm/IR/Attributes.h" |
| 21 | #include "llvm/IR/Function.h" |
| 22 | #include "llvm/IR/Type.h" |
| 23 | #include "llvm/Support/Debug.h" |
| 24 | #include "llvm/Support/ErrorHandling.h" |
| 25 | #include "llvm/Support/MathExtras.h" |
| 26 | #include "llvm/Support/raw_ostream.h" |
| 27 | #include "llvm/Target/TargetRegisterInfo.h" |
| 28 | #include <cassert> |
| 29 | #include <cstddef> |
| 30 | #include <cstdint> |
| 31 | #include <cstdlib> |
| 32 | #include <utility> |
| 33 | #include <vector> |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 34 | |
| 35 | using namespace llvm; |
| 36 | |
| 37 | typedef BitTracker BT; |
| 38 | |
Benjamin Kramer | d886151 | 2015-07-13 20:38:16 +0000 | [diff] [blame] | 39 | HexagonEvaluator::HexagonEvaluator(const HexagonRegisterInfo &tri, |
| 40 | MachineRegisterInfo &mri, |
| 41 | const HexagonInstrInfo &tii, |
| 42 | MachineFunction &mf) |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 43 | : MachineEvaluator(tri, mri), MF(mf), MFI(mf.getFrameInfo()), TII(tii) { |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 44 | // Populate the VRX map (VR to extension-type). |
| 45 | // Go over all the formal parameters of the function. If a given parameter |
| 46 | // P is sign- or zero-extended, locate the virtual register holding that |
| 47 | // parameter and create an entry in the VRX map indicating the type of ex- |
| 48 | // tension (and the source type). |
| 49 | // This is a bit complicated to do accurately, since the memory layout in- |
| 50 | // formation is necessary to precisely determine whether an aggregate para- |
| 51 | // meter will be passed in a register or in memory. What is given in MRI |
| 52 | // is the association between the physical register that is live-in (i.e. |
| 53 | // holds an argument), and the virtual register that this value will be |
| 54 | // copied into. This, by itself, is not sufficient to map back the virtual |
| 55 | // register to a formal parameter from Function (since consecutive live-ins |
| 56 | // from MRI may not correspond to consecutive formal parameters from Func- |
| 57 | // tion). To avoid the complications with in-memory arguments, only consi- |
| 58 | // der the initial sequence of formal parameters that are known to be |
| 59 | // passed via registers. |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 60 | unsigned InVirtReg, InPhysReg = 0; |
| 61 | const Function &F = *MF.getFunction(); |
| 62 | typedef Function::const_arg_iterator arg_iterator; |
| 63 | for (arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) { |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 64 | const Argument &Arg = *I; |
| 65 | Type *ATy = Arg.getType(); |
| 66 | unsigned Width = 0; |
| 67 | if (ATy->isIntegerTy()) |
| 68 | Width = ATy->getIntegerBitWidth(); |
| 69 | else if (ATy->isPointerTy()) |
| 70 | Width = 32; |
| 71 | // If pointer size is not set through target data, it will default to |
| 72 | // Module::AnyPointerSize. |
| 73 | if (Width == 0 || Width > 64) |
| 74 | break; |
Reid Kleckner | 6652a52 | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 75 | if (Arg.hasAttribute(Attribute::ByVal)) |
Krzysztof Parzyszek | 60f0b51 | 2016-08-11 18:15:16 +0000 | [diff] [blame] | 76 | continue; |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 77 | InPhysReg = getNextPhysReg(InPhysReg, Width); |
| 78 | if (!InPhysReg) |
| 79 | break; |
| 80 | InVirtReg = getVirtRegFor(InPhysReg); |
| 81 | if (!InVirtReg) |
| 82 | continue; |
Reid Kleckner | 6652a52 | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 83 | if (Arg.hasAttribute(Attribute::SExt)) |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 84 | VRX.insert(std::make_pair(InVirtReg, ExtType(ExtType::SExt, Width))); |
Reid Kleckner | 6652a52 | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 85 | else if (Arg.hasAttribute(Attribute::ZExt)) |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 86 | VRX.insert(std::make_pair(InVirtReg, ExtType(ExtType::ZExt, Width))); |
| 87 | } |
| 88 | } |
| 89 | |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 90 | BT::BitMask HexagonEvaluator::mask(unsigned Reg, unsigned Sub) const { |
Eugene Zelenko | b2ca1b3 | 2017-01-04 02:02:05 +0000 | [diff] [blame] | 91 | using namespace Hexagon; |
| 92 | |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 93 | if (Sub == 0) |
| 94 | return MachineEvaluator::mask(Reg, 0); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 95 | const TargetRegisterClass *RC = MRI.getRegClass(Reg); |
| 96 | unsigned ID = RC->getID(); |
| 97 | uint16_t RW = getRegBitWidth(RegisterRef(Reg, Sub)); |
Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 98 | auto &HRI = static_cast<const HexagonRegisterInfo&>(TRI); |
| 99 | bool IsSubLo = (Sub == HRI.getHexagonSubRegIndex(RC, Hexagon::ps_sub_lo)); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 100 | switch (ID) { |
| 101 | case DoubleRegsRegClassID: |
Krzysztof Parzyszek | 195dc8d | 2015-11-26 04:33:11 +0000 | [diff] [blame] | 102 | case VecDblRegsRegClassID: |
| 103 | case VecDblRegs128BRegClassID: |
Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 104 | return IsSubLo ? BT::BitMask(0, RW-1) |
| 105 | : BT::BitMask(RW, 2*RW-1); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 106 | default: |
| 107 | break; |
| 108 | } |
| 109 | #ifndef NDEBUG |
| 110 | dbgs() << PrintReg(Reg, &TRI, Sub) << '\n'; |
| 111 | #endif |
| 112 | llvm_unreachable("Unexpected register/subregister"); |
| 113 | } |
| 114 | |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 115 | namespace { |
Eugene Zelenko | b2ca1b3 | 2017-01-04 02:02:05 +0000 | [diff] [blame] | 116 | |
Benjamin Kramer | 9a5d788 | 2015-07-18 17:43:23 +0000 | [diff] [blame] | 117 | class RegisterRefs { |
| 118 | std::vector<BT::RegisterRef> Vector; |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 119 | |
Benjamin Kramer | 9a5d788 | 2015-07-18 17:43:23 +0000 | [diff] [blame] | 120 | public: |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 121 | RegisterRefs(const MachineInstr &MI) : Vector(MI.getNumOperands()) { |
Benjamin Kramer | 9a5d788 | 2015-07-18 17:43:23 +0000 | [diff] [blame] | 122 | for (unsigned i = 0, n = Vector.size(); i < n; ++i) { |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 123 | const MachineOperand &MO = MI.getOperand(i); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 124 | if (MO.isReg()) |
Benjamin Kramer | 9a5d788 | 2015-07-18 17:43:23 +0000 | [diff] [blame] | 125 | Vector[i] = BT::RegisterRef(MO); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 126 | // For indices that don't correspond to registers, the entry will |
| 127 | // remain constructed via the default constructor. |
| 128 | } |
| 129 | } |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 130 | |
Benjamin Kramer | 9a5d788 | 2015-07-18 17:43:23 +0000 | [diff] [blame] | 131 | size_t size() const { return Vector.size(); } |
Eugene Zelenko | b2ca1b3 | 2017-01-04 02:02:05 +0000 | [diff] [blame] | 132 | |
Benjamin Kramer | 9a5d788 | 2015-07-18 17:43:23 +0000 | [diff] [blame] | 133 | const BT::RegisterRef &operator[](unsigned n) const { |
| 134 | // The main purpose of this operator is to assert with bad argument. |
| 135 | assert(n < Vector.size()); |
| 136 | return Vector[n]; |
| 137 | } |
| 138 | }; |
Eugene Zelenko | b2ca1b3 | 2017-01-04 02:02:05 +0000 | [diff] [blame] | 139 | |
| 140 | } // end anonymous namespace |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 141 | |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 142 | bool HexagonEvaluator::evaluate(const MachineInstr &MI, |
| 143 | const CellMapType &Inputs, |
| 144 | CellMapType &Outputs) const { |
Eugene Zelenko | b2ca1b3 | 2017-01-04 02:02:05 +0000 | [diff] [blame] | 145 | using namespace Hexagon; |
| 146 | |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 147 | unsigned NumDefs = 0; |
| 148 | |
| 149 | // Sanity verification: there should not be any defs with subregisters. |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 150 | for (unsigned i = 0, n = MI.getNumOperands(); i < n; ++i) { |
| 151 | const MachineOperand &MO = MI.getOperand(i); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 152 | if (!MO.isReg() || !MO.isDef()) |
| 153 | continue; |
| 154 | NumDefs++; |
| 155 | assert(MO.getSubReg() == 0); |
| 156 | } |
| 157 | |
| 158 | if (NumDefs == 0) |
| 159 | return false; |
| 160 | |
Krzysztof Parzyszek | 1adca30 | 2016-07-26 18:30:11 +0000 | [diff] [blame] | 161 | unsigned Opc = MI.getOpcode(); |
| 162 | |
| 163 | if (MI.mayLoad()) { |
| 164 | switch (Opc) { |
| 165 | // These instructions may be marked as mayLoad, but they are generating |
| 166 | // immediate values, so skip them. |
| 167 | case CONST32: |
Krzysztof Parzyszek | a338650 | 2016-08-10 16:46:36 +0000 | [diff] [blame] | 168 | case CONST64: |
Krzysztof Parzyszek | 1adca30 | 2016-07-26 18:30:11 +0000 | [diff] [blame] | 169 | break; |
| 170 | default: |
| 171 | return evaluateLoad(MI, Inputs, Outputs); |
| 172 | } |
| 173 | } |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 174 | |
| 175 | // Check COPY instructions that copy formal parameters into virtual |
| 176 | // registers. Such parameters can be sign- or zero-extended at the |
| 177 | // call site, and we should take advantage of this knowledge. The MRI |
| 178 | // keeps a list of pairs of live-in physical and virtual registers, |
| 179 | // which provides information about which virtual registers will hold |
| 180 | // the argument values. The function will still contain instructions |
| 181 | // defining those virtual registers, and in practice those are COPY |
| 182 | // instructions from a physical to a virtual register. In such cases, |
| 183 | // applying the argument extension to the virtual register can be seen |
| 184 | // as simply mirroring the extension that had already been applied to |
| 185 | // the physical register at the call site. If the defining instruction |
| 186 | // was not a COPY, it would not be clear how to mirror that extension |
| 187 | // on the callee's side. For that reason, only check COPY instructions |
| 188 | // for potential extensions. |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 189 | if (MI.isCopy()) { |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 190 | if (evaluateFormalCopy(MI, Inputs, Outputs)) |
| 191 | return true; |
| 192 | } |
| 193 | |
| 194 | // Beyond this point, if any operand is a global, skip that instruction. |
| 195 | // The reason is that certain instructions that can take an immediate |
| 196 | // operand can also have a global symbol in that operand. To avoid |
| 197 | // checking what kind of operand a given instruction has individually |
| 198 | // for each instruction, do it here. Global symbols as operands gene- |
| 199 | // rally do not provide any useful information. |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 200 | for (unsigned i = 0, n = MI.getNumOperands(); i < n; ++i) { |
| 201 | const MachineOperand &MO = MI.getOperand(i); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 202 | if (MO.isGlobal() || MO.isBlockAddress() || MO.isSymbol() || MO.isJTI() || |
| 203 | MO.isCPI()) |
| 204 | return false; |
| 205 | } |
| 206 | |
| 207 | RegisterRefs Reg(MI); |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 208 | #define op(i) MI.getOperand(i) |
| 209 | #define rc(i) RegisterCell::ref(getCell(Reg[i], Inputs)) |
| 210 | #define im(i) MI.getOperand(i).getImm() |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 211 | |
| 212 | // If the instruction has no register operands, skip it. |
| 213 | if (Reg.size() == 0) |
| 214 | return false; |
| 215 | |
| 216 | // Record result for register in operand 0. |
| 217 | auto rr0 = [this,Reg] (const BT::RegisterCell &Val, CellMapType &Outputs) |
| 218 | -> bool { |
| 219 | putCell(Reg[0], Val, Outputs); |
| 220 | return true; |
| 221 | }; |
| 222 | // Get the cell corresponding to the N-th operand. |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 223 | auto cop = [this, &Reg, &MI, &Inputs](unsigned N, |
| 224 | uint16_t W) -> BT::RegisterCell { |
| 225 | const MachineOperand &Op = MI.getOperand(N); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 226 | if (Op.isImm()) |
| 227 | return eIMM(Op.getImm(), W); |
| 228 | if (!Op.isReg()) |
| 229 | return RegisterCell::self(0, W); |
Krzysztof Parzyszek | a45971a | 2015-07-07 16:02:11 +0000 | [diff] [blame] | 230 | assert(getRegBitWidth(Reg[N]) == W && "Register width mismatch"); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 231 | return rc(N); |
| 232 | }; |
| 233 | // Extract RW low bits of the cell. |
| 234 | auto lo = [this] (const BT::RegisterCell &RC, uint16_t RW) |
| 235 | -> BT::RegisterCell { |
Krzysztof Parzyszek | a45971a | 2015-07-07 16:02:11 +0000 | [diff] [blame] | 236 | assert(RW <= RC.width()); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 237 | return eXTR(RC, 0, RW); |
| 238 | }; |
| 239 | // Extract RW high bits of the cell. |
| 240 | auto hi = [this] (const BT::RegisterCell &RC, uint16_t RW) |
| 241 | -> BT::RegisterCell { |
| 242 | uint16_t W = RC.width(); |
| 243 | assert(RW <= W); |
| 244 | return eXTR(RC, W-RW, W); |
| 245 | }; |
| 246 | // Extract N-th halfword (counting from the least significant position). |
| 247 | auto half = [this] (const BT::RegisterCell &RC, unsigned N) |
| 248 | -> BT::RegisterCell { |
Krzysztof Parzyszek | a45971a | 2015-07-07 16:02:11 +0000 | [diff] [blame] | 249 | assert(N*16+16 <= RC.width()); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 250 | return eXTR(RC, N*16, N*16+16); |
| 251 | }; |
| 252 | // Shuffle bits (pick even/odd from cells and merge into result). |
| 253 | auto shuffle = [this] (const BT::RegisterCell &Rs, const BT::RegisterCell &Rt, |
| 254 | uint16_t BW, bool Odd) -> BT::RegisterCell { |
| 255 | uint16_t I = Odd, Ws = Rs.width(); |
| 256 | assert(Ws == Rt.width()); |
| 257 | RegisterCell RC = eXTR(Rt, I*BW, I*BW+BW).cat(eXTR(Rs, I*BW, I*BW+BW)); |
| 258 | I += 2; |
| 259 | while (I*BW < Ws) { |
| 260 | RC.cat(eXTR(Rt, I*BW, I*BW+BW)).cat(eXTR(Rs, I*BW, I*BW+BW)); |
| 261 | I += 2; |
| 262 | } |
| 263 | return RC; |
| 264 | }; |
| 265 | |
| 266 | // The bitwidth of the 0th operand. In most (if not all) of the |
| 267 | // instructions below, the 0th operand is the defined register. |
| 268 | // Pre-compute the bitwidth here, because it is needed in many cases |
| 269 | // cases below. |
| 270 | uint16_t W0 = (Reg[0].Reg != 0) ? getRegBitWidth(Reg[0]) : 0; |
| 271 | |
Krzysztof Parzyszek | 128e191 | 2017-02-23 22:11:52 +0000 | [diff] [blame] | 272 | // Register id of the 0th operand. It can be 0. |
| 273 | unsigned Reg0 = Reg[0].Reg; |
| 274 | |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 275 | switch (Opc) { |
| 276 | // Transfer immediate: |
| 277 | |
| 278 | case A2_tfrsi: |
| 279 | case A2_tfrpi: |
| 280 | case CONST32: |
Krzysztof Parzyszek | a338650 | 2016-08-10 16:46:36 +0000 | [diff] [blame] | 281 | case CONST64: |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 282 | return rr0(eIMM(im(1), W0), Outputs); |
Krzysztof Parzyszek | 1d01a79 | 2016-08-16 18:08:40 +0000 | [diff] [blame] | 283 | case PS_false: |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 284 | return rr0(RegisterCell(W0).fill(0, W0, BT::BitValue::Zero), Outputs); |
Krzysztof Parzyszek | 1d01a79 | 2016-08-16 18:08:40 +0000 | [diff] [blame] | 285 | case PS_true: |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 286 | return rr0(RegisterCell(W0).fill(0, W0, BT::BitValue::One), Outputs); |
Krzysztof Parzyszek | 1d01a79 | 2016-08-16 18:08:40 +0000 | [diff] [blame] | 287 | case PS_fi: { |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 288 | int FI = op(1).getIndex(); |
| 289 | int Off = op(2).getImm(); |
| 290 | unsigned A = MFI.getObjectAlignment(FI) + std::abs(Off); |
| 291 | unsigned L = Log2_32(A); |
| 292 | RegisterCell RC = RegisterCell::self(Reg[0].Reg, W0); |
| 293 | RC.fill(0, L, BT::BitValue::Zero); |
| 294 | return rr0(RC, Outputs); |
| 295 | } |
| 296 | |
| 297 | // Transfer register: |
| 298 | |
| 299 | case A2_tfr: |
| 300 | case A2_tfrp: |
| 301 | case C2_pxfer_map: |
| 302 | return rr0(rc(1), Outputs); |
| 303 | case C2_tfrpr: { |
| 304 | uint16_t RW = W0; |
| 305 | uint16_t PW = 8; // XXX Pred size: getRegBitWidth(Reg[1]); |
| 306 | assert(PW <= RW); |
| 307 | RegisterCell PC = eXTR(rc(1), 0, PW); |
| 308 | RegisterCell RC = RegisterCell(RW).insert(PC, BT::BitMask(0, PW-1)); |
| 309 | RC.fill(PW, RW, BT::BitValue::Zero); |
| 310 | return rr0(RC, Outputs); |
| 311 | } |
| 312 | case C2_tfrrp: { |
| 313 | RegisterCell RC = RegisterCell::self(Reg[0].Reg, W0); |
| 314 | W0 = 8; // XXX Pred size |
| 315 | return rr0(eINS(RC, eXTR(rc(1), 0, W0), 0), Outputs); |
| 316 | } |
| 317 | |
| 318 | // Arithmetic: |
| 319 | |
| 320 | case A2_abs: |
| 321 | case A2_absp: |
| 322 | // TODO |
| 323 | break; |
| 324 | |
| 325 | case A2_addsp: { |
| 326 | uint16_t W1 = getRegBitWidth(Reg[1]); |
| 327 | assert(W0 == 64 && W1 == 32); |
| 328 | RegisterCell CW = RegisterCell(W0).insert(rc(1), BT::BitMask(0, W1-1)); |
| 329 | RegisterCell RC = eADD(eSXT(CW, W1), rc(2)); |
| 330 | return rr0(RC, Outputs); |
| 331 | } |
| 332 | case A2_add: |
| 333 | case A2_addp: |
| 334 | return rr0(eADD(rc(1), rc(2)), Outputs); |
| 335 | case A2_addi: |
| 336 | return rr0(eADD(rc(1), eIMM(im(2), W0)), Outputs); |
| 337 | case S4_addi_asl_ri: { |
| 338 | RegisterCell RC = eADD(eIMM(im(1), W0), eASL(rc(2), im(3))); |
| 339 | return rr0(RC, Outputs); |
| 340 | } |
| 341 | case S4_addi_lsr_ri: { |
| 342 | RegisterCell RC = eADD(eIMM(im(1), W0), eLSR(rc(2), im(3))); |
| 343 | return rr0(RC, Outputs); |
| 344 | } |
| 345 | case S4_addaddi: { |
| 346 | RegisterCell RC = eADD(rc(1), eADD(rc(2), eIMM(im(3), W0))); |
| 347 | return rr0(RC, Outputs); |
| 348 | } |
| 349 | case M4_mpyri_addi: { |
| 350 | RegisterCell M = eMLS(rc(2), eIMM(im(3), W0)); |
| 351 | RegisterCell RC = eADD(eIMM(im(1), W0), lo(M, W0)); |
| 352 | return rr0(RC, Outputs); |
| 353 | } |
| 354 | case M4_mpyrr_addi: { |
| 355 | RegisterCell M = eMLS(rc(2), rc(3)); |
| 356 | RegisterCell RC = eADD(eIMM(im(1), W0), lo(M, W0)); |
| 357 | return rr0(RC, Outputs); |
| 358 | } |
| 359 | case M4_mpyri_addr_u2: { |
| 360 | RegisterCell M = eMLS(eIMM(im(2), W0), rc(3)); |
| 361 | RegisterCell RC = eADD(rc(1), lo(M, W0)); |
| 362 | return rr0(RC, Outputs); |
| 363 | } |
| 364 | case M4_mpyri_addr: { |
| 365 | RegisterCell M = eMLS(rc(2), eIMM(im(3), W0)); |
| 366 | RegisterCell RC = eADD(rc(1), lo(M, W0)); |
| 367 | return rr0(RC, Outputs); |
| 368 | } |
| 369 | case M4_mpyrr_addr: { |
| 370 | RegisterCell M = eMLS(rc(2), rc(3)); |
| 371 | RegisterCell RC = eADD(rc(1), lo(M, W0)); |
| 372 | return rr0(RC, Outputs); |
| 373 | } |
| 374 | case S4_subaddi: { |
| 375 | RegisterCell RC = eADD(rc(1), eSUB(eIMM(im(2), W0), rc(3))); |
| 376 | return rr0(RC, Outputs); |
| 377 | } |
| 378 | case M2_accii: { |
| 379 | RegisterCell RC = eADD(rc(1), eADD(rc(2), eIMM(im(3), W0))); |
| 380 | return rr0(RC, Outputs); |
| 381 | } |
| 382 | case M2_acci: { |
| 383 | RegisterCell RC = eADD(rc(1), eADD(rc(2), rc(3))); |
| 384 | return rr0(RC, Outputs); |
| 385 | } |
| 386 | case M2_subacc: { |
| 387 | RegisterCell RC = eADD(rc(1), eSUB(rc(2), rc(3))); |
| 388 | return rr0(RC, Outputs); |
| 389 | } |
| 390 | case S2_addasl_rrri: { |
| 391 | RegisterCell RC = eADD(rc(1), eASL(rc(2), im(3))); |
| 392 | return rr0(RC, Outputs); |
| 393 | } |
| 394 | case C4_addipc: { |
| 395 | RegisterCell RPC = RegisterCell::self(Reg[0].Reg, W0); |
| 396 | RPC.fill(0, 2, BT::BitValue::Zero); |
| 397 | return rr0(eADD(RPC, eIMM(im(2), W0)), Outputs); |
| 398 | } |
| 399 | case A2_sub: |
| 400 | case A2_subp: |
| 401 | return rr0(eSUB(rc(1), rc(2)), Outputs); |
| 402 | case A2_subri: |
| 403 | return rr0(eSUB(eIMM(im(1), W0), rc(2)), Outputs); |
| 404 | case S4_subi_asl_ri: { |
| 405 | RegisterCell RC = eSUB(eIMM(im(1), W0), eASL(rc(2), im(3))); |
| 406 | return rr0(RC, Outputs); |
| 407 | } |
| 408 | case S4_subi_lsr_ri: { |
| 409 | RegisterCell RC = eSUB(eIMM(im(1), W0), eLSR(rc(2), im(3))); |
| 410 | return rr0(RC, Outputs); |
| 411 | } |
| 412 | case M2_naccii: { |
| 413 | RegisterCell RC = eSUB(rc(1), eADD(rc(2), eIMM(im(3), W0))); |
| 414 | return rr0(RC, Outputs); |
| 415 | } |
| 416 | case M2_nacci: { |
| 417 | RegisterCell RC = eSUB(rc(1), eADD(rc(2), rc(3))); |
| 418 | return rr0(RC, Outputs); |
| 419 | } |
| 420 | // 32-bit negation is done by "Rd = A2_subri 0, Rs" |
| 421 | case A2_negp: |
| 422 | return rr0(eSUB(eIMM(0, W0), rc(1)), Outputs); |
| 423 | |
| 424 | case M2_mpy_up: { |
| 425 | RegisterCell M = eMLS(rc(1), rc(2)); |
| 426 | return rr0(hi(M, W0), Outputs); |
| 427 | } |
| 428 | case M2_dpmpyss_s0: |
| 429 | return rr0(eMLS(rc(1), rc(2)), Outputs); |
| 430 | case M2_dpmpyss_acc_s0: |
| 431 | return rr0(eADD(rc(1), eMLS(rc(2), rc(3))), Outputs); |
| 432 | case M2_dpmpyss_nac_s0: |
| 433 | return rr0(eSUB(rc(1), eMLS(rc(2), rc(3))), Outputs); |
| 434 | case M2_mpyi: { |
| 435 | RegisterCell M = eMLS(rc(1), rc(2)); |
| 436 | return rr0(lo(M, W0), Outputs); |
| 437 | } |
| 438 | case M2_macsip: { |
| 439 | RegisterCell M = eMLS(rc(2), eIMM(im(3), W0)); |
| 440 | RegisterCell RC = eADD(rc(1), lo(M, W0)); |
| 441 | return rr0(RC, Outputs); |
| 442 | } |
| 443 | case M2_macsin: { |
| 444 | RegisterCell M = eMLS(rc(2), eIMM(im(3), W0)); |
| 445 | RegisterCell RC = eSUB(rc(1), lo(M, W0)); |
| 446 | return rr0(RC, Outputs); |
| 447 | } |
| 448 | case M2_maci: { |
| 449 | RegisterCell M = eMLS(rc(2), rc(3)); |
| 450 | RegisterCell RC = eADD(rc(1), lo(M, W0)); |
| 451 | return rr0(RC, Outputs); |
| 452 | } |
| 453 | case M2_mpysmi: { |
| 454 | RegisterCell M = eMLS(rc(1), eIMM(im(2), W0)); |
| 455 | return rr0(lo(M, 32), Outputs); |
| 456 | } |
| 457 | case M2_mpysin: { |
| 458 | RegisterCell M = eMLS(rc(1), eIMM(-im(2), W0)); |
| 459 | return rr0(lo(M, 32), Outputs); |
| 460 | } |
| 461 | case M2_mpysip: { |
| 462 | RegisterCell M = eMLS(rc(1), eIMM(im(2), W0)); |
| 463 | return rr0(lo(M, 32), Outputs); |
| 464 | } |
| 465 | case M2_mpyu_up: { |
| 466 | RegisterCell M = eMLU(rc(1), rc(2)); |
| 467 | return rr0(hi(M, W0), Outputs); |
| 468 | } |
| 469 | case M2_dpmpyuu_s0: |
| 470 | return rr0(eMLU(rc(1), rc(2)), Outputs); |
| 471 | case M2_dpmpyuu_acc_s0: |
| 472 | return rr0(eADD(rc(1), eMLU(rc(2), rc(3))), Outputs); |
| 473 | case M2_dpmpyuu_nac_s0: |
| 474 | return rr0(eSUB(rc(1), eMLU(rc(2), rc(3))), Outputs); |
| 475 | //case M2_mpysu_up: |
| 476 | |
| 477 | // Logical/bitwise: |
| 478 | |
| 479 | case A2_andir: |
| 480 | return rr0(eAND(rc(1), eIMM(im(2), W0)), Outputs); |
| 481 | case A2_and: |
| 482 | case A2_andp: |
| 483 | return rr0(eAND(rc(1), rc(2)), Outputs); |
| 484 | case A4_andn: |
| 485 | case A4_andnp: |
| 486 | return rr0(eAND(rc(1), eNOT(rc(2))), Outputs); |
| 487 | case S4_andi_asl_ri: { |
| 488 | RegisterCell RC = eAND(eIMM(im(1), W0), eASL(rc(2), im(3))); |
| 489 | return rr0(RC, Outputs); |
| 490 | } |
| 491 | case S4_andi_lsr_ri: { |
| 492 | RegisterCell RC = eAND(eIMM(im(1), W0), eLSR(rc(2), im(3))); |
| 493 | return rr0(RC, Outputs); |
| 494 | } |
| 495 | case M4_and_and: |
| 496 | return rr0(eAND(rc(1), eAND(rc(2), rc(3))), Outputs); |
| 497 | case M4_and_andn: |
| 498 | return rr0(eAND(rc(1), eAND(rc(2), eNOT(rc(3)))), Outputs); |
| 499 | case M4_and_or: |
| 500 | return rr0(eAND(rc(1), eORL(rc(2), rc(3))), Outputs); |
| 501 | case M4_and_xor: |
| 502 | return rr0(eAND(rc(1), eXOR(rc(2), rc(3))), Outputs); |
| 503 | case A2_orir: |
| 504 | return rr0(eORL(rc(1), eIMM(im(2), W0)), Outputs); |
| 505 | case A2_or: |
| 506 | case A2_orp: |
| 507 | return rr0(eORL(rc(1), rc(2)), Outputs); |
| 508 | case A4_orn: |
| 509 | case A4_ornp: |
| 510 | return rr0(eORL(rc(1), eNOT(rc(2))), Outputs); |
| 511 | case S4_ori_asl_ri: { |
| 512 | RegisterCell RC = eORL(eIMM(im(1), W0), eASL(rc(2), im(3))); |
| 513 | return rr0(RC, Outputs); |
| 514 | } |
| 515 | case S4_ori_lsr_ri: { |
| 516 | RegisterCell RC = eORL(eIMM(im(1), W0), eLSR(rc(2), im(3))); |
| 517 | return rr0(RC, Outputs); |
| 518 | } |
| 519 | case M4_or_and: |
| 520 | return rr0(eORL(rc(1), eAND(rc(2), rc(3))), Outputs); |
| 521 | case M4_or_andn: |
| 522 | return rr0(eORL(rc(1), eAND(rc(2), eNOT(rc(3)))), Outputs); |
| 523 | case S4_or_andi: |
| 524 | case S4_or_andix: { |
| 525 | RegisterCell RC = eORL(rc(1), eAND(rc(2), eIMM(im(3), W0))); |
| 526 | return rr0(RC, Outputs); |
| 527 | } |
| 528 | case S4_or_ori: { |
| 529 | RegisterCell RC = eORL(rc(1), eORL(rc(2), eIMM(im(3), W0))); |
| 530 | return rr0(RC, Outputs); |
| 531 | } |
| 532 | case M4_or_or: |
| 533 | return rr0(eORL(rc(1), eORL(rc(2), rc(3))), Outputs); |
| 534 | case M4_or_xor: |
| 535 | return rr0(eORL(rc(1), eXOR(rc(2), rc(3))), Outputs); |
| 536 | case A2_xor: |
| 537 | case A2_xorp: |
| 538 | return rr0(eXOR(rc(1), rc(2)), Outputs); |
| 539 | case M4_xor_and: |
| 540 | return rr0(eXOR(rc(1), eAND(rc(2), rc(3))), Outputs); |
| 541 | case M4_xor_andn: |
| 542 | return rr0(eXOR(rc(1), eAND(rc(2), eNOT(rc(3)))), Outputs); |
| 543 | case M4_xor_or: |
| 544 | return rr0(eXOR(rc(1), eORL(rc(2), rc(3))), Outputs); |
| 545 | case M4_xor_xacc: |
| 546 | return rr0(eXOR(rc(1), eXOR(rc(2), rc(3))), Outputs); |
| 547 | case A2_not: |
| 548 | case A2_notp: |
| 549 | return rr0(eNOT(rc(1)), Outputs); |
| 550 | |
| 551 | case S2_asl_i_r: |
| 552 | case S2_asl_i_p: |
| 553 | return rr0(eASL(rc(1), im(2)), Outputs); |
| 554 | case A2_aslh: |
| 555 | return rr0(eASL(rc(1), 16), Outputs); |
| 556 | case S2_asl_i_r_acc: |
| 557 | case S2_asl_i_p_acc: |
| 558 | return rr0(eADD(rc(1), eASL(rc(2), im(3))), Outputs); |
| 559 | case S2_asl_i_r_nac: |
| 560 | case S2_asl_i_p_nac: |
| 561 | return rr0(eSUB(rc(1), eASL(rc(2), im(3))), Outputs); |
| 562 | case S2_asl_i_r_and: |
| 563 | case S2_asl_i_p_and: |
| 564 | return rr0(eAND(rc(1), eASL(rc(2), im(3))), Outputs); |
| 565 | case S2_asl_i_r_or: |
| 566 | case S2_asl_i_p_or: |
| 567 | return rr0(eORL(rc(1), eASL(rc(2), im(3))), Outputs); |
| 568 | case S2_asl_i_r_xacc: |
| 569 | case S2_asl_i_p_xacc: |
| 570 | return rr0(eXOR(rc(1), eASL(rc(2), im(3))), Outputs); |
| 571 | case S2_asl_i_vh: |
| 572 | case S2_asl_i_vw: |
| 573 | // TODO |
| 574 | break; |
| 575 | |
| 576 | case S2_asr_i_r: |
| 577 | case S2_asr_i_p: |
| 578 | return rr0(eASR(rc(1), im(2)), Outputs); |
| 579 | case A2_asrh: |
| 580 | return rr0(eASR(rc(1), 16), Outputs); |
| 581 | case S2_asr_i_r_acc: |
| 582 | case S2_asr_i_p_acc: |
| 583 | return rr0(eADD(rc(1), eASR(rc(2), im(3))), Outputs); |
| 584 | case S2_asr_i_r_nac: |
| 585 | case S2_asr_i_p_nac: |
| 586 | return rr0(eSUB(rc(1), eASR(rc(2), im(3))), Outputs); |
| 587 | case S2_asr_i_r_and: |
| 588 | case S2_asr_i_p_and: |
| 589 | return rr0(eAND(rc(1), eASR(rc(2), im(3))), Outputs); |
| 590 | case S2_asr_i_r_or: |
| 591 | case S2_asr_i_p_or: |
| 592 | return rr0(eORL(rc(1), eASR(rc(2), im(3))), Outputs); |
| 593 | case S2_asr_i_r_rnd: { |
| 594 | // The input is first sign-extended to 64 bits, then the output |
| 595 | // is truncated back to 32 bits. |
| 596 | assert(W0 == 32); |
| 597 | RegisterCell XC = eSXT(rc(1).cat(eIMM(0, W0)), W0); |
| 598 | RegisterCell RC = eASR(eADD(eASR(XC, im(2)), eIMM(1, 2*W0)), 1); |
| 599 | return rr0(eXTR(RC, 0, W0), Outputs); |
| 600 | } |
| 601 | case S2_asr_i_r_rnd_goodsyntax: { |
| 602 | int64_t S = im(2); |
| 603 | if (S == 0) |
| 604 | return rr0(rc(1), Outputs); |
| 605 | // Result: S2_asr_i_r_rnd Rs, u5-1 |
| 606 | RegisterCell XC = eSXT(rc(1).cat(eIMM(0, W0)), W0); |
| 607 | RegisterCell RC = eLSR(eADD(eASR(XC, S-1), eIMM(1, 2*W0)), 1); |
| 608 | return rr0(eXTR(RC, 0, W0), Outputs); |
| 609 | } |
| 610 | case S2_asr_r_vh: |
| 611 | case S2_asr_i_vw: |
| 612 | case S2_asr_i_svw_trun: |
| 613 | // TODO |
| 614 | break; |
| 615 | |
| 616 | case S2_lsr_i_r: |
| 617 | case S2_lsr_i_p: |
| 618 | return rr0(eLSR(rc(1), im(2)), Outputs); |
| 619 | case S2_lsr_i_r_acc: |
| 620 | case S2_lsr_i_p_acc: |
| 621 | return rr0(eADD(rc(1), eLSR(rc(2), im(3))), Outputs); |
| 622 | case S2_lsr_i_r_nac: |
| 623 | case S2_lsr_i_p_nac: |
| 624 | return rr0(eSUB(rc(1), eLSR(rc(2), im(3))), Outputs); |
| 625 | case S2_lsr_i_r_and: |
| 626 | case S2_lsr_i_p_and: |
| 627 | return rr0(eAND(rc(1), eLSR(rc(2), im(3))), Outputs); |
| 628 | case S2_lsr_i_r_or: |
| 629 | case S2_lsr_i_p_or: |
| 630 | return rr0(eORL(rc(1), eLSR(rc(2), im(3))), Outputs); |
| 631 | case S2_lsr_i_r_xacc: |
| 632 | case S2_lsr_i_p_xacc: |
| 633 | return rr0(eXOR(rc(1), eLSR(rc(2), im(3))), Outputs); |
| 634 | |
| 635 | case S2_clrbit_i: { |
| 636 | RegisterCell RC = rc(1); |
| 637 | RC[im(2)] = BT::BitValue::Zero; |
| 638 | return rr0(RC, Outputs); |
| 639 | } |
| 640 | case S2_setbit_i: { |
| 641 | RegisterCell RC = rc(1); |
| 642 | RC[im(2)] = BT::BitValue::One; |
| 643 | return rr0(RC, Outputs); |
| 644 | } |
| 645 | case S2_togglebit_i: { |
| 646 | RegisterCell RC = rc(1); |
| 647 | uint16_t BX = im(2); |
| 648 | RC[BX] = RC[BX].is(0) ? BT::BitValue::One |
| 649 | : RC[BX].is(1) ? BT::BitValue::Zero |
| 650 | : BT::BitValue::self(); |
| 651 | return rr0(RC, Outputs); |
| 652 | } |
| 653 | |
| 654 | case A4_bitspliti: { |
| 655 | uint16_t W1 = getRegBitWidth(Reg[1]); |
| 656 | uint16_t BX = im(2); |
| 657 | // Res.uw[1] = Rs[bx+1:], Res.uw[0] = Rs[0:bx] |
| 658 | const BT::BitValue Zero = BT::BitValue::Zero; |
| 659 | RegisterCell RZ = RegisterCell(W0).fill(BX, W1, Zero) |
| 660 | .fill(W1+(W1-BX), W0, Zero); |
| 661 | RegisterCell BF1 = eXTR(rc(1), 0, BX), BF2 = eXTR(rc(1), BX, W1); |
| 662 | RegisterCell RC = eINS(eINS(RZ, BF1, 0), BF2, W1); |
| 663 | return rr0(RC, Outputs); |
| 664 | } |
| 665 | case S4_extract: |
| 666 | case S4_extractp: |
| 667 | case S2_extractu: |
| 668 | case S2_extractup: { |
| 669 | uint16_t Wd = im(2), Of = im(3); |
| 670 | assert(Wd <= W0); |
| 671 | if (Wd == 0) |
| 672 | return rr0(eIMM(0, W0), Outputs); |
| 673 | // If the width extends beyond the register size, pad the register |
| 674 | // with 0 bits. |
| 675 | RegisterCell Pad = (Wd+Of > W0) ? rc(1).cat(eIMM(0, Wd+Of-W0)) : rc(1); |
| 676 | RegisterCell Ext = eXTR(Pad, Of, Wd+Of); |
| 677 | // Ext is short, need to extend it with 0s or sign bit. |
| 678 | RegisterCell RC = RegisterCell(W0).insert(Ext, BT::BitMask(0, Wd-1)); |
| 679 | if (Opc == S2_extractu || Opc == S2_extractup) |
| 680 | return rr0(eZXT(RC, Wd), Outputs); |
| 681 | return rr0(eSXT(RC, Wd), Outputs); |
| 682 | } |
| 683 | case S2_insert: |
| 684 | case S2_insertp: { |
| 685 | uint16_t Wd = im(3), Of = im(4); |
| 686 | assert(Wd < W0 && Of < W0); |
| 687 | // If Wd+Of exceeds W0, the inserted bits are truncated. |
| 688 | if (Wd+Of > W0) |
| 689 | Wd = W0-Of; |
| 690 | if (Wd == 0) |
| 691 | return rr0(rc(1), Outputs); |
| 692 | return rr0(eINS(rc(1), eXTR(rc(2), 0, Wd), Of), Outputs); |
| 693 | } |
| 694 | |
| 695 | // Bit permutations: |
| 696 | |
| 697 | case A2_combineii: |
| 698 | case A4_combineii: |
| 699 | case A4_combineir: |
| 700 | case A4_combineri: |
| 701 | case A2_combinew: |
Krzysztof Parzyszek | 23ee12e | 2016-08-03 18:35:48 +0000 | [diff] [blame] | 702 | case V6_vcombine: |
| 703 | case V6_vcombine_128B: |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 704 | assert(W0 % 2 == 0); |
| 705 | return rr0(cop(2, W0/2).cat(cop(1, W0/2)), Outputs); |
| 706 | case A2_combine_ll: |
| 707 | case A2_combine_lh: |
| 708 | case A2_combine_hl: |
| 709 | case A2_combine_hh: { |
| 710 | assert(W0 == 32); |
| 711 | assert(getRegBitWidth(Reg[1]) == 32 && getRegBitWidth(Reg[2]) == 32); |
| 712 | // Low half in the output is 0 for _ll and _hl, 1 otherwise: |
| 713 | unsigned LoH = !(Opc == A2_combine_ll || Opc == A2_combine_hl); |
| 714 | // High half in the output is 0 for _ll and _lh, 1 otherwise: |
| 715 | unsigned HiH = !(Opc == A2_combine_ll || Opc == A2_combine_lh); |
| 716 | RegisterCell R1 = rc(1); |
| 717 | RegisterCell R2 = rc(2); |
| 718 | RegisterCell RC = half(R2, LoH).cat(half(R1, HiH)); |
| 719 | return rr0(RC, Outputs); |
| 720 | } |
| 721 | case S2_packhl: { |
| 722 | assert(W0 == 64); |
| 723 | assert(getRegBitWidth(Reg[1]) == 32 && getRegBitWidth(Reg[2]) == 32); |
| 724 | RegisterCell R1 = rc(1); |
| 725 | RegisterCell R2 = rc(2); |
| 726 | RegisterCell RC = half(R2, 0).cat(half(R1, 0)).cat(half(R2, 1)) |
| 727 | .cat(half(R1, 1)); |
| 728 | return rr0(RC, Outputs); |
| 729 | } |
| 730 | case S2_shuffeb: { |
| 731 | RegisterCell RC = shuffle(rc(1), rc(2), 8, false); |
| 732 | return rr0(RC, Outputs); |
| 733 | } |
| 734 | case S2_shuffeh: { |
| 735 | RegisterCell RC = shuffle(rc(1), rc(2), 16, false); |
| 736 | return rr0(RC, Outputs); |
| 737 | } |
| 738 | case S2_shuffob: { |
| 739 | RegisterCell RC = shuffle(rc(1), rc(2), 8, true); |
| 740 | return rr0(RC, Outputs); |
| 741 | } |
| 742 | case S2_shuffoh: { |
| 743 | RegisterCell RC = shuffle(rc(1), rc(2), 16, true); |
| 744 | return rr0(RC, Outputs); |
| 745 | } |
| 746 | case C2_mask: { |
| 747 | uint16_t WR = W0; |
| 748 | uint16_t WP = 8; // XXX Pred size: getRegBitWidth(Reg[1]); |
| 749 | assert(WR == 64 && WP == 8); |
| 750 | RegisterCell R1 = rc(1); |
| 751 | RegisterCell RC(WR); |
| 752 | for (uint16_t i = 0; i < WP; ++i) { |
| 753 | const BT::BitValue &V = R1[i]; |
| 754 | BT::BitValue F = (V.is(0) || V.is(1)) ? V : BT::BitValue::self(); |
| 755 | RC.fill(i*8, i*8+8, F); |
| 756 | } |
| 757 | return rr0(RC, Outputs); |
| 758 | } |
| 759 | |
| 760 | // Mux: |
| 761 | |
| 762 | case C2_muxii: |
| 763 | case C2_muxir: |
| 764 | case C2_muxri: |
| 765 | case C2_mux: { |
| 766 | BT::BitValue PC0 = rc(1)[0]; |
| 767 | RegisterCell R2 = cop(2, W0); |
| 768 | RegisterCell R3 = cop(3, W0); |
| 769 | if (PC0.is(0) || PC0.is(1)) |
| 770 | return rr0(RegisterCell::ref(PC0 ? R2 : R3), Outputs); |
| 771 | R2.meet(R3, Reg[0].Reg); |
| 772 | return rr0(R2, Outputs); |
| 773 | } |
| 774 | case C2_vmux: |
| 775 | // TODO |
| 776 | break; |
| 777 | |
| 778 | // Sign- and zero-extension: |
| 779 | |
| 780 | case A2_sxtb: |
| 781 | return rr0(eSXT(rc(1), 8), Outputs); |
| 782 | case A2_sxth: |
| 783 | return rr0(eSXT(rc(1), 16), Outputs); |
| 784 | case A2_sxtw: { |
| 785 | uint16_t W1 = getRegBitWidth(Reg[1]); |
| 786 | assert(W0 == 64 && W1 == 32); |
| 787 | RegisterCell RC = eSXT(rc(1).cat(eIMM(0, W1)), W1); |
| 788 | return rr0(RC, Outputs); |
| 789 | } |
| 790 | case A2_zxtb: |
| 791 | return rr0(eZXT(rc(1), 8), Outputs); |
| 792 | case A2_zxth: |
| 793 | return rr0(eZXT(rc(1), 16), Outputs); |
| 794 | |
Krzysztof Parzyszek | 128e191 | 2017-02-23 22:11:52 +0000 | [diff] [blame] | 795 | // Saturations |
| 796 | |
| 797 | case A2_satb: |
| 798 | return rr0(eSXT(RegisterCell::self(0, W0).regify(Reg0), 8), Outputs); |
| 799 | case A2_sath: |
| 800 | return rr0(eSXT(RegisterCell::self(0, W0).regify(Reg0), 16), Outputs); |
| 801 | case A2_satub: |
| 802 | return rr0(eZXT(RegisterCell::self(0, W0).regify(Reg0), 8), Outputs); |
| 803 | case A2_satuh: |
| 804 | return rr0(eZXT(RegisterCell::self(0, W0).regify(Reg0), 16), Outputs); |
| 805 | |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 806 | // Bit count: |
| 807 | |
| 808 | case S2_cl0: |
| 809 | case S2_cl0p: |
| 810 | // Always produce a 32-bit result. |
Eugene Zelenko | b2ca1b3 | 2017-01-04 02:02:05 +0000 | [diff] [blame] | 811 | return rr0(eCLB(rc(1), false/*bit*/, 32), Outputs); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 812 | case S2_cl1: |
| 813 | case S2_cl1p: |
Eugene Zelenko | b2ca1b3 | 2017-01-04 02:02:05 +0000 | [diff] [blame] | 814 | return rr0(eCLB(rc(1), true/*bit*/, 32), Outputs); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 815 | case S2_clb: |
| 816 | case S2_clbp: { |
| 817 | uint16_t W1 = getRegBitWidth(Reg[1]); |
| 818 | RegisterCell R1 = rc(1); |
| 819 | BT::BitValue TV = R1[W1-1]; |
| 820 | if (TV.is(0) || TV.is(1)) |
| 821 | return rr0(eCLB(R1, TV, 32), Outputs); |
| 822 | break; |
| 823 | } |
| 824 | case S2_ct0: |
| 825 | case S2_ct0p: |
Eugene Zelenko | b2ca1b3 | 2017-01-04 02:02:05 +0000 | [diff] [blame] | 826 | return rr0(eCTB(rc(1), false/*bit*/, 32), Outputs); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 827 | case S2_ct1: |
| 828 | case S2_ct1p: |
Eugene Zelenko | b2ca1b3 | 2017-01-04 02:02:05 +0000 | [diff] [blame] | 829 | return rr0(eCTB(rc(1), true/*bit*/, 32), Outputs); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 830 | case S5_popcountp: |
| 831 | // TODO |
| 832 | break; |
| 833 | |
| 834 | case C2_all8: { |
| 835 | RegisterCell P1 = rc(1); |
| 836 | bool Has0 = false, All1 = true; |
| 837 | for (uint16_t i = 0; i < 8/*XXX*/; ++i) { |
| 838 | if (!P1[i].is(1)) |
| 839 | All1 = false; |
| 840 | if (!P1[i].is(0)) |
| 841 | continue; |
| 842 | Has0 = true; |
| 843 | break; |
| 844 | } |
| 845 | if (!Has0 && !All1) |
| 846 | break; |
| 847 | RegisterCell RC(W0); |
| 848 | RC.fill(0, W0, (All1 ? BT::BitValue::One : BT::BitValue::Zero)); |
| 849 | return rr0(RC, Outputs); |
| 850 | } |
| 851 | case C2_any8: { |
| 852 | RegisterCell P1 = rc(1); |
| 853 | bool Has1 = false, All0 = true; |
| 854 | for (uint16_t i = 0; i < 8/*XXX*/; ++i) { |
| 855 | if (!P1[i].is(0)) |
| 856 | All0 = false; |
| 857 | if (!P1[i].is(1)) |
| 858 | continue; |
| 859 | Has1 = true; |
| 860 | break; |
| 861 | } |
| 862 | if (!Has1 && !All0) |
| 863 | break; |
| 864 | RegisterCell RC(W0); |
| 865 | RC.fill(0, W0, (Has1 ? BT::BitValue::One : BT::BitValue::Zero)); |
| 866 | return rr0(RC, Outputs); |
| 867 | } |
| 868 | case C2_and: |
| 869 | return rr0(eAND(rc(1), rc(2)), Outputs); |
| 870 | case C2_andn: |
| 871 | return rr0(eAND(rc(1), eNOT(rc(2))), Outputs); |
| 872 | case C2_not: |
| 873 | return rr0(eNOT(rc(1)), Outputs); |
| 874 | case C2_or: |
| 875 | return rr0(eORL(rc(1), rc(2)), Outputs); |
| 876 | case C2_orn: |
| 877 | return rr0(eORL(rc(1), eNOT(rc(2))), Outputs); |
| 878 | case C2_xor: |
| 879 | return rr0(eXOR(rc(1), rc(2)), Outputs); |
| 880 | case C4_and_and: |
| 881 | return rr0(eAND(rc(1), eAND(rc(2), rc(3))), Outputs); |
| 882 | case C4_and_andn: |
| 883 | return rr0(eAND(rc(1), eAND(rc(2), eNOT(rc(3)))), Outputs); |
| 884 | case C4_and_or: |
| 885 | return rr0(eAND(rc(1), eORL(rc(2), rc(3))), Outputs); |
| 886 | case C4_and_orn: |
| 887 | return rr0(eAND(rc(1), eORL(rc(2), eNOT(rc(3)))), Outputs); |
| 888 | case C4_or_and: |
| 889 | return rr0(eORL(rc(1), eAND(rc(2), rc(3))), Outputs); |
| 890 | case C4_or_andn: |
| 891 | return rr0(eORL(rc(1), eAND(rc(2), eNOT(rc(3)))), Outputs); |
| 892 | case C4_or_or: |
| 893 | return rr0(eORL(rc(1), eORL(rc(2), rc(3))), Outputs); |
| 894 | case C4_or_orn: |
| 895 | return rr0(eORL(rc(1), eORL(rc(2), eNOT(rc(3)))), Outputs); |
| 896 | case C2_bitsclr: |
| 897 | case C2_bitsclri: |
| 898 | case C2_bitsset: |
| 899 | case C4_nbitsclr: |
| 900 | case C4_nbitsclri: |
| 901 | case C4_nbitsset: |
| 902 | // TODO |
| 903 | break; |
| 904 | case S2_tstbit_i: |
| 905 | case S4_ntstbit_i: { |
| 906 | BT::BitValue V = rc(1)[im(2)]; |
| 907 | if (V.is(0) || V.is(1)) { |
| 908 | // If instruction is S2_tstbit_i, test for 1, otherwise test for 0. |
| 909 | bool TV = (Opc == S2_tstbit_i); |
| 910 | BT::BitValue F = V.is(TV) ? BT::BitValue::One : BT::BitValue::Zero; |
| 911 | return rr0(RegisterCell(W0).fill(0, W0, F), Outputs); |
| 912 | } |
| 913 | break; |
| 914 | } |
| 915 | |
| 916 | default: |
| 917 | return MachineEvaluator::evaluate(MI, Inputs, Outputs); |
| 918 | } |
| 919 | #undef im |
| 920 | #undef rc |
| 921 | #undef op |
| 922 | return false; |
| 923 | } |
| 924 | |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 925 | bool HexagonEvaluator::evaluate(const MachineInstr &BI, |
| 926 | const CellMapType &Inputs, |
| 927 | BranchTargetList &Targets, |
| 928 | bool &FallsThru) const { |
Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 929 | // We need to evaluate one branch at a time. TII::analyzeBranch checks |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 930 | // all the branches in a basic block at once, so we cannot use it. |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 931 | unsigned Opc = BI.getOpcode(); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 932 | bool SimpleBranch = false; |
| 933 | bool Negated = false; |
| 934 | switch (Opc) { |
| 935 | case Hexagon::J2_jumpf: |
Krzysztof Parzyszek | a243adf | 2016-08-19 14:14:09 +0000 | [diff] [blame] | 936 | case Hexagon::J2_jumpfpt: |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 937 | case Hexagon::J2_jumpfnew: |
| 938 | case Hexagon::J2_jumpfnewpt: |
| 939 | Negated = true; |
Simon Pilgrim | 087e87d | 2017-07-07 13:21:43 +0000 | [diff] [blame] | 940 | LLVM_FALLTHROUGH; |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 941 | case Hexagon::J2_jumpt: |
Krzysztof Parzyszek | a243adf | 2016-08-19 14:14:09 +0000 | [diff] [blame] | 942 | case Hexagon::J2_jumptpt: |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 943 | case Hexagon::J2_jumptnew: |
| 944 | case Hexagon::J2_jumptnewpt: |
| 945 | // Simple branch: if([!]Pn) jump ... |
| 946 | // i.e. Op0 = predicate, Op1 = branch target. |
| 947 | SimpleBranch = true; |
| 948 | break; |
| 949 | case Hexagon::J2_jump: |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 950 | Targets.insert(BI.getOperand(0).getMBB()); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 951 | FallsThru = false; |
| 952 | return true; |
| 953 | default: |
| 954 | // If the branch is of unknown type, assume that all successors are |
| 955 | // executable. |
| 956 | return false; |
| 957 | } |
| 958 | |
| 959 | if (!SimpleBranch) |
| 960 | return false; |
| 961 | |
| 962 | // BI is a conditional branch if we got here. |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 963 | RegisterRef PR = BI.getOperand(0); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 964 | RegisterCell PC = getCell(PR, Inputs); |
| 965 | const BT::BitValue &Test = PC[0]; |
| 966 | |
| 967 | // If the condition is neither true nor false, then it's unknown. |
| 968 | if (!Test.is(0) && !Test.is(1)) |
| 969 | return false; |
| 970 | |
| 971 | // "Test.is(!Negated)" means "branch condition is true". |
| 972 | if (!Test.is(!Negated)) { |
| 973 | // Condition known to be false. |
| 974 | FallsThru = true; |
| 975 | return true; |
| 976 | } |
| 977 | |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 978 | Targets.insert(BI.getOperand(1).getMBB()); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 979 | FallsThru = false; |
| 980 | return true; |
| 981 | } |
| 982 | |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 983 | bool HexagonEvaluator::evaluateLoad(const MachineInstr &MI, |
| 984 | const CellMapType &Inputs, |
| 985 | CellMapType &Outputs) const { |
Eugene Zelenko | b2ca1b3 | 2017-01-04 02:02:05 +0000 | [diff] [blame] | 986 | using namespace Hexagon; |
| 987 | |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 988 | if (TII.isPredicated(MI)) |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 989 | return false; |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 990 | assert(MI.mayLoad() && "A load that mayn't?"); |
| 991 | unsigned Opc = MI.getOpcode(); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 992 | |
| 993 | uint16_t BitNum; |
| 994 | bool SignEx; |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 995 | |
| 996 | switch (Opc) { |
| 997 | default: |
| 998 | return false; |
| 999 | |
| 1000 | #if 0 |
| 1001 | // memb_fifo |
| 1002 | case L2_loadalignb_pbr: |
| 1003 | case L2_loadalignb_pcr: |
| 1004 | case L2_loadalignb_pi: |
| 1005 | // memh_fifo |
| 1006 | case L2_loadalignh_pbr: |
| 1007 | case L2_loadalignh_pcr: |
| 1008 | case L2_loadalignh_pi: |
| 1009 | // membh |
| 1010 | case L2_loadbsw2_pbr: |
| 1011 | case L2_loadbsw2_pci: |
| 1012 | case L2_loadbsw2_pcr: |
| 1013 | case L2_loadbsw2_pi: |
| 1014 | case L2_loadbsw4_pbr: |
| 1015 | case L2_loadbsw4_pci: |
| 1016 | case L2_loadbsw4_pcr: |
| 1017 | case L2_loadbsw4_pi: |
| 1018 | // memubh |
| 1019 | case L2_loadbzw2_pbr: |
| 1020 | case L2_loadbzw2_pci: |
| 1021 | case L2_loadbzw2_pcr: |
| 1022 | case L2_loadbzw2_pi: |
| 1023 | case L2_loadbzw4_pbr: |
| 1024 | case L2_loadbzw4_pci: |
| 1025 | case L2_loadbzw4_pcr: |
| 1026 | case L2_loadbzw4_pi: |
| 1027 | #endif |
| 1028 | |
| 1029 | case L2_loadrbgp: |
| 1030 | case L2_loadrb_io: |
| 1031 | case L2_loadrb_pbr: |
| 1032 | case L2_loadrb_pci: |
| 1033 | case L2_loadrb_pcr: |
| 1034 | case L2_loadrb_pi: |
Colin LeMahieu | 9675de5 | 2016-10-06 23:02:11 +0000 | [diff] [blame] | 1035 | case PS_loadrbabs: |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 1036 | case L4_loadrb_ap: |
| 1037 | case L4_loadrb_rr: |
| 1038 | case L4_loadrb_ur: |
| 1039 | BitNum = 8; |
| 1040 | SignEx = true; |
| 1041 | break; |
| 1042 | |
| 1043 | case L2_loadrubgp: |
| 1044 | case L2_loadrub_io: |
| 1045 | case L2_loadrub_pbr: |
| 1046 | case L2_loadrub_pci: |
| 1047 | case L2_loadrub_pcr: |
| 1048 | case L2_loadrub_pi: |
Colin LeMahieu | 9675de5 | 2016-10-06 23:02:11 +0000 | [diff] [blame] | 1049 | case PS_loadrubabs: |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 1050 | case L4_loadrub_ap: |
| 1051 | case L4_loadrub_rr: |
| 1052 | case L4_loadrub_ur: |
| 1053 | BitNum = 8; |
| 1054 | SignEx = false; |
| 1055 | break; |
| 1056 | |
| 1057 | case L2_loadrhgp: |
| 1058 | case L2_loadrh_io: |
| 1059 | case L2_loadrh_pbr: |
| 1060 | case L2_loadrh_pci: |
| 1061 | case L2_loadrh_pcr: |
| 1062 | case L2_loadrh_pi: |
Colin LeMahieu | 9675de5 | 2016-10-06 23:02:11 +0000 | [diff] [blame] | 1063 | case PS_loadrhabs: |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 1064 | case L4_loadrh_ap: |
| 1065 | case L4_loadrh_rr: |
| 1066 | case L4_loadrh_ur: |
| 1067 | BitNum = 16; |
| 1068 | SignEx = true; |
| 1069 | break; |
| 1070 | |
| 1071 | case L2_loadruhgp: |
| 1072 | case L2_loadruh_io: |
| 1073 | case L2_loadruh_pbr: |
| 1074 | case L2_loadruh_pci: |
| 1075 | case L2_loadruh_pcr: |
| 1076 | case L2_loadruh_pi: |
| 1077 | case L4_loadruh_rr: |
Colin LeMahieu | 9675de5 | 2016-10-06 23:02:11 +0000 | [diff] [blame] | 1078 | case PS_loadruhabs: |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 1079 | case L4_loadruh_ap: |
| 1080 | case L4_loadruh_ur: |
| 1081 | BitNum = 16; |
| 1082 | SignEx = false; |
| 1083 | break; |
| 1084 | |
| 1085 | case L2_loadrigp: |
| 1086 | case L2_loadri_io: |
| 1087 | case L2_loadri_pbr: |
| 1088 | case L2_loadri_pci: |
| 1089 | case L2_loadri_pcr: |
| 1090 | case L2_loadri_pi: |
| 1091 | case L2_loadw_locked: |
Colin LeMahieu | 9675de5 | 2016-10-06 23:02:11 +0000 | [diff] [blame] | 1092 | case PS_loadriabs: |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 1093 | case L4_loadri_ap: |
| 1094 | case L4_loadri_rr: |
| 1095 | case L4_loadri_ur: |
| 1096 | case LDriw_pred: |
| 1097 | BitNum = 32; |
| 1098 | SignEx = true; |
| 1099 | break; |
| 1100 | |
| 1101 | case L2_loadrdgp: |
| 1102 | case L2_loadrd_io: |
| 1103 | case L2_loadrd_pbr: |
| 1104 | case L2_loadrd_pci: |
| 1105 | case L2_loadrd_pcr: |
| 1106 | case L2_loadrd_pi: |
| 1107 | case L4_loadd_locked: |
Colin LeMahieu | 9675de5 | 2016-10-06 23:02:11 +0000 | [diff] [blame] | 1108 | case PS_loadrdabs: |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 1109 | case L4_loadrd_ap: |
| 1110 | case L4_loadrd_rr: |
| 1111 | case L4_loadrd_ur: |
| 1112 | BitNum = 64; |
| 1113 | SignEx = true; |
| 1114 | break; |
| 1115 | } |
| 1116 | |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 1117 | const MachineOperand &MD = MI.getOperand(0); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 1118 | assert(MD.isReg() && MD.isDef()); |
| 1119 | RegisterRef RD = MD; |
| 1120 | |
| 1121 | uint16_t W = getRegBitWidth(RD); |
| 1122 | assert(W >= BitNum && BitNum > 0); |
| 1123 | RegisterCell Res(W); |
| 1124 | |
| 1125 | for (uint16_t i = 0; i < BitNum; ++i) |
| 1126 | Res[i] = BT::BitValue::self(BT::BitRef(RD.Reg, i)); |
| 1127 | |
| 1128 | if (SignEx) { |
| 1129 | const BT::BitValue &Sign = Res[BitNum-1]; |
| 1130 | for (uint16_t i = BitNum; i < W; ++i) |
| 1131 | Res[i] = BT::BitValue::ref(Sign); |
| 1132 | } else { |
| 1133 | for (uint16_t i = BitNum; i < W; ++i) |
| 1134 | Res[i] = BT::BitValue::Zero; |
| 1135 | } |
| 1136 | |
| 1137 | putCell(RD, Res, Outputs); |
| 1138 | return true; |
| 1139 | } |
| 1140 | |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 1141 | bool HexagonEvaluator::evaluateFormalCopy(const MachineInstr &MI, |
| 1142 | const CellMapType &Inputs, |
| 1143 | CellMapType &Outputs) const { |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 1144 | // If MI defines a formal parameter, but is not a copy (loads are handled |
| 1145 | // in evaluateLoad), then it's not clear what to do. |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 1146 | assert(MI.isCopy()); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 1147 | |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 1148 | RegisterRef RD = MI.getOperand(0); |
| 1149 | RegisterRef RS = MI.getOperand(1); |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 1150 | assert(RD.Sub == 0); |
| 1151 | if (!TargetRegisterInfo::isPhysicalRegister(RS.Reg)) |
| 1152 | return false; |
| 1153 | RegExtMap::const_iterator F = VRX.find(RD.Reg); |
| 1154 | if (F == VRX.end()) |
| 1155 | return false; |
| 1156 | |
| 1157 | uint16_t EW = F->second.Width; |
| 1158 | // Store RD's cell into the map. This will associate the cell with a virtual |
| 1159 | // register, and make zero-/sign-extends possible (otherwise we would be ex- |
| 1160 | // tending "self" bit values, which will have no effect, since "self" values |
| 1161 | // cannot be references to anything). |
| 1162 | putCell(RD, getCell(RS, Inputs), Outputs); |
| 1163 | |
| 1164 | RegisterCell Res; |
| 1165 | // Read RD's cell from the outputs instead of RS's cell from the inputs: |
| 1166 | if (F->second.Type == ExtType::SExt) |
| 1167 | Res = eSXT(getCell(RD, Outputs), EW); |
| 1168 | else if (F->second.Type == ExtType::ZExt) |
| 1169 | Res = eZXT(getCell(RD, Outputs), EW); |
| 1170 | |
| 1171 | putCell(RD, Res, Outputs); |
| 1172 | return true; |
| 1173 | } |
| 1174 | |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 1175 | unsigned HexagonEvaluator::getNextPhysReg(unsigned PReg, unsigned Width) const { |
| 1176 | using namespace Hexagon; |
Eugene Zelenko | b2ca1b3 | 2017-01-04 02:02:05 +0000 | [diff] [blame] | 1177 | |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 1178 | bool Is64 = DoubleRegsRegClass.contains(PReg); |
| 1179 | assert(PReg == 0 || Is64 || IntRegsRegClass.contains(PReg)); |
| 1180 | |
| 1181 | static const unsigned Phys32[] = { R0, R1, R2, R3, R4, R5 }; |
| 1182 | static const unsigned Phys64[] = { D0, D1, D2 }; |
| 1183 | const unsigned Num32 = sizeof(Phys32)/sizeof(unsigned); |
| 1184 | const unsigned Num64 = sizeof(Phys64)/sizeof(unsigned); |
| 1185 | |
| 1186 | // Return the first parameter register of the required width. |
| 1187 | if (PReg == 0) |
| 1188 | return (Width <= 32) ? Phys32[0] : Phys64[0]; |
| 1189 | |
| 1190 | // Set Idx32, Idx64 in such a way that Idx+1 would give the index of the |
| 1191 | // next register. |
| 1192 | unsigned Idx32 = 0, Idx64 = 0; |
| 1193 | if (!Is64) { |
| 1194 | while (Idx32 < Num32) { |
| 1195 | if (Phys32[Idx32] == PReg) |
| 1196 | break; |
| 1197 | Idx32++; |
| 1198 | } |
| 1199 | Idx64 = Idx32/2; |
| 1200 | } else { |
| 1201 | while (Idx64 < Num64) { |
| 1202 | if (Phys64[Idx64] == PReg) |
| 1203 | break; |
| 1204 | Idx64++; |
| 1205 | } |
| 1206 | Idx32 = Idx64*2+1; |
| 1207 | } |
| 1208 | |
| 1209 | if (Width <= 32) |
| 1210 | return (Idx32+1 < Num32) ? Phys32[Idx32+1] : 0; |
| 1211 | return (Idx64+1 < Num64) ? Phys64[Idx64+1] : 0; |
| 1212 | } |
| 1213 | |
Krzysztof Parzyszek | e53b31a | 2015-07-07 15:16:42 +0000 | [diff] [blame] | 1214 | unsigned HexagonEvaluator::getVirtRegFor(unsigned PReg) const { |
| 1215 | typedef MachineRegisterInfo::livein_iterator iterator; |
| 1216 | for (iterator I = MRI.livein_begin(), E = MRI.livein_end(); I != E; ++I) { |
| 1217 | if (I->first == PReg) |
| 1218 | return I->second; |
| 1219 | } |
| 1220 | return 0; |
| 1221 | } |