-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completely revamp variable usage analysis
A new analysis now distinguishes between: - whether a variable may possibly not appear in the C code after the C preprocessor has run, triggering an unused variable error; and - the upper bound of the number of run-time uses of a variable (for substitution and elimination purposes). Quoting the comment: (* This module implements a tree traversal that updates the `mark` field of nodes (specifically: of let-binders, branch binders and function parameter binders) with information regarding the usage of those variables. This module computes two slightly different pieces of information. - The first one is whether a given variable occurs in the generated C *after* C preprocessing. This is called an occurrence, and computing it involves reasoning about ifdefs. This is used exclusively to defeat C compilers' unused variable warnings. - The second one is an upper bound on the number of uses of a given variable. We call it a usage, and it allows removing unused variables (i.e, used at most zero times), as well as inlining variables used at most once. Both of these optimizations are subject to various syntactic criteria. *)
- Loading branch information
Showing
10 changed files
with
299 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ lib/Version.ml | |
*.runlim | ||
karamel-nofstar.opam | ||
lib/AutoConfig.ml | ||
*.orig | ||
.exrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(* See comments in UseAnalysis.ml *) | ||
|
||
(* Whether the variable may occur, post-C preprocessor, in the generated code. *) | ||
type occurrence = MaybeAbsent | Present | ||
[@@deriving show] | ||
|
||
(* How many times this variable will end up being used, at runtime. *) | ||
type usage = AtMost of int | ||
[@@deriving show] | ||
|
||
let is_atmost k (AtMost n) = n <= k | ||
|
||
let default = MaybeAbsent, AtMost max_int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.