Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Do not attempt to merge inline functions by default #72

Merged
merged 4 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/mergecil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ let usePathCompression = false
(* Try to merge definitions of inline functions. They can appear in multiple
* files and we would like them all to be the same. This can slow down the
* merger an order of magnitude !!! *)
let mergeInlines = true
let merge_inlines = ref false

let mergeInlinesRepeat = mergeInlines && true
let mergeInlinesRepeat () = !merge_inlines && true

let mergeInlinesWithAlphaConvert = mergeInlines && true
let mergeInlinesWithAlphaConvert () = !merge_inlines && true

(* when true, merge duplicate definitions of externally-visible functions;
* this uses a mechanism which is faster than the one for inline functions,
Expand Down Expand Up @@ -296,7 +296,7 @@ let tEq: (int * string, typeinfo node) H.t = H.create 111 (* Type names*)
let iEq: (int * string, varinfo node) H.t = H.create 111 (* Inlines *)

(* Sometimes we want to merge synonyms. We keep some tables indexed by names.
* Each name is mapped to multiple exntries *)
* Each name is mapped to multiple entries *)
let vSyn: (string, varinfo node) H.t = H.create 111 (* Not actually used *)
let iSyn: (string, varinfo node) H.t = H.create 111 (* Inlines *)
let sSyn: (string, compinfo node) H.t = H.create 111
Expand Down Expand Up @@ -540,7 +540,7 @@ let rec combineTypes (what: combineWhat)
oldfidx oldrt fidx rt
in
if oldva != va then
raise (Failure "(diferent vararg specifiers)");
raise (Failure "(different vararg specifiers)");
(* If one does not have arguments, believe the one with the
* arguments *)
let newargs =
Expand Down Expand Up @@ -879,7 +879,7 @@ let oneFilePass1 (f:file) : unit =
if fdec.svar.vstorage <> Static then begin
matchVarinfo fdec.svar (l, !currentDeclIdx)
end else begin
if fdec.svar.vinline && mergeInlines then
if fdec.svar.vinline && !merge_inlines then
(* Just create the nodes for inline functions *)
ignore (getNode iEq iSyn !currentFidx
fdec.svar.vname fdec.svar (Some (l, !currentDeclIdx)))
Expand Down Expand Up @@ -1455,9 +1455,9 @@ let oneFilePass2 (f: file) =
setFormals fdec fdec.sformals
end;
(* See if we can remove this inline function *)
if fdec'.svar.vinline && mergeInlines then begin
if fdec'.svar.vinline && !merge_inlines then begin
let printout =
(* Temporarily turn of printing of lines *)
(* Temporarily turn off printing of lines *)
let oldprintln = !lineDirectiveStyle in
lineDirectiveStyle := None;
(* Temporarily set the name to all functions in the same way *)
Expand All @@ -1481,7 +1481,7 @@ let oneFilePass2 (f: file) =
in
(* Remember the original type *)
let origType = fdec'.svar.vtype in
if mergeInlinesWithAlphaConvert then begin
if mergeInlinesWithAlphaConvert () then begin
(* Rename the formals *)
List.iter renameOne fdec'.sformals;
(* Reflect in the type *)
Expand All @@ -1493,7 +1493,7 @@ let oneFilePass2 (f: file) =
let res = d_global () g' in
lineDirectiveStyle := oldprintln;
fdec'.svar.vname <- newname;
if mergeInlinesWithAlphaConvert then begin
if mergeInlinesWithAlphaConvert () then begin
(* Do the locals in reverse order *)
List.iter undoRenameOne (List.rev fdec'.slocals);
(* Do the formals in reverse order *)
Expand Down Expand Up @@ -1526,7 +1526,7 @@ let oneFilePass2 (f: file) =
* We should reuse this, but watch for the case when the inline
* was already used. *)
if H.mem varUsedAlready fdec'.svar.vname then begin
if mergeInlinesRepeat then begin
if mergeInlinesRepeat () then begin
repeatPass2 := true
end else begin
ignore (warn "Inline function %s because it is used before it is defined" fdec'.svar.vname);
Expand Down Expand Up @@ -1708,7 +1708,7 @@ let oneFilePass2 (f: file) =
(* See if we must re-visit the globals in this file because an inline that
* is being removed was used before we saw the definition and we decided to
* remove it *)
if mergeInlinesRepeat && !repeatPass2 then begin
if mergeInlinesRepeat () && !repeatPass2 then begin
if debugMerge || !E.verboseFlag then
ignore (E.log "Repeat final merging phase (%d): %s\n"
!currentFidx f.fileName);
Expand Down Expand Up @@ -1754,7 +1754,7 @@ let merge (files: file list) (newname: string) : file =
doMergeSynonyms sSyn sEq matchCompInfo;
doMergeSynonyms eSyn eEq matchEnumInfo;
doMergeSynonyms tSyn tEq matchTypeInfo;
if mergeInlines then begin
if !merge_inlines then begin
(* Copy all the nodes from the iEq to vEq as well. This is needed
* because vEq will be used for variable renaming *)
H.iter (fun k n -> H.add vEq k n) iEq;
Expand All @@ -1768,7 +1768,7 @@ let merge (files: file list) (newname: string) : file =
dumpGraph "struct and union" sEq;
dumpGraph "enum" eEq;
dumpGraph "variable" vEq;
if mergeInlines then dumpGraph "inline" iEq;
if !merge_inlines then dumpGraph "inline" iEq;
end;
(* Make the second pass over the files. This is when we start rewriting the
* file *)
Expand Down
9 changes: 7 additions & 2 deletions src/mergecil.mli
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(*
*
* Copyright (c) 2001-2002,
* Copyright (c) 2001-2002,
* George C. Necula <necula@cs.berkeley.edu>
* Scott McPeak <smcpeak@cs.berkeley.edu>
* Wes Weimer <weimer@cs.berkeley.edu>
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
Expand Down Expand Up @@ -38,5 +38,10 @@
(** Set this to true to ignore the merge conflicts *)
val ignore_merge_conflicts: bool ref

(** Try to merge definitions of inline functions. They can appear in multiple
* files and we would like them all to be the same. This can slow down the
* merger an order of magnitude !!! *)
val merge_inlines: bool ref

(** Merge a number of CIL files *)
val merge: Cil.file list -> string -> Cil.file