|
LLVM 24.0.0git
|
#include "llvm/CodeGen/MachinePipeliner.h"#include "CodeGenOptions.h"#include "llvm/ADT/ArrayRef.h"#include "llvm/ADT/BitVector.h"#include "llvm/ADT/DenseMap.h"#include "llvm/ADT/PriorityQueue.h"#include "llvm/ADT/STLExtras.h"#include "llvm/ADT/SetOperations.h"#include "llvm/ADT/SetVector.h"#include "llvm/ADT/SmallPtrSet.h"#include "llvm/ADT/SmallSet.h"#include "llvm/ADT/SmallVector.h"#include "llvm/ADT/Statistic.h"#include "llvm/ADT/iterator_range.h"#include "llvm/Analysis/AliasAnalysis.h"#include "llvm/Analysis/MemoryLocation.h"#include "llvm/Analysis/OptimizationRemarkEmitter.h"#include "llvm/Analysis/ValueTracking.h"#include "llvm/CodeGen/DFAPacketizer.h"#include "llvm/CodeGen/LiveIntervals.h"#include "llvm/CodeGen/MachineBasicBlock.h"#include "llvm/CodeGen/MachineFunction.h"#include "llvm/CodeGen/MachineFunctionPass.h"#include "llvm/CodeGen/MachineInstr.h"#include "llvm/CodeGen/MachineInstrBuilder.h"#include "llvm/CodeGen/MachineLoopInfo.h"#include "llvm/CodeGen/MachineMemOperand.h"#include "llvm/CodeGen/MachineOperand.h"#include "llvm/CodeGen/MachinePassManager.h"#include "llvm/CodeGen/MachineRegisterInfo.h"#include "llvm/CodeGen/ModuloSchedule.h"#include "llvm/CodeGen/Register.h"#include "llvm/CodeGen/RegisterClassInfo.h"#include "llvm/CodeGen/RegisterPressure.h"#include "llvm/CodeGen/ScheduleDAG.h"#include "llvm/CodeGen/ScheduleDAGMutation.h"#include "llvm/CodeGen/TargetInstrInfo.h"#include "llvm/CodeGen/TargetOpcodes.h"#include "llvm/CodeGen/TargetPassConfig.h"#include "llvm/CodeGen/TargetRegisterInfo.h"#include "llvm/CodeGen/TargetSubtargetInfo.h"#include "llvm/Config/llvm-config.h"#include "llvm/IR/Attributes.h"#include "llvm/IR/Function.h"#include "llvm/InitializePasses.h"#include "llvm/MC/LaneBitmask.h"#include "llvm/MC/MCInstrDesc.h"#include "llvm/MC/MCInstrItineraries.h"#include "llvm/Pass.h"#include "llvm/Support/Compiler.h"#include "llvm/Support/Debug.h"#include "llvm/Support/raw_ostream.h"#include <algorithm>#include <cassert>#include <climits>#include <cstdint>#include <deque>#include <functional>#include <iomanip>#include <iterator>#include <map>#include <memory>#include <sstream>#include <tuple>#include <utility>#include <vector>Go to the source code of this file.
Classes | |
| struct | false::SUnitWithMemInfo |
| This class holds an SUnit corresponding to a memory operation and other information related to the instruction. More... | |
| class | false::LoopCarriedOrderDepsTracker |
| Add loop-carried chain dependencies. More... | |
| class | false::MachinePipelinerImpl |
| The main class in the implementation of the target independent software pipeliner pass. More... | |
| struct | false::MachinePipelinerImpl::LoopInfo |
| Cache the target analysis information about the loop. More... | |
Namespaces | |
| namespace | false |
Macros | |
| #define | DEBUG_TYPE "pipeliner" |
Functions | |
| STATISTIC (NumTrytoPipeline, "Number of loops that we attempt to pipeline") | |
| STATISTIC (NumPipelined, "Number of loops software pipelined") | |
| STATISTIC (NumNodeOrderIssues, "Number of node order issues found") | |
| STATISTIC (NumFailBranch, "Pipeliner abort due to unknown branch") | |
| STATISTIC (NumFailLoop, "Pipeliner abort due to unsupported loop") | |
| STATISTIC (NumFailPreheader, "Pipeliner abort due to missing preheader") | |
| STATISTIC (NumFailLargeMaxMII, "Pipeliner abort due to MaxMII too large") | |
| STATISTIC (NumFailZeroMII, "Pipeliner abort due to zero MII") | |
| STATISTIC (NumFailNoSchedule, "Pipeliner abort due to no schedule found") | |
| STATISTIC (NumFailZeroStage, "Pipeliner abort due to zero stage") | |
| STATISTIC (NumFailLargeMaxStage, "Pipeliner abort due to too many stages") | |
| STATISTIC (NumFailTooManyStores, "Pipeliner abort due to too many stores") | |
| INITIALIZE_PASS_BEGIN (MachinePipelinerLegacy, DEBUG_TYPE, "Modulo Software Pipelining", false, false) INITIALIZE_PASS_END(MachinePipelinerLegacy | |
| static bool | runMachinePipeliner (MachineFunction &MF, function_ref< const MachineLoopInfo &()> GetMLI, function_ref< LiveIntervals &()> GetLIS, function_ref< AAResults &()> GetAA, function_ref< MachineOptimizationRemarkEmitter &()> GetORE, function_ref< RegisterClassInfo &()> GetRCI, function_ref< MachineDominatorTree *()> GetMDT) |
| static bool | hasPHICycleDFS (unsigned Reg, const DenseMap< unsigned, SmallVector< unsigned, 2 > > &PhiDeps, SmallSet< unsigned, 8 > &Visited, SmallSet< unsigned, 8 > &RecStack) |
| Depth-first search to detect cycles among PHI dependencies. | |
| static bool | hasPHICycle (const MachineBasicBlock *LoopHeader, const MachineRegisterInfo &MRI) |
| static void | getPhiRegs (const MachineInstr &Phi, const MachineBasicBlock *Loop, Register &InitVal, Register &LoopVal) |
| Return the register values for the operands of a Phi instruction. | |
| static Register | getLoopPhiReg (const MachineInstr &Phi, const MachineBasicBlock *LoopBB) |
| Return the Phi register value that comes the loop block. | |
| static bool | isSuccOrder (SUnit *SUa, SUnit *SUb) |
| Return true if SUb can be reached from SUa following the chain edges. | |
| static bool | hasLoopCarriedMemDep (const SUnitWithMemInfo &Src, const SUnitWithMemInfo &Dst, BatchAAResults &BAA, const TargetInstrInfo *TII) |
Returns true if there is a loop-carried order dependency from Src to Dst. | |
| static void | computeScheduledInsts (const SwingSchedulerDAG *SSD, SMSchedule &Schedule, std::vector< MachineInstr * > &OrderedInsts, DenseMap< MachineInstr *, unsigned > &Stages) |
| Create an instruction stream that represents a single iteration and stage of each instruction. | |
| static bool | pred_L (SetVector< SUnit * > &NodeOrder, SmallSetVector< SUnit *, 8 > &Preds, SwingSchedulerDDG *DDG, const NodeSet *S=nullptr) |
| Compute the Pred_L(O) set, as defined in the paper. | |
| static bool | succ_L (SetVector< SUnit * > &NodeOrder, SmallSetVector< SUnit *, 8 > &Succs, SwingSchedulerDDG *DDG, const NodeSet *S=nullptr) |
| Compute the Succ_L(O) set, as defined in the paper. | |
| static bool | computePath (SUnit *Cur, SetVector< SUnit * > &Path, SetVector< SUnit * > &DestNodes, SetVector< SUnit * > &Exclude, SmallPtrSet< SUnit *, 8 > &Visited, SwingSchedulerDDG *DDG) |
| Return true if there is a path from the specified node to any of the nodes in DestNodes. | |
| static void | computeLiveOuts (MachineFunction &MF, RegPressureTracker &RPTracker, NodeSet &NS) |
| Compute the live-out registers for the instructions in a node-set. | |
| static bool | isIntersect (SmallSetVector< SUnit *, 8 > &Set1, const NodeSet &Set2, SmallSetVector< SUnit *, 8 > &Result) |
| Return true if Set1 contains elements in Set2. | |
| static Register | findUniqueOperandDefinedInLoop (const MachineInstr &MI) |
| static bool | findLoopIncrementValue (const MachineInstr &MI, const MachineOperand &Op, int &Value) |
| When Op is a value that is incremented recursively in a loop and there is a unique instruction that increments it, returns true and sets Value. | |
| static bool | computeDelta (const MachineInstr &MI, const TargetInstrInfo &TII, int &Delta) |
| Return true if we can compute the amount the instruction changes during each iteration. | |
| static SUnit * | multipleIterations (SUnit *SU, SwingSchedulerDAG *DAG) |
| If an instruction has a use that spans multiple iterations, then return true. | |
Variables | |
| DEBUG_TYPE | |
| Modulo Software | Pipelining |
| Modulo Software | false |
| #define DEBUG_TYPE "pipeliner" |
Definition at line 101 of file MachinePipeliner.cpp.
|
static |
Return true if we can compute the amount the instruction changes during each iteration.
Set Delta to the amount of the change.
Definition at line 3023 of file MachinePipeliner.cpp.
References findLoopIncrementValue(), llvm::MachineOperand::isReg(), MI, llvm::Offset, and TII.
Referenced by llvm::mayOverlapInLaterIter().
|
static |
Compute the live-out registers for the instructions in a node-set.
The live-out registers are those that are defined in the node-set, but not used. Except for use operands of Phis.
Definition at line 2368 of file MachinePipeliner.cpp.
References llvm::RegPressureTracker::addLiveRegs(), llvm::MachineInstr::all_defs(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::SUnit::getInstr(), llvm::LaneBitmask::getNone(), llvm::MachineFunction::getRegInfo(), llvm::TargetSubtargetInfo::getRegisterInfo(), llvm::MachineFunction::getSubtarget(), MI, MRI, Reg, TRI, and Uses.
|
static |
Return true if there is a path from the specified node to any of the nodes in DestNodes.
Keep track and return the nodes in any path.
Definition at line 2338 of file MachinePipeliner.cpp.
References computePath(), llvm::SetVector< T, Vector, Set, N >::contains(), llvm::SwingSchedulerDDG::getInEdges(), llvm::SwingSchedulerDDG::getOutEdges(), llvm::SmallPtrSetImpl< PtrType >::insert(), and llvm::SUnit::isBoundaryNode().
Referenced by computePath().
|
static |
Create an instruction stream that represents a single iteration and stage of each instruction.
This function differs from SMSchedule::finalizeSchedule in that this doesn't have any side-effect to SwingSchedulerDAG. That is, this function is an approximation of SMSchedule::finalizeSchedule with all non-const operations removed.
Definition at line 1470 of file MachinePipeliner.cpp.
References llvm::SMSchedule::getFinalCycle(), llvm::SMSchedule::getFirstCycle(), llvm::SMSchedule::getInitiationInterval(), llvm::SUnit::getInstr(), llvm::SMSchedule::getInstructions(), llvm::SMSchedule::getMaxStageCount(), MI, llvm::SMSchedule::reorderInstructions(), llvm::reverse(), and llvm::SMSchedule::stageScheduled().
|
static |
When Op is a value that is incremented recursively in a loop and there is a unique instruction that increments it, returns true and sets Value.
Definition at line 2946 of file MachinePipeliner.cpp.
References findUniqueOperandDefinedInLoop(), llvm::TargetSubtargetInfo::getInstrInfo(), getLoopPhiReg(), llvm::MachineBasicBlock::getParent(), llvm::MachineOperand::getReg(), llvm::MachineFunction::getRegInfo(), llvm::MachineFunction::getSubtarget(), llvm::Increment, llvm::Register::isValid(), llvm::Register::isVirtual(), MI, MRI, llvm::Offset, and TII.
Referenced by computeDelta().
|
static |
Definition at line 2928 of file MachinePipeliner.cpp.
References MI, MRI, Reg, and Register.
Referenced by findLoopIncrementValue().
|
static |
Return the Phi register value that comes the loop block.
Definition at line 1011 of file MachinePipeliner.cpp.
References Register.
Referenced by findLoopIncrementValue(), and llvm::SMSchedule::isLoopCarriedDefOfUse().
|
static |
Return the register values for the operands of a Phi instruction.
This function assume the instruction is a Phi.
Definition at line 995 of file MachinePipeliner.cpp.
References assert(), and Register.
Referenced by llvm::ModuloScheduleExpanderMVE::canApply(), getLoopPhiUser(), llvm::SMSchedule::isLoopCarried(), and llvm::mayOverlapInLaterIter().
|
static |
Returns true if there is a loop-carried order dependency from Src to Dst.
Definition at line 1086 of file MachinePipeliner.cpp.
References llvm::MemoryLocation::getBeforeOrAfter(), llvm::MachineBasicBlock::getParent(), llvm::MachineInstr::getParent(), llvm::MachineFunction::getRegInfo(), llvm::BatchAAResults::isNoAlias(), isSuccOrder(), llvm::mayOverlapInLaterIter(), MRI, and TII.
Referenced by llvm::WindowScheduler::collectLoopCarriedMemDeps().
|
static |
Definition at line 529 of file MachinePipeliner.cpp.
References hasPHICycleDFS(), I, MI, MRI, llvm::MachineBasicBlock::phis(), Reg, and llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace().
|
static |
Depth-first search to detect cycles among PHI dependencies.
Returns true if a cycle is detected within the PHI-only subgraph.
Definition at line 503 of file MachinePipeliner.cpp.
References llvm::SmallSet< T, N, C >::count(), llvm::SmallSet< T, N, C >::erase(), hasPHICycleDFS(), llvm::SmallSet< T, N, C >::insert(), and Reg.
Referenced by hasPHICycle(), and hasPHICycleDFS().
| INITIALIZE_PASS_BEGIN | ( | MachinePipelinerLegacy | , |
| DEBUG_TYPE | , | ||
| "Modulo Software Pipelining" | , | ||
| false | , | ||
| false | ) |
References DEBUG_TYPE, and INITIALIZE_PASS_DEPENDENCY.
|
static |
Return true if Set1 contains elements in Set2.
The elements in common are returned in a different container.
Definition at line 2578 of file MachinePipeliner.cpp.
References llvm::NodeSet::count().
Return true if SUb can be reached from SUa following the chain edges.
Definition at line 1020 of file MachinePipeliner.cpp.
References llvm::SmallPtrSetImpl< PtrType >::count(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::SDep::Order, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::SUnit::Succs.
Referenced by hasLoopCarriedMemDep(), and llvm::LoopCarriedEdges::modifySUnits().
|
static |
If an instruction has a use that spans multiple iterations, then return true.
These instructions are characterized by having a back-ege to a Phi, which contains a reference to another Phi.
Definition at line 3304 of file MachinePipeliner.cpp.
References llvm::SDep::Anti, llvm::SDep::Data, P, and llvm::SUnit::Preds.
Referenced by llvm::SMSchedule::computeStart().
|
static |
Compute the Pred_L(O) set, as defined in the paper.
The set is defined as the predecessors of the elements of NodeOrder that are not also in NodeOrder.
Definition at line 2267 of file MachinePipeliner.cpp.
References llvm::SetVector< T, Vector, Set, N >::clear(), llvm::SetVector< T, Vector, Set, N >::empty(), llvm::SwingSchedulerDDG::getInEdges(), llvm::SwingSchedulerDDG::getOutEdges(), llvm::SetVector< T, Vector, Set, N >::insert(), and llvm::NodeOrder.
|
static |
Definition at line 320 of file MachinePipeliner.cpp.
References llvm::TargetSubtargetInfo::enableMachinePipeliner(), llvm::Function::getAttributes(), llvm::getCodeGenOptions(), llvm::MachineFunction::getFunction(), llvm::TargetSubtargetInfo::getInstrItineraryData(), llvm::MachineFunction::getSubtarget(), llvm::InstrItineraryData::isEmpty(), and llvm::TargetSubtargetInfo::useDFAforSMS().
Referenced by llvm::MachinePipelinerPass::run(), and llvm::MachinePipelinerLegacy::runOnMachineFunction().
| STATISTIC | ( | NumFailBranch | , |
| "Pipeliner abort due to unknown branch" | ) |
| STATISTIC | ( | NumFailLargeMaxMII | , |
| "Pipeliner abort due to MaxMII too large" | ) |
| STATISTIC | ( | NumFailLargeMaxStage | , |
| "Pipeliner abort due to too many stages" | ) |
| STATISTIC | ( | NumFailLoop | , |
| "Pipeliner abort due to unsupported loop" | ) |
| STATISTIC | ( | NumFailNoSchedule | , |
| "Pipeliner abort due to no schedule found" | ) |
| STATISTIC | ( | NumFailPreheader | , |
| "Pipeliner abort due to missing preheader" | ) |
| STATISTIC | ( | NumFailTooManyStores | , |
| "Pipeliner abort due to too many stores" | ) |
References llvm::MachinePipelinerLegacy::ID.
| STATISTIC | ( | NumFailZeroMII | , |
| "Pipeliner abort due to zero MII" | ) |
| STATISTIC | ( | NumFailZeroStage | , |
| "Pipeliner abort due to zero stage" | ) |
| STATISTIC | ( | NumNodeOrderIssues | , |
| "Number of node order issues found" | ) |
| STATISTIC | ( | NumPipelined | , |
| "Number of loops software pipelined" | ) |
| STATISTIC | ( | NumTrytoPipeline | , |
| "Number of loops that we attempt to pipeline" | ) |
|
static |
Compute the Succ_L(O) set, as defined in the paper.
The set is defined as the successors of the elements of NodeOrder that are not also in NodeOrder.
Definition at line 2303 of file MachinePipeliner.cpp.
References llvm::SetVector< T, Vector, Set, N >::clear(), llvm::SetVector< T, Vector, Set, N >::empty(), llvm::SwingSchedulerDDG::getInEdges(), llvm::SwingSchedulerDDG::getOutEdges(), llvm::SetVector< T, Vector, Set, N >::insert(), and llvm::NodeOrder.
| DEBUG_TYPE |
Definition at line 126 of file MachinePipeliner.cpp.
| Modulo Software false |
Definition at line 127 of file MachinePipeliner.cpp.
| Modulo Software Pipelining |
Definition at line 127 of file MachinePipeliner.cpp.