Skip to content

Commit b7df828

Browse files
mi-acV8-internal LUCI CQ
authored andcommitted
Diversify argument patterns for optimized function generators
This diversifies the arguments for the function calls in V8's typical function-optimization shortcuts. Often, reproducers have an argument pattern across the functions that is not all equal. For getting polymorphic feedback or a type deviation in the optimized function call, we see patterns like: f(a); f(a); %Opt(f); f(b); Or: f(a); f(b); %Opt(f); f(c); Though Fuzzilli will eventually mutate the arguments, this change attempts to tickle out this diversity a bit more. With the largest percentage we retain the old behavior. Change-Id: I58c8e7361aa3ce122a034417708dcedb8b4d7888 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/9020237 Reviewed-by: Dominik Klemba <tacet@google.com> Commit-Queue: Michael Achenbach <machenbach@google.com>
1 parent d896980 commit b7df828

1 file changed

Lines changed: 32 additions & 10 deletions

File tree

Sources/FuzzilliCli/Profiles/V8CommonProfile.swift

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,40 +73,62 @@ public let ForceJITCompilationThroughLoopGenerator = CodeGenerator("ForceJITComp
7373
}
7474
}
7575

76+
// Choose argument lists for four function calls of the same function with
77+
// interesting optimization patterns.
78+
func chooseArgumentLists(_ b: ProgramBuilder, forCalling f: Variable) -> ([Variable], [Variable], [Variable], [Variable]) {
79+
var pool: [[Variable]?] = [nil, nil, nil]
80+
81+
let getArg = { (i: Int) -> [Variable] in
82+
if pool[i] == nil {
83+
pool[i] = b.randomArguments(forCalling: f)
84+
}
85+
return pool[i]!
86+
}
87+
88+
let keepRates = [1.0, 0.97, 0.85, 0.75]
89+
90+
let args = (0..<4).map { i in
91+
probability(keepRates[i]) ? getArg(0) : getArg(probability(0.5) ? 1 : 2)
92+
}
93+
94+
assert(args.count == 4)
95+
return (args[0], args[1], args[2], args[3])
96+
}
97+
7698
public let ForceTurboFanCompilationGenerator = CodeGenerator("ForceTurboFanCompilationGenerator", inputs: .required(.function())) { b, f in
7799
assert(b.type(of: f).Is(.function()))
78-
let arguments = b.randomArguments(forCalling: f)
100+
let (args1, args2, args3, args4) = chooseArgumentLists(b, forCalling: f)
79101

80102
let guardCalls = probability(0.5)
81103

82-
b.callFunction(f, withArgs: arguments, guard: guardCalls)
104+
b.callFunction(f, withArgs: args1, guard: guardCalls)
83105

84106
b.eval("%PrepareFunctionForOptimization(%@)", with: [f]);
85107

86-
b.callFunction(f, withArgs: arguments, guard: guardCalls)
87-
b.callFunction(f, withArgs: arguments, guard: guardCalls)
108+
b.callFunction(f, withArgs: args2, guard: guardCalls)
109+
b.callFunction(f, withArgs: args3, guard: guardCalls)
88110

89111
b.eval("%OptimizeFunctionOnNextCall(%@)", with: [f]);
90112

91-
b.callFunction(f, withArgs: arguments, guard: guardCalls)
113+
b.callFunction(f, withArgs: args4, guard: guardCalls)
92114
}
93115

94116
public let ForceMaglevCompilationGenerator = CodeGenerator("ForceMaglevCompilationGenerator", inputs: .required(.function())) { b, f in
95117
assert(b.type(of: f).Is(.function()))
96-
let arguments = b.randomArguments(forCalling: f)
118+
let (args1, args2, args3, args4) = chooseArgumentLists(b, forCalling: f)
97119

98120
let guardCalls = probability(0.5)
99121

100-
b.callFunction(f, withArgs: arguments, guard: guardCalls)
122+
b.callFunction(f, withArgs: args1, guard: guardCalls)
101123

102124
b.eval("%PrepareFunctionForOptimization(%@)", with: [f]);
103125

104-
b.callFunction(f, withArgs: arguments, guard: guardCalls)
105-
b.callFunction(f, withArgs: arguments, guard: guardCalls)
126+
b.callFunction(f, withArgs: args2, guard: guardCalls)
127+
b.callFunction(f, withArgs: args3, guard: guardCalls)
106128

107129
b.eval("%OptimizeMaglevOnNextCall(%@)", with: [f]);
108130

109-
b.callFunction(f, withArgs: arguments, guard: guardCalls)
131+
b.callFunction(f, withArgs: args4, guard: guardCalls)
110132
}
111133

112134
public let TurbofanVerifyTypeGenerator = CodeGenerator("TurbofanVerifyTypeGenerator", inputs: .one) { b, v in

0 commit comments

Comments
 (0)