64 #ifndef LLVM_CODEGEN_GLOBALISEL_REGBANKSELECT_H
65 #define LLVM_CODEGEN_GLOBALISEL_REGBANKSELECT_H
74 class MachineBranchProbabilityInfo;
75 class MachineBlockFrequencyInfo;
76 class MachineRegisterInfo;
77 class TargetPassConfig;
78 class TargetRegisterInfo;
179 virtual bool isSplit()
const {
return false; }
202 void materialize()
override;
233 void materialize()
override {
237 return Beginning ? MBB.
begin() : MBB.
end();
248 "Invalid beginning point");
252 "Invalid end point");
254 bool isSplit()
const override {
return false; }
271 void materialize()
override;
280 return DstOrSplit->
begin();
287 :
InsertPoint(), Src(Src), DstOrSplit(&Dst), P(P) {}
383 assert(NewKind != Kind &&
"Already of the right Kind");
385 InsertPoints.
clear();
386 CanMaterialize = NewKind != RepairingKind::Impossible;
388 assert(NewKind != RepairingKind::Insert &&
389 "We would need more MI to switch to Insert");
412 uint64_t NonLocalCost;
416 MappingCost(uint64_t LocalCost, uint64_t NonLocalCost, uint64_t LocalFreq)
417 : LocalCost(LocalCost), NonLocalCost(NonLocalCost),
418 LocalFreq(LocalFreq) {}
421 bool isSaturated()
const;
426 MappingCost(
const BlockFrequency &LocalFreq);
430 bool addLocalCost(uint64_t Cost);
435 bool addNonLocalCost(uint64_t Cost);
442 static MappingCost ImpossibleCost();
445 bool operator<(
const MappingCost &Cost)
const;
447 bool operator==(
const MappingCost &Cost)
const;
449 bool operator!=(
const MappingCost &Cost)
const {
return !(*
this == Cost); }
451 bool operator>(
const MappingCost &Cost)
const {
452 return *
this != Cost && Cost < *
this;
459 void print(raw_ostream &OS)
const;
462 friend raw_ostream &
operator<<(raw_ostream &OS,
const MappingCost &Cost) {
474 MachineRegisterInfo *MRI;
477 const TargetRegisterInfo *TRI;
481 MachineBlockFrequencyInfo *MBFI;
485 MachineBranchProbabilityInfo *MBPI;
488 MachineIRBuilder MIRBuilder;
494 const TargetPassConfig *TPC;
498 bool assignInstr(MachineInstr &
MI);
501 void init(MachineFunction &MF);
507 bool assignmentMatch(
unsigned Reg,
508 const RegisterBankInfo::ValueMapping &ValMapping,
509 bool &OnlyAssign)
const;
543 bool repairReg(MachineOperand &MO,
544 const RegisterBankInfo::ValueMapping &ValMapping,
545 RegBankSelect::RepairingPlacement &RepairPt,
555 getRepairCost(
const MachineOperand &MO,
556 const RegisterBankInfo::ValueMapping &ValMapping)
const;
560 RegisterBankInfo::InstructionMapping &
561 findBestMapping(MachineInstr &
MI,
563 SmallVectorImpl<RepairingPlacement> &RepairPts);
573 computeMapping(MachineInstr &
MI,
574 const RegisterBankInfo::InstructionMapping &InstrMapping,
575 SmallVectorImpl<RepairingPlacement> &RepairPts,
576 const MappingCost *BestCost =
nullptr);
586 void tryAvoidingSplit(RegBankSelect::RepairingPlacement &RepairPt,
587 const MachineOperand &MO,
588 const RegisterBankInfo::ValueMapping &ValMapping)
const;
594 bool applyMapping(MachineInstr &
MI,
595 const RegisterBankInfo::InstructionMapping &InstrMapping,
596 SmallVectorImpl<RepairingPlacement> &RepairPts);
Pass interface - Implemented by all 'passes'.
unsigned succ_size() const
bool canMaterialize() const override
Check whether this insertion point can be materialized.
Assign the register banks as fast as possible (default).
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
virtual MachineBasicBlock & getInsertMBBImpl()=0
Return the materialized insertion basic block.
insertpt_iterator begin()
Accessors related to the insertion points.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
bool operator>(int64_t V1, const APSInt &V2)
Reparing code needs to happen before InsertPoints.
bool isSplit() const override
Does this point involve splitting an edge or block? As soon as ::getPoint is called and thus...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Mode
List of the modes supported by the RegBankSelect pass.
void switchTo(RepairingKind NewKind)
Change the type of this repairing placement to NewKind.
MachineBasicBlock::iterator getPoint()
The first call to this method will cause the splitting to happen if need be, then sub sequent calls j...
Mark this repairing placement as impossible.
bool canMaterialize() const override
Check whether this insertion point can be materialized.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Abstract class used to represent an insertion point in a CFG.
Reg
All possible values of the reg field in the ModR/M byte.
RepairingKind
Define the kind of action this repairing needs.
const_insertpt_iterator end() const
unsigned getOpIdx() const
virtual bool isSplit() const
Does this point involve splitting an edge or block? As soon as ::getPoint is called and thus...
virtual bool canMaterialize() const
Check whether this insertion point can be materialized.
RepairingPlacement(MachineInstr &MI, unsigned OpIdx, const TargetRegisterInfo &TRI, Pass &P, RepairingKind Kind=RepairingKind::Insert)
Create a repairing placement for the OpIdx-th operand of MI.
const MachineBasicBlock * getParent() const
InsertionPoints::const_iterator const_insertpt_iterator
uint64_t frequency(const Pass &P) const override
Frequency of the insertion point.
This pass implements the reg bank selector pass used in the GlobalISel pipeline.
Insertion point on an edge.
SmallVector< InstructionMapping, 4 > InstructionMappings
Convenient type to represent the alternatives for mapping an instruction.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
RegBankSelect(Mode RunningMode=Fast)
Create a RegBankSelect pass with the specified RunningMode.
Represent the analysis usage information of a pass.
RepairingKind getKind() const
Getters.
unsigned getNumInsertPoints() const
virtual void materialize()=0
Materialize the insertion point.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual MachineBasicBlock::iterator getPointImpl()=0
Return the materialized insertion point.
SmallVector< std::unique_ptr< InsertPoint >, 2 > InsertionPoints
Convenient types for a list of insertion points.
MBBInsertPoint(MachineBasicBlock &MBB, bool Beginning=true)
Struct used to represent the placement of a repairing point for a given operand.
SuperClass::const_iterator const_iterator
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
virtual uint64_t frequency(const Pass &P) const
Frequency of the insertion point.
MachineBasicBlock & getInsertMBB()
The first call to this method will cause the splitting to happen if need be, then sub sequent calls j...
This file declares the MachineIRBuilder class.
InsertionPoints::iterator insertpt_iterator
MachineFunctionProperties getSetProperties() const override
RegisterBankInfo(RegisterBank **RegBanks, unsigned NumRegBanks)
Create a RegisterBankInfo that can accomodate up to NumRegBanks RegisterBank instances.
bool canMaterialize() const
MachineFunctionProperties & set(Property P)
bool operator!=(uint64_t V1, const APInt &V2)
const_insertpt_iterator begin() const
Representation of each machine instruction.
bool canMaterialize() const override
Check whether this insertion point can be materialized.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
bool isSplit() const override
Does this point involve splitting an edge or block? As soon as ::getPoint is called and thus...
Insertion point before or after an instruction.
EdgeInsertPoint(MachineBasicBlock &Src, MachineBasicBlock &Dst, Pass &P)
InstrInsertPoint(MachineInstr &Instr, bool Before=true)
Create an insertion point before (Before=true) or after Instr.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
uint64_t frequency(const Pass &P) const override
Frequency of the insertion point.
bool WasMaterialized
Tell if the insert point has already been materialized.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
void addInsertPoint(MachineBasicBlock &MBB, bool Beginning)
Overloaded methods to add an insertion point.
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
bool runOnMachineFunction(MachineFunction &MF) override
Walk through MF and assign a register bank to every virtual register that are still mapped to nothing...
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
MachineFunctionProperties getRequiredProperties() const override
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator<(int64_t V1, const APSInt &V2)
(Re)assign the register bank of the operand.
bool isPredecessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a predecessor of this block.
virtual void print(raw_ostream &O, const Module *M) const
print - Print out the internal state of the pass.
StringRef - Represent a constant reference to a string, i.e.
bool operator==(uint64_t V1, const APInt &V2)
uint64_t frequency(const Pass &P) const override
Frequency of the insertion point.
Greedily minimize the cost of assigning register banks.
unsigned pred_size() const
Insertion point at the beginning or end of a basic block.
MachineBasicBlock::iterator insert(MachineInstr &MI)
Insert MI in the just before ::getPoint()
Nothing to repair, just drop this action.
Properties which a MachineFunction may have at a given point in time.
bool isSplit() const override
Does this point involve splitting an edge or block? As soon as ::getPoint is called and thus...