[cost] Fix control variables to pick up global vars in prune instructions

Reviewed By: ngorogiannis

Differential Revision: D13322062

fbshipit-source-id: 4e8081103
master
Ezgi Çiçek 6 years ago committed by Facebook Github Bot
parent 4b2c65f2e2
commit 6017c2ec54

@ -73,10 +73,18 @@ module TransferFunctionsControlDeps (CFG : ProcCfg.S) = struct
let get_vars_in_exp exp prune_node loop_head =
assert (Exp.program_vars exp |> Sequence.is_empty) ;
(* We should never have program variables in prune nodes *)
let global_control_vars =
Exp.program_vars exp
|> Sequence.fold ~init:ControlDepSet.empty ~f:(fun global_acc pvar ->
let cvar = Var.of_pvar pvar in
if Pvar.is_global pvar then ControlDepSet.add {cvar; loop_head} global_acc
else
Logging.die InternalError
"We should never have non-global program variables in prune nodes: %a@." Var.pp
cvar )
in
Exp.free_vars exp
|> Sequence.fold ~init:ControlDepSet.empty ~f:(fun acc id ->
|> Sequence.fold ~init:global_control_vars ~f:(fun acc id ->
match
Procdesc.Node.find_in_node_or_preds prune_node ~f:(find_vars_in_decl id loop_head)
with

@ -160,6 +160,9 @@ codetoanalyze/c/performance/loops.c, larger_state_FN, 3, EXPENSIVE_EXECUTION_TIM
codetoanalyze/c/performance/loops.c, larger_state_FN, 4, EXPENSIVE_EXECUTION_TIME_CALL, no_bucket, ERROR, [with estimated cost 1006, degree = 0]
codetoanalyze/c/performance/loops.c, larger_state_FN, 5, EXPENSIVE_EXECUTION_TIME_CALL, no_bucket, ERROR, [with estimated cost 1006, degree = 0]
codetoanalyze/c/performance/loops.c, larger_state_FN, 7, EXPENSIVE_EXECUTION_TIME_CALL, no_bucket, ERROR, [with estimated cost 1006, degree = 0]
codetoanalyze/c/performance/loops.c, loop_use_global_vars, 1, EXPENSIVE_EXECUTION_TIME_CALL, no_bucket, ERROR, [with estimated cost 4 + 4 ⋅ x.ub + 2 ⋅ (1+max(0, x.ub)), degree = 1]
codetoanalyze/c/performance/loops.c, loop_use_global_vars, 1, EXPENSIVE_EXECUTION_TIME_CALL, no_bucket, ERROR, [with estimated cost 3 + 4 ⋅ x.ub + 2 ⋅ (1+max(0, x.ub)), degree = 1]
codetoanalyze/c/performance/loops.c, loop_use_global_vars, 1, EXPENSIVE_EXECUTION_TIME_CALL, no_bucket, ERROR, [with estimated cost 3 + 4 ⋅ x.ub + 2 ⋅ (1+max(0, x.ub)), degree = 1]
codetoanalyze/c/performance/purity.c, loop, 2, EXPENSIVE_EXECUTION_TIME_CALL, no_bucket, ERROR, [with estimated cost 7006, degree = 0]
codetoanalyze/c/performance/purity.c, loop, 2, EXPENSIVE_EXECUTION_TIME_CALL, no_bucket, ERROR, [with estimated cost 7006, degree = 0]
codetoanalyze/c/performance/purity.c, loop, 3, EXPENSIVE_EXECUTION_TIME_CALL, no_bucket, ERROR, [with estimated cost 7006, degree = 0]

@ -59,3 +59,14 @@ void larger_state_FN() {
}
}
}
static int array1[] = {1, 2, 3};
static int array2[] = {};
// Cvars will initially contain array1 and array2 but will be removed
// since they are invariant
void loop_use_global_vars(int x) {
for (int i = 0; i < x && array1 != array2; i++) {
// do something
}
}

Loading…
Cancel
Save