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
407 // We don't need to generate a Phi anymore, but we need to rename any uses
408 // of the Phi value.
416 // and the distance from where the Phi is first scheduled. The number of
427 // Phi name, because the epilog and prolog blocks execute the same stage.
428 // The correct name is from the previous block only when the Phi has
429 // been completely scheduled prior to the epilog, and Phi value is not
440 // If the Phi hasn't been scheduled, then use the initial Phi operand
442 // is a little complicated when a Phi references another Phi.
445 // Check if the Phi has already been scheduled in a prolog stage.
449 // Check if the Phi has already been scheduled, but the loop instruction
450 // is either another Phi, or doesn't occur in the loop.
452 // If the Phi references another Phi, we need to examine the other
453 // Phi to get the correct value.
475 // If this references a generated Phi in the kernel, get the Phi operand
491 // contains the last definition of the Phi.
496 // Use the value defined by the Phi. We add one because we switch
497 // from looking at the loop value to the Phi definition.
505 // Use the value defined by the Phi, unless we're generating the first
506 // epilog and the Phi refers to a Phi in a different stage.
513 // Check if we can reuse an existing Phi. This occurs when a Phi
514 // references another Phi, and the other Phi is scheduled in an
515 // earlier stage. We can try to reuse an existing Phi up until the last
516 // stage of the current Phi.
522 // Make sure the loop value Phi has been processed already.
528 // Check if the Phi to reuse has been generated yet. If not, then
535 // Update the map with the new Phi name.
564 // we need to rename the Phi values in scheduled instructions.
571 // If the Phi has been scheduled, use the new name for rewriting.
579 // register to replace depends on whether the Phi is scheduled in the
584 // In the kernel, a dependent Phi uses the value from this Phi.
588 // Update the map with the new Phi name.
597 // Check if we need to rename a Phi that has been eliminated due to
612 // Compute the stage number that contains the initial Phi value, and
613 // the Phi from the previous stage.
668 // %Phi0 = Phi %Clone1, Prolog1, %Clone2, Kernel
669 // %Phi1 = Phi %Clone0, Prolog1, %Phi0, Kernel
672 // %Phi2 = Phi %Clone1, Prolog1, %Clone2, Kernel
673 // %Phi3 = Phi %Clone0, Prolog1, %Phi0, Kernel
675 // %Phi4 = Phi %Clone0, Prolog0, %Phi2, Epilog0
780 // In the kernel block, check if we can remove a Phi that generates a value
806 // Check for any Phi definition that used as an operand of another Phi
819 // Search through the rest of the block looking for uses of the Phi
945 // Check if there is a Phi. If so, get the definition in the loop.
1065 /// If the definition is a Phi, then follow the Phi operand to
1111 /// Rewrite the Phi values in the specified block to use the mappings
1112 /// from the initial operand. Once the Phi is scheduled, we switch
1113 /// to using the loop value instead of the Phi value, so those names
1146 unsigned PhiNum, MachineInstr *Phi, unsigned OldReg, unsigned NewReg,
1149 int StagePhi = Schedule.getStage(Phi) + PhiNum;
1151 // Phi register.
1158 if (!Phi->isPHI() && UseMI->getOperand(0).getReg() == NewReg)
1170 if (StagePhi == StageSched && Phi->isPHI()) {
1171 int CyclePhi = Schedule.getCycle(Phi);
1174 else if (PrevReg && !isLoopCarried(*Phi) &&
1180 // The scheduled instruction occurs before the scheduled Phi, and the
1181 // Phi is not loop carried.
1182 if (!InProlog && StagePhi + 1 == StageSched && !isLoopCarried(*Phi))
1184 if (StagePhi > StageSched && Phi->isPHI())
1186 if (!InProlog && !Phi->isPHI() && StagePhi < StageSched)
1204 bool ModuloScheduleExpander::isLoopCarried(MachineInstr &Phi) {
1205 if (!Phi.isPHI())
1207 int DefCycle = Schedule.getCycle(&Phi);
1208 int DefStage = Schedule.getStage(&Phi);
1212 getPhiRegs(Phi, Phi.getParent(), InitVal, LoopVal);
1651 // PHI, we need to create a legal Phi.
1653 // The legal Phi is not necessary if the illegal phi's stage
1693 // Helper to clone Phi instructions into the destination block. We clone Phi
1694 // greedily to avoid combinatorial explosion of Phi instructions.
1695 auto clonePhi = [&](MachineInstr *Phi) {
1696 MachineInstr *NewMI = MF.CloneMachineInstr(Phi);
1698 Register OrigR = Phi->getOperand(0).getReg();
1704 CanonicalMIs[NewMI] = CanonicalMIs[Phi];
1705 BlockMIs[{DestBB, CanonicalMIs[Phi]}] = NewMI;
1706 PhiNodeLoopIteration[NewMI] = PhiNodeLoopIteration[Phi];
1730 MachineInstr *Phi) {
1731 unsigned distance = PhiNodeLoopIteration[Phi];
1792 for (MachineInstr &Phi : B->phis())
1793 PhiNodeLoopIteration[&Phi] = Schedule.getNumStages() - I;
1800 // Move stage one block at a time so that Phi nodes are updated correctly.
1925 // Postpone deleting the Phi as it may be referenced by BlockMIs and used
2216 // NewInitVal = Phi OrigInitVal, Check, PipelineLastVal, Epilog
2228 // Merged = Phi OrigVal, OrigKernel, PipelineVal, Epilog
2365 for (MachineInstr &Phi : Loop->phis()) {
2367 getPhiRegs(Phi, Loop, InitVal, LoopVal);
2369 return &Phi;
2432 MachineInstr *Phi = getLoopPhiUser(OrigReg, OrigKernel);
2433 if (!Phi)
2435 CorrespondReg = getInitPhiReg(*Phi, OrigKernel);
2450 static void replacePhiSrc(MachineInstr &Phi, Register OrigReg, Register NewReg,
2452 for (unsigned Idx = 1; Idx < Phi.getNumOperands(); Idx += 2) {
2453 if (Phi.getOperand(Idx).getReg() == OrigReg) {
2454 Phi.getOperand(Idx).setReg(NewReg);
2455 Phi.getOperand(Idx + 1).setMBB(NewMBB);
2500 for (MachineInstr *Phi : LoopPhis) {
2502 getPhiRegs(*Phi, OrigKernel, InitReg, LoopReg);
2504 BuildMI(*NewPreheader, NewPreheader->getFirstNonPHI(), Phi->getDebugLoc(),
2510 replacePhiSrc(*Phi, InitReg, NewInit, NewPreheader);