@@ -506,25 +506,33 @@ Value *PredicateInfoBuilder::materializeStack(unsigned int &Counter,
506
506
ValInfo->RenamedOp = (RenameStack.end () - Start) == RenameStack.begin ()
507
507
? OrigOp
508
508
: (RenameStack.end () - Start - 1 )->Def ;
509
+ auto CreateSSACopy = [this ](IRBuilderBase &B, Value *Op,
510
+ const Twine &Name = " " ) {
511
+ auto It = PI.DeclarationCache .try_emplace (Op->getType ());
512
+ if (It.second ) {
513
+ // The number of named values is used to detect if a new declaration
514
+ // was added. If so, that declaration is tracked so that it can be
515
+ // removed when the analysis is done. The corner case were a new
516
+ // declaration results in a name clash and the old name being renamed
517
+ // is not considered as that represents an invalid module.
518
+ auto NumDecls = F.getParent ()->getNumNamedValues ();
519
+ Function *IF = Intrinsic::getOrInsertDeclaration (
520
+ F.getParent (), Intrinsic::ssa_copy, Op->getType ());
521
+ if (NumDecls != F.getParent ()->getNumNamedValues ())
522
+ PI.CreatedDeclarations .insert (IF);
523
+ It.first ->second = IF;
524
+ }
525
+ return B.CreateCall (It.first ->second , Op, Name);
526
+ };
509
527
// For edge predicates, we can just place the operand in the block before
510
528
// the terminator. For assume, we have to place it right after the assume
511
529
// to ensure we dominate all uses except assume itself. Always insert
512
530
// right before the terminator or after the assume, so that we insert in
513
531
// proper order in the case of multiple predicateinfo in the same block.
514
- // The number of named values is used to detect if a new declaration was
515
- // added. If so, that declaration is tracked so that it can be removed when
516
- // the analysis is done. The corner case were a new declaration results in
517
- // a name clash and the old name being renamed is not considered as that
518
- // represents an invalid module.
519
532
if (isa<PredicateWithEdge>(ValInfo)) {
520
533
IRBuilder<> B (getBranchTerminator (ValInfo));
521
- auto NumDecls = F.getParent ()->getNumNamedValues ();
522
- Function *IF = Intrinsic::getOrInsertDeclaration (
523
- F.getParent (), Intrinsic::ssa_copy, Op->getType ());
524
- if (NumDecls != F.getParent ()->getNumNamedValues ())
525
- PI.CreatedDeclarations .insert (IF);
526
534
CallInst *PIC =
527
- B. CreateCall (IF , Op, Op->getName () + " ." + Twine (Counter++));
535
+ CreateSSACopy (B , Op, Op->getName () + " ." + Twine (Counter++));
528
536
PI.PredicateMap .insert ({PIC, ValInfo});
529
537
Result.Def = PIC;
530
538
} else {
@@ -534,12 +542,7 @@ Value *PredicateInfoBuilder::materializeStack(unsigned int &Counter,
534
542
// Insert the predicate directly after the assume. While it also holds
535
543
// directly before it, assume(i1 true) is not a useful fact.
536
544
IRBuilder<> B (PAssume->AssumeInst ->getNextNode ());
537
- auto NumDecls = F.getParent ()->getNumNamedValues ();
538
- Function *IF = Intrinsic::getOrInsertDeclaration (
539
- F.getParent (), Intrinsic::ssa_copy, Op->getType ());
540
- if (NumDecls != F.getParent ()->getNumNamedValues ())
541
- PI.CreatedDeclarations .insert (IF);
542
- CallInst *PIC = B.CreateCall (IF, Op);
545
+ CallInst *PIC = CreateSSACopy (B, Op);
543
546
PI.PredicateMap .insert ({PIC, ValInfo});
544
547
Result.Def = PIC;
545
548
}
0 commit comments