10 #define DEBUG_TYPE "hbr"
37 bool SbAE = (S < AE) || (S == AE && A.
TiedEnd);
38 bool ASbE = (AS <
E) || (AS ==
E &&
TiedEnd);
39 if ((AS < S && SbAE) || (S < AS && ASbE))
46 if (start() <= A.
start()) {
86 iterator Iter =
begin();
88 while (Iter !=
end()-1) {
89 iterator Next = std::next(Iter);
92 bool Merge = MergeAdjacent && (Iter->end() == Next->start());
93 if (Merge || Iter->overlaps(*Next)) {
103 void HexagonBlockRanges::RangeList::addsub(
const IndexRange &
A,
113 IndexType AS = A.
start(), AE = A.
end();
114 IndexType BS = B.
start(), BE = B.
end();
143 for (iterator Next,
I =
begin();
I !=
end();
I = Next) {
147 Next = this->erase(
I);
160 if (
In.isDebugValue())
163 Map.insert(std::make_pair(Idx, &
In));
170 auto F = Map.find(Idx);
171 return (
F != Map.end()) ?
F->second :
nullptr;
206 for (
auto &
I : Map) {
207 if (
I.second != OldMI)
209 if (NewMI !=
nullptr)
219 TII(*HST.getInstrInfo()), TRI(*HST.getRegisterInfo()),
220 Reserved(TRI.getReservedRegs(mf)) {
223 if (RC->isAllocatable())
225 for (
unsigned R : *RC)
238 if (
I.LaneMask.all() || (
I.LaneMask.any() && !S.isValid())) {
239 Tmp.insert({
I.PhysReg, 0});
242 for (; S.isValid(); ++S) {
243 unsigned SI = S.getSubRegIndex();
245 Tmp.insert({S.getSubReg(), 0});
250 if (!Reserved[R.Reg])
252 for (
auto S : expandToSubRegs(R, MRI, TRI))
253 if (!Reserved[S.Reg])
272 SRs.insert({R.
Reg, 0});
273 for (;
I.isValid(); ++
I)
278 unsigned PReg = *RC.
begin();
281 SRs.insert({R.Reg, 0});
282 for (;
I.isValid(); ++
I)
283 SRs.insert({R.Reg,
I.getSubRegIndex()});
288 void HexagonBlockRanges::computeInitialLiveRanges(InstrIndexMap &IndexMap,
289 RegToRangeMap &LiveMap) {
290 std::map<RegisterRef,IndexType> LastDef, LastUse;
295 for (
auto R : getLiveIns(B, MRI, TRI))
296 LiveOnEntry.insert(R);
298 for (
auto R : LiveOnEntry)
301 auto closeRange = [&LastUse,&LastDef,&LiveMap] (RegisterRef R) ->
void {
302 auto LD = LastDef[R], LU = LastUse[R];
307 LiveMap[R].add(
LD, LU,
false,
false);
314 if (
In.isDebugValue())
316 IndexType Index = IndexMap.getIndex(&
In);
318 for (
auto &
Op :
In.operands()) {
319 if (!
Op.isReg() || !
Op.isUse() ||
Op.isUndef())
321 RegisterRef R = {
Op.getReg(),
Op.getSubReg() };
324 bool IsKill =
Op.isKill();
334 for (
auto &
Op :
In.operands()) {
335 if (!
Op.isReg() || !
Op.isDef() ||
Op.isUndef())
337 RegisterRef R = {
Op.getReg(),
Op.getSubReg() };
348 for (
auto &
Op :
In.operands()) {
352 for (
unsigned PR = 1,
N = TRI.
getNumRegs(); PR !=
N; ++PR) {
360 if (BM[PR/32] & (1u << (PR%32)))
362 RegisterRef R = { PR, 0 };
369 for (RegisterRef R : Defs)
373 for (RegisterRef S : Defs) {
382 for (RegisterRef S : Clobbers) {
389 LastDef[S] = LastUse[S] = Index;
396 for (
auto *
SB : B.successors())
397 for (
auto R : getLiveIns(*
SB, MRI, TRI))
398 LiveOnExit.insert(R);
400 for (
auto R : LiveOnExit)
405 for (
auto &
I : LastUse)
407 Left.insert(
I.first);
408 for (
auto &
I : LastDef)
410 Left.insert(
I.first);
415 for (
auto &
P : LiveMap)
422 DEBUG(
dbgs() << __func__ <<
": index map\n" << IndexMap <<
'\n');
423 computeInitialLiveRanges(IndexMap, LiveMap);
424 DEBUG(
dbgs() << __func__ <<
": live map\n"
433 auto addDeadRanges = [&IndexMap,&LiveMap,&DeadMap] (
RegisterRef R) ->
void {
434 auto F = LiveMap.find(R);
435 if (
F == LiveMap.end() ||
F->second.empty()) {
441 RangeList::iterator A = RL.begin(),
Z = RL.end()-1;
458 DeadMap[R].add(DS, DE,
false,
false);
474 for (
unsigned R = 1; R < NumRegs; ++R) {
476 if (Reserved[S.Reg] || Visited[S.Reg])
479 Visited[S.Reg] =
true;
482 for (
auto &
P : LiveMap)
484 addDeadRanges(
P.first);
486 DEBUG(
dbgs() << __func__ <<
": dead map\n"
505 OS <<
'[' << IR.
start() <<
':' << IR.
end() << (IR.
TiedEnd ?
'}' :
']');
520 for (
auto &
In : M.Block) {
522 OS << Idx << (Idx == M.
Last ?
". " :
" ") <<
In;
529 for (
auto &
I : P.Map) {
531 OS <<
PrintReg(
I.first.Reg, &P.TRI,
I.first.Sub) <<
" -> " << RL <<
"\n";
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const_iterator end(StringRef path)
Get end iterator over path.
iterator_range< livein_iterator > liveins() const
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
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)
LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const
Return a bitmask representing the parts of a register that are covered by SubIdx. ...
iterator_range< regclass_iterator > regclasses() const
std::set< RegisterRef > RegisterSet
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
iterator begin() const
begin/end - Return all of the registers in this class.
zlib-gnu style compression
bool overlaps(const IndexRange &A) const
MachineBasicBlock & getBlock() const
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
IndexType getNextIndex(IndexType Idx) const
Printable PrintReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubRegIdx=0)
Prints virtual and physical registers with or without a TRI instance.
INITIALIZE_PASS(HexagonEarlyIfConversion,"hexagon-eif","Hexagon early if conversion", false, false) bool HexagonEarlyIfConversion MachineBasicBlock * SB
MachineInstr * getInstr(IndexType Idx) const
unsigned const MachineRegisterInfo * MRI
Iterator that enumerates the sub-registers of a Reg and the associated sub-register indices...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MCSubRegIterator enumerates all sub-registers of Reg.
void subtract(const IndexRange &Range)
void include(const RangeList &RL)
static void Merge(const std::string &Input, const std::vector< std::string > Result, size_t NumNewFeatures)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
HexagonBlockRanges(MachineFunction &MF)
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
IndexType getPrevIndex(IndexType Idx) const
Representation of each machine instruction.
bool contains(const IndexRange &A) const
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
RegToRangeMap computeLiveMap(InstrIndexMap &IndexMap)
std::map< RegisterRef, RangeList > RegToRangeMap
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
IndexType getIndex(MachineInstr *MI) const
void merge(const IndexRange &A)
RegToRangeMap computeDeadMap(InstrIndexMap &IndexMap, RegToRangeMap &LiveMap)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
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 sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
void replaceInstr(MachineInstr *OldMI, MachineInstr *NewMI)
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.