MCPcopy Create free account
hub / github.com/AdaptiveCpp/AdaptiveCpp / generateWhileSwitchAround

Function generateWhileSwitchAround

src/compiler/cbs/SubCfgFormation.cpp:1198–1226  ·  view source on GitHub ↗

create the actual while loop around the subcfgs and the switch instruction to select the next subCFG based on the value in \a LastBarrierIdStorage

Source from the content-addressed store, hash-verified

1196// create the actual while loop around the subcfgs and the switch instruction to
1197// select the next subCFG based on the value in \a LastBarrierIdStorage
1198llvm::BasicBlock *generateWhileSwitchAround(llvm::BasicBlock *PreHeader, llvm::BasicBlock *OldEntry,
1199 llvm::BasicBlock *Exit,
1200 llvm::AllocaInst *LastBarrierIdStorage,
1201 std::vector<SubCFG> &SubCFGs) {
1202 auto &F = *PreHeader->getParent();
1203 auto &M = *F.getParent();
1204 const auto &DL = M.getDataLayout();
1205
1206 auto *WhileHeader = llvm::BasicBlock::Create(PreHeader->getContext(), "cbs.while.header",
1207 PreHeader->getParent(), OldEntry);
1208 llvm::IRBuilder Builder{WhileHeader, WhileHeader->getFirstInsertionPt()};
1209 auto *LastID = Builder.CreateLoad(LastBarrierIdStorage->getAllocatedType(), LastBarrierIdStorage,
1210 "cbs.while.last_barr.load");
1211 auto *Switch = Builder.CreateSwitch(LastID, createUnreachableBlock(F), SubCFGs.size());
1212 for (auto &Cfg : SubCFGs) {
1213 Switch->addCase(Builder.getIntN(DL.getLargestLegalIntTypeSizeInBits(), Cfg.getEntryId()),
1214 Cfg.getEntry());
1215 Cfg.getEntry()->replacePhiUsesWith(PreHeader, WhileHeader);
1216 Cfg.getExit()->getTerminator()->replaceSuccessorWith(Exit, WhileHeader);
1217 }
1218 Switch->addCase(Builder.getIntN(DL.getLargestLegalIntTypeSizeInBits(), ExitBarrierId), Exit);
1219
1220 Builder.SetInsertPoint(PreHeader->getTerminator());
1221 Builder.CreateStore(
1222 llvm::ConstantInt::get(LastBarrierIdStorage->getAllocatedType(), EntryBarrierId),
1223 LastBarrierIdStorage);
1224 PreHeader->getTerminator()->replaceSuccessorWith(OldEntry, WhileHeader);
1225 return WhileHeader;
1226}
1227
1228// drops all lifetime intrinsics - they are misinforming ASAN otherwise (and are
1229// not really fixable at the right scope..)

Callers 1

formSubCfgsFunction · 0.85

Calls 6

createUnreachableBlockFunction · 0.85
getFunction · 0.85
getEntryIdMethod · 0.80
getEntryMethod · 0.80
getExitMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected