llvm.org GIT mirror llvm / b5af2d9
Specify SubRegIndex components on the index itself. It is simpler to define a composite index directly: def ssub_2 : SubRegIndex<[dsub_1, ssub_0]>; def ssub_3 : SubRegIndex<[dsub_1, ssub_1]>; Than specifying the composite indices on each register: CompositeIndices = [(ssub_2 dsub_1, ssub_0), (ssub_3 dsub_1, ssub_1)] in ... This also makes it clear that SubRegIndex composition is supposed to be unique. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149556 91177308-0d34-0410-b5e6-96231b3b80d8 Jakob Stoklund Olesen 7 years ago
3 changed file(s) with 83 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
2121 class RegisterClass; // Forward def
2222
2323 // SubRegIndex - Use instances of SubRegIndex to identify subregisters.
24 class SubRegIndex {
24 class SubRegIndex comps = []> {
2525 string Namespace = "";
26
27 // ComposedOf - A list of two SubRegIndex instances, [A, B].
28 // This indicates that this SubRegIndex is the result of composing A and B.
29 list ComposedOf = comps;
2630 }
2731
2832 // RegAltNameIndex - The alternate name set to use for register operands of
4646 N += "::";
4747 N += getName();
4848 return N;
49 }
50
51 void CodeGenSubRegIndex::updateComponents(CodeGenRegBank &RegBank) {
52 std::vector Comps = TheDef->getValueAsListOfDefs("ComposedOf");
53 if (Comps.empty())
54 return;
55 if (Comps.size() != 2)
56 throw TGError(TheDef->getLoc(), "ComposedOf must have exactly two entries");
57 CodeGenSubRegIndex *A = RegBank.getSubRegIdx(Comps[0]);
58 CodeGenSubRegIndex *B = RegBank.getSubRegIdx(Comps[1]);
59 CodeGenSubRegIndex *X = A->addComposite(B, this);
60 if (X)
61 throw TGError(TheDef->getLoc(), "Ambiguous ComposedOf entries");
4962 }
5063
5164 void CodeGenSubRegIndex::cleanComposites() {
7487 return TheDef->getName();
7588 }
7689
77 namespace {
78 struct Orphan {
79 CodeGenRegister *SubReg;
80 CodeGenSubRegIndex *First, *Second;
81 Orphan(CodeGenRegister *r, CodeGenSubRegIndex *a, CodeGenSubRegIndex *b)
82 : SubReg(r), First(a), Second(b) {}
83 };
84 }
85
8690 const CodeGenRegister::SubRegMap &
8791 CodeGenRegister::getSubRegs(CodeGenRegBank &RegBank) {
8892 // Only compute this map once.
9195 SubRegsComplete = true;
9296
9397 std::vector SubList = TheDef->getValueAsListOfDefs("SubRegs");
94 std::vector Indices = TheDef->getValueAsListOfDefs("SubRegIndices");
95 if (SubList.size() != Indices.size())
98 std::vector IdxList = TheDef->getValueAsListOfDefs("SubRegIndices");
99 if (SubList.size() != IdxList.size())
96100 throw TGError(TheDef->getLoc(), "Register " + getName() +
97101 " SubRegIndices doesn't match SubRegs");
98102
99103 // First insert the direct subregs and make sure they are fully indexed.
104 SmallVector Indices;
100105 for (unsigned i = 0, e = SubList.size(); i != e; ++i) {
101106 CodeGenRegister *SR = RegBank.getReg(SubList[i]);
102 CodeGenSubRegIndex *Idx = RegBank.getSubRegIdx(Indices[i]);
107 CodeGenSubRegIndex *Idx = RegBank.getSubRegIdx(IdxList[i]);
108 Indices.push_back(Idx);
103109 if (!SubRegs.insert(std::make_pair(Idx, SR)).second)
104110 throw TGError(TheDef->getLoc(), "SubRegIndex " + Idx->getName() +
105111 " appears twice in Register " + getName());
106112 }
107113
108114 // Keep track of inherited subregs and how they can be reached.
109 SmallVector Orphans;
110
111 // Clone inherited subregs and place duplicate entries on Orphans.
115 SmallPtrSet Orphans;
116
117 // Clone inherited subregs and place duplicate entries in Orphans.
112118 // Here the order is important - earlier subregs take precedence.
113119 for (unsigned i = 0, e = SubList.size(); i != e; ++i) {
114120 CodeGenRegister *SR = RegBank.getReg(SubList[i]);
115 CodeGenSubRegIndex *Idx = RegBank.getSubRegIdx(Indices[i]);
116121 const SubRegMap &Map = SR->getSubRegs(RegBank);
117122
118123 // Add this as a super-register of SR now all sub-registers are in the list.
123128 for (SubRegMap::const_iterator SI = Map.begin(), SE = Map.end(); SI != SE;
124129 ++SI) {
125130 if (!SubRegs.insert(*SI).second)
126 Orphans.push_back(Orphan(SI->second, Idx, SI->first));
131 Orphans.insert(SI->second);
127132
128133 // Noop sub-register indexes are possible, so avoid duplicates.
129134 if (SI->second != SR)
130135 SI->second->SuperRegs.push_back(this);
136 }
137 }
138
139 // Expand any composed subreg indices.
140 // If dsub_2 has ComposedOf = [qsub_1, dsub_0], and this register has a
141 // qsub_1 subreg, add a dsub_2 subreg. Keep growing Indices and process
142 // expanded subreg indices recursively.
143 for (unsigned i = 0; i != Indices.size(); ++i) {
144 CodeGenSubRegIndex *Idx = Indices[i];
145 const CodeGenSubRegIndex::CompMap &Comps = Idx->getComposites();
146 CodeGenRegister *SR = SubRegs[Idx];
147 const SubRegMap &Map = SR->getSubRegs(RegBank);
148
149 // Look at the possible compositions of Idx.
150 // They may not all be supported by SR.
151 for (CodeGenSubRegIndex::CompMap::const_iterator I = Comps.begin(),
152 E = Comps.end(); I != E; ++I) {
153 SubRegMap::const_iterator SRI = Map.find(I->first);
154 if (SRI == Map.end())
155 continue; // Idx + I->first doesn't exist in SR.
156 // Add I->second as a name for the subreg SRI->second, assuming it is
157 // orphaned, and the name isn't already used for something else.
158 if (SubRegs.count(I->second) || !Orphans.erase(SRI->second))
159 continue;
160 // We found a new name for the orphaned sub-register.
161 SubRegs.insert(std::make_pair(I->second, SRI->second));
162 Indices.push_back(I->second);
131163 }
132164 }
133165
166198 SubRegs[BaseIdx] = R2;
167199
168200 // R2 is no longer an orphan.
169 for (unsigned j = 0, je = Orphans.size(); j != je; ++j)
170 if (Orphans[j].SubReg == R2)
171 Orphans[j].SubReg = 0;
201 Orphans.erase(R2);
172202 }
173203
174204 // Now Orphans contains the inherited subregisters without a direct index.
175205 // Create inferred indexes for all missing entries.
176 for (unsigned i = 0, e = Orphans.size(); i != e; ++i) {
177 Orphan &O = Orphans[i];
178 if (!O.SubReg)
179 continue;
180 SubRegs[RegBank.getCompositeSubRegIndex(O.First, O.Second)] =
181 O.SubReg;
206 // Work backwards in the Indices vector in order to compose subregs bottom-up.
207 // Consider this subreg sequence:
208 //
209 // qsub_1 -> dsub_0 -> ssub_0
210 //
211 // The qsub_1 -> dsub_0 composition becomes dsub_2, so the ssub_0 register
212 // can be reached in two different ways:
213 //
214 // qsub_1 -> ssub_0
215 // dsub_2 -> ssub_0
216 //
217 // We pick the latter composition because another register may have [dsub_0,
218 // dsub_1, dsub_2] subregs without neccessarily having a qsub_1 subreg. The
219 // dsub_2 -> ssub_0 composition can be shared.
220 while (!Indices.empty() && !Orphans.empty()) {
221 CodeGenSubRegIndex *Idx = Indices.pop_back_val();
222 CodeGenRegister *SR = SubRegs[Idx];
223 const SubRegMap &Map = SR->getSubRegs(RegBank);
224 for (SubRegMap::const_iterator SI = Map.begin(), SE = Map.end(); SI != SE;
225 ++SI)
226 if (Orphans.erase(SI->second))
227 SubRegs[RegBank.getCompositeSubRegIndex(Idx, SI->first)] = SI->second;
182228 }
183229 return SubRegs;
184230 }
589635 NumNamedIndices = SRIs.size();
590636 for (unsigned i = 0, e = SRIs.size(); i != e; ++i)
591637 getSubRegIdx(SRIs[i]);
638 // Build composite maps from ComposedOf fields.
639 for (unsigned i = 0, e = SubRegIndices.size(); i != e; ++i)
640 SubRegIndices[i]->updateComponents(*this);
592641
593642 // Read in the register definitions.
594643 std::vector Regs = Records.getAllDerivedDefinitions("Register");
6969 Composed.insert(std::make_pair(A, B));
7070 return (Ins.second || Ins.first->second == B) ? 0 : Ins.first->second;
7171 }
72
73 // Update the composite maps of components specified in 'ComposedOf'.
74 void updateComponents(CodeGenRegBank&);
7275
7376 // Clean out redundant composite mappings.
7477 void cleanComposites();