llvm.org GIT mirror llvm / aca5f16
[WebAssembly] Only RAUW a constant once in FixFunctionBitcasts When we collect 2 uses of a function in FindUses and then RAUW when we visit the first, we end up visiting the wrapper (because the second was RAUW'd). We still want to use RAUW instead of just Use->set() because it has special handling for Constants, so this patch just ensures that only one use of each constant is added to the work list. Differential Revision: https://reviews.llvm.org/D28504 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291603 91177308-0d34-0410-b5e6-96231b3b80d8 Derek Schuff 3 years ago
2 changed file(s) with 28 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
6161 // Recursively descend the def-use lists from V to find non-bitcast users of
6262 // bitcasts of V.
6363 static void FindUses(Value *V, Function &F,
64 SmallVectorImpl> &Uses) {
64 SmallVectorImpl> &Uses,
65 SmallPtrSetImpl &ConstantBCs) {
6566 for (Use &U : V->uses()) {
6667 if (BitCastOperator *BC = dyn_cast(U.getUser()))
67 FindUses(BC, F, Uses);
68 else if (U.get()->getType() != F.getType())
68 FindUses(BC, F, Uses, ConstantBCs);
69 else if (U.get()->getType() != F.getType()) {
70 if (isa(U.get())) {
71 // Only add constant bitcasts to the list once; they get RAUW'd
72 auto c = ConstantBCs.insert(cast(U.get()));
73 if (!c.second) continue;
74 }
6975 Uses.push_back(std::make_pair(&U, &F));
76 }
7077 }
7178 }
7279
121128
122129 bool FixFunctionBitcasts::runOnModule(Module &M) {
123130 SmallVector, 0> Uses;
131 SmallPtrSet ConstantBCs;
124132
125133 // Collect all the places that need wrappers.
126 for (Function &F : M)
127 FindUses(&F, F, Uses);
134 for (Function &F : M) FindUses(&F, F, Uses, ConstantBCs);
128135
129136 DenseMap, Function *> Wrappers;
130137
66
77 ; CHECK-LABEL: test:
88 ; CHECK-NEXT: call .Lbitcast@FUNCTION{{$}}
9 ; CHECK-NEXT: call .Lbitcast@FUNCTION{{$}}
910 ; CHECK-NEXT: call .Lbitcast.1@FUNCTION{{$}}
1011 ; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 0
1112 ; CHECK-NEXT: call .Lbitcast.2@FUNCTION, $pop[[L0]]{{$}}
13 ; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 0
14 ; CHECK-NEXT: call .Lbitcast.2@FUNCTION, $pop[[L1]]{{$}}
15 ; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 0
16 ; CHECK-NEXT: call .Lbitcast.2@FUNCTION, $pop[[L2]]{{$}}
17 ; CHECK-NEXT: call foo0@FUNCTION
1218 ; CHECK-NEXT: i32.call $drop=, .Lbitcast.3@FUNCTION{{$}}
1319 ; CHECK-NEXT: call foo2@FUNCTION{{$}}
20 ; CHECK-NEXT: call foo1@FUNCTION{{$}}
1421 ; CHECK-NEXT: call foo3@FUNCTION{{$}}
1522 ; CHECK-NEXT: .endfunc
1623
4653 define void @test() {
4754 entry:
4855 call void bitcast (void (i32)* @has_i32_arg to void ()*)()
56 call void bitcast (void (i32)* @has_i32_arg to void ()*)()
4957 call void bitcast (i32 ()* @has_i32_ret to void ()*)()
5058 call void bitcast (void ()* @foo0 to void (i32)*)(i32 0)
59 %p = bitcast void ()* @foo0 to void (i32)*
60 call void %p(i32 0)
61 %q = bitcast void ()* @foo0 to void (i32)*
62 call void %q(i32 0)
63 %r = bitcast void (i32)* %q to void ()*
64 call void %r()
5165 %t = call i32 bitcast (void ()* @foo1 to i32 ()*)()
5266 call void bitcast (void ()* @foo2 to void ()*)()
67 call void @foo1()
5368 call void @foo3()
69
5470 ret void
5571 }