aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--utils/TableGen/CodeGenRegisters.cpp41
-rw-r--r--utils/TableGen/CodeGenRegisters.h37
-rw-r--r--utils/TableGen/RegisterInfoEmitter.cpp3
3 files changed, 51 insertions, 30 deletions
diff --git a/utils/TableGen/CodeGenRegisters.cpp b/utils/TableGen/CodeGenRegisters.cpp
index 3b15d06..7c66617 100644
--- a/utils/TableGen/CodeGenRegisters.cpp
+++ b/utils/TableGen/CodeGenRegisters.cpp
@@ -49,6 +49,16 @@ std::string CodeGenSubRegIndex::getQualifiedName() const {
return N;
}
+void CodeGenSubRegIndex::cleanComposites() {
+ // Clean out redundant mappings of the form this+X -> X.
+ for (CompMap::iterator i = Composed.begin(), e = Composed.end(); i != e;) {
+ CompMap::iterator j = i;
+ ++i;
+ if (j->first == j->second)
+ Composed.erase(j);
+ }
+}
+
//===----------------------------------------------------------------------===//
// CodeGenRegister
//===----------------------------------------------------------------------===//
@@ -168,7 +178,7 @@ CodeGenRegister::getSubRegs(CodeGenRegBank &RegBank) {
Orphan &O = Orphans[i];
if (!O.SubReg)
continue;
- SubRegs[RegBank.getCompositeSubRegIndex(O.First, O.Second, true)] =
+ SubRegs[RegBank.getCompositeSubRegIndex(O.First, O.Second)] =
O.SubReg;
}
return SubRegs;
@@ -679,16 +689,16 @@ CodeGenRegisterClass *CodeGenRegBank::getRegClass(Record *Def) {
CodeGenSubRegIndex*
CodeGenRegBank::getCompositeSubRegIndex(CodeGenSubRegIndex *A,
- CodeGenSubRegIndex *B,
- bool create) {
+ CodeGenSubRegIndex *B) {
// Look for an existing entry.
- CodeGenSubRegIndex *&Comp = Composite[std::make_pair(A, B)];
- if (Comp || !create)
+ CodeGenSubRegIndex *Comp = A->compose(B);
+ if (Comp)
return Comp;
// None exists, synthesize one.
std::string Name = A->getName() + "_then_" + B->getName();
Comp = getSubRegIdx(new Record(Name, SMLoc(), Records));
+ A->addComposite(B, Comp);
return Comp;
}
@@ -707,8 +717,7 @@ void CodeGenRegBank::computeComposites() {
// Try composing Idx1 with another SubRegIndex.
for (CodeGenRegister::SubRegMap::const_iterator i2 = SRM2.begin(),
e2 = SRM2.end(); i2 != e2; ++i2) {
- std::pair<CodeGenSubRegIndex*, CodeGenSubRegIndex*>
- IdxPair(Idx1, i2->first);
+ CodeGenSubRegIndex *Idx2 = i2->first;
CodeGenRegister *Reg3 = i2->second;
// Ignore identity compositions.
if (Reg2 == Reg3)
@@ -717,16 +726,13 @@ void CodeGenRegBank::computeComposites() {
for (CodeGenRegister::SubRegMap::const_iterator i1d = SRM1.begin(),
e1d = SRM1.end(); i1d != e1d; ++i1d) {
if (i1d->second == Reg3) {
- std::pair<CompositeMap::iterator, bool> Ins =
- Composite.insert(std::make_pair(IdxPair, i1d->first));
// Conflicting composition? Emit a warning but allow it.
- if (!Ins.second && Ins.first->second != i1d->first) {
+ if (CodeGenSubRegIndex *Prev = Idx1->addComposite(Idx2, i1d->first))
errs() << "Warning: SubRegIndex " << Idx1->getQualifiedName()
- << " and " << IdxPair.second->getQualifiedName()
+ << " and " << Idx2->getQualifiedName()
<< " compose ambiguously as "
- << Ins.first->second->getQualifiedName() << " or "
+ << Prev->getQualifiedName() << " or "
<< i1d->first->getQualifiedName() << "\n";
- }
}
}
}
@@ -735,13 +741,8 @@ void CodeGenRegBank::computeComposites() {
// We don't care about the difference between (Idx1, Idx2) -> Idx2 and invalid
// compositions, so remove any mappings of that form.
- for (CompositeMap::iterator i = Composite.begin(), e = Composite.end();
- i != e;) {
- CompositeMap::iterator j = i;
- ++i;
- if (j->first.second == j->second)
- Composite.erase(j);
- }
+ for (unsigned i = 0, e = SubRegIndices.size(); i != e; ++i)
+ SubRegIndices[i]->cleanComposites();
}
// Compute sets of overlapping registers.
diff --git a/utils/TableGen/CodeGenRegisters.h b/utils/TableGen/CodeGenRegisters.h
index 7b96bd5..b83ad6e 100644
--- a/utils/TableGen/CodeGenRegisters.h
+++ b/utils/TableGen/CodeGenRegisters.h
@@ -51,6 +51,34 @@ namespace llvm {
return A->EnumValue < B->EnumValue;
}
};
+
+ // Map of composite subreg indices.
+ typedef std::map<CodeGenSubRegIndex*, CodeGenSubRegIndex*, Less> CompMap;
+
+ // Returns the subreg index that results from composing this with Idx.
+ // Returns NULL if this and Idx don't compose.
+ CodeGenSubRegIndex *compose(CodeGenSubRegIndex *Idx) const {
+ CompMap::const_iterator I = Composed.find(Idx);
+ return I == Composed.end() ? 0 : I->second;
+ }
+
+ // Add a composite subreg index: this+A = B.
+ // Return a conflicting composite, or NULL
+ CodeGenSubRegIndex *addComposite(CodeGenSubRegIndex *A,
+ CodeGenSubRegIndex *B) {
+ std::pair<CompMap::iterator, bool> Ins =
+ Composed.insert(std::make_pair(A, B));
+ return (Ins.second || Ins.first->second == B) ? 0 : Ins.first->second;
+ }
+
+ // Clean out redundant composite mappings.
+ void cleanComposites();
+
+ // Return the map of composites.
+ const CompMap &getComposites() const { return Composed; }
+
+ private:
+ CompMap Composed;
};
/// CodeGenRegister - Represents a register definition.
@@ -298,12 +326,6 @@ namespace llvm {
void inferMatchingSuperRegClass(CodeGenRegisterClass *RC,
unsigned FirstSubRegRC = 0);
- // Composite SubRegIndex instances.
- // Map (SubRegIndex, SubRegIndex) -> SubRegIndex.
- typedef DenseMap<std::pair<CodeGenSubRegIndex*, CodeGenSubRegIndex*>,
- CodeGenSubRegIndex*> CompositeMap;
- CompositeMap Composite;
-
// Populate the Composite map from sub-register relationships.
void computeComposites();
@@ -323,8 +345,7 @@ namespace llvm {
// Find or create a sub-register index representing the A+B composition.
CodeGenSubRegIndex *getCompositeSubRegIndex(CodeGenSubRegIndex *A,
- CodeGenSubRegIndex *B,
- bool create = false);
+ CodeGenSubRegIndex *B);
const std::vector<CodeGenRegister*> &getRegisters() { return Registers; }
diff --git a/utils/TableGen/RegisterInfoEmitter.cpp b/utils/TableGen/RegisterInfoEmitter.cpp
index 2734896..fb950d0 100644
--- a/utils/TableGen/RegisterInfoEmitter.cpp
+++ b/utils/TableGen/RegisterInfoEmitter.cpp
@@ -766,8 +766,7 @@ RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target,
bool Open = false;
for (unsigned j = 0; j != e; ++j) {
if (CodeGenSubRegIndex *Comp =
- RegBank.getCompositeSubRegIndex(SubRegIndices[i],
- SubRegIndices[j])) {
+ SubRegIndices[i]->compose(SubRegIndices[j])) {
if (!Open) {
OS << " case " << SubRegIndices[i]->getQualifiedName()
<< ": switch(IdxB) {\n default: return IdxB;\n";