31 #define DEBUG_TYPE "mips-pseudo" 50 return "Mips pseudo instruction expansion pass";
75 bool MipsExpandPseudo::expandAtomicCmpSwapSubword(
81 const bool ArePtrs64bit = STI->getABI().ArePtrs64bit();
85 unsigned ZERO = Mips::ZERO;
86 unsigned BNE = Mips::BNE;
87 unsigned BEQ = Mips::BEQ;
89 I->getOpcode() == Mips::ATOMIC_CMP_SWAP_I8_POSTRA ? Mips::SEB : Mips::SEH;
91 if (STI->inMicroMipsMode()) {
92 LL = STI->hasMips32r6() ? Mips::LL_MMR6 : Mips::LL_MM;
93 SC = STI->hasMips32r6() ? Mips::SC_MMR6 : Mips::SC_MM;
94 BNE = STI->hasMips32r6() ? Mips::BNEC_MMR6 : Mips::BNE_MM;
95 BEQ = STI->hasMips32r6() ? Mips::BEQC_MMR6 : Mips::BEQ_MM;
97 LL = STI->hasMips32r6() ? (ArePtrs64bit ? Mips::LL64_R6 : Mips::LL_R6)
98 : (ArePtrs64bit ? Mips::LL64 : Mips::LL);
99 SC = STI->hasMips32r6() ? (ArePtrs64bit ? Mips::SC64_R6 : Mips::SC_R6)
100 : (ArePtrs64bit ? Mips::SC64 :
Mips::SC);
103 unsigned Dest = I->getOperand(0).getReg();
104 unsigned Ptr = I->getOperand(1).getReg();
105 unsigned Mask = I->getOperand(2).getReg();
106 unsigned ShiftCmpVal = I->getOperand(3).getReg();
107 unsigned Mask2 = I->getOperand(4).getReg();
108 unsigned ShiftNewVal = I->getOperand(5).getReg();
109 unsigned ShiftAmnt = I->getOperand(6).getReg();
110 unsigned Scratch = I->getOperand(7).getReg();
111 unsigned Scratch2 = I->getOperand(8).getReg();
176 BuildMI(sinkMBB, DL,
TII->get(Mips::SRLV), Dest)
179 if (STI->hasMips32r2()) {
180 BuildMI(sinkMBB, DL,
TII->get(SEOp), Dest).addReg(Dest);
182 const unsigned ShiftImm =
183 I->getOpcode() == Mips::ATOMIC_CMP_SWAP_I16_POSTRA ? 16 : 24;
184 BuildMI(sinkMBB, DL,
TII->get(Mips::SLL), Dest)
199 I->eraseFromParent();
207 const unsigned Size =
208 I->getOpcode() == Mips::ATOMIC_CMP_SWAP_I32_POSTRA ? 4 : 8;
211 const bool ArePtrs64bit = STI->getABI().ArePtrs64bit();
214 unsigned LL,
SC, ZERO, BNE, BEQ, MOVE;
217 if (STI->inMicroMipsMode()) {
218 LL = STI->hasMips32r6() ? Mips::LL_MMR6 : Mips::LL_MM;
219 SC = STI->hasMips32r6() ? Mips::SC_MMR6 : Mips::SC_MM;
220 BNE = STI->hasMips32r6() ? Mips::BNEC_MMR6 : Mips::BNE_MM;
221 BEQ = STI->hasMips32r6() ? Mips::BEQC_MMR6 : Mips::BEQ_MM;
223 LL = STI->hasMips32r6()
224 ? (ArePtrs64bit ? Mips::LL64_R6 : Mips::LL_R6)
225 : (ArePtrs64bit ? Mips::LL64 : Mips::LL);
226 SC = STI->hasMips32r6()
227 ? (ArePtrs64bit ? Mips::SC64_R6 : Mips::SC_R6)
228 : (ArePtrs64bit ? Mips::SC64 :
Mips::SC);
236 LL = STI->hasMips64r6() ? Mips::LLD_R6 : Mips::LLD;
237 SC = STI->hasMips64r6() ? Mips::SCD_R6 : Mips::SCD;
238 ZERO = Mips::ZERO_64;
244 unsigned Dest = I->getOperand(0).getReg();
245 unsigned Ptr = I->getOperand(1).getReg();
246 unsigned OldVal = I->getOperand(2).getReg();
247 unsigned NewVal = I->getOperand(3).getReg();
248 unsigned Scratch = I->getOperand(4).getReg();
299 I->eraseFromParent();
303 bool MipsExpandPseudo::expandAtomicBinOpSubword(
309 const bool ArePtrs64bit = STI->getABI().ArePtrs64bit();
313 unsigned BEQ = Mips::BEQ;
314 unsigned SEOp = Mips::SEH;
316 if (STI->inMicroMipsMode()) {
317 LL = STI->hasMips32r6() ? Mips::LL_MMR6 : Mips::LL_MM;
318 SC = STI->hasMips32r6() ? Mips::SC_MMR6 : Mips::SC_MM;
319 BEQ = STI->hasMips32r6() ? Mips::BEQC_MMR6 : Mips::BEQ_MM;
321 LL = STI->hasMips32r6() ? (ArePtrs64bit ? Mips::LL64_R6 : Mips::LL_R6)
322 : (ArePtrs64bit ? Mips::LL64 : Mips::LL);
323 SC = STI->hasMips32r6() ? (ArePtrs64bit ? Mips::SC64_R6 : Mips::SC_R6)
324 : (ArePtrs64bit ? Mips::SC64 :
Mips::SC);
331 switch (I->getOpcode()) {
332 case Mips::ATOMIC_LOAD_NAND_I8_POSTRA:
335 case Mips::ATOMIC_LOAD_NAND_I16_POSTRA:
338 case Mips::ATOMIC_SWAP_I8_POSTRA:
341 case Mips::ATOMIC_SWAP_I16_POSTRA:
344 case Mips::ATOMIC_LOAD_ADD_I8_POSTRA:
347 case Mips::ATOMIC_LOAD_ADD_I16_POSTRA:
350 case Mips::ATOMIC_LOAD_SUB_I8_POSTRA:
353 case Mips::ATOMIC_LOAD_SUB_I16_POSTRA:
356 case Mips::ATOMIC_LOAD_AND_I8_POSTRA:
359 case Mips::ATOMIC_LOAD_AND_I16_POSTRA:
362 case Mips::ATOMIC_LOAD_OR_I8_POSTRA:
365 case Mips::ATOMIC_LOAD_OR_I16_POSTRA:
368 case Mips::ATOMIC_LOAD_XOR_I8_POSTRA:
371 case Mips::ATOMIC_LOAD_XOR_I16_POSTRA:
378 unsigned Dest = I->getOperand(0).getReg();
379 unsigned Ptr = I->getOperand(1).getReg();
380 unsigned Incr = I->getOperand(2).getReg();
381 unsigned Mask = I->getOperand(3).getReg();
382 unsigned Mask2 = I->getOperand(4).getReg();
383 unsigned ShiftAmnt = I->getOperand(5).getReg();
384 unsigned OldVal = I->getOperand(6).getReg();
385 unsigned BinOpRes = I->getOperand(7).getReg();
386 unsigned StoreVal = I->getOperand(8).getReg();
413 BuildMI(loopMBB, DL,
TII->get(Mips::NOR), BinOpRes)
419 }
else if (!IsSwap) {
422 BuildMI(loopMBB, DL,
TII->get(Opcode), BinOpRes)
440 .addReg(OldVal).
addReg(Mask2);
442 .addReg(StoreVal).
addReg(BinOpRes);
456 .addReg(OldVal).
addReg(Mask);
457 BuildMI(sinkMBB, DL,
TII->get(Mips::SRLV), Dest)
458 .addReg(Dest).
addReg(ShiftAmnt);
460 if (STI->hasMips32r2()) {
461 BuildMI(sinkMBB, DL,
TII->get(SEOp), Dest).addReg(Dest);
463 const unsigned ShiftImm = SEOp == Mips::SEH ? 16 : 24;
464 BuildMI(sinkMBB, DL,
TII->get(Mips::SLL), Dest)
478 I->eraseFromParent();
489 const bool ArePtrs64bit = STI->getABI().ArePtrs64bit();
492 unsigned LL,
SC, ZERO, BEQ;
495 if (STI->inMicroMipsMode()) {
496 LL = STI->hasMips32r6() ? Mips::LL_MMR6 : Mips::LL_MM;
497 SC = STI->hasMips32r6() ? Mips::SC_MMR6 : Mips::SC_MM;
498 BEQ = STI->hasMips32r6() ? Mips::BEQC_MMR6 : Mips::BEQ_MM;
500 LL = STI->hasMips32r6()
501 ? (ArePtrs64bit ? Mips::LL64_R6 : Mips::LL_R6)
502 : (ArePtrs64bit ? Mips::LL64 : Mips::LL);
503 SC = STI->hasMips32r6()
504 ? (ArePtrs64bit ? Mips::SC64_R6 : Mips::SC_R6)
505 : (ArePtrs64bit ? Mips::SC64 :
Mips::SC);
511 LL = STI->hasMips64r6() ? Mips::LLD_R6 : Mips::LLD;
512 SC = STI->hasMips64r6() ? Mips::SCD_R6 : Mips::SCD;
513 ZERO = Mips::ZERO_64;
517 unsigned OldVal = I->getOperand(0).getReg();
518 unsigned Ptr = I->getOperand(1).getReg();
519 unsigned Incr = I->getOperand(2).getReg();
520 unsigned Scratch = I->getOperand(3).getReg();
527 switch (I->getOpcode()) {
528 case Mips::ATOMIC_LOAD_ADD_I32_POSTRA:
531 case Mips::ATOMIC_LOAD_SUB_I32_POSTRA:
534 case Mips::ATOMIC_LOAD_AND_I32_POSTRA:
537 case Mips::ATOMIC_LOAD_OR_I32_POSTRA:
540 case Mips::ATOMIC_LOAD_XOR_I32_POSTRA:
543 case Mips::ATOMIC_LOAD_NAND_I32_POSTRA:
548 case Mips::ATOMIC_SWAP_I32_POSTRA:
551 case Mips::ATOMIC_LOAD_ADD_I64_POSTRA:
552 Opcode = Mips::DADDu;
554 case Mips::ATOMIC_LOAD_SUB_I64_POSTRA:
555 Opcode = Mips::DSUBu;
557 case Mips::ATOMIC_LOAD_AND_I64_POSTRA:
558 Opcode = Mips::AND64;
560 case Mips::ATOMIC_LOAD_OR_I64_POSTRA:
563 case Mips::ATOMIC_LOAD_XOR_I64_POSTRA:
564 Opcode = Mips::XOR64;
566 case Mips::ATOMIC_LOAD_NAND_I64_POSTRA:
571 case Mips::ATOMIC_SWAP_I64_POSTRA:
594 assert((OldVal != Ptr) &&
"Clobbered the wrong ptr reg!");
595 assert((OldVal != Incr) &&
"Clobbered the wrong reg!");
597 BuildMI(loopMBB, DL,
TII->get(Opcode), Scratch).addReg(OldVal).
addReg(Incr);
600 "Unknown nand instruction for atomic pseudo expansion");
604 assert(OR &&
"Unknown instruction for atomic pseudo expansion!");
612 I->eraseFromParent();
627 switch (MBBI->getOpcode()) {
628 case Mips::ATOMIC_CMP_SWAP_I32_POSTRA:
629 case Mips::ATOMIC_CMP_SWAP_I64_POSTRA:
630 return expandAtomicCmpSwap(MBB, MBBI, NMBB);
631 case Mips::ATOMIC_CMP_SWAP_I8_POSTRA:
632 case Mips::ATOMIC_CMP_SWAP_I16_POSTRA:
633 return expandAtomicCmpSwapSubword(MBB, MBBI, NMBB);
634 case Mips::ATOMIC_SWAP_I8_POSTRA:
635 case Mips::ATOMIC_SWAP_I16_POSTRA:
636 case Mips::ATOMIC_LOAD_NAND_I8_POSTRA:
637 case Mips::ATOMIC_LOAD_NAND_I16_POSTRA:
638 case Mips::ATOMIC_LOAD_ADD_I8_POSTRA:
639 case Mips::ATOMIC_LOAD_ADD_I16_POSTRA:
640 case Mips::ATOMIC_LOAD_SUB_I8_POSTRA:
641 case Mips::ATOMIC_LOAD_SUB_I16_POSTRA:
642 case Mips::ATOMIC_LOAD_AND_I8_POSTRA:
643 case Mips::ATOMIC_LOAD_AND_I16_POSTRA:
644 case Mips::ATOMIC_LOAD_OR_I8_POSTRA:
645 case Mips::ATOMIC_LOAD_OR_I16_POSTRA:
646 case Mips::ATOMIC_LOAD_XOR_I8_POSTRA:
647 case Mips::ATOMIC_LOAD_XOR_I16_POSTRA:
648 return expandAtomicBinOpSubword(MBB, MBBI, NMBB);
649 case Mips::ATOMIC_LOAD_ADD_I32_POSTRA:
650 case Mips::ATOMIC_LOAD_SUB_I32_POSTRA:
651 case Mips::ATOMIC_LOAD_AND_I32_POSTRA:
652 case Mips::ATOMIC_LOAD_OR_I32_POSTRA:
653 case Mips::ATOMIC_LOAD_XOR_I32_POSTRA:
654 case Mips::ATOMIC_LOAD_NAND_I32_POSTRA:
655 case Mips::ATOMIC_SWAP_I32_POSTRA:
656 return expandAtomicBinOp(MBB, MBBI, NMBB, 4);
657 case Mips::ATOMIC_LOAD_ADD_I64_POSTRA:
658 case Mips::ATOMIC_LOAD_SUB_I64_POSTRA:
659 case Mips::ATOMIC_LOAD_AND_I64_POSTRA:
660 case Mips::ATOMIC_LOAD_OR_I64_POSTRA:
661 case Mips::ATOMIC_LOAD_XOR_I64_POSTRA:
662 case Mips::ATOMIC_LOAD_NAND_I64_POSTRA:
663 case Mips::ATOMIC_SWAP_I64_POSTRA:
664 return expandAtomicBinOp(MBB, MBBI, NMBB, 8);
676 Modified |= expandMI(MBB, MBBI, NMBBI);
685 TII = STI->getInstrInfo();
690 Modified |= expandMBB(*MFI);
701 return new MipsExpandPseudo();
This class represents lattice values for constants.
void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)
RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them...
void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
static BranchProbability getOne()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
void normalizeSuccProbs()
Normalize probabilities of all successors so that the sum of them becomes one.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
LLVM Basic Block Representation.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static ManagedStatic< OptionRegistry > OR
FunctionPass class - This class is used to implement most global optimizations.
self_iterator getIterator()
FunctionPass * createMipsExpandPseudoPass()
createMipsExpandPseudoPass - returns an instance of the pseudo instruction expansion pass...
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Iterator for intrusive lists based on ilist_node.
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
CHAIN = SC CHAIN, Imm128 - System call.
void computeAndAddLiveIns(LivePhysRegs &LiveRegs, MachineBasicBlock &MBB)
Convenience function combining computeLiveIns() and addLiveIns().
MachineFunctionProperties & set(Property P)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Bitwise operators - logical and, logical or, logical xor.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
A set of physical registers with utility functions to track liveness when walking backward/forward th...
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void insert(iterator MBBI, MachineBasicBlock *MBB)
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
StringRef - Represent a constant reference to a string, i.e.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
Properties which a MachineFunction may have at a given point in time.