class ModuloScheduleExpander

Declaration

class ModuloScheduleExpander { /* full declaration omitted */ };

Description

The ModuloScheduleExpander takes a ModuloSchedule and expands it in-place, rewriting the old loop and inserting prologs and epilogs as required.

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:160

Member Variables

private llvm::ModuloSchedule& Schedule
private llvm::MachineFunction& MF
private const llvm::TargetSubtargetInfo& ST
private llvm::MachineRegisterInfo& MRI
private const llvm::TargetInstrInfo* TII
private llvm::LiveIntervals& LIS
private llvm::MachineBasicBlock* BB
private llvm::MachineBasicBlock* Preheader
private llvm::MachineBasicBlock* NewKernel = nullptr
private std::unique_ptr< TargetInstrInfo::PipelinerLoopInfo> LoopInfo
private std::map<unsigned int, std::pair<unsigned int, bool>> RegToStageDiff
Map for each register and the max difference between its uses and def. The first element in the pair is the max difference in stages. The second is true if the register defines a Phi value and loop value is scheduled before the Phi.
private llvm::ModuloScheduleExpander::InstrChangesTy InstrChanges
Instructions to change when emitting the final schedule.

Method Overview

  • public ModuloScheduleExpander(llvm::MachineFunction & MF, llvm::ModuloSchedule & S, llvm::LiveIntervals & LIS, llvm::ModuloScheduleExpander::InstrChangesTy InstrChanges)
  • private void addBranches(llvm::MachineBasicBlock & PreheaderBB, llvm::ModuloScheduleExpander::MBBVectorTy & PrologBBs, llvm::MachineBasicBlock * KernelBB, llvm::ModuloScheduleExpander::MBBVectorTy & EpilogBBs, llvm::ModuloScheduleExpander::ValueMapTy * VRMap)
  • public void cleanup()
  • private llvm::MachineInstr * cloneAndChangeInstr(llvm::MachineInstr * OldMI, unsigned int CurStageNum, unsigned int InstStageNum)
  • private llvm::MachineInstr * cloneInstr(llvm::MachineInstr * OldMI, unsigned int CurStageNum, unsigned int InstStageNum)
  • private bool computeDelta(llvm::MachineInstr & MI, unsigned int & Delta)
  • public void expand()
  • private llvm::MachineInstr * findDefInLoop(unsigned int Reg)
  • private void generateEpilog(unsigned int LastStage, llvm::MachineBasicBlock * KernelBB, llvm::MachineBasicBlock * OrigBB, llvm::ModuloScheduleExpander::ValueMapTy * VRMap, llvm::ModuloScheduleExpander::MBBVectorTy & EpilogBBs, llvm::ModuloScheduleExpander::MBBVectorTy & PrologBBs)
  • private void generateExistingPhis(llvm::MachineBasicBlock * NewBB, llvm::MachineBasicBlock * BB1, llvm::MachineBasicBlock * BB2, llvm::MachineBasicBlock * KernelBB, llvm::ModuloScheduleExpander::ValueMapTy * VRMap, llvm::ModuloScheduleExpander::InstrMapTy & InstrMap, unsigned int LastStageNum, unsigned int CurStageNum, bool IsLast)
  • private void generatePhis(llvm::MachineBasicBlock * NewBB, llvm::MachineBasicBlock * BB1, llvm::MachineBasicBlock * BB2, llvm::MachineBasicBlock * KernelBB, llvm::ModuloScheduleExpander::ValueMapTy * VRMap, llvm::ModuloScheduleExpander::InstrMapTy & InstrMap, unsigned int LastStageNum, unsigned int CurStageNum, bool IsLast)
  • private void generatePipelinedLoop()
  • private void generateProlog(unsigned int LastStage, llvm::MachineBasicBlock * KernelBB, llvm::ModuloScheduleExpander::ValueMapTy * VRMap, llvm::ModuloScheduleExpander::MBBVectorTy & PrologBBs)
  • private unsigned int getPrevMapVal(unsigned int StageNum, unsigned int PhiStage, unsigned int LoopVal, unsigned int LoopStage, llvm::ModuloScheduleExpander::ValueMapTy * VRMap, llvm::MachineBasicBlock * BB)
  • public llvm::MachineBasicBlock * getRewrittenKernel()
  • private unsigned int getStagesForPhi(int Reg)
  • private unsigned int getStagesForReg(int Reg, unsigned int CurStage)
  • private bool isLoopCarried(llvm::MachineInstr & Phi)
  • private void removeDeadInstructions(llvm::MachineBasicBlock * KernelBB, llvm::ModuloScheduleExpander::MBBVectorTy & EpilogBBs)
  • private void rewritePhiValues(llvm::MachineBasicBlock * NewBB, unsigned int StageNum, llvm::ModuloScheduleExpander::ValueMapTy * VRMap, llvm::ModuloScheduleExpander::InstrMapTy & InstrMap)
  • private void rewriteScheduledInstr(llvm::MachineBasicBlock * BB, llvm::ModuloScheduleExpander::InstrMapTy & InstrMap, unsigned int CurStageNum, unsigned int PhiNum, llvm::MachineInstr * Phi, unsigned int OldReg, unsigned int NewReg, unsigned int PrevReg = 0)
  • private void splitLifetimes(llvm::MachineBasicBlock * KernelBB, llvm::ModuloScheduleExpander::MBBVectorTy & EpilogBBs)
  • private void updateInstruction(llvm::MachineInstr * NewMI, bool LastDef, unsigned int CurStageNum, unsigned int InstrStageNum, llvm::ModuloScheduleExpander::ValueMapTy * VRMap)
  • private void updateMemOperands(llvm::MachineInstr & NewMI, llvm::MachineInstr & OldMI, unsigned int Num)

Methods

ModuloScheduleExpander(
    llvm::MachineFunction& MF,
    llvm::ModuloSchedule& S,
    llvm::LiveIntervals& LIS,
    llvm::ModuloScheduleExpander::InstrChangesTy
        InstrChanges)

Description

Create a new ModuloScheduleExpander.

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:262

Parameters

llvm::MachineFunction& MF
llvm::ModuloSchedule& S
llvm::LiveIntervals& LIS
llvm::ModuloScheduleExpander::InstrChangesTy InstrChanges

void addBranches(
    llvm::MachineBasicBlock& PreheaderBB,
    llvm::ModuloScheduleExpander::MBBVectorTy&
        PrologBBs,
    llvm::MachineBasicBlock* KernelBB,
    llvm::ModuloScheduleExpander::MBBVectorTy&
        EpilogBBs,
    llvm::ModuloScheduleExpander::ValueMapTy*
        VRMap)

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:208

Parameters

llvm::MachineBasicBlock& PreheaderBB
llvm::ModuloScheduleExpander::MBBVectorTy& PrologBBs
llvm::MachineBasicBlock* KernelBB
llvm::ModuloScheduleExpander::MBBVectorTy& EpilogBBs
llvm::ModuloScheduleExpander::ValueMapTy* VRMap

void cleanup()

Description

Performs final cleanup after expansion.

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:271

llvm::MachineInstr* cloneAndChangeInstr(
    llvm::MachineInstr* OldMI,
    unsigned int CurStageNum,
    unsigned int InstStageNum)

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:216

Parameters

llvm::MachineInstr* OldMI
unsigned int CurStageNum
unsigned int InstStageNum

llvm::MachineInstr* cloneInstr(
    llvm::MachineInstr* OldMI,
    unsigned int CurStageNum,
    unsigned int InstStageNum)

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:214

Parameters

llvm::MachineInstr* OldMI
unsigned int CurStageNum
unsigned int InstStageNum

bool computeDelta(llvm::MachineInstr& MI,
                  unsigned int& Delta)

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:211

Parameters

llvm::MachineInstr& MI
unsigned int& Delta

void expand()

Description

Performs the actual expansion.

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:269

llvm::MachineInstr* findDefInLoop(
    unsigned int Reg)

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:221

Parameters

unsigned int Reg

void generateEpilog(
    unsigned int LastStage,
    llvm::MachineBasicBlock* KernelBB,
    llvm::MachineBasicBlock* OrigBB,
    llvm::ModuloScheduleExpander::ValueMapTy*
        VRMap,
    llvm::ModuloScheduleExpander::MBBVectorTy&
        EpilogBBs,
    llvm::ModuloScheduleExpander::MBBVectorTy&
        PrologBBs)

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:193

Parameters

unsigned int LastStage
llvm::MachineBasicBlock* KernelBB
llvm::MachineBasicBlock* OrigBB
llvm::ModuloScheduleExpander::ValueMapTy* VRMap
llvm::ModuloScheduleExpander::MBBVectorTy& EpilogBBs
llvm::ModuloScheduleExpander::MBBVectorTy& PrologBBs

void generateExistingPhis(
    llvm::MachineBasicBlock* NewBB,
    llvm::MachineBasicBlock* BB1,
    llvm::MachineBasicBlock* BB2,
    llvm::MachineBasicBlock* KernelBB,
    llvm::ModuloScheduleExpander::ValueMapTy*
        VRMap,
    llvm::ModuloScheduleExpander::InstrMapTy&
        InstrMap,
    unsigned int LastStageNum,
    unsigned int CurStageNum,
    bool IsLast)

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:196

Parameters

llvm::MachineBasicBlock* NewBB
llvm::MachineBasicBlock* BB1
llvm::MachineBasicBlock* BB2
llvm::MachineBasicBlock* KernelBB
llvm::ModuloScheduleExpander::ValueMapTy* VRMap
llvm::ModuloScheduleExpander::InstrMapTy& InstrMap
unsigned int LastStageNum
unsigned int CurStageNum
bool IsLast

void generatePhis(
    llvm::MachineBasicBlock* NewBB,
    llvm::MachineBasicBlock* BB1,
    llvm::MachineBasicBlock* BB2,
    llvm::MachineBasicBlock* KernelBB,
    llvm::ModuloScheduleExpander::ValueMapTy*
        VRMap,
    llvm::ModuloScheduleExpander::InstrMapTy&
        InstrMap,
    unsigned int LastStageNum,
    unsigned int CurStageNum,
    bool IsLast)

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:201

Parameters

llvm::MachineBasicBlock* NewBB
llvm::MachineBasicBlock* BB1
llvm::MachineBasicBlock* BB2
llvm::MachineBasicBlock* KernelBB
llvm::ModuloScheduleExpander::ValueMapTy* VRMap
llvm::ModuloScheduleExpander::InstrMapTy& InstrMap
unsigned int LastStageNum
unsigned int CurStageNum
bool IsLast

void generatePipelinedLoop()

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:190

void generateProlog(
    unsigned int LastStage,
    llvm::MachineBasicBlock* KernelBB,
    llvm::ModuloScheduleExpander::ValueMapTy*
        VRMap,
    llvm::ModuloScheduleExpander::MBBVectorTy&
        PrologBBs)

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:191

Parameters

unsigned int LastStage
llvm::MachineBasicBlock* KernelBB
llvm::ModuloScheduleExpander::ValueMapTy* VRMap
llvm::ModuloScheduleExpander::MBBVectorTy& PrologBBs

unsigned int getPrevMapVal(
    unsigned int StageNum,
    unsigned int PhiStage,
    unsigned int LoopVal,
    unsigned int LoopStage,
    llvm::ModuloScheduleExpander::ValueMapTy*
        VRMap,
    llvm::MachineBasicBlock* BB)

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:222

Parameters

unsigned int StageNum
unsigned int PhiStage
unsigned int LoopVal
unsigned int LoopStage
llvm::ModuloScheduleExpander::ValueMapTy* VRMap
llvm::MachineBasicBlock* BB

llvm::MachineBasicBlock* getRewrittenKernel()

Description

Returns the newly rewritten kernel block, or nullptr if this was optimized away.

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:275

unsigned int getStagesForPhi(int Reg)

Description

The number of stages for a Phi is a little different than other instructions. The minimum value computed in RegToStageDiff is 1 because we assume the Phi is needed for at least 1 iteration. This is not the case if the loop value is scheduled prior to the Phi in the same stage. This function returns the number of stages or iterations needed between the Phi definition and any uses.

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:249

Parameters

int Reg

unsigned int getStagesForReg(
    int Reg,
    unsigned int CurStage)

Description

Return the max. number of stages/iterations that can occur between a register definition and its uses.

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:235

Parameters

int Reg
unsigned int CurStage

bool isLoopCarried(llvm::MachineInstr& Phi)

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:231

Parameters

llvm::MachineInstr& Phi

void removeDeadInstructions(
    llvm::MachineBasicBlock* KernelBB,
    llvm::ModuloScheduleExpander::MBBVectorTy&
        EpilogBBs)

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:205

Parameters

llvm::MachineBasicBlock* KernelBB
llvm::ModuloScheduleExpander::MBBVectorTy& EpilogBBs

void rewritePhiValues(
    llvm::MachineBasicBlock* NewBB,
    unsigned int StageNum,
    llvm::ModuloScheduleExpander::ValueMapTy*
        VRMap,
    llvm::ModuloScheduleExpander::InstrMapTy&
        InstrMap)

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:225

Parameters

llvm::MachineBasicBlock* NewBB
unsigned int StageNum
llvm::ModuloScheduleExpander::ValueMapTy* VRMap
llvm::ModuloScheduleExpander::InstrMapTy& InstrMap

void rewriteScheduledInstr(
    llvm::MachineBasicBlock* BB,
    llvm::ModuloScheduleExpander::InstrMapTy&
        InstrMap,
    unsigned int CurStageNum,
    unsigned int PhiNum,
    llvm::MachineInstr* Phi,
    unsigned int OldReg,
    unsigned int NewReg,
    unsigned int PrevReg = 0)

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:227

Parameters

llvm::MachineBasicBlock* BB
llvm::ModuloScheduleExpander::InstrMapTy& InstrMap
unsigned int CurStageNum
unsigned int PhiNum
llvm::MachineInstr* Phi
unsigned int OldReg
unsigned int NewReg
unsigned int PrevReg = 0

void splitLifetimes(
    llvm::MachineBasicBlock* KernelBB,
    llvm::ModuloScheduleExpander::MBBVectorTy&
        EpilogBBs)

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:207

Parameters

llvm::MachineBasicBlock* KernelBB
llvm::ModuloScheduleExpander::MBBVectorTy& EpilogBBs

void updateInstruction(
    llvm::MachineInstr* NewMI,
    bool LastDef,
    unsigned int CurStageNum,
    unsigned int InstrStageNum,
    llvm::ModuloScheduleExpander::ValueMapTy*
        VRMap)

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:218

Parameters

llvm::MachineInstr* NewMI
bool LastDef
unsigned int CurStageNum
unsigned int InstrStageNum
llvm::ModuloScheduleExpander::ValueMapTy* VRMap

void updateMemOperands(llvm::MachineInstr& NewMI,
                       llvm::MachineInstr& OldMI,
                       unsigned int Num)

Declared at: llvm/include/llvm/CodeGen/ModuloSchedule.h:212

Parameters

llvm::MachineInstr& NewMI
llvm::MachineInstr& OldMI
unsigned int Num