Mercurial > hg > CbC > CbC_llvm
comparison lib/Target/Hexagon/HexagonNewValueJump.cpp @ 148:63bd29f05246
merged
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 19:46:37 +0900 |
parents | c2174574ed3a |
children |
comparison
equal
deleted
inserted
replaced
146:3fc4d5c3e21e | 148:63bd29f05246 |
---|---|
1 //===- HexagonNewValueJump.cpp - Hexagon Backend New Value Jump -----------===// | 1 //===- HexagonNewValueJump.cpp - Hexagon Backend New Value Jump -----------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 // | 4 // See https://llvm.org/LICENSE.txt for license information. |
5 // This file is distributed under the University of Illinois Open Source | 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 // License. See LICENSE.TXT for details. | |
7 // | 6 // |
8 //===----------------------------------------------------------------------===// | 7 //===----------------------------------------------------------------------===// |
9 // | 8 // |
10 // This implements NewValueJump pass in Hexagon. | 9 // This implements NewValueJump pass in Hexagon. |
11 // Ideally, we should merge this as a Peephole pass prior to register | 10 // Ideally, we should merge this as a Peephole pass prior to register |
14 // Having said that, we should re-attempt to pull this earlier at some point | 13 // Having said that, we should re-attempt to pull this earlier at some point |
15 // in future. | 14 // in future. |
16 | 15 |
17 // The basic approach looks for sequence of predicated jump, compare instruciton | 16 // The basic approach looks for sequence of predicated jump, compare instruciton |
18 // that genereates the predicate and, the feeder to the predicate. Once it finds | 17 // that genereates the predicate and, the feeder to the predicate. Once it finds |
19 // all, it collapses compare and jump instruction into a new valu jump | 18 // all, it collapses compare and jump instruction into a new value jump |
20 // intstructions. | 19 // intstructions. |
21 // | 20 // |
22 //===----------------------------------------------------------------------===// | 21 //===----------------------------------------------------------------------===// |
23 | 22 |
24 #include "Hexagon.h" | 23 #include "Hexagon.h" |
25 #include "HexagonInstrInfo.h" | 24 #include "HexagonInstrInfo.h" |
26 #include "HexagonRegisterInfo.h" | 25 #include "HexagonRegisterInfo.h" |
26 #include "HexagonSubtarget.h" | |
27 #include "llvm/ADT/Statistic.h" | 27 #include "llvm/ADT/Statistic.h" |
28 #include "llvm/CodeGen/MachineBasicBlock.h" | 28 #include "llvm/CodeGen/MachineBasicBlock.h" |
29 #include "llvm/CodeGen/MachineBranchProbabilityInfo.h" | 29 #include "llvm/CodeGen/MachineBranchProbabilityInfo.h" |
30 #include "llvm/CodeGen/MachineFunction.h" | 30 #include "llvm/CodeGen/MachineFunction.h" |
31 #include "llvm/CodeGen/MachineFunctionPass.h" | 31 #include "llvm/CodeGen/MachineFunctionPass.h" |
93 | 93 |
94 private: | 94 private: |
95 const HexagonInstrInfo *QII; | 95 const HexagonInstrInfo *QII; |
96 const HexagonRegisterInfo *QRI; | 96 const HexagonRegisterInfo *QRI; |
97 | 97 |
98 /// \brief A handle to the branch probability pass. | 98 /// A handle to the branch probability pass. |
99 const MachineBranchProbabilityInfo *MBPI; | 99 const MachineBranchProbabilityInfo *MBPI; |
100 | 100 |
101 bool isNewValueJumpCandidate(const MachineInstr &MI) const; | 101 bool isNewValueJumpCandidate(const MachineInstr &MI) const; |
102 }; | 102 }; |
103 | 103 |
156 if (!Hexagon::IntRegsRegClass.contains(Op.getReg())) | 156 if (!Hexagon::IntRegsRegClass.contains(Op.getReg())) |
157 return false; | 157 return false; |
158 } | 158 } |
159 assert(HadDef); | 159 assert(HadDef); |
160 | 160 |
161 // Make sure there there is no 'def' or 'use' of any of the uses of | 161 // Make sure there is no 'def' or 'use' of any of the uses of |
162 // feeder insn between it's definition, this MI and jump, jmpInst | 162 // feeder insn between its definition, this MI and jump, jmpInst |
163 // skipping compare, cmpInst. | 163 // skipping compare, cmpInst. |
164 // Here's the example. | 164 // Here's the example. |
165 // r21=memub(r22+r24<<#0) | 165 // r21=memub(r22+r24<<#0) |
166 // p0 = cmp.eq(r21, #0) | 166 // p0 = cmp.eq(r21, #0) |
167 // r4=memub(r3+r21<<#0) | 167 // r4=memub(r3+r21<<#0) |
284 // If the same register appears as both operands, we cannot generate a new | 284 // If the same register appears as both operands, we cannot generate a new |
285 // value compare. Only one operand may use the .new suffix. | 285 // value compare. Only one operand may use the .new suffix. |
286 if (cmpReg1 == cmpOp2) | 286 if (cmpReg1 == cmpOp2) |
287 return false; | 287 return false; |
288 | 288 |
289 // Make sure that that second register is not from COPY | 289 // Make sure that the second register is not from COPY |
290 // At machine code level, we don't need this, but if we decide | 290 // at machine code level, we don't need this, but if we decide |
291 // to move new value jump prior to RA, we would be needing this. | 291 // to move new value jump prior to RA, we would be needing this. |
292 MachineRegisterInfo &MRI = MF.getRegInfo(); | 292 MachineRegisterInfo &MRI = MF.getRegInfo(); |
293 if (secondReg && !TargetRegisterInfo::isPhysicalRegister(cmpOp2)) { | 293 if (secondReg && !Register::isPhysicalRegister(cmpOp2)) { |
294 MachineInstr *def = MRI.getVRegDef(cmpOp2); | 294 MachineInstr *def = MRI.getVRegDef(cmpOp2); |
295 if (def->getOpcode() == TargetOpcode::COPY) | 295 if (def->getOpcode() == TargetOpcode::COPY) |
296 return false; | 296 return false; |
297 } | 297 } |
298 } | 298 } |
299 | 299 |
300 // Walk the instructions after the compare (predicate def) to the jump, | 300 // Walk the instructions after the compare (predicate def) to the jump, |
301 // and satisfy the following conditions. | 301 // and satisfy the following conditions. |
302 ++II; | 302 ++II; |
303 for (MachineBasicBlock::iterator localII = II; localII != end; ++localII) { | 303 for (MachineBasicBlock::iterator localII = II; localII != end; ++localII) { |
304 if (localII->isDebugValue()) | 304 if (localII->isDebugInstr()) |
305 continue; | 305 continue; |
306 | 306 |
307 // Check 1. | 307 // Check 1. |
308 // If "common" checks fail, bail out. | 308 // If "common" checks fail, bail out. |
309 if (!commonChecksToProhibitNewValueJump(optLocation, localII)) | 309 if (!commonChecksToProhibitNewValueJump(optLocation, localII)) |
445 return false; | 445 return false; |
446 } | 446 } |
447 } | 447 } |
448 | 448 |
449 bool HexagonNewValueJump::runOnMachineFunction(MachineFunction &MF) { | 449 bool HexagonNewValueJump::runOnMachineFunction(MachineFunction &MF) { |
450 DEBUG(dbgs() << "********** Hexagon New Value Jump **********\n" | 450 LLVM_DEBUG(dbgs() << "********** Hexagon New Value Jump **********\n" |
451 << "********** Function: " << MF.getName() << "\n"); | 451 << "********** Function: " << MF.getName() << "\n"); |
452 | 452 |
453 if (skipFunction(MF.getFunction())) | 453 if (skipFunction(MF.getFunction())) |
454 return false; | 454 return false; |
455 | 455 |
456 // If we move NewValueJump before register allocation we'll need live variable | 456 // If we move NewValueJump before register allocation we'll need live variable |
459 QII = static_cast<const HexagonInstrInfo *>(MF.getSubtarget().getInstrInfo()); | 459 QII = static_cast<const HexagonInstrInfo *>(MF.getSubtarget().getInstrInfo()); |
460 QRI = static_cast<const HexagonRegisterInfo *>( | 460 QRI = static_cast<const HexagonRegisterInfo *>( |
461 MF.getSubtarget().getRegisterInfo()); | 461 MF.getSubtarget().getRegisterInfo()); |
462 MBPI = &getAnalysis<MachineBranchProbabilityInfo>(); | 462 MBPI = &getAnalysis<MachineBranchProbabilityInfo>(); |
463 | 463 |
464 if (DisableNewValueJumps) { | 464 if (DisableNewValueJumps || |
465 return false; | 465 !MF.getSubtarget<HexagonSubtarget>().useNewValueJumps()) |
466 } | 466 return false; |
467 | 467 |
468 int nvjCount = DbgNVJCount; | 468 int nvjCount = DbgNVJCount; |
469 int nvjGenerated = 0; | 469 int nvjGenerated = 0; |
470 | 470 |
471 // Loop through all the bb's of the function | 471 // Loop through all the bb's of the function |
472 for (MachineFunction::iterator MBBb = MF.begin(), MBBe = MF.end(); | 472 for (MachineFunction::iterator MBBb = MF.begin(), MBBe = MF.end(); |
473 MBBb != MBBe; ++MBBb) { | 473 MBBb != MBBe; ++MBBb) { |
474 MachineBasicBlock *MBB = &*MBBb; | 474 MachineBasicBlock *MBB = &*MBBb; |
475 | 475 |
476 DEBUG(dbgs() << "** dumping bb ** " << MBB->getNumber() << "\n"); | 476 LLVM_DEBUG(dbgs() << "** dumping bb ** " << MBB->getNumber() << "\n"); |
477 DEBUG(MBB->dump()); | 477 LLVM_DEBUG(MBB->dump()); |
478 DEBUG(dbgs() << "\n" << "********** dumping instr bottom up **********\n"); | 478 LLVM_DEBUG(dbgs() << "\n" |
479 << "********** dumping instr bottom up **********\n"); | |
479 bool foundJump = false; | 480 bool foundJump = false; |
480 bool foundCompare = false; | 481 bool foundCompare = false; |
481 bool invertPredicate = false; | 482 bool invertPredicate = false; |
482 unsigned predReg = 0; // predicate reg of the jump. | 483 unsigned predReg = 0; // predicate reg of the jump. |
483 unsigned cmpReg1 = 0; | 484 unsigned cmpReg1 = 0; |
491 bool isSecondOpNewified = false; | 492 bool isSecondOpNewified = false; |
492 // Traverse the basic block - bottom up | 493 // Traverse the basic block - bottom up |
493 for (MachineBasicBlock::iterator MII = MBB->end(), E = MBB->begin(); | 494 for (MachineBasicBlock::iterator MII = MBB->end(), E = MBB->begin(); |
494 MII != E;) { | 495 MII != E;) { |
495 MachineInstr &MI = *--MII; | 496 MachineInstr &MI = *--MII; |
496 if (MI.isDebugValue()) { | 497 if (MI.isDebugInstr()) { |
497 continue; | 498 continue; |
498 } | 499 } |
499 | 500 |
500 if ((nvjCount == 0) || (nvjCount > -1 && nvjCount <= nvjGenerated)) | 501 if ((nvjCount == 0) || (nvjCount > -1 && nvjCount <= nvjGenerated)) |
501 break; | 502 break; |
502 | 503 |
503 DEBUG(dbgs() << "Instr: "; MI.dump(); dbgs() << "\n"); | 504 LLVM_DEBUG(dbgs() << "Instr: "; MI.dump(); dbgs() << "\n"); |
504 | 505 |
505 if (!foundJump && (MI.getOpcode() == Hexagon::J2_jumpt || | 506 if (!foundJump && (MI.getOpcode() == Hexagon::J2_jumpt || |
506 MI.getOpcode() == Hexagon::J2_jumptpt || | 507 MI.getOpcode() == Hexagon::J2_jumptpt || |
507 MI.getOpcode() == Hexagon::J2_jumpf || | 508 MI.getOpcode() == Hexagon::J2_jumpf || |
508 MI.getOpcode() == Hexagon::J2_jumpfpt || | 509 MI.getOpcode() == Hexagon::J2_jumpfpt || |
513 // This is where you would insert your compare and | 514 // This is where you would insert your compare and |
514 // instr that feeds compare | 515 // instr that feeds compare |
515 jmpPos = MII; | 516 jmpPos = MII; |
516 jmpInstr = &MI; | 517 jmpInstr = &MI; |
517 predReg = MI.getOperand(0).getReg(); | 518 predReg = MI.getOperand(0).getReg(); |
518 afterRA = TargetRegisterInfo::isPhysicalRegister(predReg); | 519 afterRA = Register::isPhysicalRegister(predReg); |
519 | 520 |
520 // If ifconverter had not messed up with the kill flags of the | 521 // If ifconverter had not messed up with the kill flags of the |
521 // operands, the following check on the kill flag would suffice. | 522 // operands, the following check on the kill flag would suffice. |
522 // if(!jmpInstr->getOperand(0).isKill()) break; | 523 // if(!jmpInstr->getOperand(0).isKill()) break; |
523 | 524 |
524 // This predicate register is live out out of BB | 525 // This predicate register is live out of BB |
525 // this would only work if we can actually use Live | 526 // this would only work if we can actually use Live |
526 // variable analysis on phy regs - but LLVM does not | 527 // variable analysis on phy regs - but LLVM does not |
527 // provide LV analysis on phys regs. | 528 // provide LV analysis on phys regs. |
528 //if(LVs.isLiveOut(predReg, *MBB)) break; | 529 //if(LVs.isLiveOut(predReg, *MBB)) break; |
529 | 530 |