64 #ifndef LLVM_CODEGEN_GLOBALISEL_REGBANKSELECT_H
65 #define LLVM_CODEGEN_GLOBALISEL_REGBANKSELECT_H
80 class MachineBlockFrequencyInfo;
81 class MachineBranchProbabilityInfo;
83 class MachineRegisterInfo;
86 class TargetPassConfig;
87 class TargetRegisterInfo;
188 virtual bool isSplit()
const {
return false; }
212 void materialize()
override;
245 void materialize()
override {
249 return Beginning ? MBB.
begin() : MBB.
end();
260 "Invalid beginning point");
264 "Invalid end point");
267 bool isSplit()
const override {
return false; }
286 void materialize()
override;
295 return DstOrSplit->
begin();
302 :
InsertPoint(), Src(Src), DstOrSplit(&Dst), P(P) {}
343 bool HasSplit =
false;
400 assert(NewKind != Kind &&
"Already of the right Kind");
402 InsertPoints.
clear();
403 CanMaterialize = NewKind != RepairingKind::Impossible;
405 assert(NewKind != RepairingKind::Insert &&
406 "We would need more MI to switch to Insert");
426 uint64_t LocalCost = 0;
429 uint64_t NonLocalCost = 0;
433 MappingCost(uint64_t LocalCost, uint64_t NonLocalCost, uint64_t LocalFreq)
434 : LocalCost(LocalCost), NonLocalCost(NonLocalCost),
435 LocalFreq(LocalFreq) {}
438 bool isSaturated()
const;
443 MappingCost(
const BlockFrequency &LocalFreq);
447 bool addLocalCost(uint64_t Cost);
452 bool addNonLocalCost(uint64_t Cost);
459 static MappingCost ImpossibleCost();
462 bool operator<(
const MappingCost &Cost)
const;
464 bool operator==(
const MappingCost &Cost)
const;
466 bool operator!=(
const MappingCost &Cost)
const {
return !(*
this == Cost); }
468 bool operator>(
const MappingCost &Cost)
const {
469 return *
this != Cost && Cost < *
this;
476 void print(raw_ostream &OS)
const;
479 friend raw_ostream &
operator<<(raw_ostream &OS,
const MappingCost &Cost) {
491 MachineRegisterInfo *MRI =
nullptr;
494 const TargetRegisterInfo *TRI =
nullptr;
498 MachineBlockFrequencyInfo *MBFI =
nullptr;
502 MachineBranchProbabilityInfo *MBPI =
nullptr;
505 std::unique_ptr<MachineOptimizationRemarkEmitter> MORE;
508 MachineIRBuilder MIRBuilder;
514 const TargetPassConfig *TPC;
518 bool assignInstr(MachineInstr &
MI);
521 void init(MachineFunction &MF);
527 bool assignmentMatch(
unsigned Reg,
528 const RegisterBankInfo::ValueMapping &ValMapping,
529 bool &OnlyAssign)
const;
563 bool repairReg(MachineOperand &MO,
564 const RegisterBankInfo::ValueMapping &ValMapping,
565 RegBankSelect::RepairingPlacement &RepairPt,
575 getRepairCost(
const MachineOperand &MO,
576 const RegisterBankInfo::ValueMapping &ValMapping)
const;
580 const RegisterBankInfo::InstructionMapping &
581 findBestMapping(MachineInstr &
MI,
583 SmallVectorImpl<RepairingPlacement> &RepairPts);
593 computeMapping(MachineInstr &
MI,
594 const RegisterBankInfo::InstructionMapping &InstrMapping,
595 SmallVectorImpl<RepairingPlacement> &RepairPts,
596 const MappingCost *BestCost =
nullptr);
606 void tryAvoidingSplit(RegBankSelect::RepairingPlacement &RepairPt,
607 const MachineOperand &MO,
608 const RegisterBankInfo::ValueMapping &ValMapping)
const;
614 bool applyMapping(MachineInstr &
MI,
615 const RegisterBankInfo::InstructionMapping &InstrMapping,
616 SmallVectorImpl<RepairingPlacement> &RepairPts);
665 #endif // LLVM_CODEGEN_GLOBALISEL_REGBANKSELECT_H
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).
virtual ~InsertPoint()=default
typename SuperClass::const_iterator const_iterator
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()
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...
InsertionPoints::const_iterator const_insertpt_iterator
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...
InsertionPoints::iterator insertpt_iterator
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.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
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
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.
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
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.
print lazy value Lazy Value Info Printer Pass
MBBInsertPoint(MachineBasicBlock &MBB, bool Beginning=true)
Struct used to represent the placement of a repairing point for a given operand.
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.
MachineFunctionProperties getSetProperties() const override
RegisterBankInfo(RegisterBank **RegBanks, unsigned NumRegBanks)
Create a RegisterBankInfo that can accommodate up to NumRegBanks RegisterBank instances.
typename SuperClass::iterator iterator
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.
void addInsertPoint(MachineBasicBlock &MBB, bool Beginning)
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.
SmallVector< const InstructionMapping *, 4 > InstructionMappings
Convenient type to represent the alternatives for mapping an instruction.
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...