forked from OSchip/llvm-project
Handle reference counts in one function: release().
This new function will decrement the reference count, and collapse a domain value when the last reference is gone. This simplifies DomainValue reference counting, and decouples it from the LiveRegs array. llvm-svn: 144131
This commit is contained in:
parent
08a558eeef
commit
1438e191bd
|
@ -139,7 +139,7 @@ private:
|
||||||
|
|
||||||
// DomainValue allocation.
|
// DomainValue allocation.
|
||||||
DomainValue *Alloc(int domain = -1);
|
DomainValue *Alloc(int domain = -1);
|
||||||
void Recycle(DomainValue*);
|
void release(DomainValue*);
|
||||||
|
|
||||||
// LiveRegs manipulations.
|
// LiveRegs manipulations.
|
||||||
void SetLiveReg(int rx, DomainValue *DV);
|
void SetLiveReg(int rx, DomainValue *DV);
|
||||||
|
@ -176,10 +176,19 @@ DomainValue *ExeDepsFix::Alloc(int domain) {
|
||||||
return dv;
|
return dv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExeDepsFix::Recycle(DomainValue *dv) {
|
/// release - Release a reference to DV. When the last reference is released,
|
||||||
assert(dv && "Cannot recycle NULL");
|
/// collapse if needed.
|
||||||
dv->clear();
|
void ExeDepsFix::release(DomainValue *DV) {
|
||||||
Avail.push_back(dv);
|
assert(DV && DV->Refs && "Bad DomainValue");
|
||||||
|
if (--DV->Refs)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// There are no more DV references. Collapse any contained instructions.
|
||||||
|
if (DV->AvailableDomains && !DV->isCollapsed())
|
||||||
|
Collapse(DV, DV->getFirstDomain());
|
||||||
|
|
||||||
|
DV->clear();
|
||||||
|
Avail.push_back(DV);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set LiveRegs[rx] = dv, updating reference counts.
|
/// Set LiveRegs[rx] = dv, updating reference counts.
|
||||||
|
@ -192,10 +201,8 @@ void ExeDepsFix::SetLiveReg(int rx, DomainValue *dv) {
|
||||||
|
|
||||||
if (LiveRegs[rx] == dv)
|
if (LiveRegs[rx] == dv)
|
||||||
return;
|
return;
|
||||||
if (LiveRegs[rx]) {
|
if (LiveRegs[rx])
|
||||||
assert(LiveRegs[rx]->Refs && "Bad refcount");
|
release(LiveRegs[rx]);
|
||||||
if (--LiveRegs[rx]->Refs == 0) Recycle(LiveRegs[rx]);
|
|
||||||
}
|
|
||||||
LiveRegs[rx] = dv;
|
LiveRegs[rx] = dv;
|
||||||
if (dv) ++dv->Refs;
|
if (dv) ++dv->Refs;
|
||||||
}
|
}
|
||||||
|
@ -205,12 +212,8 @@ void ExeDepsFix::Kill(int rx) {
|
||||||
assert(unsigned(rx) < NumRegs && "Invalid index");
|
assert(unsigned(rx) < NumRegs && "Invalid index");
|
||||||
if (!LiveRegs || !LiveRegs[rx]) return;
|
if (!LiveRegs || !LiveRegs[rx]) return;
|
||||||
|
|
||||||
// Before killing the last reference to an open DomainValue, collapse it to
|
release(LiveRegs[rx]);
|
||||||
// the first available domain.
|
LiveRegs[rx] = 0;
|
||||||
if (LiveRegs[rx]->Refs == 1 && !LiveRegs[rx]->isCollapsed())
|
|
||||||
Collapse(LiveRegs[rx], LiveRegs[rx]->getFirstDomain());
|
|
||||||
else
|
|
||||||
SetLiveReg(rx, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Force register rx into domain.
|
/// Force register rx into domain.
|
||||||
|
|
Loading…
Reference in New Issue