llvm.org GIT mirror llvm / e47feeb
Stack Coloring: Add support for multiple regions of the same slot, within a single basic block. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163507 91177308-0d34-0410-b5e6-96231b3b80d8 Nadav Rotem 7 years ago
2 changed file(s) with 62 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
350350 Finishes.clear();
351351 Finishes.resize(NumSlots);
352352
353 // Create the interval for the basic blocks with lifetime markers in them.
354 for (SmallVector::iterator it = Markers.begin(),
355 e = Markers.end(); it != e; ++it) {
356 MachineInstr *MI = *it;
357 if (MI->getParent() != MBB)
358 continue;
359
360 assert((MI->getOpcode() == TargetOpcode::LIFETIME_START ||
361 MI->getOpcode() == TargetOpcode::LIFETIME_END) &&
362 "Invalid Lifetime marker");
363
364 bool IsStart = MI->getOpcode() == TargetOpcode::LIFETIME_START;
365 MachineOperand &Mo = MI->getOperand(0);
366 int Slot = Mo.getIndex();
367 assert(Slot >= 0 && "Invalid slot");
368
369 SlotIndex ThisIndex = Indexes->getInstructionIndex(MI);
370
371 if (IsStart) {
372 if (!Starts[Slot].isValid() || Starts[Slot] > ThisIndex)
373 Starts[Slot] = ThisIndex;
374 } else {
375 if (!Finishes[Slot].isValid() || Finishes[Slot] < ThisIndex)
376 Finishes[Slot] = ThisIndex;
377 }
378 }
379
380 // Create the interval of the blocks that we previously found to be 'alive'.
353381 BitVector Alive = BlockLiveness[MBB].LiveIn;
354382 Alive |= BlockLiveness[MBB].LiveOut;
355383
356384 if (Alive.any()) {
357385 for (int pos = Alive.find_first(); pos != -1;
358386 pos = Alive.find_next(pos)) {
359 Starts[pos] = Indexes->getMBBStartIdx(MBB);
360 Finishes[pos] = Indexes->getMBBEndIdx(MBB);
361 }
362 }
363
364 for (SmallVector::iterator it = Markers.begin(),
365 e = Markers.end(); it != e; ++it) {
366 MachineInstr *MI = *it;
367 assert((MI->getOpcode() == TargetOpcode::LIFETIME_START ||
368 MI->getOpcode() == TargetOpcode::LIFETIME_END) &&
369 "Invalid Lifetime marker");
370
371 if (MI->getParent() == MBB) {
372 bool IsStart = MI->getOpcode() == TargetOpcode::LIFETIME_START;
373 MachineOperand &Mo = MI->getOperand(0);
374 int Slot = Mo.getIndex();
375 assert(Slot >= 0 && "Invalid slot");
376 if (IsStart) {
377 Starts[Slot] = Indexes->getInstructionIndex(MI);
378 } else {
379 Finishes[Slot] = Indexes->getInstructionIndex(MI);
380 }
387 if (!Starts[pos].isValid())
388 Starts[pos] = Indexes->getMBBStartIdx(MBB);
389 if (!Finishes[pos].isValid())
390 Finishes[pos] = Indexes->getMBBEndIdx(MBB);
381391 }
382392 }
383393
384394 for (unsigned i = 0; i < NumSlots; ++i) {
385 assert(!!Starts[i] == !!Finishes[i] && "Unmatched range");
386 if (Starts[i] == Finishes[i])
395 assert(Starts[i].isValid() == Finishes[i].isValid() && "Unmatched range");
396 if (!Starts[i].isValid())
387397 continue;
388398
389399 assert(Starts[i] && Finishes[i] && "Invalid interval");
296296 ret i32 0
297297 }
298298
299
300 ;YESCOLOR: multi_region_bb
301 ;NOCOLOR: multi_region_bb
302 define void @multi_region_bb() nounwind ssp {
303 entry:
304 %A.i1 = alloca [100 x i32], align 4
305 %B.i2 = alloca [100 x i32], align 4
306 %A.i = alloca [100 x i32], align 4
307 %B.i = alloca [100 x i32], align 4
308 %0 = bitcast [100 x i32]* %A.i to i8*
309 call void @llvm.lifetime.start(i64 -1, i8* %0) nounwind ; <---- start #1
310 %1 = bitcast [100 x i32]* %B.i to i8*
311 call void @llvm.lifetime.start(i64 -1, i8* %1) nounwind
312 call void @bar([100 x i32]* %A.i, [100 x i32]* %B.i) nounwind
313 call void @llvm.lifetime.end(i64 -1, i8* %0) nounwind
314 call void @llvm.lifetime.end(i64 -1, i8* %1) nounwind
315 %2 = bitcast [100 x i32]* %A.i1 to i8*
316 call void @llvm.lifetime.start(i64 -1, i8* %2) nounwind
317 %3 = bitcast [100 x i32]* %B.i2 to i8*
318 call void @llvm.lifetime.start(i64 -1, i8* %3) nounwind
319 call void @llvm.lifetime.start(i64 -1, i8* %0) nounwind ; <---- start #2
320 call void @bar([100 x i32]* %A.i1, [100 x i32]* %B.i2) nounwind
321 call void @llvm.lifetime.end(i64 -1, i8* %2) nounwind
322 call void @llvm.lifetime.end(i64 -1, i8* %0) nounwind
323 call void @llvm.lifetime.end(i64 -1, i8* %3) nounwind
324 ret void
325 }
326
299327 declare void @bar([100 x i32]* , [100 x i32]*) nounwind
300328
301329 declare void @llvm.lifetime.start(i64, i8* nocapture) nounwind