blob: 51aba946183935cc7f050958ead0581ce402059b [file] [log] [blame]
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001//===----- HexagonMCChecker.cpp - Instruction bundle checking -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This implements the checking of insns inside a bundle according to the
11// packet constraint rules of the Hexagon ISA.
12//
13//===----------------------------------------------------------------------===//
14
15#include "HexagonMCChecker.h"
16
17#include "HexagonBaseInfo.h"
18
Colin LeMahieu7cd08922015-11-09 04:07:48 +000019#include "llvm/MC/MCInstrDesc.h"
20#include "llvm/MC/MCInstrInfo.h"
21#include "llvm/Support/CommandLine.h"
22#include "llvm/Support/Debug.h"
23#include "llvm/Support/raw_ostream.h"
24
25using namespace llvm;
26
27static cl::opt<bool> RelaxNVChecks("relax-nv-checks", cl::init(false),
28 cl::ZeroOrMore, cl::Hidden, cl::desc("Relax checks of new-value validity"));
29
30const HexagonMCChecker::PredSense
31 HexagonMCChecker::Unconditional(Hexagon::NoRegister, false);
32
33void HexagonMCChecker::init() {
34 // Initialize read-only registers set.
35 ReadOnly.insert(Hexagon::PC);
36
37 // Figure out the loop-registers definitions.
38 if (HexagonMCInstrInfo::isInnerLoop(MCB)) {
39 Defs[Hexagon::SA0].insert(Unconditional); // FIXME: define or change SA0?
40 Defs[Hexagon::LC0].insert(Unconditional);
41 }
42 if (HexagonMCInstrInfo::isOuterLoop(MCB)) {
43 Defs[Hexagon::SA1].insert(Unconditional); // FIXME: define or change SA0?
44 Defs[Hexagon::LC1].insert(Unconditional);
45 }
46
47 if (HexagonMCInstrInfo::isBundle(MCB))
48 // Unfurl a bundle.
49 for (auto const&I : HexagonMCInstrInfo::bundleInstructions(MCB)) {
Krzysztof Parzyszek8cdfe8e2017-02-06 19:35:46 +000050 MCInst const &Inst = *I.getInst();
51 if (HexagonMCInstrInfo::isDuplex(MCII, Inst)) {
52 init(*Inst.getOperand(0).getInst());
53 init(*Inst.getOperand(1).getInst());
54 }
55 else
56 init(Inst);
Colin LeMahieu7cd08922015-11-09 04:07:48 +000057 }
58 else
59 init(MCB);
60}
61
Krzysztof Parzyszek8cdfe8e2017-02-06 19:35:46 +000062void HexagonMCChecker::initReg(MCInst const &MCI, unsigned R, unsigned &PredReg,
63 bool &isTrue) {
64 if (HexagonMCInstrInfo::isPredicated(MCII, MCI) && isPredicateRegister(R)) {
65 // Note an used predicate register.
66 PredReg = R;
67 isTrue = HexagonMCInstrInfo::isPredicatedTrue(MCII, MCI);
68
69 // Note use of new predicate register.
70 if (HexagonMCInstrInfo::isPredicatedNew(MCII, MCI))
71 NewPreds.insert(PredReg);
72 }
73 else
74 // Note register use. Super-registers are not tracked directly,
75 // but their components.
76 for(MCRegAliasIterator SRI(R, &RI, !MCSubRegIterator(R, &RI).isValid());
77 SRI.isValid();
78 ++SRI)
79 if (!MCSubRegIterator(*SRI, &RI).isValid())
80 // Skip super-registers used indirectly.
81 Uses.insert(*SRI);
82}
83
Colin LeMahieu7cd08922015-11-09 04:07:48 +000084void HexagonMCChecker::init(MCInst const& MCI) {
85 const MCInstrDesc& MCID = HexagonMCInstrInfo::getDesc(MCII, MCI);
86 unsigned PredReg = Hexagon::NoRegister;
87 bool isTrue = false;
88
89 // Get used registers.
90 for (unsigned i = MCID.getNumDefs(); i < MCID.getNumOperands(); ++i)
Krzysztof Parzyszek8cdfe8e2017-02-06 19:35:46 +000091 if (MCI.getOperand(i).isReg())
92 initReg(MCI, MCI.getOperand(i).getReg(), PredReg, isTrue);
93 for (unsigned i = 0; i < MCID.getNumImplicitUses(); ++i)
94 initReg(MCI, MCID.getImplicitUses()[i], PredReg, isTrue);
Colin LeMahieu7cd08922015-11-09 04:07:48 +000095
96 // Get implicit register definitions.
Craig Topper5c322792015-12-05 17:34:07 +000097 if (const MCPhysReg *ImpDef = MCID.getImplicitDefs())
98 for (; *ImpDef; ++ImpDef) {
99 unsigned R = *ImpDef;
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000100
Craig Topper5c322792015-12-05 17:34:07 +0000101 if (Hexagon::R31 != R && MCID.isCall())
102 // Any register other than the LR and the PC are actually volatile ones
103 // as defined by the ABI, not modified implicitly by the call insn.
104 continue;
105 if (Hexagon::PC == R)
106 // Branches are the only insns that can change the PC,
107 // otherwise a read-only register.
108 continue;
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000109
Craig Topper5c322792015-12-05 17:34:07 +0000110 if (Hexagon::USR_OVF == R)
111 // Many insns change the USR implicitly, but only one or another flag.
112 // The instruction table models the USR.OVF flag, which can be implicitly
113 // modified more than once, but cannot be modified in the same packet
114 // with an instruction that modifies is explicitly. Deal with such situ-
115 // ations individually.
116 SoftDefs.insert(R);
117 else if (isPredicateRegister(R) &&
118 HexagonMCInstrInfo::isPredicateLate(MCII, MCI))
119 // Include implicit late predicates.
120 LatePreds.insert(R);
121 else
122 Defs[R].insert(PredSense(PredReg, isTrue));
123 }
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000124
125 // Figure out explicit register definitions.
126 for (unsigned i = 0; i < MCID.getNumDefs(); ++i) {
127 unsigned R = MCI.getOperand(i).getReg(),
128 S = Hexagon::NoRegister;
Krzysztof Parzyszek96bb4fe2016-05-28 01:51:16 +0000129 // USR has subregisters (while C8 does not for technical reasons), so
130 // reset R to USR, since we know how to handle multiple defs of USR,
131 // taking into account its subregisters.
132 if (R == Hexagon::C8)
133 R = Hexagon::USR;
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000134
135 // Note register definitions, direct ones as well as indirect side-effects.
136 // Super-registers are not tracked directly, but their components.
137 for(MCRegAliasIterator SRI(R, &RI, !MCSubRegIterator(R, &RI).isValid());
138 SRI.isValid();
139 ++SRI) {
140 if (MCSubRegIterator(*SRI, &RI).isValid())
141 // Skip super-registers defined indirectly.
142 continue;
143
144 if (R == *SRI) {
145 if (S == R)
146 // Avoid scoring the defined register multiple times.
147 continue;
148 else
149 // Note that the defined register has already been scored.
150 S = R;
151 }
152
153 if (Hexagon::P3_0 != R && Hexagon::P3_0 == *SRI)
154 // P3:0 is a special case, since multiple predicate register definitions
155 // in a packet is allowed as the equivalent of their logical "and".
156 // Only an explicit definition of P3:0 is noted as such; if a
157 // side-effect, then note as a soft definition.
158 SoftDefs.insert(*SRI);
159 else if (HexagonMCInstrInfo::isPredicateLate(MCII, MCI) && isPredicateRegister(*SRI))
160 // Some insns produce predicates too late to be used in the same packet.
161 LatePreds.insert(*SRI);
162 else if (i == 0 && llvm::HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeCVI_VM_CUR_LD)
163 // Current loads should be used in the same packet.
164 // TODO: relies on the impossibility of a current and a temporary loads
165 // in the same packet.
166 CurDefs.insert(*SRI), Defs[*SRI].insert(PredSense(PredReg, isTrue));
167 else if (i == 0 && llvm::HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeCVI_VM_TMP_LD)
168 // Temporary loads should be used in the same packet, but don't commit
169 // results, so it should be disregarded if another insn changes the same
170 // register.
171 // TODO: relies on the impossibility of a current and a temporary loads
172 // in the same packet.
173 TmpDefs.insert(*SRI);
174 else if (i <= 1 && llvm::HexagonMCInstrInfo::hasNewValue2(MCII, MCI) )
175 // vshuff(Vx, Vy, Rx) <- Vx(0) and Vy(1) are both source and
176 // destination registers with this instruction. same for vdeal(Vx,Vy,Rx)
177 Uses.insert(*SRI);
178 else
179 Defs[*SRI].insert(PredSense(PredReg, isTrue));
180 }
181 }
182
183 // Figure out register definitions that produce new values.
184 if (HexagonMCInstrInfo::hasNewValue(MCII, MCI)) {
185 unsigned R = HexagonMCInstrInfo::getNewValueOperand(MCII, MCI).getReg();
186
187 if (HexagonMCInstrInfo::isCompound(MCII, MCI))
188 compoundRegisterMap(R); // Compound insns have a limited register range.
189
190 for(MCRegAliasIterator SRI(R, &RI, !MCSubRegIterator(R, &RI).isValid());
191 SRI.isValid();
192 ++SRI)
193 if (!MCSubRegIterator(*SRI, &RI).isValid())
194 // No super-registers defined indirectly.
195 NewDefs[*SRI].push_back(NewSense::Def(PredReg, HexagonMCInstrInfo::isPredicatedTrue(MCII, MCI),
196 HexagonMCInstrInfo::isFloat(MCII, MCI)));
197
198 // For fairly unique 2-dot-new producers, example:
199 // vdeal(V1, V9, R0) V1.new and V9.new can be used by consumers.
200 if (HexagonMCInstrInfo::hasNewValue2(MCII, MCI)) {
201 unsigned R2 = HexagonMCInstrInfo::getNewValueOperand2(MCII, MCI).getReg();
202
203 for(MCRegAliasIterator SRI(R2, &RI, !MCSubRegIterator(R2, &RI).isValid());
204 SRI.isValid();
205 ++SRI)
206 if (!MCSubRegIterator(*SRI, &RI).isValid())
207 NewDefs[*SRI].push_back(NewSense::Def(PredReg, HexagonMCInstrInfo::isPredicatedTrue(MCII, MCI),
208 HexagonMCInstrInfo::isFloat(MCII, MCI)));
209 }
210 }
211
212 // Figure out definitions of new predicate registers.
213 if (HexagonMCInstrInfo::isPredicatedNew(MCII, MCI))
214 for (unsigned i = MCID.getNumDefs(); i < MCID.getNumOperands(); ++i)
215 if (MCI.getOperand(i).isReg()) {
216 unsigned P = MCI.getOperand(i).getReg();
217
218 if (isPredicateRegister(P))
219 NewPreds.insert(P);
220 }
221
222 // Figure out uses of new values.
223 if (HexagonMCInstrInfo::isNewValue(MCII, MCI)) {
224 unsigned N = HexagonMCInstrInfo::getNewValueOperand(MCII, MCI).getReg();
225
226 if (!MCSubRegIterator(N, &RI).isValid()) {
227 // Super-registers cannot use new values.
228 if (MCID.isBranch())
Krzysztof Parzyszek8cdfe8e2017-02-06 19:35:46 +0000229 NewUses[N] = NewSense::Jmp(
230 llvm::HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeNCJ);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000231 else
Krzysztof Parzyszek8cdfe8e2017-02-06 19:35:46 +0000232 NewUses[N] = NewSense::Use(
233 PredReg, HexagonMCInstrInfo::isPredicatedTrue(MCII, MCI));
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000234 }
235 }
236}
237
238HexagonMCChecker::HexagonMCChecker(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCInst &mcb, MCInst &mcbdx,
239 MCRegisterInfo const &ri)
240 : MCB(mcb), MCBDX(mcbdx), RI(ri), MCII(MCII), STI(STI),
241 bLoadErrInfo(false) {
242 init();
243}
244
Krzysztof Parzyszek8cdfe8e2017-02-06 19:35:46 +0000245bool HexagonMCChecker::check(bool FullCheck) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000246 bool chkB = checkBranches();
247 bool chkP = checkPredicates();
248 bool chkNV = checkNewValues();
249 bool chkR = checkRegisters();
250 bool chkS = checkSolo();
Krzysztof Parzyszek8cdfe8e2017-02-06 19:35:46 +0000251 bool chkSh = true;
252 if (FullCheck)
253 chkSh = checkShuffle();
254 bool chkSl = true;
255 if (FullCheck)
256 chkSl = checkSlots();
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000257 bool chk = chkB && chkP && chkNV && chkR && chkS && chkSh && chkSl;
258
259 return chk;
260}
261
262bool HexagonMCChecker::checkSlots()
263
264{
265 unsigned slotsUsed = 0;
266 for (auto HMI: HexagonMCInstrInfo::bundleInstructions(MCBDX)) {
267 MCInst const& MCI = *HMI.getInst();
268 if (HexagonMCInstrInfo::isImmext(MCI))
269 continue;
270 if (HexagonMCInstrInfo::isDuplex(MCII, MCI))
271 slotsUsed += 2;
272 else
273 ++slotsUsed;
274 }
275
276 if (slotsUsed > HEXAGON_PACKET_SIZE) {
277 HexagonMCErrInfo errInfo;
278 errInfo.setError(HexagonMCErrInfo::CHECK_ERROR_NOSLOTS);
279 addErrInfo(errInfo);
280 return false;
281 }
282 return true;
283}
284
285// Check legal use of branches.
286bool HexagonMCChecker::checkBranches() {
287 HexagonMCErrInfo errInfo;
288 if (HexagonMCInstrInfo::isBundle(MCB)) {
289 bool hasConditional = false;
290 unsigned Branches = 0, Returns = 0, NewIndirectBranches = 0,
291 NewValueBranches = 0, Conditional = HEXAGON_PRESHUFFLE_PACKET_SIZE,
292 Unconditional = HEXAGON_PRESHUFFLE_PACKET_SIZE;
293
294 for (unsigned i = HexagonMCInstrInfo::bundleInstructionsOffset;
295 i < MCB.size(); ++i) {
296 MCInst const &MCI = *MCB.begin()[i].getInst();
297
298 if (HexagonMCInstrInfo::isImmext(MCI))
299 continue;
300 if (HexagonMCInstrInfo::getDesc(MCII, MCI).isBranch() ||
301 HexagonMCInstrInfo::getDesc(MCII, MCI).isCall()) {
302 ++Branches;
303 if (HexagonMCInstrInfo::getDesc(MCII, MCI).isIndirectBranch() &&
304 HexagonMCInstrInfo::isPredicatedNew(MCII, MCI))
305 ++NewIndirectBranches;
306 if (HexagonMCInstrInfo::isNewValue(MCII, MCI))
307 ++NewValueBranches;
308
309 if (HexagonMCInstrInfo::isPredicated(MCII, MCI) ||
310 HexagonMCInstrInfo::isPredicatedNew(MCII, MCI)) {
311 hasConditional = true;
312 Conditional = i; // Record the position of the conditional branch.
313 } else {
314 Unconditional = i; // Record the position of the unconditional branch.
315 }
316 }
317 if (HexagonMCInstrInfo::getDesc(MCII, MCI).isReturn() &&
318 HexagonMCInstrInfo::getDesc(MCII, MCI).mayLoad())
319 ++Returns;
320 }
321
322 if (Branches) // FIXME: should "Defs.count(Hexagon::PC)" be here too?
323 if (HexagonMCInstrInfo::isInnerLoop(MCB) ||
324 HexagonMCInstrInfo::isOuterLoop(MCB)) {
325 // Error out if there's any branch in a loop-end packet.
326 errInfo.setError(HexagonMCErrInfo::CHECK_ERROR_ENDLOOP, Hexagon::PC);
327 addErrInfo(errInfo);
328 return false;
329 }
330 if (Branches > 1)
331 if (!hasConditional || Conditional > Unconditional) {
332 // Error out if more than one unconditional branch or
333 // the conditional branch appears after the unconditional one.
334 errInfo.setError(HexagonMCErrInfo::CHECK_ERROR_BRANCHES);
335 addErrInfo(errInfo);
336 return false;
337 }
338 }
339
340 return true;
341}
342
343// Check legal use of predicate registers.
344bool HexagonMCChecker::checkPredicates() {
345 HexagonMCErrInfo errInfo;
346 // Check for proper use of new predicate registers.
347 for (const auto& I : NewPreds) {
348 unsigned P = I;
349
350 if (!Defs.count(P) || LatePreds.count(P)) {
351 // Error out if the new predicate register is not defined,
352 // or defined "late"
353 // (e.g., "{ if (p3.new)... ; p3 = sp1loop0(#r7:2, Rs) }").
354 errInfo.setError(HexagonMCErrInfo::CHECK_ERROR_NEWP, P);
355 addErrInfo(errInfo);
356 return false;
357 }
358 }
359
360 // Check for proper use of auto-anded of predicate registers.
361 for (const auto& I : LatePreds) {
362 unsigned P = I;
363
364 if (LatePreds.count(P) > 1 || Defs.count(P)) {
365 // Error out if predicate register defined "late" multiple times or
366 // defined late and regularly defined
367 // (e.g., "{ p3 = sp1loop0(...); p3 = cmp.eq(...) }".
368 errInfo.setError(HexagonMCErrInfo::CHECK_ERROR_REGISTERS, P);
369 addErrInfo(errInfo);
370 return false;
371 }
372 }
373
374 return true;
375}
376
377// Check legal use of new values.
378bool HexagonMCChecker::checkNewValues() {
379 HexagonMCErrInfo errInfo;
380 memset(&errInfo, 0, sizeof(errInfo));
381 for (auto& I : NewUses) {
382 unsigned R = I.first;
383 NewSense &US = I.second;
384
385 if (!hasValidNewValueDef(US, NewDefs[R])) {
386 errInfo.setError(HexagonMCErrInfo::CHECK_ERROR_NEWV, R);
387 addErrInfo(errInfo);
388 return false;
389 }
390 }
391
392 return true;
393}
394
395// Check for legal register uses and definitions.
396bool HexagonMCChecker::checkRegisters() {
397 HexagonMCErrInfo errInfo;
398 // Check for proper register definitions.
399 for (const auto& I : Defs) {
400 unsigned R = I.first;
401
402 if (ReadOnly.count(R)) {
403 // Error out for definitions of read-only registers.
404 errInfo.setError(HexagonMCErrInfo::CHECK_ERROR_READONLY, R);
405 addErrInfo(errInfo);
406 return false;
407 }
408 if (isLoopRegister(R) && Defs.count(R) > 1 &&
409 (HexagonMCInstrInfo::isInnerLoop(MCB) ||
410 HexagonMCInstrInfo::isOuterLoop(MCB))) {
411 // Error out for definitions of loop registers at the end of a loop.
412 errInfo.setError(HexagonMCErrInfo::CHECK_ERROR_LOOP, R);
413 addErrInfo(errInfo);
414 return false;
415 }
416 if (SoftDefs.count(R)) {
417 // Error out for explicit changes to registers also weakly defined
418 // (e.g., "{ usr = r0; r0 = sfadd(...) }").
419 unsigned UsrR = Hexagon::USR; // Silence warning about mixed types in ?:.
420 unsigned BadR = RI.isSubRegister(Hexagon::USR, R) ? UsrR : R;
421 errInfo.setError(HexagonMCErrInfo::CHECK_ERROR_REGISTERS, BadR);
422 addErrInfo(errInfo);
423 return false;
424 }
425 if (!isPredicateRegister(R) && Defs[R].size() > 1) {
426 // Check for multiple register definitions.
427 PredSet &PM = Defs[R];
428
429 // Check for multiple unconditional register definitions.
430 if (PM.count(Unconditional)) {
431 // Error out on an unconditional change when there are any other
432 // changes, conditional or not.
433 unsigned UsrR = Hexagon::USR;
434 unsigned BadR = RI.isSubRegister(Hexagon::USR, R) ? UsrR : R;
435 errInfo.setError(HexagonMCErrInfo::CHECK_ERROR_REGISTERS, BadR);
436 addErrInfo(errInfo);
437 return false;
438 }
439 // Check for multiple conditional register definitions.
440 for (const auto& J : PM) {
441 PredSense P = J;
442
443 // Check for multiple uses of the same condition.
444 if (PM.count(P) > 1) {
445 // Error out on conditional changes based on the same predicate
446 // (e.g., "{ if (!p0) r0 =...; if (!p0) r0 =... }").
447 errInfo.setError(HexagonMCErrInfo::CHECK_ERROR_REGISTERS, R);
448 addErrInfo(errInfo);
449 return false;
450 }
451 // Check for the use of the complementary condition.
452 P.second = !P.second;
453 if (PM.count(P) && PM.size() > 2) {
454 // Error out on conditional changes based on the same predicate
455 // multiple times
456 // (e.g., "{ if (p0) r0 =...; if (!p0) r0 =... }; if (!p0) r0 =... }").
457 errInfo.setError(HexagonMCErrInfo::CHECK_ERROR_REGISTERS, R);
458 addErrInfo(errInfo);
459 return false;
460 }
461 }
462 }
463 }
464
465 // Check for use of current definitions.
466 for (const auto& I : CurDefs) {
467 unsigned R = I;
468
469 if (!Uses.count(R)) {
470 // Warn on an unused current definition.
471 errInfo.setWarning(HexagonMCErrInfo::CHECK_WARN_CURRENT, R);
472 addErrInfo(errInfo);
473 return true;
474 }
475 }
476
477 // Check for use of temporary definitions.
478 for (const auto& I : TmpDefs) {
479 unsigned R = I;
480
481 if (!Uses.count(R)) {
482 // special case for vhist
483 bool vHistFound = false;
484 for (auto const&HMI : HexagonMCInstrInfo::bundleInstructions(MCB)) {
485 if(llvm::HexagonMCInstrInfo::getType(MCII, *HMI.getInst()) == HexagonII::TypeCVI_HIST) {
486 vHistFound = true; // vhist() implicitly uses ALL REGxx.tmp
487 break;
488 }
489 }
490 // Warn on an unused temporary definition.
491 if (vHistFound == false) {
492 errInfo.setWarning(HexagonMCErrInfo::CHECK_WARN_TEMPORARY, R);
493 addErrInfo(errInfo);
494 return true;
495 }
496 }
497 }
498
499 return true;
500}
501
502// Check for legal use of solo insns.
503bool HexagonMCChecker::checkSolo() {
504 HexagonMCErrInfo errInfo;
505 if (HexagonMCInstrInfo::isBundle(MCB) &&
506 HexagonMCInstrInfo::bundleSize(MCB) > 1) {
507 for (auto const&I : HexagonMCInstrInfo::bundleInstructions(MCB)) {
508 if (llvm::HexagonMCInstrInfo::isSolo(MCII, *I.getInst())) {
509 errInfo.setError(HexagonMCErrInfo::CHECK_ERROR_SOLO);
510 addErrInfo(errInfo);
511 return false;
512 }
513 }
514 }
515
516 return true;
517}
518
519bool HexagonMCChecker::checkShuffle() {
520 HexagonMCErrInfo errInfo;
521 // Branch info is lost when duplexing. The unduplexed insns must be
522 // checked and only branch errors matter for this case.
Krzysztof Parzyszek8cdfe8e2017-02-06 19:35:46 +0000523 HexagonMCShuffler MCS(true, MCII, STI, MCB);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000524 if (!MCS.check()) {
525 if (MCS.getError() == HexagonShuffler::SHUFFLE_ERROR_BRANCHES) {
526 errInfo.setError(HexagonMCErrInfo::CHECK_ERROR_SHUFFLE);
527 errInfo.setShuffleError(MCS.getError());
528 addErrInfo(errInfo);
529 return false;
530 }
531 }
Krzysztof Parzyszek8cdfe8e2017-02-06 19:35:46 +0000532 HexagonMCShuffler MCSDX(true, MCII, STI, MCBDX);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000533 if (!MCSDX.check()) {
534 errInfo.setError(HexagonMCErrInfo::CHECK_ERROR_SHUFFLE);
535 errInfo.setShuffleError(MCSDX.getError());
536 addErrInfo(errInfo);
537 return false;
538 }
539 return true;
540}
541
542void HexagonMCChecker::compoundRegisterMap(unsigned& Register) {
543 switch (Register) {
544 default:
545 break;
546 case Hexagon::R15:
547 Register = Hexagon::R23;
548 break;
549 case Hexagon::R14:
550 Register = Hexagon::R22;
551 break;
552 case Hexagon::R13:
553 Register = Hexagon::R21;
554 break;
555 case Hexagon::R12:
556 Register = Hexagon::R20;
557 break;
558 case Hexagon::R11:
559 Register = Hexagon::R19;
560 break;
561 case Hexagon::R10:
562 Register = Hexagon::R18;
563 break;
564 case Hexagon::R9:
565 Register = Hexagon::R17;
566 break;
567 case Hexagon::R8:
568 Register = Hexagon::R16;
569 break;
570 }
571}
572
573bool HexagonMCChecker::hasValidNewValueDef(const NewSense &Use,
574 const NewSenseList &Defs) const {
575 bool Strict = !RelaxNVChecks;
576
577 for (unsigned i = 0, n = Defs.size(); i < n; ++i) {
578 const NewSense &Def = Defs[i];
579 // NVJ cannot use a new FP value [7.6.1]
580 if (Use.IsNVJ && (Def.IsFloat || Def.PredReg != 0))
581 continue;
582 // If the definition was not predicated, then it does not matter if
583 // the use is.
584 if (Def.PredReg == 0)
585 return true;
586 // With the strict checks, both the definition and the use must be
587 // predicated on the same register and condition.
588 if (Strict) {
589 if (Def.PredReg == Use.PredReg && Def.Cond == Use.Cond)
590 return true;
591 } else {
592 // With the relaxed checks, if the definition was predicated, the only
593 // detectable violation is if the use is predicated on the opposing
594 // condition, otherwise, it's ok.
595 if (Def.PredReg != Use.PredReg || Def.Cond == Use.Cond)
596 return true;
597 }
598 }
599 return false;
600}
601