@@ -206,6 +206,23 @@ unsigned int LowerGEPForPrivMem::extractAllocaSize(llvm::AllocaInst* pAlloca)
206
206
return totalArrayStructureSize;
207
207
}
208
208
209
+ static void GetAllocaLiverange (Instruction* I, unsigned int & liverangeStart, unsigned int & liverangeEnd, RegisterPressureEstimate* rpe)
210
+ {
211
+ for (Value::user_iterator use_it = I->user_begin (), use_e = I->user_end (); use_it != use_e; ++use_it)
212
+ {
213
+ if (isa<GetElementPtrInst>(*use_it) || isa<BitCastInst>(*use_it))
214
+ {
215
+ GetAllocaLiverange (cast<Instruction>(*use_it), liverangeStart, liverangeEnd, rpe);
216
+ }
217
+ else if (isa<LoadInst>(*use_it) || isa<StoreInst>(*use_it) || isa<llvm::IntrinsicInst>(*use_it))
218
+ {
219
+ unsigned int idx = rpe->getAssignedNumberForInst (cast<Instruction>(*use_it));
220
+ liverangeStart = std::min (liverangeStart, idx);
221
+ liverangeEnd = std::max (liverangeEnd, idx);
222
+ }
223
+ }
224
+ }
225
+
209
226
bool LowerGEPForPrivMem::CheckIfAllocaPromotable (llvm::AllocaInst* pAlloca)
210
227
{
211
228
auto WI = &getAnalysis<WIAnalysis>();
@@ -261,24 +278,15 @@ bool LowerGEPForPrivMem::CheckIfAllocaPromotable(llvm::AllocaInst* pAlloca)
261
278
262
279
// get all the basic blocks that contain the uses of the alloca
263
280
// then estimate how much changing this alloca to register adds to the pressure at that block.
264
- unsigned int assignedNumber = 0 ;
265
- unsigned int lowestAssignedNumber = m_pRegisterPressureEstimate->getMaxAssignedNumberForFunction ();
281
+ unsigned int lowestAssignedNumber = 0xFFFFFFFF ;
266
282
unsigned int highestAssignedNumber = 0 ;
267
283
268
- for (auto II = pAlloca->user_begin (), IE = pAlloca->user_end (); II != IE; ++II)
269
- {
270
- if (Instruction* inst = dyn_cast<Instruction>(*II))
271
- {
272
- assignedNumber = m_pRegisterPressureEstimate->getAssignedNumberForInst (inst);
273
- lowestAssignedNumber = (lowestAssignedNumber < assignedNumber) ? lowestAssignedNumber : assignedNumber;
274
- highestAssignedNumber = (highestAssignedNumber > assignedNumber) ? highestAssignedNumber : assignedNumber;
275
- }
276
- }
284
+ GetAllocaLiverange (pAlloca, lowestAssignedNumber, highestAssignedNumber, m_pRegisterPressureEstimate);
277
285
278
286
uint32_t maxGRFPressure = (uint32_t )(grfRatio * MAX_PRESSURE_GRF_NUM * 4 );
279
287
280
288
unsigned int pressure = 0 ;
281
- for (unsigned int i = lowestAssignedNumber; i < highestAssignedNumber; i++)
289
+ for (unsigned int i = lowestAssignedNumber; i <= highestAssignedNumber; i++)
282
290
{
283
291
pressure = std::max (
284
292
pressure, m_pRegisterPressureEstimate->getRegisterPressureForInstructionFromRPMap (i));
0 commit comments