create the actual while loop around the subcfgs and the switch instruction to select the next subCFG based on the value in \a LastBarrierIdStorage
| 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 |
| 1198 | llvm::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..) |
no test coverage detected