Lines Matching defs:Phi
38 /// Return the register values for the operands of a Phi instruction.
39 /// This function assume the instruction is a Phi.
40 static void getPhiRegs(MachineInstr &Phi, MachineBasicBlock *Loop,
42 assert(Phi.isPHI() && "Expecting a Phi.");
46 for (unsigned i = 1, e = Phi.getNumOperands(); i != e; i += 2)
47 if (Phi.getOperand(i + 1).getMBB() != Loop)
48 InitVal = Phi.getOperand(i).getReg();
50 LoopVal = Phi.getOperand(i).getReg();
52 assert(InitVal != 0 && LoopVal != 0 && "Unexpected Phi structure.");
55 /// Return the Phi register value that comes from the incoming block.
56 static unsigned getInitPhiReg(MachineInstr &Phi, MachineBasicBlock *LoopBB) {
57 for (unsigned i = 1, e = Phi.getNumOperands(); i != e; i += 2)
58 if (Phi.getOperand(i + 1).getMBB() != LoopBB)
59 return Phi.getOperand(i).getReg();
63 /// Return the Phi register value that comes the loop block.
64 static unsigned getLoopPhiReg(MachineInstr &Phi, MachineBasicBlock *LoopBB) {
65 for (unsigned i = 1, e = Phi.getNumOperands(); i != e; i += 2)
66 if (Phi.getOperand(i + 1).getMBB() == LoopBB)
67 return Phi.getOperand(i).getReg();
322 // Fix any Phi nodes in the loop exit block.
373 // Compute the stage number for the initial value of the Phi, which
375 // epilog that we're adding the Phi.
397 // The Phi value from the loop body typically is defined in the loop, but
408 // We don't need to generate a Phi anymore, but we need to rename any uses
409 // of the Phi value.
417 // and the distance from where the Phi is first scheduled. The number of
428 // Phi name, because the epilog and prolog blocks execute the same stage.
429 // The correct name is from the previous block only when the Phi has
430 // been completely scheduled prior to the epilog, and Phi value is not
441 // If the Phi hasn't been scheduled, then use the initial Phi operand
443 // is a little complicated when a Phi references another Phi.
446 // Check if the Phi has already been scheduled in a prolog stage.
450 // Check if the Phi has already been scheduled, but the loop instruction
451 // is either another Phi, or doesn't occur in the loop.
453 // If the Phi references another Phi, we need to examine the other
454 // Phi to get the correct value.
476 // If this references a generated Phi in the kernel, get the Phi operand
492 // contains the last definition of the Phi.
497 // Use the value defined by the Phi. We add one because we switch
498 // from looking at the loop value to the Phi definition.
506 // Use the value defined by the Phi, unless we're generating the first
507 // epilog and the Phi refers to a Phi in a different stage.
514 // Check if we can reuse an existing Phi. This occurs when a Phi
515 // references another Phi, and the other Phi is scheduled in an
516 // earlier stage. We can try to reuse an existing Phi up until the last
517 // stage of the current Phi.
523 // Make sure the loop value Phi has been processed already.
529 // Check if the Phi to reuse has been generated yet. If not, then
536 // Update the map with the new Phi name.
565 // we need to rename the Phi values in scheduled instructions.
572 // If the Phi has been scheduled, use the new name for rewriting.
580 // register to replace depends on whether the Phi is scheduled in the
585 // In the kernel, a dependent Phi uses the value from this Phi.
589 // Update the map with the new Phi name.
598 // Check if we need to rename a Phi that has been eliminated due to
613 // Compute the stage number that contains the initial Phi value, and
614 // the Phi from the previous stage.
669 // %Phi0 = Phi %Clone1, Prolog1, %Clone2, Kernel
670 // %Phi1 = Phi %Clone0, Prolog1, %Phi0, Kernel
673 // %Phi2 = Phi %Clone1, Prolog1, %Clone2, Kernel
674 // %Phi3 = Phi %Clone0, Prolog1, %Phi0, Kernel
676 // %Phi4 = Phi %Clone0, Prolog0, %Phi2, Epilog0
781 // In the kernel block, check if we can remove a Phi that generates a value
807 // Check for any Phi definition that used as an operand of another Phi
820 // Search through the rest of the block looking for uses of the Phi
946 // Check if there is a Phi. If so, get the definition in the loop.
1066 /// If the definition is a Phi, then follow the Phi operand to
1112 /// Rewrite the Phi values in the specified block to use the mappings
1113 /// from the initial operand. Once the Phi is scheduled, we switch
1114 /// to using the loop value instead of the Phi value, so those names
1147 unsigned PhiNum, MachineInstr *Phi, unsigned OldReg, unsigned NewReg,
1150 int StagePhi = Schedule.getStage(Phi) + PhiNum;
1152 // Phi register.
1159 if (!Phi->isPHI() && UseMI->getOperand(0).getReg() == NewReg)
1171 if (StagePhi == StageSched && Phi->isPHI()) {
1172 int CyclePhi = Schedule.getCycle(Phi);
1175 else if (PrevReg && !isLoopCarried(*Phi) &&
1181 // The scheduled instruction occurs before the scheduled Phi, and the
1182 // Phi is not loop carried.
1183 if (!InProlog && StagePhi + 1 == StageSched && !isLoopCarried(*Phi))
1185 if (StagePhi > StageSched && Phi->isPHI())
1187 if (!InProlog && !Phi->isPHI() && StagePhi < StageSched)
1205 bool ModuloScheduleExpander::isLoopCarried(MachineInstr &Phi) {
1206 if (!Phi.isPHI())
1208 int DefCycle = Schedule.getCycle(&Phi);
1209 int DefStage = Schedule.getStage(&Phi);
1213 getPhiRegs(Phi, Phi.getParent(), InitVal, LoopVal);
1652 // PHI, we need to create a legal Phi.
1654 // The legal Phi is not necessary if the illegal phi's stage
1694 // Helper to clone Phi instructions into the destination block. We clone Phi
1695 // greedily to avoid combinatorial explosion of Phi instructions.
1696 auto clonePhi = [&](MachineInstr *Phi) {
1697 MachineInstr *NewMI = MF.CloneMachineInstr(Phi);
1699 Register OrigR = Phi->getOperand(0).getReg();
1705 CanonicalMIs[NewMI] = CanonicalMIs[Phi];
1706 BlockMIs[{DestBB, CanonicalMIs[Phi]}] = NewMI;
1707 PhiNodeLoopIteration[NewMI] = PhiNodeLoopIteration[Phi];
1731 MachineInstr *Phi) {
1732 unsigned distance = PhiNodeLoopIteration[Phi];
1793 for (MachineInstr &Phi : B->phis())
1794 PhiNodeLoopIteration[&Phi] = Schedule.getNumStages() - I;
1801 // Move stage one block at a time so that Phi nodes are updated correctly.
1926 // Postpone deleting the Phi as it may be referenced by BlockMIs and used
2217 // NewInitVal = Phi OrigInitVal, Check, PipelineLastVal, Epilog
2229 // Merged = Phi OrigVal, OrigKernel, PipelineVal, Epilog
2366 for (MachineInstr &Phi : Loop->phis()) {
2368 getPhiRegs(Phi, Loop, InitVal, LoopVal);
2370 return Φ
2433 MachineInstr *Phi = getLoopPhiUser(OrigReg, OrigKernel);
2434 if (!Phi)
2436 CorrespondReg = getInitPhiReg(*Phi, OrigKernel);
2451 static void replacePhiSrc(MachineInstr &Phi, Register OrigReg, Register NewReg,
2453 for (unsigned Idx = 1; Idx < Phi.getNumOperands(); Idx += 2) {
2454 if (Phi.getOperand(Idx).getReg() == OrigReg) {
2455 Phi.getOperand(Idx).setReg(NewReg);
2456 Phi.getOperand(Idx + 1).setMBB(NewMBB);
2501 for (MachineInstr *Phi : LoopPhis) {
2503 getPhiRegs(*Phi, OrigKernel, InitReg, LoopReg);
2505 BuildMI(*NewPreheader, NewPreheader->getFirstNonPHI(), Phi->getDebugLoc(),
2511 replacePhiSrc(*Phi, InitReg, NewInit, NewPreheader);