llvm.org GIT mirror llvm / 0535028
Be careful when to add implicit kill / dead operands. Don't add them during / post reg-allocation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36458 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 13 years ago
2 changed file(s) with 41 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
146146 SmallVector *PHIVarInfo;
147147
148148 /// addRegisterKilled - We have determined MI kills a register. Look for the
149 /// operand that uses it and mark it as IsKill.
150 void addRegisterKilled(unsigned IncomingReg, MachineInstr *MI);
149 /// operand that uses it and mark it as IsKill. If AddIfNotFound is true,
150 /// add a implicit operand if it's not found. Returns true if the operand
151 /// exists / is added.
152 bool addRegisterKilled(unsigned IncomingReg, MachineInstr *MI,
153 bool AddIfNotFound = false);
151154
152155 /// addRegisterDead - We have determined MI defined a register without a use.
153 /// Look for the operand that defines it and mark it as IsDead.
154 void addRegisterDead(unsigned IncomingReg, MachineInstr *MI);
156 /// Look for the operand that defines it and mark it as IsDead. If
157 /// AddIfNotFound is true, add a implicit operand if it's not found. Returns
158 /// true if the operand exists / is added.
159 bool addRegisterDead(unsigned IncomingReg, MachineInstr *MI,
160 bool AddIfNotFound = false);
155161
156162 void HandlePhysRegUse(unsigned Reg, MachineInstr *MI);
157163 void HandlePhysRegDef(unsigned Reg, MachineInstr *MI);
188194
189195 /// addVirtualRegisterKilled - Add information about the fact that the
190196 /// specified register is killed after being used by the specified
191 /// instruction.
192 ///
193 void addVirtualRegisterKilled(unsigned IncomingReg, MachineInstr *MI) {
194 addRegisterKilled(IncomingReg, MI);
195 getVarInfo(IncomingReg).Kills.push_back(MI);
197 /// instruction. If AddIfNotFound is true, add a implicit operand if it's
198 /// not found.
199 void addVirtualRegisterKilled(unsigned IncomingReg, MachineInstr *MI,
200 bool AddIfNotFound = false) {
201 if (addRegisterKilled(IncomingReg, MI, AddIfNotFound))
202 getVarInfo(IncomingReg).Kills.push_back(MI);
196203 }
197204
198205 /// removeVirtualRegisterKilled - Remove the specified virtual
224231 void removeVirtualRegistersKilled(MachineInstr *MI);
225232
226233 /// addVirtualRegisterDead - Add information about the fact that the specified
227 /// register is dead after being used by the specified instruction.
228 ///
229 void addVirtualRegisterDead(unsigned IncomingReg, MachineInstr *MI) {
230 addRegisterDead(IncomingReg, MI);
231 getVarInfo(IncomingReg).Kills.push_back(MI);
234 /// register is dead after being used by the specified instruction. If
235 /// AddIfNotFound is true, add a implicit operand if it's not found.
236 void addVirtualRegisterDead(unsigned IncomingReg, MachineInstr *MI,
237 bool AddIfNotFound = false) {
238 if (addRegisterDead(IncomingReg, MI, AddIfNotFound))
239 getVarInfo(IncomingReg).Kills.push_back(MI);
232240 }
233241
234242 /// removeVirtualRegisterDead - Remove the specified virtual
169169 MarkVirtRegAliveInBlock(VRInfo, *PI);
170170 }
171171
172 void LiveVariables::addRegisterKilled(unsigned IncomingReg, MachineInstr *MI) {
172 bool LiveVariables::addRegisterKilled(unsigned IncomingReg, MachineInstr *MI,
173 bool AddIfNotFound) {
173174 bool Found = false;
174175 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
175176 MachineOperand &MO = MI->getOperand(i);
186187 RegInfo->isSuperRegister(IncomingReg, Reg) &&
187188 MO.isKill())
188189 // A super-register kill already exists.
189 return;
190 return true;
190191 }
191192 }
192193
193194 // If not found, this means an alias of one of the operand is killed. Add a
194 // new implicit operand.
195 if (!Found)
195 // new implicit operand if required.
196 if (!Found && AddIfNotFound) {
196197 MI->addRegOperand(IncomingReg, false/*IsDef*/,true/*IsImp*/,true/*IsKill*/);
197 }
198
199 void LiveVariables::addRegisterDead(unsigned IncomingReg, MachineInstr *MI) {
198 return true;
199 }
200 return Found;
201 }
202
203 bool LiveVariables::addRegisterDead(unsigned IncomingReg, MachineInstr *MI,
204 bool AddIfNotFound) {
200205 bool Found = false;
201206 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
202207 MachineOperand &MO = MI->getOperand(i);
213218 RegInfo->isSuperRegister(IncomingReg, Reg) &&
214219 MO.isDead())
215220 // There exists a super-register that's marked dead.
216 return;
221 return true;
217222 }
218223 }
219224
220225 // If not found, this means an alias of one of the operand is dead. Add a
221226 // new implicit operand.
222 if (!Found)
227 if (!Found && AddIfNotFound) {
223228 MI->addRegOperand(IncomingReg, true/*IsDef*/,true/*IsImp*/,false/*IsKill*/,
224229 true/*IsDead*/);
230 return true;
231 }
232 return Found;
225233 }
226234
227235 void LiveVariables::HandlePhysRegUse(unsigned Reg, MachineInstr *MI) {
270278 addRegisterKilled(Reg, LastRef);
271279 else if (PhysRegPartUse[Reg])
272280 // Add implicit use / kill to last use of a sub-register.
273 addRegisterKilled(Reg, PhysRegPartUse[Reg]);
281 addRegisterKilled(Reg, PhysRegPartUse[Reg], true);
274282 else
275 addRegisterDead(Reg, LastRef);
283 addRegisterDead(Reg, LastRef, true);
276284 }
277285 PhysRegInfo[Reg] = MI;
278286 PhysRegUsed[Reg] = false;