44 #define DEBUG_TYPE "chr" 46 #define CHR_DEBUG(X) LLVM_DEBUG(X) 49 cl::desc(
"Apply CHR for all functions"));
53 cl::desc(
"CHR considers a branch bias greater than this ratio as biased"));
57 cl::desc(
"CHR merges a group of N branches/selects where N >= this value"));
61 cl::desc(
"Specify file to retrieve the list of modules to apply CHR to"));
65 cl::desc(
"Specify file to retrieve the list of functions to apply CHR to"));
74 errs() <<
"Error: Couldn't read the chr-module-list file " <<
CHRModuleList <<
"\n";
77 StringRef Buf = FileOrErr->get()->getBuffer();
79 Buf.
split(Lines,
'\n');
92 StringRef Buf = FileOrErr->get()->getBuffer();
94 Buf.
split(Lines,
'\n');
104 class ControlHeightReductionLegacyPass :
public FunctionPass {
129 "Reduce control height in the hot paths",
137 "Reduce control height in the hot paths",
141 return new ControlHeightReductionLegacyPass();
147 CHRStats() : NumBranches(0), NumBranchesDelta(0),
148 WeightedNumBranchesDelta(0) {}
150 OS <<
"CHRStats: NumBranches " << NumBranches
151 <<
" NumBranchesDelta " << NumBranchesDelta
152 <<
" WeightedNumBranchesDelta " << WeightedNumBranchesDelta;
154 uint64_t NumBranches;
156 uint64_t NumBranchesDelta;
158 uint64_t WeightedNumBranchesDelta;
164 RegInfo() : R(
nullptr), HasBranch(
false) {}
165 RegInfo(
Region *RegionIn) : R(RegionIn), HasBranch(
false) {}
178 CHRScope(RegInfo RI) : BranchInsertPoint(
nullptr) {
179 assert(RI.R &&
"Null RegionIn");
180 RegInfos.push_back(RI);
183 Region *getParentRegion() {
184 assert(RegInfos.size() > 0 &&
"Empty CHRScope");
186 assert(Parent &&
"Unexpected to call this on the top-level region");
191 assert(RegInfos.size() > 0 &&
"Empty CHRScope");
192 return RegInfos.front().R->getEntry();
196 assert(RegInfos.size() > 0 &&
"Empty CHRScope");
197 return RegInfos.back().R->getExit();
200 bool appendable(CHRScope *Next) {
204 BasicBlock *NextEntry = Next->getEntryBlock();
205 if (getExitBlock() != NextEntry)
208 Region *LastRegion = RegInfos.back().R;
217 void append(CHRScope *Next) {
218 assert(RegInfos.size() > 0 &&
"Empty CHRScope");
219 assert(Next->RegInfos.size() > 0 &&
"Empty CHRScope");
220 assert(getParentRegion() == Next->getParentRegion() &&
222 assert(getExitBlock() == Next->getEntryBlock() &&
224 for (RegInfo &RI : Next->RegInfos)
225 RegInfos.push_back(RI);
226 for (CHRScope *Sub : Next->Subs)
230 void addSub(CHRScope *SubIn) {
232 bool IsChild =
false;
233 for (RegInfo &RI : RegInfos)
234 if (RI.R == SubIn->getParentRegion()) {
238 assert(IsChild &&
"Must be a child");
240 Subs.push_back(SubIn);
246 assert(Boundary &&
"Boundary null");
247 assert(RegInfos.begin()->R != Boundary &&
248 "Can't be split at beginning");
249 auto BoundaryIt =
std::find_if(RegInfos.begin(), RegInfos.end(),
250 [&Boundary](
const RegInfo& RI) {
251 return Boundary == RI.R;
253 if (BoundaryIt == RegInfos.end())
257 TailRegInfos.
insert(TailRegInfos.
begin(), BoundaryIt, RegInfos.end());
258 RegInfos.resize(BoundaryIt - RegInfos.begin());
260 for (RegInfo &RI : TailRegInfos)
261 TailRegionSet.
insert(RI.R);
262 for (
auto It = Subs.begin(); It != Subs.end(); ) {
264 assert(Sub &&
"null Sub");
265 Region *Parent = Sub->getParentRegion();
266 if (TailRegionSet.
count(Parent)) {
271 [&Parent](
const RegInfo& RI) {
272 return Parent == RI.R;
273 }) != RegInfos.end() &&
278 assert(HoistStopMap.empty() &&
"MapHoistStops must be empty");
279 return new CHRScope(TailRegInfos, TailSubs);
284 for (
const RegInfo &RI : RegInfos)
285 if (RI.R->contains(Parent))
314 HoistStopMapTy HoistStopMap;
319 : RegInfos(RegInfosIn), Subs(SubsIn), BranchInsertPoint(
nullptr) {}
327 :
F(Fin),
BFI(BFIin), DT(DTin), PSI(PSIin), RI(RIin), ORE(OREin) {}
330 for (CHRScope *
Scope : Scopes) {
342 Region *R = RI.getTopLevelRegion();
343 CHRScope *
Scope = findScopes(R,
nullptr,
nullptr, Output);
350 CHRScope *findScope(
Region *R);
351 void checkScopeHoistable(CHRScope *
Scope);
363 void classifyBiasedScopes(CHRScope *Scope, CHRScope *OutermostScope);
370 void setCHRRegions(CHRScope *Scope, CHRScope *OutermostScope);
377 void cloneScopeBlocks(CHRScope *Scope,
386 void fixupBranchesAndSelects(CHRScope *Scope,
390 void fixupBranch(
Region *R,
398 void addToMergedCondition(
bool IsTrueBiased,
Value *Cond,
402 Value *&MergedCondition);
432 const CHRStats &
Stats) {
463 CHR_DEBUG(
dbgs() <<
"CHR IR dump " << Label <<
" " << ModuleName <<
" " 472 assert(RegInfos.size() > 0 &&
"Empty CHRScope");
474 OS << RegInfos.size() <<
", Regions[";
475 for (
const RegInfo &RI : RegInfos) {
476 OS << RI.R->getNameStr();
479 if (RI.Selects.size() > 0)
480 OS <<
" S" << RI.Selects.size();
483 if (RegInfos[0].R->getParent()) {
484 OS <<
"], Parent " << RegInfos[0].R->getParent()->getNameStr();
490 for (CHRScope *Sub : Subs) {
498 return isa<BinaryOperator>(
I) || isa<CastInst>(I) || isa<SelectInst>(
I) ||
499 isa<GetElementPtrInst>(I) || isa<CmpInst>(
I) ||
500 isa<InsertElementInst>(I) || isa<ExtractElementInst>(
I) ||
501 isa<ShuffleVectorInst>(I) || isa<ExtractValueInst>(
I) ||
502 isa<InsertValueInst>(I);
520 if (Visited.count(V)) {
523 std::set<Value *> Result;
524 if (
auto *
I = dyn_cast<Instruction>(V)) {
529 Visited.insert(std::make_pair(V, Result));
535 Result.insert(OpResult.begin(), OpResult.end());
537 Visited.insert(std::make_pair(V, Result));
540 if (isa<Argument>(V)) {
542 Visited.insert(std::make_pair(V, Result));
548 Visited.insert(std::make_pair(V, Result));
561 assert(InsertPoint &&
"Null InsertPoint");
562 if (
auto *
I = dyn_cast<Instruction>(V)) {
566 assert(DT.
getNode(
I->getParent()) &&
"DT must contain I's parent block");
568 if (Unhoistables.
count(
I)) {
585 bool AllOpsHoisted =
true;
589 AllOpsHoisted =
false;
612 if (!MD)
return false;
614 if (MDName->
getString() !=
"branch_weights" ||
619 if (!TrueWeight || !FalseWeight)
622 uint64_t FalseWt = FalseWeight->getValue().getZExtValue();
623 uint64_t SumWt = TrueWt + FalseWt;
625 assert(SumWt >= TrueWt && SumWt >= FalseWt &&
626 "Overflow calculating branch probabilities.");
646 template <
typename K,
typename S,
typename M>
651 if (TrueProb >= Threshold) {
653 BiasMap[
Key] = TrueProb;
655 }
else if (FalseProb >= Threshold) {
656 FalseSet.insert(Key);
657 BiasMap[
Key] = FalseProb;
679 "Invariant from findScopes");
690 TrueBiasedRegionsGlobal, FalseBiasedRegionsGlobal,
703 TrueProb, FalseProb))
708 return checkBias(SI, TrueProb, FalseProb,
709 TrueBiasedSelectsGlobal, FalseBiasedSelectsGlobal,
730 assert(HoistPoint &&
"Null HoistPoint");
737 EntryBlockSelectSet.
insert(SI);
741 if (EntryBlockSelectSet.
count(&
I) > 0) {
743 "HoistPoint must be the first one in Selects");
752 CHRScope * CHR::findScope(
Region *R) {
753 CHRScope *Result =
nullptr;
756 assert(Entry &&
"Entry must not be null");
758 "Only top level region has a null exit");
769 bool EntryInSubregion = RI.getRegionFor(Entry) != R;
770 if (EntryInSubregion)
783 CHR_DEBUG(
dbgs() <<
"BI.isConditional " << BI->isConditional() <<
"\n");
786 if (BI && BI->isConditional()) {
791 if (S0 != S1 && (S0 == Exit || S1 == Exit)) {
794 BI, R, TrueBiasedRegionsGlobal, FalseBiasedRegionsGlobal,
796 Result =
new CHRScope(RI);
797 Scopes.insert(Result);
803 <<
"Branch not biased";
824 if (
E->isSubRegion())
832 if (
auto *
SI = dyn_cast<SelectInst>(&
I)) {
838 if (Selects.
size() > 0) {
839 auto AddSelects = [&](RegInfo &RI) {
840 for (
auto *
SI : Selects)
842 TrueBiasedSelectsGlobal,
843 FalseBiasedSelectsGlobal,
845 RI.Selects.push_back(
SI);
849 <<
"Select not biased";
856 Result =
new CHRScope(RI);
857 Scopes.insert(Result);
859 CHR_DEBUG(
dbgs() <<
"Found select(s) in a region with a branch\n");
860 AddSelects(Result->RegInfos[0]);
866 checkScopeHoistable(Result);
893 void CHR::checkScopeHoistable(CHRScope *
Scope) {
894 RegInfo &RI = Scope->RegInfos[0];
897 auto *
Branch = RI.HasBranch ?
900 if (RI.HasBranch || !Selects.empty()) {
912 for (
auto it = Selects.begin(); it != Selects.end(); ) {
914 if (SI == InsertPoint) {
920 DT, Unhoistables,
nullptr, Visited);
925 "DropUnhoistableSelect", SI)
926 <<
"Dropped unhoistable select";
928 it = Selects.erase(it);
931 Unhoistables.erase(SI);
938 if (RI.HasBranch && InsertPoint !=
Branch) {
941 DT, Unhoistables,
nullptr, Visited);
946 assert(InsertPoint !=
Branch &&
"Branch must not be the hoist point");
950 dbgs() <<
"SI " << *
SI <<
"\n";
955 "DropSelectUnhoistableBranch",
SI)
956 <<
"Dropped select due to unhoistable branch";
961 return SI->getParent() == EntryBB;
963 Unhoistables.clear();
971 "Branch can't be already above the hoist point");
974 DT, Unhoistables,
nullptr, Visited) &&
975 "checkHoistValue for branch");
977 for (
auto *
SI : Selects) {
978 assert(!DT.dominates(
SI, InsertPoint) &&
979 "SI can't be already above the hoist point");
982 Unhoistables,
nullptr, Visited) &&
983 "checkHoistValue for selects");
989 for (
auto *
SI : Selects) {
1000 CHRScope *Result = findScope(R);
1002 CHRScope *ConsecutiveSubscope =
nullptr;
1004 for (
auto It = R->
begin(); It != R->
end(); ++It) {
1005 const std::unique_ptr<Region> &SubR = *It;
1006 auto NextIt = std::next(It);
1007 Region *NextSubR = NextIt != R->
end() ? NextIt->get() :
nullptr;
1008 CHR_DEBUG(
dbgs() <<
"Looking at subregion " << SubR.get()->getNameStr()
1010 CHRScope *SubCHRScope = findScopes(SubR.get(), NextSubR, R, Scopes);
1012 CHR_DEBUG(
dbgs() <<
"Subregion Scope " << *SubCHRScope <<
"\n");
1017 if (!ConsecutiveSubscope)
1018 ConsecutiveSubscope = SubCHRScope;
1019 else if (!ConsecutiveSubscope->appendable(SubCHRScope)) {
1020 Subscopes.
push_back(ConsecutiveSubscope);
1021 ConsecutiveSubscope = SubCHRScope;
1023 ConsecutiveSubscope->append(SubCHRScope);
1025 if (ConsecutiveSubscope) {
1026 Subscopes.
push_back(ConsecutiveSubscope);
1028 ConsecutiveSubscope =
nullptr;
1031 if (ConsecutiveSubscope) {
1032 Subscopes.
push_back(ConsecutiveSubscope);
1034 for (CHRScope *Sub : Subscopes) {
1037 Result->addSub(Sub);
1049 auto *BI = cast<BranchInst>(RI.R->getEntry()->getTerminator());
1050 ConditionValues.
insert(BI->getCondition());
1055 return ConditionValues;
1070 assert(InsertPoint &&
"Null InsertPoint");
1072 dbgs() <<
"shouldSplit " << *InsertPoint <<
" PrevConditionValues ";
1073 for (
Value *V : PrevConditionValues) {
1074 dbgs() << *V <<
", ";
1076 dbgs() <<
" ConditionValues ";
1077 for (
Value *V : ConditionValues) {
1078 dbgs() << *V <<
", ";
1082 for (
Value *V : ConditionValues) {
1084 if (!
checkHoistValue(V, InsertPoint, DT, Unhoistables,
nullptr, Visited)) {
1085 CHR_DEBUG(
dbgs() <<
"Split. checkHoistValue false " << *V <<
"\n");
1092 if (!PrevConditionValues.empty() && !ConditionValues.empty()) {
1094 std::set<Value *> PrevBases, Bases;
1096 for (
Value *V : PrevConditionValues) {
1097 std::set<Value *> BaseValues =
getBaseValues(V, DT, Visited);
1098 PrevBases.insert(BaseValues.begin(), BaseValues.end());
1100 for (
Value *V : ConditionValues) {
1101 std::set<Value *> BaseValues =
getBaseValues(V, DT, Visited);
1102 Bases.insert(BaseValues.begin(), BaseValues.end());
1105 dbgs() <<
"PrevBases ";
1106 for (
Value *V : PrevBases) {
1107 dbgs() << *V <<
", ";
1109 dbgs() <<
" Bases ";
1110 for (
Value *V : Bases) {
1111 dbgs() << *V <<
", ";
1114 std::set<Value *> Intersection;
1115 std::set_intersection(PrevBases.begin(), PrevBases.end(),
1116 Bases.begin(), Bases.end(),
1117 std::inserter(Intersection, Intersection.begin()));
1118 if (Intersection.empty()) {
1130 for (RegInfo &RI : Scope->RegInfos)
1133 for (CHRScope *Sub : Scope->Subs)
1139 for (CHRScope *Scope : Input) {
1140 assert(!Scope->BranchInsertPoint &&
1141 "BranchInsertPoint must not be set");
1144 splitScope(Scope,
nullptr,
nullptr,
nullptr, Output, Unhoistables);
1147 for (CHRScope *Scope : Output) {
1148 assert(Scope->BranchInsertPoint &&
"BranchInsertPoint must be set");
1161 assert(OuterConditionValues &&
"Null OuterConditionValues");
1162 assert(OuterInsertPoint &&
"Null OuterInsertPoint");
1164 bool PrevSplitFromOuter =
true;
1172 for (RegInfo &RI : RegInfos) {
1176 dbgs() <<
"ConditionValues ";
1177 for (
Value *V : ConditionValues) {
1178 dbgs() << *V <<
", ";
1181 if (RI.R == RegInfos[0].R) {
1186 << RI.R->getNameStr() <<
"\n");
1187 if (
shouldSplit(OuterInsertPoint, *OuterConditionValues,
1188 ConditionValues, DT, Unhoistables)) {
1189 PrevConditionValues = ConditionValues;
1190 PrevInsertPoint = InsertPoint;
1193 "SplitScopeFromOuter",
1194 RI.R->getEntry()->getTerminator())
1195 <<
"Split scope from outer due to unhoistable branch/select " 1196 <<
"and/or lack of common condition values";
1201 PrevSplitFromOuter =
false;
1202 PrevConditionValues = *OuterConditionValues;
1203 PrevConditionValues.
insert(ConditionValues.begin(),
1204 ConditionValues.end());
1205 PrevInsertPoint = OuterInsertPoint;
1209 PrevConditionValues = ConditionValues;
1210 PrevInsertPoint = InsertPoint;
1214 << RI.R->getNameStr() <<
"\n");
1215 if (
shouldSplit(PrevInsertPoint, PrevConditionValues, ConditionValues,
1216 DT, Unhoistables)) {
1217 CHRScope *
Tail = Scope->split(RI.R);
1220 SplitsSplitFromOuter.
push_back(PrevSplitFromOuter);
1221 SplitsConditionValues.
push_back(PrevConditionValues);
1222 SplitsInsertPoints.
push_back(PrevInsertPoint);
1224 PrevConditionValues = ConditionValues;
1225 PrevInsertPoint = InsertPoint;
1226 PrevSplitFromOuter =
true;
1229 "SplitScopeFromPrev",
1230 RI.R->getEntry()->getTerminator())
1231 <<
"Split scope from previous due to unhoistable branch/select " 1232 <<
"and/or lack of common condition values";
1236 PrevConditionValues.
insert(ConditionValues.begin(), ConditionValues.end());
1241 SplitsSplitFromOuter.
push_back(PrevSplitFromOuter);
1242 SplitsConditionValues.
push_back(PrevConditionValues);
1243 assert(PrevInsertPoint &&
"Null PrevInsertPoint");
1244 SplitsInsertPoints.
push_back(PrevInsertPoint);
1246 Splits.
size() == SplitsSplitFromOuter.
size() &&
1247 Splits.
size() == SplitsInsertPoints.
size() &&
"Mismatching sizes");
1248 for (
size_t I = 0;
I < Splits.
size(); ++
I) {
1249 CHRScope *Split = Splits[
I];
1255 for (CHRScope *Sub : Split->Subs) {
1257 Sub, Split, &SplitConditionValues, SplitInsertPoint, Output,
1261 Split->Subs = NewSubs;
1264 for (
size_t I = 0;
I < Splits.
size(); ++
I) {
1265 CHRScope *Split = Splits[
I];
1266 if (SplitsSplitFromOuter[
I]) {
1269 Split->BranchInsertPoint = SplitsInsertPoints[
I];
1270 CHR_DEBUG(
dbgs() <<
"BranchInsertPoint " << *SplitsInsertPoints[I]
1279 "If no outer (top-level), must return no nested ones");
1284 for (CHRScope *Scope : Scopes) {
1285 assert(Scope->TrueBiasedRegions.empty() && Scope->FalseBiasedRegions.empty() &&
"Empty");
1286 classifyBiasedScopes(Scope, Scope);
1288 dbgs() <<
"classifyBiasedScopes " << *Scope <<
"\n";
1289 dbgs() <<
"TrueBiasedRegions ";
1290 for (
Region *R : Scope->TrueBiasedRegions) {
1294 dbgs() <<
"FalseBiasedRegions ";
1295 for (
Region *R : Scope->FalseBiasedRegions) {
1299 dbgs() <<
"TrueBiasedSelects ";
1301 dbgs() << *SI <<
", ";
1304 dbgs() <<
"FalseBiasedSelects ";
1305 for (
SelectInst *SI : Scope->FalseBiasedSelects) {
1306 dbgs() << *SI <<
", ";
1312 void CHR::classifyBiasedScopes(CHRScope *Scope, CHRScope *OutermostScope) {
1313 for (RegInfo &RI : Scope->RegInfos) {
1316 if (TrueBiasedRegionsGlobal.count(R) > 0)
1317 OutermostScope->TrueBiasedRegions.insert(R);
1318 else if (FalseBiasedRegionsGlobal.count(R) > 0)
1319 OutermostScope->FalseBiasedRegions.insert(R);
1324 if (TrueBiasedSelectsGlobal.count(SI) > 0)
1325 OutermostScope->TrueBiasedSelects.insert(SI);
1326 else if (FalseBiasedSelectsGlobal.count(SI) > 0)
1327 OutermostScope->FalseBiasedSelects.insert(SI);
1332 for (CHRScope *Sub : Scope->Subs) {
1333 classifyBiasedScopes(Sub, OutermostScope);
1338 unsigned NumBiased = Scope->TrueBiasedRegions.size() +
1339 Scope->FalseBiasedRegions.size() +
1340 Scope->TrueBiasedSelects.size() +
1341 Scope->FalseBiasedSelects.size();
1347 for (CHRScope *Scope : Input) {
1350 CHR_DEBUG(
dbgs() <<
"Filtered out by biased branches truthy-regions " 1351 << Scope->TrueBiasedRegions.size()
1352 <<
" falsy-regions " << Scope->FalseBiasedRegions.size()
1353 <<
" true-selects " << Scope->TrueBiasedSelects.size()
1354 <<
" false-selects " << Scope->FalseBiasedSelects.size() <<
"\n");
1358 "DropScopeWithOneBranchOrSelect",
1359 Scope->RegInfos[0].R->getEntry()->getTerminator())
1360 <<
"Drop scope with < " 1362 <<
" biased branch(es) or select(s)";
1372 for (CHRScope *Scope : Input) {
1373 assert(Scope->HoistStopMap.empty() && Scope->CHRRegions.empty() &&
1375 setCHRRegions(Scope, Scope);
1378 dbgs() <<
"setCHRRegions HoistStopMap " << *Scope <<
"\n";
1379 for (
auto pair : Scope->HoistStopMap) {
1380 Region *R = pair.first;
1381 dbgs() <<
"Region " << R->getNameStr() <<
"\n";
1382 for (Instruction *I : pair.second) {
1383 dbgs() <<
"HoistStop " << *I <<
"\n";
1386 dbgs() <<
"CHRRegions" <<
"\n";
1387 for (RegInfo &RI : Scope->CHRRegions) {
1388 dbgs() << RI.R->getNameStr() <<
"\n";
1393 void CHR::setCHRRegions(CHRScope *
Scope, CHRScope *OutermostScope) {
1398 for (RegInfo &RI : Scope->RegInfos) {
1403 Instruction *InsertPoint = OutermostScope->BranchInsertPoint;
1404 for (RegInfo &RI : Scope->RegInfos) {
1407 bool IsHoisted =
false;
1409 assert((OutermostScope->TrueBiasedRegions.count(R) > 0 ||
1410 OutermostScope->FalseBiasedRegions.count(R) > 0) &&
1411 "Must be truthy or falsy");
1412 auto *BI = cast<BranchInst>(R->
getEntry()->getTerminator());
1415 bool IsHoistable =
checkHoistValue(BI->getCondition(), InsertPoint, DT,
1416 Unhoistables, &HoistStops, Visited);
1417 assert(IsHoistable &&
"Must be hoistable");
1418 (void)(IsHoistable);
1422 assert((OutermostScope->TrueBiasedSelects.count(SI) > 0 ||
1423 OutermostScope->FalseBiasedSelects.count(SI) > 0) &&
1424 "Must be true or false biased");
1428 Unhoistables, &HoistStops, Visited);
1429 assert(IsHoistable &&
"Must be hoistable");
1430 (void)(IsHoistable);
1434 OutermostScope->CHRRegions.push_back(RI);
1435 OutermostScope->HoistStopMap[R] = HoistStops;
1438 for (CHRScope *Sub : Scope->Subs)
1439 setCHRRegions(Sub, OutermostScope);
1443 return Scope1->RegInfos[0].R->getDepth() < Scope2->RegInfos[0].R->getDepth();
1456 HoistStopMapTy &HoistStopMap,
1460 auto IT = HoistStopMap.find(R);
1461 assert(
IT != HoistStopMap.end() &&
"Region must be in hoist stop map");
1463 if (
auto *
I = dyn_cast<Instruction>(V)) {
1464 if (
I == HoistPoint)
1466 if (HoistStops.count(
I))
1468 if (
auto *PN = dyn_cast<PHINode>(
I))
1469 if (TrivialPHIs.
count(PN))
1479 assert(DT.
getNode(
I->getParent()) &&
"DT must contain I's block");
1481 "DT must contain HoistPoint block");
1493 hoistValue(
Op, HoistPoint, R, HoistStopMap, HoistedSet, TrivialPHIs, DT);
1495 I->moveBefore(HoistPoint);
1507 for (
const RegInfo &RI : Scope->CHRRegions) {
1509 bool IsTrueBiased = Scope->TrueBiasedRegions.count(R);
1510 bool IsFalseBiased = Scope->FalseBiasedRegions.count(R);
1511 if (RI.HasBranch && (IsTrueBiased || IsFalseBiased)) {
1512 auto *BI = cast<BranchInst>(R->
getEntry()->getTerminator());
1513 hoistValue(BI->getCondition(), HoistPoint, R, Scope->HoistStopMap,
1514 HoistedSet, TrivialPHIs, DT);
1517 bool IsTrueBiased = Scope->TrueBiasedSelects.count(SI);
1518 bool IsFalseBiased = Scope->FalseBiasedSelects.count(SI);
1519 if (!(IsTrueBiased || IsFalseBiased))
1522 HoistedSet, TrivialPHIs, DT);
1533 if (U == ExcludedUser)
1535 if (isa<BranchInst>(U) && cast<BranchInst>(U)->isConditional())
1537 if (isa<SelectInst>(U) && cast<SelectInst>(U)->getCondition() == ICmp)
1542 if (U == ExcludedUser)
1544 if (
auto *BI = dyn_cast<BranchInst>(U)) {
1545 assert(BI->isConditional() &&
"Must be conditional");
1546 BI->swapSuccessors();
1554 if (
auto *
SI = dyn_cast<SelectInst>(U)) {
1557 SI->swapProfMetadata();
1558 if (Scope->TrueBiasedSelects.count(
SI)) {
1559 assert(Scope->FalseBiasedSelects.count(
SI) == 0 &&
1560 "Must not be already in");
1561 Scope->FalseBiasedSelects.insert(
SI);
1562 }
else if (Scope->FalseBiasedSelects.count(
SI)) {
1563 assert(Scope->TrueBiasedSelects.count(
SI) == 0 &&
1564 "Must not be already in");
1565 Scope->TrueBiasedSelects.insert(
SI);
1583 for (RegInfo &RI : Scope->RegInfos) {
1586 BlocksInScopeSet.
insert(BB);
1591 dbgs() <<
"Inserting redudant phis\n";
1593 dbgs() <<
"BlockInScope " << BB->getName() <<
"\n";
1598 for (
User *U :
I.users()) {
1599 if (
auto *UI = dyn_cast<Instruction>(U)) {
1600 if (BlocksInScopeSet.
count(UI->getParent()) == 0 &&
1602 !(isa<PHINode>(UI) && UI->getParent() == ExitBlock)) {
1604 CHR_DEBUG(
dbgs() <<
"Used outside scope by user " << *UI <<
"\n");
1606 }
else if (UI->getParent() == EntryBlock && isa<PHINode>(UI)) {
1611 <<
"Used at entry block (for a back edge) by a phi user " 1617 if (Users.
size() > 0) {
1621 unsigned PredCount = std::distance(
pred_begin(ExitBlock),
1624 &ExitBlock->
front());
1631 for (
unsigned J = 0, NumOps = UI->getNumOperands(); J < NumOps; ++J) {
1632 if (UI->getOperand(J) == &
I) {
1633 UI->setOperand(J, PN);
1647 auto HasBiasedBranchOrSelect = [](RegInfo &RI, CHRScope *
Scope) {
1648 if (Scope->TrueBiasedRegions.count(RI.R) ||
1649 Scope->FalseBiasedRegions.count(RI.R))
1652 if (Scope->TrueBiasedSelects.count(SI) ||
1653 Scope->FalseBiasedSelects.count(SI))
1657 for (RegInfo &RI : Scope->CHRRegions) {
1658 assert(HasBiasedBranchOrSelect(RI, Scope) &&
1659 "Must have biased branch or select");
1667 CHRScope *Scope,
BasicBlock *PreEntryBlock) {
1669 for (RegInfo &RI : Scope->CHRRegions) {
1671 bool IsTrueBiased = Scope->TrueBiasedRegions.count(R);
1672 bool IsFalseBiased = Scope->FalseBiasedRegions.count(R);
1673 if (RI.HasBranch && (IsTrueBiased || IsFalseBiased)) {
1674 auto *BI = cast<BranchInst>(R->
getEntry()->getTerminator());
1675 Value *V = BI->getCondition();
1677 if (
auto *
I = dyn_cast<Instruction>(V)) {
1679 assert((
I->getParent() == PreEntryBlock ||
1680 !Scope->contains(
I)) &&
1681 "Must have been hoisted to PreEntryBlock or outside the scope");
1685 bool IsTrueBiased = Scope->TrueBiasedSelects.count(SI);
1686 bool IsFalseBiased = Scope->FalseBiasedSelects.count(SI);
1687 if (!(IsTrueBiased || IsFalseBiased))
1691 if (
auto *
I = dyn_cast<Instruction>(V)) {
1693 assert((
I->getParent() == PreEntryBlock ||
1694 !Scope->contains(
I)) &&
1695 "Must have been hoisted to PreEntryBlock or outside the scope");
1704 assert(Scope->RegInfos.size() >= 1 &&
"Should have at least one Region");
1705 Region *FirstRegion = Scope->RegInfos[0].R;
1706 BasicBlock *EntryBlock = FirstRegion->getEntry();
1707 Region *LastRegion = Scope->RegInfos[Scope->RegInfos.size() - 1].R;
1729 <<
" at " << *Scope->BranchInsertPoint <<
"\n");
1731 SplitBlock(EntryBlock, Scope->BranchInsertPoint, &DT);
1732 assert(NewEntryBlock->getSinglePredecessor() == EntryBlock &&
1733 "NewEntryBlock's only pred must be EntryBlock");
1734 FirstRegion->replaceEntryRecursive(NewEntryBlock);
1741 cloneScopeBlocks(Scope, PreEntryBlock, ExitBlock, LastRegion, VMap);
1745 BranchInst *MergedBr = createMergedBranch(PreEntryBlock, EntryBlock,
1746 NewEntryBlock, VMap);
1761 fixupBranchesAndSelects(Scope, PreEntryBlock, MergedBr,
1762 ProfileCount ? ProfileCount.
getValue() : 0);
1768 void CHR::cloneScopeBlocks(CHRScope *Scope,
1779 for (RegInfo &RI : Scope->RegInfos)
1782 assert(BB != PreEntryBlock &&
"Don't copy the preetntry block");
1792 F.getBasicBlockList(),
1793 NewBlocks[0]->getIterator(),
F.end());
1796 for (
unsigned i = 0,
e = NewBlocks.
size(); i !=
e; ++i)
1806 for (
unsigned I = 0, NumOps = PN.getNumIncomingValues();
I < NumOps;
1810 Value *V = PN.getIncomingValue(
I);
1811 auto It = VMap.
find(V);
1812 if (It != VMap.
end()) V = It->second;
1813 assert(VMap.
find(Pred) != VMap.
end() &&
"Pred must have been cloned");
1814 PN.addIncoming(V, cast<BasicBlock>(VMap[Pred]));
1827 "SplitBlock did not work correctly!");
1829 "NewEntryBlock's only pred must be EntryBlock");
1831 "NewEntryBlock must have been copied");
1837 cast<BasicBlock>(VMap[NewEntryBlock]),
1840 assert(NewEntryBlock->getSinglePredecessor() == EntryBlock &&
1841 "NewEntryBlock's only pred must be EntryBlock");
1847 void CHR::fixupBranchesAndSelects(CHRScope *Scope,
1853 uint64_t NumCHRedBranches = 0;
1855 for (RegInfo &RI : Scope->CHRRegions) {
1858 fixupBranch(R, Scope, IRB, MergedCondition, CHRBranchBias);
1862 fixupSelect(SI, Scope, IRB, MergedCondition, CHRBranchBias);
1866 Stats.NumBranchesDelta += NumCHRedBranches - 1;
1867 Stats.WeightedNumBranchesDelta += (NumCHRedBranches - 1) * ProfileCount;
1873 <<
"Merged " <<
ore::NV(
"NumCHRedBranches", NumCHRedBranches)
1874 <<
" branches or selects";
1878 Weights.
push_back(static_cast<uint32_t>(CHRBranchBias.scale(1000)));
1879 Weights.
push_back(static_cast<uint32_t>(CHRBranchBias.getCompl().scale(1000)));
1881 MergedBR->
setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(Weights));
1882 CHR_DEBUG(
dbgs() <<
"CHR branch bias " << Weights[0] <<
":" << Weights[1]
1888 void CHR::fixupBranch(
Region *R, CHRScope *Scope,
1890 Value *&MergedCondition,
1892 bool IsTrueBiased = Scope->TrueBiasedRegions.count(R);
1893 assert((IsTrueBiased || Scope->FalseBiasedRegions.count(R)) &&
1894 "Must be truthy or falsy");
1895 auto *BI = cast<BranchInst>(R->
getEntry()->getTerminator());
1896 assert(BranchBiasMap.find(R) != BranchBiasMap.end() &&
1897 "Must be in the bias map");
1901 if (CHRBranchBias > Bias)
1902 CHRBranchBias = Bias;
1906 assert(RegionExitBlock &&
"Null ExitBlock");
1907 assert((IfThen == RegionExitBlock || IfElse == RegionExitBlock) &&
1908 IfThen != IfElse &&
"Invariant from findScopes");
1909 if (IfThen == RegionExitBlock) {
1915 <<
" IfElse " << IfElse->
getName() <<
"\n");
1916 Value *Cond = BI->getCondition();
1917 BasicBlock *HotTarget = IsTrueBiased ? IfThen : IfElse;
1918 bool ConditionTrue = HotTarget == BI->getSuccessor(0);
1919 addToMergedCondition(ConditionTrue, Cond, BI, Scope, IRB,
1922 assert(ConditionTrue == (HotTarget == BI->getSuccessor(0)) &&
1923 "The successor shouldn't change");
1924 Value *NewCondition = ConditionTrue ?
1927 BI->setCondition(NewCondition);
1934 Value *&MergedCondition,
1936 bool IsTrueBiased = Scope->TrueBiasedSelects.count(SI);
1938 Scope->FalseBiasedSelects.count(SI)) &&
"Must be biased");
1939 assert(SelectBiasMap.find(SI) != SelectBiasMap.end() &&
1940 "Must be in the bias map");
1944 if (CHRBranchBias > Bias)
1945 CHRBranchBias = Bias;
1947 addToMergedCondition(IsTrueBiased, Cond, SI, Scope, IRB,
1949 Value *NewCondition = IsTrueBiased ?
1957 void CHR::addToMergedCondition(
bool IsTrueBiased,
Value *Cond,
1961 Value *&MergedCondition) {
1963 MergedCondition = IRB.
CreateAnd(MergedCondition, Cond);
1969 if (
auto *ICmp = dyn_cast<ICmpInst>(Cond))
1971 MergedCondition = IRB.
CreateAnd(MergedCondition, Cond);
1977 MergedCondition = IRB.
CreateAnd(MergedCondition, Negate);
1985 for (CHRScope *Scope : CHRScopes) {
1986 transformScopes(Scope, TrivialPHIs);
1988 std::ostringstream oss;
1989 oss <<
" after transformScopes " << I++;
1990 dumpIR(
F, oss.str().c_str(),
nullptr));
1997 dbgs() << Label <<
" " << Scopes.
size() <<
"\n";
1998 for (CHRScope *Scope : Scopes) {
1999 dbgs() << *Scope <<
"\n";
2009 bool Changed =
false;
2012 dbgs() <<
"RegionInfo:\n";
2018 findScopes(AllScopes);
2027 splitScopes(AllScopes, SplitScopes);
2032 classifyBiasedScopes(SplitScopes);
2038 filterScopes(SplitScopes, FilteredScopes);
2043 setCHRRegions(FilteredScopes, SetScopes);
2050 sortScopes(SetScopes, SortedScopes);
2054 dbgs() <<
"RegionInfo:\n";
2058 if (!SortedScopes.
empty()) {
2059 transformScopes(SortedScopes);
2069 <<
"Reduced the number of branches in hot paths by " 2072 <<
ore::NV(
"WeightedNumBranchesDelta",
Stats.WeightedNumBranchesDelta)
2073 <<
" (weighted by PGO count)";
2082 getAnalysis<BlockFrequencyInfoWrapperPass>().getBFI();
2083 DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
2085 getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
2086 RegionInfo &RI = getAnalysis<RegionInfoPass>().getRegionInfo();
2087 std::unique_ptr<OptimizationRemarkEmitter> OwnedORE =
2088 std::make_unique<OptimizationRemarkEmitter>(&
F);
2089 return CHR(F, BFI, DT, PSI, RI, *OwnedORE.get()).run();
2104 auto &MAM = MAMProxy.getManager();
2108 bool Changed = CHR(F,
BFI, DT, PSI, RI, ORE).
run();
Legacy wrapper pass to provide the GlobalsAAResult object.
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface ...
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
static ConstantInt * getFalse(LLVMContext &Context)
static bool checkMDProf(MDNode *MD, BranchProbability &TrueProb, BranchProbability &FalseProb)
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
uint64_t getZExtValue() const
Get zero extended value.
DiagnosticInfoOptimizationBase::Argument NV
void dropAllReferences()
Drop all references to operands.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class represents lattice values for constants.
This is the interface for a simple mod/ref and alias analysis over globals.
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
static bool checkBias(K *Key, BranchProbability TrueProb, BranchProbability FalseProb, S &TrueSet, S &FalseSet, M &BiasMap)
Implements a dense probed hash-table based set.
static DenseSet< Value * > getCHRConditionValuesForRegion(RegInfo &RI)
void push_back(const T &Elt)
Analysis providing profile information.
static bool checkHoistValue(Value *V, Instruction *InsertPoint, DominatorTree &DT, DenseSet< Instruction *> &Unhoistables, DenseSet< Instruction *> *HoistStops, DenseMap< Instruction *, bool > &Visited)
BasicBlock * getSuccessor(unsigned i) const
StringRef getName() const
Get a short "name" for the module.
static bool checkBiasedSelect(SelectInst *SI, Region *R, DenseSet< SelectInst *> &TrueBiasedSelectsGlobal, DenseSet< SelectInst *> &FalseBiasedSelectsGlobal, DenseMap< SelectInst *, BranchProbability > &SelectBiasMap)
Analysis pass which computes a DominatorTree.
static void parseCHRFilterFiles()
static cl::opt< double > CHRBiasThreshold("chr-bias-threshold", cl::init(0.99), cl::Hidden, cl::desc("CHR considers a branch bias greater than this ratio as biased"))
static void hoistScopeConditions(CHRScope *Scope, Instruction *HoistPoint, DenseSet< PHINode *> &TrivialPHIs, DominatorTree &DT)
const MDOperand & getOperand(unsigned I) const
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
iv Induction Variable Users
BasicBlock * SplitBlock(BasicBlock *Old, Instruction *SplitPt, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="")
Split the specified block at the specified instruction - everything before SplitPt stays in Old and e...
static void getSelectsInScope(CHRScope *Scope, DenseSet< Instruction *> &Output)
BlockT * getExit() const
Get the exit BasicBlock of the Region.
static BranchProbability getCHRBiasThreshold()
return AArch64::GPR64RegClass contains(Reg)
void dump() const
Support for debugging, callable in GDB: V->dump()
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
ControlHeightReductionPass()
This class represents the LLVM 'select' instruction.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
static bool checkBiasedBranch(BranchInst *BI, Region *R, DenseSet< Region *> &TrueBiasedRegionsGlobal, DenseSet< Region *> &FalseBiasedRegionsGlobal, DenseMap< Region *, BranchProbability > &BranchBiasMap)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Legacy analysis pass which computes BlockFrequencyInfo.
static bool shouldApply(Function &F, ProfileSummaryInfo &PSI)
static void LLVM_ATTRIBUTE_UNUSED assertBranchOrSelectConditionHoisted(CHRScope *Scope, BasicBlock *PreEntryBlock)
block placement Basic Block Placement Stats
static cl::opt< unsigned > CHRMergeThreshold("chr-merge-threshold", cl::init(2), cl::Hidden, cl::desc("CHR merges a group of N branches/selects where N >= this value"))
static cl::opt< bool > ForceCHR("force-chr", cl::init(false), cl::Hidden, cl::desc("Apply CHR for all functions"))
static cl::opt< std::string > CHRFunctionList("chr-function-list", cl::init(""), cl::Hidden, cl::desc("Specify file to retrieve the list of functions to apply CHR to"))
const T & getValue() const LLVM_LVALUE_FUNCTION
iterator find(const KeyT &Val)
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
const APInt & getValue() const
Return the constant as an APInt value reference.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
If this flag is set, the remapper knows that only local values within a function (such as an instruct...
StringRef getString() const
bool hasProfileSummary()
Returns true if profile summary is available.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
static bool runOnFunction(Function &F, bool PostInlining)
initializer< Ty > init(const Ty &Val)
static bool shouldSplit(Instruction *InsertPoint, DenseSet< Value *> &PrevConditionValues, DenseSet< Value *> &ConditionValues, DominatorTree &DT, DenseSet< Instruction *> &Unhoistables)
A set of analyses that are preserved following a run of a transformation pass.
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
static void insertTrivialPHIs(CHRScope *Scope, BasicBlock *EntryBlock, BasicBlock *ExitBlock, DenseSet< PHINode *> &TrivialPHIs)
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
LLVM Basic Block Representation.
Conditional or Unconditional Branch instruction.
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static StringSet CHRFunctions
static cl::opt< std::string > CHRModuleList("chr-module-list", cl::init(""), cl::Hidden, cl::desc("Specify file to retrieve the list of modules to apply CHR to"))
const Instruction & front() const
std::pair< iterator, bool > insert(const ValueT &V)
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
static std::set< Value * > getBaseValues(Value *V, DominatorTree &DT, DenseMap< Value *, std::set< Value *>> &Visited)
Represent the analysis usage information of a pass.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
#define LLVM_ATTRIBUTE_UNUSED
This instruction compares its operands according to the predicate given to the constructor.
Analysis pass providing a never-invalidated alias analysis result.
static bool isHoistableInstructionType(Instruction *I)
FunctionPass class - This class is used to implement most global optimizations.
Interval::pred_iterator pred_end(Interval *I)
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
self_iterator getIterator()
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
bool isTopLevelRegion() const
Check if a Region is the TopLevel region.
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
const Value * getCondition() const
void initializeControlHeightReductionLegacyPassPass(PassRegistry &)
Used in the streaming interface as the general argument type.
static void LLVM_ATTRIBUTE_UNUSED assertCHRRegionsHaveBiasedBranchOrSelect(CHRScope *Scope)
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Class to represent profile counts.
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
std::pair< typename base::iterator, bool > insert(StringRef Key)
const InstListType & getInstList() const
Return the underlying instruction list container.
Analysis pass which computes BlockFrequencyInfo.
This is the shared class of boolean and integer constants.
BlockT * getEntry() const
Get the entry BasicBlock of the Region.
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
static BranchProbability getBranchProbability(uint64_t Numerator, uint64_t Denominator)
static bool negateICmpIfUsedByBranchOrSelectOnly(ICmpInst *ICmp, Instruction *ExcludedUser, CHRScope *Scope)
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
bool isConditional() const
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
pred_range predecessors(BasicBlock *BB)
static void LLVM_ATTRIBUTE_UNUSED dumpScopes(SmallVectorImpl< CHRScope *> &Scopes, const char *Label)
static ConstantInt * getTrue(LLVMContext &Context)
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
Analysis pass that exposes the RegionInfo for a function.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
static StringSet CHRModules
void push_back(pointer val)
BasicBlock * CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, const Twine &NameSuffix="", Function *F=nullptr, ClonedCodeInfo *CodeInfo=nullptr, DebugInfoFinder *DIFinder=nullptr)
Return a copy of the specified basic block, but without embedding the block into a particular functio...
iterator_range< user_iterator > users()
void RemapInstruction(Instruction *I, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Convert the instruction operands from referencing the current values into those specified by VM...
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
iterator insert(iterator I, T &&Elt)
void setCondition(Value *V)
If this flag is set, the remapper ignores missing function-local entries (Argument, Instruction, BasicBlock) that are not in the value map.
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::ZeroOrMore, cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate IT block based on arch"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow deprecated IT based on ARMv8"), clEnumValN(NoRestrictedIT, "arm-no-restrict-it", "Allow IT blocks based on ARMv7")))
static void LLVM_ATTRIBUTE_UNUSED dumpIR(Function &F, const char *Label, CHRStats *Stats)
std::string getNameStr() const
Returns the name of the Region.
Predicate getPredicate() const
Return the predicate for this instruction.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
bool isFunctionEntryHot(const Function *F)
Returns true if F has hot function entry.
bool contains(const BlockT *BB) const
Check if the region contains a BasicBlock.
LLVM_NODISCARD bool empty() const
StringRef getName() const
Return a constant reference to the value's name.
static bool isHoistable(Instruction *I, DominatorTree &DT)
static bool hasAtLeastTwoBiasedBranches(CHRScope *Scope)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static void hoistValue(Value *V, Instruction *HoistPoint, Region *R, HoistStopMapTy &HoistStopMap, DenseSet< Instruction *> &HoistedSet, DenseSet< PHINode *> &TrivialPHIs, DominatorTree &DT)
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Tail - This calling convention attemps to make calls as fast as possible while guaranteeing that tail...
bool isUnconditional() const
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
void setCondition(Value *V)
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
RegionT * getParent() const
Get the parent of the Region.
static Instruction * getBranchInsertPoint(RegInfo &RI)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isSafeToSpeculativelyExecute(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Return true if the instruction does not have any effects besides calculating the result and does not ...
void stable_sort(R &&Range)
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
StringSet - A wrapper for StringMap that provides set-like functionality.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
A container for analyses that lazily runs them and caches their results.
FunctionPass * createControlHeightReductionLegacyPass()
Legacy analysis pass which computes a DominatorTree.
bool CHRScopeSorter(CHRScope *Scope1, CHRScope *Scope2)
INITIALIZE_PASS_BEGIN(ControlHeightReductionLegacyPass, "chr", "Reduce control height in the hot paths", false, false) INITIALIZE_PASS_END(ControlHeightReductionLegacyPass
unsigned getNumOperands() const
Return number of MDNode operands.
OutputIt copy(R &&Range, OutputIt Out)
iterator_range< element_iterator > elements()
const BasicBlock * getParent() const