llvm.org GIT mirror llvm / 73ff512
Change MRegisterDesc::AliasSet, TargetInstrDescriptor::ImplicitDefs and TargetInstrDescriptor::ImplicitUses to always point to a null terminated array and never be null. So there is no need to check for pointer validity when iterating over those sets. Code that looked like: if (const unsigned* AS = TID.ImplicitDefs) { for (int i = 0; AS[i]; ++i) { // use AS[i] } } was changed to: for (const unsigned* AS = TID.ImplicitDefs; *AS; ++AS) { // use *AS } git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8960 91177308-0d34-0410-b5e6-96231b3b80d8 Alkis Evlogimenos 17 years ago
6 changed file(s) with 67 addition(s) and 51 deletion(s). Raw diff Collapse all Expand all
107107 if (PhysRegInfo[Reg]) {
108108 PhysRegInfo[Reg] = MI;
109109 PhysRegUsed[Reg] = true;
110 } else if (const unsigned *AliasSet = RegInfo->getAliasSet(Reg)) {
111 for (; unsigned NReg = AliasSet[0]; ++AliasSet)
112 if (MachineInstr *LastUse = PhysRegInfo[NReg]) {
113 PhysRegInfo[NReg] = MI;
114 PhysRegUsed[NReg] = true;
115 }
110 } else {
111 for (const unsigned *AliasSet = RegInfo->getAliasSet(Reg);
112 *AliasSet; ++AliasSet) {
113 if (MachineInstr *LastUse = PhysRegInfo[*AliasSet]) {
114 PhysRegInfo[*AliasSet] = MI;
115 PhysRegUsed[*AliasSet] = true;
116 }
117 }
116118 }
117119 }
118120
123125 RegistersKilled.insert(std::make_pair(LastUse, Reg));
124126 else
125127 RegistersDead.insert(std::make_pair(LastUse, Reg));
126 } else if (const unsigned *AliasSet = RegInfo->getAliasSet(Reg)) {
127 for (; unsigned NReg = AliasSet[0]; ++AliasSet)
128 if (MachineInstr *LastUse = PhysRegInfo[NReg]) {
129 if (PhysRegUsed[NReg])
130 RegistersKilled.insert(std::make_pair(LastUse, NReg));
128 } else {
129 for (const unsigned *AliasSet = RegInfo->getAliasSet(Reg);
130 *AliasSet; ++AliasSet) {
131 if (MachineInstr *LastUse = PhysRegInfo[*AliasSet]) {
132 if (PhysRegUsed[*AliasSet])
133 RegistersKilled.insert(std::make_pair(LastUse, *AliasSet));
131134 else
132 RegistersDead.insert(std::make_pair(LastUse, NReg));
133 PhysRegInfo[NReg] = 0; // Kill the aliased register
134 }
135 RegistersDead.insert(std::make_pair(LastUse, *AliasSet));
136 PhysRegInfo[*AliasSet] = 0; // Kill the aliased register
137 }
138 }
135139 }
136140 PhysRegInfo[Reg] = MI;
137141 PhysRegUsed[Reg] = false;
205209 NumOperandsToProcess = 1;
206210
207211 // Loop over implicit uses, using them.
208 if (const unsigned *ImplicitUses = MID.ImplicitUses)
209 for (unsigned i = 0; ImplicitUses[i]; ++i)
210 HandlePhysRegUse(ImplicitUses[i], MI);
212 for (const unsigned *ImplicitUses = MID.ImplicitUses;
213 *ImplicitUses; ++ImplicitUses)
214 HandlePhysRegUse(*ImplicitUses, MI);
211215
212216 // Process all explicit uses...
213217 for (unsigned i = 0; i != NumOperandsToProcess; ++i) {
126126 unsigned Reg = CSRegs[i];
127127 if (ModifiedRegs[Reg]) {
128128 RegsToSave.push_back(Reg); // If modified register...
129 } else if (const unsigned *AliasSet = RegInfo->getAliasSet(Reg))
130 for (unsigned j = 0; AliasSet[j]; ++j) // Check alias registers too...
131 if (ModifiedRegs[AliasSet[j]]) {
129 } else {
130 for (const unsigned *AliasSet = RegInfo->getAliasSet(Reg);
131 *AliasSet; ++AliasSet) { // Check alias registers too...
132 if (ModifiedRegs[*AliasSet]) {
132133 RegsToSave.push_back(Reg);
133134 break;
134135 }
136 }
137 }
135138 }
136139
137140 if (RegsToSave.empty())
119119 ///
120120 bool areRegsEqual(unsigned R1, unsigned R2) const {
121121 if (R1 == R2) return true;
122 if (const unsigned *AliasSet = RegInfo->getAliasSet(R2))
123 for (unsigned i = 0; AliasSet[i]; ++i)
124 if (AliasSet[i] == R1) return true;
122 for (const unsigned *AliasSet = RegInfo->getAliasSet(R2);
123 *AliasSet; ++AliasSet) {
124 if (*AliasSet == R1) return true;
125 }
125126 return false;
126127 }
127128
270271 if (PI != PhysRegsUsed.end()) { // Only spill it if it's used!
271272 if (PI->second || !OnlyVirtRegs)
272273 spillVirtReg(MBB, I, PI->second, PhysReg);
273 } else if (const unsigned *AliasSet = RegInfo->getAliasSet(PhysReg)) {
274 } else {
274275 // If the selected register aliases any other registers, we must make
275276 // sure that one of the aliases isn't alive...
276 for (unsigned i = 0; AliasSet[i]; ++i) {
277 PI = PhysRegsUsed.find(AliasSet[i]);
277 for (const unsigned *AliasSet = RegInfo->getAliasSet(PhysReg);
278 *AliasSet; ++AliasSet) {
279 PI = PhysRegsUsed.find(*AliasSet);
278280 if (PI != PhysRegsUsed.end()) // Spill aliased register...
279281 if (PI->second || !OnlyVirtRegs)
280 spillVirtReg(MBB, I, PI->second, AliasSet[i]);
282 spillVirtReg(MBB, I, PI->second, *AliasSet);
281283 }
282284 }
283285 }
307309
308310 // If the selected register aliases any other allocated registers, it is
309311 // not free!
310 if (const unsigned *AliasSet = RegInfo->getAliasSet(PhysReg))
311 for (unsigned i = 0; AliasSet[i]; ++i)
312 if (PhysRegsUsed.count(AliasSet[i])) // Aliased register in use?
313 return false; // Can't use this reg then.
312 for (const unsigned *AliasSet = RegInfo->getAliasSet(PhysReg);
313 *AliasSet; ++AliasSet)
314 if (PhysRegsUsed.count(*AliasSet)) // Aliased register in use?
315 return false; // Can't use this reg then.
314316 return true;
315317 }
316318
413415 } else {
414416 // If one of the registers aliased to the current register is
415417 // compatible, use it.
416 if (const unsigned *AliasSet = RegInfo->getAliasSet(R))
417 for (unsigned a = 0; AliasSet[a]; ++a)
418 if (RegInfo->getRegClass(AliasSet[a]) == RC) {
419 PhysReg = AliasSet[a]; // Take an aliased register
420 break;
421 }
418 for (const unsigned *AliasSet = RegInfo->getAliasSet(R);
419 *AliasSet; ++AliasSet) {
420 if (RegInfo->getRegClass(*AliasSet) == RC) {
421 PhysReg = *AliasSet; // Take an aliased register
422 break;
423 }
424 }
422425 }
423426 }
424427 }
484487
485488 // Loop over the implicit uses, making sure that they are at the head of the
486489 // use order list, so they don't get reallocated.
487 if (const unsigned *ImplicitUses = TID.ImplicitUses)
488 for (unsigned i = 0; ImplicitUses[i]; ++i)
489 MarkPhysRegRecentlyUsed(ImplicitUses[i]);
490 for (const unsigned *ImplicitUses = TID.ImplicitUses;
491 *ImplicitUses; ++ImplicitUses)
492 MarkPhysRegRecentlyUsed(*ImplicitUses);
490493
491494 // Get the used operands into registers. This has the potential to spill
492495 // incoming values if we are out of registers. Note that we completely
152152 // are used by the instruction (including implicit uses)
153153 unsigned Opcode = MI->getOpcode();
154154 const TargetInstrDescriptor &Desc = TM->getInstrInfo().get(Opcode);
155 if (const unsigned *Regs = Desc.ImplicitUses)
156 while (*Regs)
157 RegsUsed[*Regs++] = true;
158
159 if (const unsigned *Regs = Desc.ImplicitDefs)
160 while (*Regs)
161 RegsUsed[*Regs++] = true;
155 const unsigned *Regs = Desc.ImplicitUses;
156 while (*Regs)
157 RegsUsed[*Regs++] = true;
158
159 Regs = Desc.ImplicitDefs;
160 while (*Regs)
161 RegsUsed[*Regs++] = true;
162162
163163 // Loop over uses, move from memory into registers
164164 for (int i = MI->getNumOperands() - 1; i >= 0; --i) {
6464 std::vector Instructions =
6565 Records.getAllDerivedDefinitions("Instruction");
6666
67 // Emit empty implicit uses and defs lists
68 OS << "static const unsigned EmptyImpUses[] = { 0 };\n"
69 << "static const unsigned EmptyImpDefs[] = { 0 };\n";
70
6771 // Emit all of the instruction's implicit uses and defs...
6872 for (unsigned i = 0, e = Instructions.size(); i != e; ++i) {
6973 Record *Inst = Instructions[i];
112116 // Emit the implicit uses and defs lists...
113117 LI = R->getValueAsListInit("Uses");
114118 if (!LI->getSize())
115 OS << "0, ";
119 OS << "EmptyImpUses, ";
116120 else
117121 OS << R->getName() << "ImpUses, ";
118122
119123 LI = R->getValueAsListInit("Defs");
120124 if (!LI->getSize())
121 OS << "0 ";
125 OS << "EmptyImpDefs ";
122126 else
123127 OS << R->getName() << "ImpDefs ";
124128
137137 std::vector RegisterAliasesRecs =
138138 Records.getAllDerivedDefinitions("RegisterAliases");
139139 std::map > RegisterAliases;
140
140
141141 for (unsigned i = 0, e = RegisterAliasesRecs.size(); i != e; ++i) {
142142 Record *AS = RegisterAliasesRecs[i];
143143 Record *R = AS->getValueAsDef("Reg");
165165 if (!RegisterAliases.empty())
166166 OS << "\n\n // Register Alias Sets...\n";
167167
168 // Emit the empty alias list
169 OS << " const unsigned Empty_AliasSet[] = { 0 };\n";
168170 // Loop over all of the registers which have aliases, emitting the alias list
169171 // to memory.
170172 for (std::map >::iterator
191193 if (RegisterAliases.count(Reg))
192194 OS << Reg->getName() << "_AliasSet,\t";
193195 else
194 OS << "0,\t\t";
196 OS << "Empty_AliasSet,\t";
195197 OS << "0, 0 },\n";
196198 }
197199 OS << " };\n"; // End of register descriptors...