@@ -4303,37 +4303,46 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
4303
4303
" branch argument types do not match arguments for dest bb" );
4304
4304
}
4305
4305
4306
- void checkCondBranchInst (CondBranchInst *CBI ) {
4306
+ void checkCondBranchInst (CondBranchInst *cbi ) {
4307
4307
// It is important that cond_br keeps an i1 type. ARC Sequence Opts assumes
4308
4308
// that cond_br does not use reference counted values or decrement reference
4309
4309
// counted values under the assumption that the instruction that computes
4310
4310
// the i1 is the use/decrement that ARC cares about and that after that
4311
4311
// instruction is evaluated, the scalar i1 has a different identity and the
4312
4312
// object can be deallocated.
4313
- requireSameType (CBI ->getCondition ()->getType (),
4313
+ requireSameType (cbi ->getCondition ()->getType (),
4314
4314
SILType::getBuiltinIntegerType (
4315
- 1 , CBI ->getCondition ()->getType ().getASTContext ()),
4315
+ 1 , cbi ->getCondition ()->getType ().getASTContext ()),
4316
4316
" condition of conditional branch must have Int1 type" );
4317
4317
4318
- require (CBI ->getTrueArgs ().size () == CBI ->getTrueBB ()->args_size (),
4318
+ require (cbi ->getTrueArgs ().size () == cbi ->getTrueBB ()->args_size (),
4319
4319
" true branch has wrong number of arguments for dest bb" );
4320
- require (CBI->getTrueBB () != CBI->getFalseBB (),
4321
- " identical destinations" );
4322
- require (std::equal (CBI->getTrueArgs ().begin (), CBI->getTrueArgs ().end (),
4323
- CBI->getTrueBB ()->args_begin (),
4320
+ require (cbi->getTrueBB () != cbi->getFalseBB (), " identical destinations" );
4321
+ require (std::equal (cbi->getTrueArgs ().begin (), cbi->getTrueArgs ().end (),
4322
+ cbi->getTrueBB ()->args_begin (),
4324
4323
[&](SILValue branchArg, SILArgument *bbArg) {
4325
4324
return verifyBranchArgs (branchArg, bbArg);
4326
4325
}),
4327
4326
" true branch argument types do not match arguments for dest bb" );
4328
4327
4329
- require (CBI ->getFalseArgs ().size () == CBI ->getFalseBB ()->args_size (),
4328
+ require (cbi ->getFalseArgs ().size () == cbi ->getFalseBB ()->args_size (),
4330
4329
" false branch has wrong number of arguments for dest bb" );
4331
- require (std::equal (CBI ->getFalseArgs ().begin (), CBI ->getFalseArgs ().end (),
4332
- CBI ->getFalseBB ()->args_begin (),
4330
+ require (std::equal (cbi ->getFalseArgs ().begin (), cbi ->getFalseArgs ().end (),
4331
+ cbi ->getFalseBB ()->args_begin (),
4333
4332
[&](SILValue branchArg, SILArgument *bbArg) {
4334
4333
return verifyBranchArgs (branchArg, bbArg);
4335
4334
}),
4336
4335
" false branch argument types do not match arguments for dest bb" );
4336
+ // When we are in ossa, cond_br can not have any arguments that are
4337
+ // non-trivial.
4338
+ if (!F.hasOwnership ())
4339
+ return ;
4340
+
4341
+ require (llvm::all_of (cbi->getOperandValues (),
4342
+ [&](SILValue v) -> bool {
4343
+ return v->getType ().isTrivial (*cbi->getFunction ());
4344
+ }),
4345
+ " cond_br must not have a non-trivial value in ossa." );
4337
4346
}
4338
4347
4339
4348
void checkDynamicMethodBranchInst (DynamicMethodBranchInst *DMBI) {
@@ -4905,38 +4914,13 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
4905
4914
CurInstruction = TI;
4906
4915
4907
4916
// Check for non-cond_br critical edges.
4908
- auto *CBI = dyn_cast<CondBranchInst>(TI);
4909
- if (!CBI) {
4910
- for (unsigned Idx = 0 , e = BB.getSuccessors ().size (); Idx != e; ++Idx) {
4911
- require (!isCriticalEdgePred (TI, Idx),
4912
- " non cond_br critical edges not allowed" );
4913
- }
4917
+ if (isa<CondBranchInst>(TI)) {
4914
4918
continue ;
4915
4919
}
4916
- // In ownership qualified SIL, ban critical edges from CondBranchInst that
4917
- // have non-trivial arguments.
4918
- //
4919
- // FIXME: it would be far simpler to ban all critical edges in general.
4920
- if (!F->hasOwnership ())
4921
- continue ;
4922
4920
4923
- if (isCriticalEdgePred (CBI, CondBranchInst::TrueIdx)) {
4924
- require (
4925
- llvm::all_of (CBI->getTrueArgs (),
4926
- [](SILValue V) -> bool {
4927
- return V.getOwnershipKind () ==
4928
- ValueOwnershipKind::None;
4929
- }),
4930
- " cond_br with critical edges must not have a non-trivial value" );
4931
- }
4932
- if (isCriticalEdgePred (CBI, CondBranchInst::FalseIdx)) {
4933
- require (
4934
- llvm::all_of (CBI->getFalseArgs (),
4935
- [](SILValue V) -> bool {
4936
- return V.getOwnershipKind () ==
4937
- ValueOwnershipKind::None;
4938
- }),
4939
- " cond_br with critical edges must not have a non-trivial value" );
4921
+ for (unsigned Idx = 0 , e = BB.getSuccessors ().size (); Idx != e; ++Idx) {
4922
+ require (!isCriticalEdgePred (TI, Idx),
4923
+ " non cond_br critical edges not allowed" );
4940
4924
}
4941
4925
}
4942
4926
}
0 commit comments