Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/cil.tex
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ \subsection{Using CIL as a library}
The \t{Mergecil.merge: Cil.file list -> string -> Cil.file} function merges
multiple files. You can then invoke your analysis function on the resulting
\t{Cil.file} data structure. You might want to call
\t{Rmtmps.removeUnusedTemps} first to clean up the prototypes and variables
\t{RmUnused.removeUnused} first to clean up the prototypes and variables
that are not used. Then you can call the function \t{Cil.dumpFile:
cilPrinter -> out\_channel -> Cil.file -> unit} to print the file to a
given output channel. A good \t{cilPrinter} to use is
Expand Down
2 changes: 1 addition & 1 deletion src/cil.mli
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ and varinfo = {

mutable vreferenced: bool;
(** True if this variable is ever referenced. This is computed by
{!Rmtmps.removeUnusedTemps}. It is safe to just initialize this to False *)
{!RmUnused.removeUnused}. It is safe to just initialize this to False *)

mutable vdescr: Pretty.doc;
(** For most temporary variables, a description of what the var holds.
Expand Down
16 changes: 8 additions & 8 deletions src/ciloptions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -330,24 +330,24 @@ let options : (string * Arg.spec * string) list =
is_default (not !Cil.useCaseRange));

"--keepunused",
Arg.Set Rmtmps.keepUnused,
Arg.Set RmUnused.keepUnused,
(" Do not remove the unused variables and types" ^
is_default !Rmtmps.keepUnused);
is_default !RmUnused.keepUnused);

"--nokeepunused",
Arg.Clear Rmtmps.keepUnused,
Arg.Clear RmUnused.keepUnused,
(" Remove unused variables and types" ^
is_default (not !Rmtmps.keepUnused));
is_default (not !RmUnused.keepUnused));

"--rmUnusedInlines",
Arg.Set Rmtmps.rmUnusedInlines,
Arg.Set RmUnused.rmUnusedInlines,
(" Delete any unused inline functions" ^
is_default !Rmtmps.rmUnusedInlines);
is_default !RmUnused.rmUnusedInlines);

"--noRmUnusedInlines",
Arg.Clear Rmtmps.rmUnusedInlines,
Arg.Clear RmUnused.rmUnusedInlines,
(" Do not delete any unused inline functions" ^
is_default (not !Rmtmps.rmUnusedInlines));
is_default (not !RmUnused.rmUnusedInlines));

(* Output Options *)
"", Arg.Unit (fun () -> ()), " \n\t\tOutput Options\n";
Expand Down
2 changes: 1 addition & 1 deletion src/cilutil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let strictChecking= ref false (* If doCheck is true and warnings are found,

let printStats = ref false

(* when 'sliceGlobal' is set, then when 'rmtmps' runs, only globals*)
(* when 'sliceGlobal' is set, then when 'rmUnused' runs, only globals*)
(* marked with #pragma cilnoremove(whatever) are kept; when used with *)
(* cilly.asm.exe, the effect is to slice the input on the noremove symbols *)
let sliceGlobal = ref false
Expand Down
4 changes: 2 additions & 2 deletions src/frontc/cparser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -958,13 +958,13 @@ statement_no_null:
{(* The only attribute that should appear here
is "unused". For now, we drop this on the
floor, since unused labels are usually
removed anyways by Rmtmps. *)
removed anyways by RmUnused. *)
LABEL (fst $1, $5, joinLoc (snd $1) $4)}
| IDENT COLON attribute_nocv_list location SEMICOLON
{(* The only attribute that should appear here
is "unused". For now, we drop this on the
floor, since unused labels are usually
removed anyways by Rmtmps. *)
removed anyways by RmUnused. *)
LABEL (fst $1, NOP ($5), joinLoc (snd $1) $4)}
| CASE expression COLON statement location
{CASE (fst $2, $4, joinLoc $1 $5, joinLoc $1 $3)}
Expand Down
2 changes: 1 addition & 1 deletion src/goblintCil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Formatcil = Formatcil
module Machdep = Machdep
module Machdepenv = Machdepenv
module Mergecil = Mergecil
module Rmtmps = Rmtmps
module RmUnused = RmUnused

(** {1 FrontC modules} *)

Expand Down
4 changes: 2 additions & 2 deletions src/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ let parseOneFile (fname: string) : C.file =

if (not (Feature.enabled "epicenter")) then (
(* sm: remove unused temps to cut down on gcc warnings *)
(* (Stats.time "usedVar" Rmtmps.removeUnusedTemps cil); *)
(* (Stats.time "usedVar" RmUnused.removeUnused cil); *)
(* (trace "sm" (dprintf "removing unused temporaries\n")); *)
(Rmtmps.removeUnusedTemps cil)
(RmUnused.removeUnused cil)
);
cil

Expand Down
13 changes: 7 additions & 6 deletions src/rmtmps.ml → src/rmUnused.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@

*)

(* rmtmps.ml *)
(* implementation for rmtmps.mli *)
(* rmUnused.ml *)
(* implementation for rmUnused.mli *)
(* previously named Rmtmps, renamed to RmUnused to clarify that not only temporaries are removed *)

open Pretty
open Cil
Expand All @@ -50,7 +51,7 @@ let keepUnused = ref false
let rmUnusedInlines = ref false


let trace = Trace.trace "rmtmps"
let trace = Trace.trace "rmunused"



Expand Down Expand Up @@ -637,7 +638,7 @@ class markUsedLabels (labelMap: (string, unit) H.t) = object
Goto (dest, _) ->
let (ln, _, _), _ = labelsToKeep !dest.labels in
if ln = "" then
E.s (E.bug "rmtmps: destination of statement does not have labels");
E.s (E.bug "rmUnused: destination of statement does not have labels");
(* Mark it as used *)
H.replace labelMap ln ();
DoChildren
Expand All @@ -648,7 +649,7 @@ class markUsedLabels (labelMap: (string, unit) H.t) = object
| AddrOfLabel dest ->
let (ln, _, _), _ = labelsToKeep !dest.labels in
if ln = "" then
E.s (E.bug "rmtmps: destination of address of label does not have labels");
E.s (E.bug "rmUnused: destination of address of label does not have labels");
(* Mark it as used *)
H.replace labelMap ln ();
SkipChildren
Expand Down Expand Up @@ -778,7 +779,7 @@ type rootsFilter = global -> bool

let isDefaultRoot = isExportedRoot

let removeUnusedTemps ?(isRoot : rootsFilter = isDefaultRoot) file =
let removeUnused ?(isRoot : rootsFilter = isDefaultRoot) file =
if !keepUnused || Trace.traceActive "disableTmpRemoval" then
Trace.trace "disableTmpRemoval" (dprintf "temp removal disabled\n")
else
Expand Down
16 changes: 8 additions & 8 deletions src/rmtmps.mli → src/rmUnused.mli
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

*)

(* rmtmps.mli *)
(* rmUnused.mli *)
(* remove unused things from cil files: *)
(* - local temporaries introduced but not used *)
(* - global declarations that are not used *)
Expand All @@ -46,18 +46,18 @@

(* Some clients may wish to augment or replace the standard strategy
for finding the initially reachable roots. The optional
"isRoot" argument to Rmtmps.removeUnusedTemps grants this
"isRoot" argument to RmUnused.removeUnused grants this
flexibility. If given, it should name a function which will return
true if a given global should be treated as a retained root.

Function Rmtmps.isDefaultRoot encapsulates the default root
Function RmUnused.isDefaultRoot encapsulates the default root
collection, which consists of those global variables and functions
which are visible to the linker and runtime loader. A client's
root filter can use this if the goal is to augment rather than
replace the standard logic. Function Rmtmps.isExportedRoot is an
replace the standard logic. Function RmUnused.isExportedRoot is an
alternate name for this same function.

Function Rmtmps.isCompleteProgramRoot is an example of an alternate
Function RmUnused.isCompleteProgramRoot is an example of an alternate
root collection. This function assumes that it is operating on a
complete program rather than just one object file. It treats
"main()" as a root, as well as any function carrying the
Expand All @@ -75,8 +75,8 @@ val isExportedRoot : rootsFilter
val isCompleteProgramRoot : rootsFilter

(* process a complete Cil file *)
val removeUnusedTemps: ?isRoot:rootsFilter -> Cil.file -> unit
val removeUnused : ?isRoot:rootsFilter -> Cil.file -> unit


val keepUnused: bool ref (* Set this to true to turn off this module *)
val rmUnusedInlines: bool ref (* Delete unused inline funcs in gcc mode? *)
val keepUnused : bool ref (* Set this to true to turn off this module *)
val rmUnusedInlines : bool ref (* Delete unused inline funcs in gcc mode? *)
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions test/testcil.pl
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ sub addToGroup {
"Notbug. Should fail since we don't pad argument lists");
addTest("test/restrict EXTRAARGS=-std=c9x _GNUCC=1");
addTest("test/restrict1 _GNUCC=1");
addTest("testrun/rmtmps1 ");
addTest("testrun/rmtmps2 _GNUCC=1");
addTest("testrun/rmUnused1 ");
addTest("testrun/rmUnused2 _GNUCC=1");
addTest("test/proto1 ");
addBadComment("test/proto1",
"Bug. CIL doesn't like pointers to old-style functions...");
Expand All @@ -487,8 +487,8 @@ sub addToGroup {
"Bug. Unsupported C11 implicit initialization of union padding.");
addTest("runall/extinline ");

addTest("testrun/rmtmps-attr ");
addBadComment("testrun/rmtmps-attr",
addTest("testrun/rmUnused-attr ");
addBadComment("testrun/rmUnused-attr",
"Bug. A limitation of our support for attributes");

addTest("testrun/vsp");
Expand Down