Lines Matching full:scope

128   // NumBranchesDelta weighted by the profile count at the scope entry.
171 // The next scope is appendable only if this scope is directly connected to
172 // it (which implies it post-dominates this scope) and this scope dominates
173 // it (no edge to the next scope outside this scope).
181 // There's an edge going into the entry of the next scope from outside
182 // of this scope.
211 // Split this scope at the boundary region into two, which will belong to the
242 auto *Scope = new CHRScope(TailRegInfos, TailSubs);
245 return Scope;
258 SmallVector<RegInfo, 8> RegInfos; // Regions that belong to this scope
266 // respectively. Used only for the outermost scope and includes regions in
274 // outermost scope and includes ones in subscopes.
296 for (CHRScope *Scope : Scopes) {
297 delete Scope;
309 if (CHRScope *Scope = findScopes(R, nullptr, nullptr, Output)) {
310 Output.push_back(Scope);
316 void checkScopeHoistable(CHRScope *Scope);
320 SmallVector<CHRScope *, 8> splitScope(CHRScope *Scope,
328 void classifyBiasedScopes(CHRScope *Scope, CHRScope *OutermostScope);
335 void setCHRRegions(CHRScope *Scope, CHRScope *OutermostScope);
341 void transformScopes(CHRScope *Scope, DenseSet<PHINode *> &TrivialPHIs);
342 void cloneScopeBlocks(CHRScope *Scope,
351 void fixupBranchesAndSelects(CHRScope *Scope, BasicBlock *PreEntryBlock,
353 void fixupBranch(Region *R, CHRScope *Scope, IRBuilder<> &IRB,
355 void fixupSelect(SelectInst *SI, CHRScope *Scope, IRBuilder<> &IRB,
358 Instruction *BranchOrSelect, CHRScope *Scope,
409 raw_ostream &operator<<(raw_ostream &OS, const CHRScope &Scope) {
410 Scope.print(OS);
486 // of the unhoistable base values defined within the scope (excluding the
489 // scope. The returned set doesn't include constants.
499 // We don't stop at a block that's not in the Scope because we would miss
506 // I is hoistable above the Scope.
714 // Find a CHR scope in the given region.
749 // scope and hoisting more branches.
857 // For example, for the following scope/region with selects, we want to insert
873 void CHR::checkScopeHoistable(CHRScope *Scope) {
874 RegInfo &RI = Scope->RegInfos[0];
991 CHR_DEBUG(dbgs() << "Subregion Scope " << *SubCHRScope << "\n");
993 CHR_DEBUG(dbgs() << "Subregion Scope null\n");
1038 // Determine whether to split a scope depending on the sets of the branch
1040 // (return true) it if 1) the condition values of the inner/lower scope can't be
1041 // hoisted up to the outer/upper scope, or 2) the two sets of the condition
1106 static void getSelectsInScope(CHRScope *Scope,
1108 for (RegInfo &RI : Scope->RegInfos)
1111 for (CHRScope *Sub : Scope->Subs)
1117 for (CHRScope *Scope : Input) {
1118 assert(!Scope->BranchInsertPoint &&
1121 getSelectsInScope(Scope, Unhoistables);
1122 splitScope(Scope, nullptr, nullptr, nullptr, Output, Unhoistables);
1125 for (CHRScope *Scope : Output) {
1126 assert(Scope->BranchInsertPoint && "BranchInsertPoint must be set");
1132 CHRScope *Scope,
1149 SmallVector<RegInfo, 8> RegInfos(Scope->RegInfos); // Copy
1173 << "Split scope from outer due to unhoistable branch/select "
1195 CHRScope *Tail = Scope->split(RI.R);
1197 Splits.push_back(Scope);
1201 Scope = Tail;
1209 << "Split scope from previous due to unhoistable branch/select "
1218 Splits.push_back(Scope);
1262 for (CHRScope *Scope : Scopes) {
1263 assert(Scope->TrueBiasedRegions.empty() && Scope->FalseBiasedRegions.empty() && "Empty");
1264 classifyBiasedScopes(Scope, Scope);
1266 dbgs() << "classifyBiasedScopes " << *Scope << "\n";
1268 for (Region *R : Scope->TrueBiasedRegions) {
1273 for (Region *R : Scope->FalseBiasedRegions) {
1278 for (SelectInst *SI : Scope->TrueBiasedSelects) {
1283 for (SelectInst *SI : Scope->FalseBiasedSelects) {
1290 void CHR::classifyBiasedScopes(CHRScope *Scope, CHRScope *OutermostScope) {
1291 for (RegInfo &RI : Scope->RegInfos) {
1310 for (CHRScope *Sub : Scope->Subs) {
1315 static bool hasAtLeastTwoBiasedBranches(CHRScope *Scope) {
1316 unsigned NumBiased = Scope->TrueBiasedRegions.size() +
1317 Scope->FalseBiasedRegions.size() +
1318 Scope->TrueBiasedSelects.size() +
1319 Scope->FalseBiasedSelects.size();
1325 for (CHRScope *Scope : Input) {
1327 if (!hasAtLeastTwoBiasedBranches(Scope)) {
1329 << Scope->TrueBiasedRegions.size()
1330 << " falsy-regions " << Scope->FalseBiasedRegions.size()
1331 << " true-selects " << Scope->TrueBiasedSelects.size()
1332 << " false-selects " << Scope->FalseBiasedSelects.size() << "\n");
1337 Scope->RegInfos[0].R->getEntry()->getTerminator())
1338 << "Drop scope with < "
1344 Output.push_back(Scope);
1350 for (CHRScope *Scope : Input) {
1351 assert(Scope->HoistStopMap.empty() && Scope->CHRRegions.empty() &&
1353 setCHRRegions(Scope, Scope);
1354 Output.push_back(Scope);
1356 dbgs() << "setCHRRegions HoistStopMap " << *Scope << "\n";
1357 for (auto pair : Scope->HoistStopMap) {
1365 for (RegInfo &RI : Scope->CHRRegions) {
1371 void CHR::setCHRRegions(CHRScope *Scope, CHRScope *OutermostScope) {
1376 for (RegInfo &RI : Scope->RegInfos) {
1382 for (RegInfo &RI : Scope->RegInfos) {
1416 for (CHRScope *Sub : Scope->Subs)
1448 // The trivial phi inserted by the previous CHR scope could replace a
1450 // previous CHR scope, which dominates this scope, it's safe to stop
1463 // instruction. Since an outer (dominating) scope would hoist it to its
1464 // entry before an inner (dominated) scope would to its entry, the inner
1465 // scope may see the instruction already hoisted, in which case it
1466 // potentially wrong for the inner scope to hoist it and could cause bad
1468 // it's already in a block that dominates the inner scope.
1480 // scope to the insert point.
1481 static void hoistScopeConditions(CHRScope *Scope, Instruction *HoistPoint,
1485 for (const RegInfo &RI : Scope->CHRRegions) {
1487 bool IsTrueBiased = Scope->TrueBiasedRegions.count(R);
1488 bool IsFalseBiased = Scope->FalseBiasedRegions.count(R);
1491 hoistValue(BI->getCondition(), HoistPoint, R, Scope->HoistStopMap,
1495 bool IsTrueBiased = Scope->TrueBiasedSelects.count(SI);
1496 bool IsFalseBiased = Scope->FalseBiasedSelects.count(SI);
1499 hoistValue(SI->getCondition(), HoistPoint, R, Scope->HoistStopMap,
1509 CHRScope *Scope) {
1536 if (Scope->TrueBiasedSelects.count(SI)) {
1537 assert(!Scope->FalseBiasedSelects.contains(SI) &&
1539 Scope->FalseBiasedSelects.insert(SI);
1540 } else if (Scope->FalseBiasedSelects.count(SI)) {
1541 assert(!Scope->TrueBiasedSelects.contains(SI) &&
1543 Scope->TrueBiasedSelects.insert(SI);
1553 // A helper for transformScopes. Insert a trivial phi at the scope exit block
1554 // for a value that's defined in the scope but used outside it (meaning it's
1556 static void insertTrivialPHIs(CHRScope *Scope,
1560 for (RegInfo &RI : Scope->RegInfos) {
1580 CHR_DEBUG(dbgs() << "Used outside scope by user " << *UI << "\n");
1584 // scope to the entry block.
1617 // Assert that all the CHR regions of the scope have a biased branch or select.
1619 assertCHRRegionsHaveBiasedBranchOrSelect(CHRScope *Scope) {
1621 auto HasBiasedBranchOrSelect = [](RegInfo &RI, CHRScope *Scope) {
1622 if (Scope->TrueBiasedRegions.count(RI.R) ||
1623 Scope->FalseBiasedRegions.count(RI.R))
1626 if (Scope->TrueBiasedSelects.count(SI) ||
1627 Scope->FalseBiasedSelects.count(SI))
1631 for (RegInfo &RI : Scope->CHRRegions) {
1632 assert(HasBiasedBranchOrSelect(RI, Scope) &&
1639 // been hoisted to the pre-entry block or outside of the scope.
1641 CHRScope *Scope, BasicBlock *PreEntryBlock) {
1643 for (RegInfo &RI : Scope->CHRRegions) {
1645 bool IsTrueBiased = Scope->TrueBiasedRegions.count(R);
1646 bool IsFalseBiased = Scope->FalseBiasedRegions.count(R);
1654 !Scope->contains(I)) &&
1655 "Must have been hoisted to PreEntryBlock or outside the scope");
1659 bool IsTrueBiased = Scope->TrueBiasedSelects.count(SI);
1660 bool IsFalseBiased = Scope->FalseBiasedSelects.count(SI);
1668 !Scope->contains(I)) &&
1669 "Must have been hoisted to PreEntryBlock or outside the scope");
1675 void CHR::transformScopes(CHRScope *Scope, DenseSet<PHINode *> &TrivialPHIs) {
1676 CHR_DEBUG(dbgs() << "transformScopes " << *Scope << "\n");
1678 assert(Scope->RegInfos.size() >= 1 && "Should have at least one Region");
1680 for (RegInfo &RI : Scope->RegInfos) {
1696 for (RegInfo &RI : Scope->RegInfos) {
1700 Region *FirstRegion = Scope->RegInfos[0].R;
1702 Region *LastRegion = Scope->RegInfos[Scope->RegInfos.size() - 1].R;
1708 // cold path merges) for a value that's defined in the scope but used
1713 insertTrivialPHIs(Scope, EntryBlock, ExitBlock, TrivialPHIs);
1724 << " at " << *Scope->BranchInsertPoint << "\n");
1726 SplitBlock(EntryBlock, Scope->BranchInsertPoint, &DT);
1733 // Clone the blocks in the scope (excluding the PreEntryBlock) to split into a
1736 cloneScopeBlocks(Scope, PreEntryBlock, ExitBlock, LastRegion, VMap);
1744 assertCHRRegionsHaveBiasedBranchOrSelect(Scope);
1748 hoistScopeConditions(Scope, PreEntryBlock->getTerminator(), TrivialPHIs, DT);
1751 assertBranchOrSelectConditionHoisted(Scope, PreEntryBlock);
1756 fixupBranchesAndSelects(Scope, PreEntryBlock, MergedBr,
1760 // A helper for transformScopes. Clone the blocks in the scope (excluding the
1763 void CHR::cloneScopeBlocks(CHRScope *Scope,
1774 for (RegInfo &RI : Scope->RegInfos)
1848 void CHR::fixupBranchesAndSelects(CHRScope *Scope,
1856 for (RegInfo &RI : Scope->CHRRegions) {
1859 fixupBranch(R, Scope, IRB, MergedCondition, CHRBranchBias);
1863 fixupSelect(SI, Scope, IRB, MergedCondition, CHRBranchBias);
1889 void CHR::fixupBranch(Region *R, CHRScope *Scope,
1893 bool IsTrueBiased = Scope->TrueBiasedRegions.count(R);
1894 assert((IsTrueBiased || Scope->FalseBiasedRegions.count(R)) &&
1919 addToMergedCondition(ConditionTrue, Cond, BI, Scope, IRB,
1932 void CHR::fixupSelect(SelectInst *SI, CHRScope *Scope,
1936 bool IsTrueBiased = Scope->TrueBiasedSelects.count(SI);
1938 Scope->FalseBiasedSelects.count(SI)) && "Must be biased");
1946 addToMergedCondition(IsTrueBiased, Cond, SI, Scope, IRB,
1957 Instruction *BranchOrSelect, CHRScope *Scope,
1965 !negateICmpIfUsedByBranchOrSelectOnly(ICmp, BranchOrSelect, Scope))
1980 for (CHRScope *Scope : CHRScopes) {
1981 transformScopes(Scope, TrivialPHIs);
1993 for (CHRScope *Scope : Scopes) {
1994 dbgs() << *Scope << "\n";
2017 // branches/selects of the inner/lower scope can't be hoisted up to the
2018 // outermost/uppermost scope entry, or 2) the condition values of the biased
2019 // branches/selects in a scope (including subscopes) don't share at least
2025 // After splitting, set the biased regions and selects of a scope (a tree
2028 CHR_DEBUG(dbgs() << "Set per-scope bias " << SplitScopes.size() << "\n");
2036 // Set the regions to be CHR'ed and their hoist stops for each scope.