Skip to content

Commit

Permalink
Move option into separate forceLoopUnrollForFewLoops
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-schwarz committed Feb 12, 2023
1 parent 1af132a commit 8992f1a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
35 changes: 20 additions & 15 deletions src/util/loopUnrolling.ml
Original file line number Diff line number Diff line change
Expand Up @@ -334,22 +334,27 @@ end

let loop_unrolling_factor loopStatement func totalLoops =
let configFactor = get_int "exp.unrolling-factor" in
let unrollFunctionCalled = try
let thisVisitor = new loopUnrollingCallVisitor in
ignore (visitCilStmt thisVisitor loopStatement);
false;
with
Found -> true
in
(*unroll up to near an instruction count, higher if the loop uses malloc/lock/threads *)
let targetInstructions = if unrollFunctionCalled then 50 else 25 in
let loopStats = AutoTune0.collectFactors visitCilStmt loopStatement in
let targetFactor = if loopStats.instructions > 0 then targetInstructions / loopStats.instructions else 0 in (* Don't unroll empty (= while(1){}) loops*)
let fixedLoop = fixedLoopSize loopStatement func in
if AutoTune0.isActivated "loopUnrollHeuristic" then
match fixedLoop with
| Some i -> if i * loopStats.instructions < 100 then (print_endline "fixed loop size"; i) else if totalLoops < 17 then max (100 / loopStats.instructions) 10 else 100 / loopStats.instructions
| _ -> if totalLoops < 17 then max 10 targetFactor else targetFactor (*unroll at least 10 times if there are only few loops*)
let unrollFunctionCalled = try
let thisVisitor = new loopUnrollingCallVisitor in
ignore (visitCilStmt thisVisitor loopStatement);
false;
with
Found -> true
in
(*unroll up to near an instruction count, higher if the loop uses malloc/lock/threads *)
let targetInstructions = if unrollFunctionCalled then 50 else 25 in
let loopStats = AutoTune0.collectFactors visitCilStmt loopStatement in
if loopStats.instructions > 0 then
let fixedLoop = fixedLoopSize loopStatement func in
(* Unroll at least 10 times if there are only few (17?) loops *)
let unroll_min = if totalLoops < 17 && AutoTune0.isActivated "forceLoopUnrollForFewLoops" then 10 else 0 in
match fixedLoop with
| Some i -> if i * loopStats.instructions < 100 then (print_endline "fixed loop size"; i) else max unroll_min (100 / loopStats.instructions)
| _ -> max unroll_min (targetInstructions / loopStats.instructions)
else
(* Don't unroll empty (= while(1){}) loops*)
0
else
configFactor

Expand Down
2 changes: 1 addition & 1 deletion src/util/options.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@
},
"activated": {
"title": "ana.autotune.activated",
"description": "Lists of activated tuning options. By default all are activated",
"description": "Lists of activated tuning options.",
"type": "array",
"items": { "type": "string" },
"default": [
Expand Down

0 comments on commit 8992f1a

Please sign in to comment.