30#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()) {
74 for (
const auto &R : RL)
88 while (Iter != end()-1) {
92 bool Merge = MergeAdjacent && (Iter->end() ==
Next->start());
103void HexagonBlockRanges::RangeList::addsub(
const IndexRange &
A,
107 if (!
A.overlaps(
B)) {
113 IndexType AS =
A.start(), AE =
A.end();
114 IndexType BS =
B.start(), BE =
B.end();
126 add(AS, BS,
A.Fixed,
false);
132 add(BS, AE,
A.Fixed,
false);
134 add(BE, AE,
A.Fixed,
false);
160 if (In.isDebugInstr())
163 Map.insert(std::make_pair(Idx, &In));
170 auto F = Map.find(Idx);
171 return (
F != Map.end()) ?
F->second :
nullptr;
176 for (
const auto &
I : Map)
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)
236 for (
auto I :
B.liveins()) {
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();
244 if ((
I.LaneMask & TRI.getSubRegIndexLaneMask(SI)).any())
245 Tmp.insert({S.getSubReg(), 0});
250 if (!Reserved[
R.Reg])
253 if (!Reserved[S.Reg])
269 if (R.Reg.isPhysical()) {
270 if (TRI.subregs(R.Reg).empty())
271 SRs.insert({R.Reg, 0});
275 assert(R.Reg.isVirtual());
276 auto &RC = *
MRI.getRegClass(R.Reg);
277 unsigned PReg = *RC.begin();
280 SRs.insert({R.Reg, 0});
281 for (;
I.isValid(); ++
I)
282 SRs.insert({R.Reg, I.getSubRegIndex()});
287void HexagonBlockRanges::computeInitialLiveRanges(InstrIndexMap &IndexMap,
288 RegToRangeMap &LiveMap) {
289 std::map<RegisterRef,IndexType> LastDef, LastUse;
290 RegisterSet LiveOnEntry;
294 for (
auto R : getLiveIns(
B,
MRI,
TRI))
295 LiveOnEntry.insert(R);
297 for (
auto R : LiveOnEntry)
300 auto closeRange = [&LastUse,&LastDef,&LiveMap] (RegisterRef R) ->
void {
301 auto LD = LastDef[R], LU = LastUse[R];
306 LiveMap[R].add(LD, LU,
false,
false);
310 RegisterSet Defs, Clobbers;
313 if (In.isDebugInstr())
315 IndexType Index = IndexMap.getIndex(&In);
317 for (
auto &
Op : In.operands()) {
318 if (!
Op.isReg() || !
Op.isUse() ||
Op.isUndef())
320 RegisterRef R = {
Op.getReg(),
Op.getSubReg() };
321 if (
R.Reg.isPhysical() && Reserved[
R.Reg])
323 bool IsKill =
Op.isKill();
333 for (
auto &
Op :
In.operands()) {
334 if (!
Op.isReg() || !
Op.isDef() ||
Op.isUndef())
338 if (S.Reg.isPhysical() && Reserved[S.Reg])
347 for (
auto &
Op :
In.operands()) {
350 const uint32_t *BM =
Op.getRegMask();
351 for (
unsigned PR = 1,
N = TRI.getNumRegs(); PR !=
N; ++PR) {
355 if (!TRI.subregs(PR).empty())
359 if (BM[PR/32] & (1u << (PR%32)))
374 assert(!S.Reg.isPhysical() || TRI.subregs(S.Reg).empty());
382 assert(!S.Reg.isPhysical() || TRI.subregs(S.Reg).empty());
386 LastDef[S] = LastUse[S] =
Index;
393 for (
auto *SB :
B.successors())
394 for (
auto R : getLiveIns(*SB,
MRI, TRI))
395 LiveOnExit.insert(R);
397 for (
auto R : LiveOnExit)
402 for (
auto &
I : LastUse)
404 Left.insert(
I.first);
405 for (
auto &
I : LastDef)
407 Left.insert(
I.first);
412 for (
auto &
P : LiveMap)
419 LLVM_DEBUG(
dbgs() << __func__ <<
": index map\n" << IndexMap <<
'\n');
420 computeInitialLiveRanges(IndexMap, LiveMap);
430 auto addDeadRanges = [&IndexMap,&LiveMap,&DeadMap] (
RegisterRef R) ->
void {
431 auto F = LiveMap.find(R);
432 if (
F == LiveMap.end() ||
F->second.empty()) {
438 RangeList::iterator
A = RL.begin(), Z = RL.end()-1;
455 DeadMap[R].add(DS, DE,
false,
false);
468 auto &
MRI = MF.getRegInfo();
469 unsigned NumRegs = TRI.getNumRegs();
471 for (
unsigned R = 1; R < NumRegs; ++R) {
473 if (Reserved[S.Reg] || Visited[S.Reg])
476 Visited[S.Reg] =
true;
479 for (
auto &
P : LiveMap)
480 if (
P.first.Reg.isVirtual())
481 addDeadRanges(
P.first);
502 OS <<
'[' <<
IR.start() <<
':' <<
IR.end() << (
IR.TiedEnd ?
'}' :
']');
510 for (
const auto &R : RL)
517 for (
auto &In : M.Block) {
519 OS << Idx << (Idx == M.Last ?
". " :
" ") << In;
526 for (
const auto &
I :
P.Map) {
528 OS <<
printReg(
I.first.Reg, &
P.TRI,
I.first.Sub) <<
" -> " << RL <<
"\n";
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements the BitVector class.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Legalize the Machine IR a function s Machine IR
Register const TargetRegisterInfo * TRI
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
void merge(const IndexRange &A)
bool overlaps(const IndexRange &A) const
bool contains(const IndexRange &A) const
void replaceInstr(MachineInstr *OldMI, MachineInstr *NewMI)
MachineBasicBlock & getBlock() const
IndexType getNextIndex(IndexType Idx) const
IndexType getPrevIndex(IndexType Idx) const
IndexType getIndex(MachineInstr *MI) const
InstrIndexMap(MachineBasicBlock &B)
MachineInstr * getInstr(IndexType Idx) const
void subtract(const IndexRange &Range)
void include(const RangeList &RL)
void unionize(bool MergeAdjacent=false)
Iterator that enumerates the sub-registers of a Reg and the associated sub-register indices.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
FunctionAddr VTableAddr Next
DWARFExpression::Operation Op
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
RegToRangeMap computeLiveMap(InstrIndexMap &IndexMap)
std::set< RegisterRef > RegisterSet
static RegisterSet expandToSubRegs(RegisterRef R, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI)
RegToRangeMap computeDeadMap(InstrIndexMap &IndexMap, RegToRangeMap &LiveMap)
HexagonBlockRanges(MachineFunction &MF)
std::map< RegisterRef, RangeList > RegToRangeMap