23
23
24
24
using namespace swift ;
25
25
26
- // / Adds a new argument to an edge between a branch and a destination
27
- // / block.
28
- // /
29
- // / \param branch The terminator to add the argument to.
30
- // / \param dest The destination block of the edge.
31
- // / \param val The value to the arguments of the branch.
32
- // / \return The created branch. The old branch is deleted.
33
- // / The argument is appended at the end of the argument tuple.
34
26
TermInst *swift::addNewEdgeValueToBranch (TermInst *branch, SILBasicBlock *dest,
35
- SILValue val) {
27
+ SILValue val,
28
+ const InstModCallbacks &callbacks) {
36
29
SILBuilderWithScope builder (branch);
37
30
TermInst *newBr = nullptr ;
38
31
@@ -59,6 +52,7 @@ TermInst *swift::addNewEdgeValueToBranch(TermInst *branch, SILBasicBlock *dest,
59
52
cbi->getLoc (), cbi->getCondition (), cbi->getTrueBB (), trueArgs,
60
53
cbi->getFalseBB (), falseArgs, cbi->getTrueBBCount (),
61
54
cbi->getFalseBBCount ());
55
+ callbacks.createdNewInst (newBr);
62
56
} else if (auto *bi = dyn_cast<BranchInst>(branch)) {
63
57
SmallVector<SILValue, 8 > args;
64
58
@@ -68,13 +62,13 @@ TermInst *swift::addNewEdgeValueToBranch(TermInst *branch, SILBasicBlock *dest,
68
62
args.push_back (val);
69
63
assert (args.size () == dest->getNumArguments ());
70
64
newBr = builder.createBranch (bi->getLoc (), bi->getDestBB (), args);
65
+ callbacks.createdNewInst (newBr);
71
66
} else {
72
67
// At the moment we can only add arguments to br and cond_br.
73
68
llvm_unreachable (" Can't add argument to terminator" );
74
69
}
75
70
76
- branch->dropAllReferences ();
77
- branch->eraseFromParent ();
71
+ callbacks.deleteInst (branch);
78
72
79
73
return newBr;
80
74
}
0 commit comments