| OLD | NEW |
| 1 //===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===// | 1 //===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 /// | 9 /// |
| 10 /// \file | 10 /// \file |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 TimerMarker T(TimerStack::TT_doArgLowering, this); | 450 TimerMarker T(TimerStack::TT_doArgLowering, this); |
| 451 getTarget()->lowerArguments(); | 451 getTarget()->lowerArguments(); |
| 452 } | 452 } |
| 453 | 453 |
| 454 void Cfg::sortAllocas(CfgVector<Inst *> &Allocas, InstList &Insts, | 454 void Cfg::sortAllocas(CfgVector<Inst *> &Allocas, InstList &Insts, |
| 455 bool IsKnownFrameOffset) { | 455 bool IsKnownFrameOffset) { |
| 456 if (Allocas.empty()) | 456 if (Allocas.empty()) |
| 457 return; | 457 return; |
| 458 // Sort by decreasing alignment. This does not really matter at the moment, | 458 // Sort by decreasing alignment. This does not really matter at the moment, |
| 459 // but will allow compacting stack allocation when we fuse to one alloca. | 459 // but will allow compacting stack allocation when we fuse to one alloca. |
| 460 std::sort(Allocas.begin(), Allocas.end(), | 460 std::sort(Allocas.begin(), Allocas.end(), [](Inst *I1, Inst *I2) { |
| 461 [](Inst *I1, Inst *I2) { | 461 auto *A1 = llvm::dyn_cast<InstAlloca>(I1); |
| 462 auto *A1 = llvm::dyn_cast<InstAlloca>(I1); | 462 auto *A2 = llvm::dyn_cast<InstAlloca>(I2); |
| 463 auto *A2 = llvm::dyn_cast<InstAlloca>(I2); | 463 return A1->getAlignInBytes() > A2->getAlignInBytes(); |
| 464 return A1->getAlignInBytes() > A2->getAlignInBytes(); | 464 }); |
| 465 }); | 465 for (Inst *Instr : Allocas) { |
| 466 for (Inst *Instr: Allocas) { | |
| 467 auto *Alloca = llvm::cast<InstAlloca>(Instr); | 466 auto *Alloca = llvm::cast<InstAlloca>(Instr); |
| 468 // Move the alloca to its sorted position. | 467 // Move the alloca to its sorted position. |
| 469 InstAlloca *NewAlloca = InstAlloca::create(this, | 468 InstAlloca *NewAlloca = |
| 470 Alloca->getSizeInBytes(), | 469 InstAlloca::create(this, Alloca->getSizeInBytes(), |
| 471 Alloca->getAlignInBytes(), | 470 Alloca->getAlignInBytes(), Alloca->getDest()); |
| 472 Alloca->getDest()); | |
| 473 if (IsKnownFrameOffset) | 471 if (IsKnownFrameOffset) |
| 474 NewAlloca->setKnownFrameOffset(); | 472 NewAlloca->setKnownFrameOffset(); |
| 475 Insts.push_front(NewAlloca); | 473 Insts.push_front(NewAlloca); |
| 476 Alloca->setDeleted(); | 474 Alloca->setDeleted(); |
| 477 } | 475 } |
| 478 } | 476 } |
| 479 | 477 |
| 480 void Cfg::processAllocas() { | 478 void Cfg::processAllocas() { |
| 481 const uint32_t StackAlignment = getTarget()->getStackAlignment(); | 479 const uint32_t StackAlignment = getTarget()->getStackAlignment(); |
| 482 CfgNode *EntryNode = getEntryNode(); | 480 CfgNode *EntryNode = getEntryNode(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 499 } | 497 } |
| 500 uint32_t AlignmentParam = Alloca->getAlignInBytes(); | 498 uint32_t AlignmentParam = Alloca->getAlignInBytes(); |
| 501 // For default align=0, set it to the real value 1, to avoid any | 499 // For default align=0, set it to the real value 1, to avoid any |
| 502 // bit-manipulation problems below. | 500 // bit-manipulation problems below. |
| 503 AlignmentParam = std::max(AlignmentParam, 1u); | 501 AlignmentParam = std::max(AlignmentParam, 1u); |
| 504 assert(llvm::isPowerOf2_32(AlignmentParam)); | 502 assert(llvm::isPowerOf2_32(AlignmentParam)); |
| 505 if (AlignmentParam > StackAlignment) { | 503 if (AlignmentParam > StackAlignment) { |
| 506 // Allocations aligned more than the stack require a frame pointer. | 504 // Allocations aligned more than the stack require a frame pointer. |
| 507 RequiresFramePointer = true; | 505 RequiresFramePointer = true; |
| 508 AlignedAllocas.push_back(Alloca); | 506 AlignedAllocas.push_back(Alloca); |
| 509 } | 507 } else |
| 510 else | |
| 511 FixedAllocas.push_back(Alloca); | 508 FixedAllocas.push_back(Alloca); |
| 512 } | 509 } |
| 513 } | 510 } |
| 514 // Look for alloca instructions in other blocks | 511 // Look for alloca instructions in other blocks |
| 515 for (CfgNode *Node : Nodes) { | 512 for (CfgNode *Node : Nodes) { |
| 516 if (Node == EntryNode) | 513 if (Node == EntryNode) |
| 517 continue; | 514 continue; |
| 518 for (Inst &Instr : Node->getInsts()) { | 515 for (Inst &Instr : Node->getInsts()) { |
| 519 if (llvm::isa<InstAlloca>(&Instr)) { | 516 if (llvm::isa<InstAlloca>(&Instr)) { |
| 520 // Allocations outside the entry block require a frame pointer. | 517 // Allocations outside the entry block require a frame pointer. |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 } | 895 } |
| 899 } | 896 } |
| 900 // Print each basic block | 897 // Print each basic block |
| 901 for (CfgNode *Node : Nodes) | 898 for (CfgNode *Node : Nodes) |
| 902 Node->dump(this); | 899 Node->dump(this); |
| 903 if (isVerbose(IceV_Instructions)) | 900 if (isVerbose(IceV_Instructions)) |
| 904 Str << "}\n"; | 901 Str << "}\n"; |
| 905 } | 902 } |
| 906 | 903 |
| 907 } // end of namespace Ice | 904 } // end of namespace Ice |
| OLD | NEW |