33 #define DEBUG_TYPE "hbr" 40 bool SbAE = (S < AE) || (S == AE && A.
TiedEnd);
41 bool ASbE = (AS <
E) || (AS ==
E &&
TiedEnd);
42 if ((AS < S && SbAE) || (S < AS && ASbE))
89 iterator Iter =
begin();
91 while (Iter !=
end()-1) {
92 iterator Next = std::next(Iter);
95 bool Merge = MergeAdjacent && (Iter->end() == Next->start());
96 if (Merge || Iter->overlaps(*Next)) {
106 void HexagonBlockRanges::RangeList::addsub(
const IndexRange &A,
146 for (iterator Next,
I =
begin();
I !=
end();
I = Next) {
150 Next = this->erase(
I);
163 if (
In.isDebugInstr())
166 Map.insert(std::make_pair(Idx, &
In));
173 auto F = Map.find(Idx);
174 return (
F != Map.end()) ?
F->second :
nullptr;
209 for (
auto &
I : Map) {
210 if (
I.second != OldMI)
212 if (NewMI !=
nullptr)
222 TII(*HST.getInstrInfo()),
TRI(*HST.getRegisterInfo()),
223 Reserved(
TRI.getReservedRegs(mf)) {
226 if (RC->isAllocatable())
228 for (
unsigned R : *RC)
241 if (
I.LaneMask.all() || (
I.LaneMask.any() && !S.
isValid())) {
242 Tmp.insert({
I.PhysReg, 0});
248 Tmp.insert({S.getSubReg(), 0});
253 if (!Reserved[R.Reg])
256 if (!Reserved[S.Reg])
275 SRs.insert({R.Reg, 0});
281 unsigned PReg = *RC.
begin();
284 SRs.insert({R.Reg, 0});
286 SRs.insert({R.Reg, I.getSubRegIndex()});
291 void HexagonBlockRanges::computeInitialLiveRanges(
InstrIndexMap &IndexMap,
293 std::map<RegisterRef,IndexType> LastDef, LastUse;
298 for (
auto R : getLiveIns(B, MRI, TRI))
299 LiveOnEntry.insert(R);
301 for (
auto R : LiveOnEntry)
304 auto closeRange = [&LastUse,&LastDef,&LiveMap] (
RegisterRef R) ->
void {
305 auto LD = LastDef[R], LU = LastUse[R];
310 LiveMap[R].add(
LD, LU,
false,
false);
317 if (
In.isDebugInstr())
321 for (
auto &
Op :
In.operands()) {
322 if (!
Op.isReg() || !
Op.isUse() ||
Op.isUndef())
327 bool IsKill =
Op.isKill();
337 for (
auto &
Op :
In.operands()) {
338 if (!
Op.isReg() || !
Op.isDef() ||
Op.isUndef())
351 for (
auto &
Op :
In.operands()) {
355 for (
unsigned PR = 1,
N = TRI.
getNumRegs(); PR !=
N; ++PR) {
363 if (BM[PR/32] & (1u << (PR%32)))
392 LastDef[S] = LastUse[S] =
Index;
399 for (
auto *SB : B.successors())
400 for (
auto R : getLiveIns(*SB, MRI, TRI))
401 LiveOnExit.insert(R);
403 for (
auto R : LiveOnExit)
408 for (
auto &
I : LastUse)
410 Left.insert(
I.first);
411 for (
auto &
I : LastDef)
413 Left.insert(
I.first);
418 for (
auto &
P : LiveMap)
425 LLVM_DEBUG(
dbgs() << __func__ <<
": index map\n" << IndexMap <<
'\n');
426 computeInitialLiveRanges(IndexMap, LiveMap);
436 auto addDeadRanges = [&IndexMap,&LiveMap,&DeadMap] (
RegisterRef R) ->
void {
437 auto F = LiveMap.find(R);
438 if (
F == LiveMap.end() ||
F->second.empty()) {
444 RangeList::iterator A = RL.begin(),
Z = RL.end()-1;
461 DeadMap[R].add(DS, DE,
false,
false);
477 for (
unsigned R = 1; R < NumRegs; ++R) {
479 if (Reserved[S.Reg] || Visited[S.Reg])
482 Visited[S.Reg] =
true;
485 for (
auto &
P : LiveMap)
487 addDeadRanges(
P.first);
508 OS <<
'[' << IR.
start() <<
':' << IR.
end() << (IR.
TiedEnd ?
'}' :
']');
523 for (
auto &
In : M.Block) {
525 OS << Idx << (Idx == M.
Last ?
". " :
" ") <<
In;
532 for (
auto &
I : P.Map) {
534 OS <<
printReg(
I.first.Reg, &P.TRI,
I.first.Sub) <<
" -> " << RL <<
"\n";
MachineBasicBlock & getBlock() const
MachineInstr * getInstr(IndexType Idx) const
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
This class represents lattice values for constants.
iterator begin() const
begin/end - Return all of the registers in this class.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
static RegisterSet expandToSubRegs(RegisterRef R, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI)
unsigned const TargetRegisterInfo * TRI
std::set< RegisterRef > RegisterSet
std::map< RegisterRef, RangeList > RegToRangeMap
const HexagonInstrInfo * TII
Printable printReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
bool overlaps(const IndexRange &A) const
iterator_range< regclass_iterator > regclasses() const
zlib-gnu style compression
unsigned getSubRegIndex() const
Returns sub-register index of the current sub-register.
IndexType getNextIndex(IndexType Idx) const
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
Iterator that enumerates the sub-registers of a Reg and the associated sub-register indices...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MCSubRegIterator enumerates all sub-registers of Reg.
IndexType getIndex(MachineInstr *MI) const
void subtract(const IndexRange &Range)
void sort(IteratorTy Start, IteratorTy End)
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
void include(const RangeList &RL)
bool isValid() const
Returns true if this iterator is not yet at the end.
LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const
Return a bitmask representing the parts of a register that are covered by SubIdx. ...
IndexType getPrevIndex(IndexType Idx) const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
HexagonBlockRanges(MachineFunction &MF)
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
RegToRangeMap computeLiveMap(InstrIndexMap &IndexMap)
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
void merge(const IndexRange &A)
RegToRangeMap computeDeadMap(InstrIndexMap &IndexMap, RegToRangeMap &LiveMap)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
iterator_range< livein_iterator > liveins() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void unionize(bool MergeAdjacent=false)
This class implements an extremely fast bulk output stream that can only output to a stream...
void replaceInstr(MachineInstr *OldMI, MachineInstr *NewMI)
bool contains(const IndexRange &A) const
InstrIndexMap(MachineBasicBlock &B)
Statically lint checks LLVM IR
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.