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