Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
d7250f4
Just use `Int` for `Hashcons`
bmourad01 Nov 17, 2025
18321c6
sroa
bmourad01 Nov 4, 2025
b1558bb
Relaxed guard on zext for `move_ri` callback
bmourad01 Nov 8, 2025
9814437
progress
bmourad01 Nov 8, 2025
62bf90e
`def_of_op` for `Abi.Insn`
bmourad01 Nov 9, 2025
6470f00
style
bmourad01 Nov 9, 2025
b8a1add
Some cleanup
bmourad01 Nov 9, 2025
745caf2
`Resolve_constant_blk_args` for ABI
bmourad01 Nov 9, 2025
d74c23f
Expose SROA pass
bmourad01 Nov 9, 2025
b4ad93a
Native test for `sumphi`
bmourad01 Nov 10, 2025
ae12c1e
Move scalars analysis to its own module
bmourad01 Nov 10, 2025
28e26f4
Adds Allen's Interval Algebra
bmourad01 Nov 16, 2025
49b6a40
Remove redundant stores in `Abi_loadopt`
bmourad01 Nov 16, 2025
a287d64
simple slot coalescing
bmourad01 Nov 16, 2025
c049aec
Use the `logs` package for debug logging
bmourad01 Nov 16, 2025
fcb3557
Fix warnings
bmourad01 Nov 16, 2025
70ab27c
Specify build profile with `DEBUG` var
bmourad01 Nov 16, 2025
d9126ab
Filter out dead stores to slots
bmourad01 Nov 16, 2025
54dd6aa
Mark current function in debug logs
bmourad01 Nov 16, 2025
4538f39
Fixes several bugs
bmourad01 Nov 17, 2025
90115b2
Actually propagate block args
bmourad01 Nov 17, 2025
0e93ef0
Another native test
bmourad01 Nov 17, 2025
c36f4b0
Input modules for SROA and coalesce are the same
bmourad01 Nov 17, 2025
01e6a36
Some cleanup
bmourad01 Nov 17, 2025
a9c6b44
Explicit test
bmourad01 Nov 17, 2025
0c2497d
Simplify `liveness_insn` for coalescing
bmourad01 Nov 19, 2025
ceee06b
Exclude propagating via block params in SROA for now
bmourad01 Nov 19, 2025
138993a
Don't prematurely filter out partially overlapping accesses
bmourad01 Nov 19, 2025
7884c26
Fix lowering of `ftosi/ftoui`
bmourad01 Nov 19, 2025
58c60a0
Adds tests for Allen algebra
bmourad01 Nov 19, 2025
1306641
Fix warnings
bmourad01 Nov 19, 2025
3566480
Fix partial redundancy calculation
bmourad01 Nov 19, 2025
58e5dc8
Some tidying, more logging
bmourad01 Nov 20, 2025
59bcb8b
More bug fixes
bmourad01 Nov 21, 2025
816606c
Use priority when selecting group members as well
bmourad01 Nov 21, 2025
5222b06
Handle load before store
bmourad01 Nov 22, 2025
6da2a6e
Prevent promotion errors with uninitialized loads
bmourad01 Nov 22, 2025
256935a
Some performance improvements to coalesce partitioning
bmourad01 Nov 23, 2025
66f1751
Some cleanups in the amd64 code
bmourad01 Nov 23, 2025
2bf7718
Some cleanups in the isel code
bmourad01 Nov 23, 2025
6559aff
Use `Slot_initialization` analysis when building live ranges
bmourad01 Nov 23, 2025
f8c2a3d
Make `peephole` run to a (bounded) fixpoint
bmourad01 Nov 23, 2025
f367b5d
Refine `and_test` peephole opt
bmourad01 Nov 23, 2025
5b5e9ad
Block comments and cleanups in lexer
bmourad01 Nov 24, 2025
071ea12
Use a heuristic for coalescing trivial DU chains
bmourad01 Nov 24, 2025
048ec9d
Rename `Sroa_coalesce_common` to `Scalars_common`
bmourad01 Nov 24, 2025
a053452
Use the Allen algebra in SROA
bmourad01 Nov 24, 2025
492de75
Small fixes for jump tables
bmourad01 Nov 25, 2025
ca108f0
Remove `fmt` from test_opt
bmourad01 Nov 26, 2025
3b0ccab
Peephole rule for merging adjacent blocks
bmourad01 Nov 26, 2025
b685e4c
Fixes targets not being initialized at exe time
bmourad01 Nov 27, 2025
7b6d907
Adds more debug logging
bmourad01 Nov 27, 2025
087285d
Adds `bsearch` test, fixes some bugs
bmourad01 Nov 27, 2025
fee78ad
Change C style
bmourad01 Nov 28, 2025
29e81b8
silence warnings
bmourad01 Nov 28, 2025
a61b396
interval tree
bmourad01 Nov 28, 2025
f7a8cdc
Use Quickcheck for float32 and bv_interval
bmourad01 Nov 28, 2025
3582747
Use a more precise domain for `Slot_initialization`
bmourad01 Nov 28, 2025
f35366a
More compound type tests
bmourad01 Nov 28, 2025
1e38a37
Tweak printer for SROA accesses
bmourad01 Nov 29, 2025
9b3c3f7
Compare egraph cost unsigned, debug print function name
bmourad01 Nov 29, 2025
a07ac1c
Adds a `Bitset` abstraction
bmourad01 Nov 29, 2025
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
179 changes: 35 additions & 144 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,149 +1,40 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveBitFields: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BasedOnStyle: LLVM
IndentWidth: 2
ContinuationIndentWidth: 2
UseTab: Never
TabWidth: 2

# Function definitions like:
# static int
# name(...)
# {
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
AfterFunction: true
AfterStruct: true
AfterClass: true
AfterNamespace: true
AfterExternBlock: true
BeforeCatch: false
BeforeElse: false

# K&R control-flow braces (same-line)
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
- Regex: '.*'
Priority: 1
SortPriority: 0
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true

# Spacing rules
SpaceBeforeParens: ControlStatements
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
...
SpaceBeforeAssignmentOperators: true

# Pointer alignment
PointerAlignment: Right

# Do not wrap long lines unless needed
ColumnLimit: 80

# Do not cram short functions onto one line
AllowShortFunctionsOnASingleLine: None

# Keep return type on its own line if desired
AlwaysBreakAfterDefinitionReturnType: true
AlwaysBreakAfterReturnType: None
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
SRC := ./src/

.PHONY: build clean install uninstall test doc deps indent status-clean check-style
.PHONY: build clean install uninstall test doc deps
.PHONY: ocaml-indent clang-indent indent status-clean check-style

all: install

Expand All @@ -25,9 +26,14 @@ doc:
deps:
$(MAKE) deps -C $(SRC)

indent:
ocaml-indent:
sh tools/ocp-indent-all.sh

clang-indent:
sh tools/clang-format-all.sh

indent: ocaml-indent clang-indent

status-clean:
git diff --quiet --exit-code

Expand Down
9 changes: 7 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
.PHONY: clean install uninstall test doc deps bap-deps

PROFILE = release
ifeq ($(DEBUG),1)
PROFILE = dev
endif

BAP_DEPS = \
bitvec \
bitvec-binprot \
Expand All @@ -12,7 +17,7 @@ BAP_DEPS = \
BAP_REPO := git+https://github.com/BinaryAnalysisPlatform/opam-repository\#testing

all:
dune build --profile=release
dune build --profile=$(PROFILE)

clean:
dune clean
Expand All @@ -24,7 +29,7 @@ uninstall:
dune uninstall

test:
dune test --profile=release
dune test --profile=$(PROFILE)

doc:
dune build @doc
Expand Down
43 changes: 21 additions & 22 deletions src/bin/cli.ml
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
open Cmdliner

(* Why is this here, when we have `Cgen.Target.find`?

The targets should be getting declared at the toplevel in their
respective modules, but the evaluation of these modules is not
guaranteed to happen by the time we start parsing command-line
arguments.

It just so happens that, for the front-end executable, we should
know all of the out-of-the-box targets provided by the library,
so this feels like a tolerable compromise in the design of extending
the supported targets.
*)
let targets =
Core.Map.of_alist_exn (module Core.String) @@
Core.List.map ~f:(fun t -> Cgen.Target.name t, t) @@
Cgen.Machine.[
X86.Amd64_sysv.target;
]
let () = Cgen.Machine.force_initialization ()

let bail () = exit Cmd.Exit.ok

Expand Down Expand Up @@ -100,7 +83,8 @@ let dump_no_comment =
let man_targets =
`S "TARGET" ::
`Pre "Supported target platforms" :: begin
Core.Map.data targets |>
Cgen.Target.enum_targets () |>
Core.Sequence.to_list |>
Core.List.map ~f:(fun t ->
`P (Format.asprintf "%a" Cgen.Target.pp t))
end
Expand Down Expand Up @@ -134,7 +118,14 @@ type t = {
target : Cgen.Target.t;
}

let go f file output dump nc target =
let log_env = Cmd.Env.info "CGEN_LOG"

let setup_log level =
Logs.set_level level;
Logs.set_reporter @@ Logs_fmt.reporter ()

let go f file output dump nc target log_level =
setup_log log_level;
let file = match file with
| "" -> Istdin
| _ -> Ifile file in
Expand All @@ -144,12 +135,20 @@ let go f file output dump nc target =
let dump = match dump_of_string_opt dump with
| None -> fatal "invalid dump option: %s\n%!" dump ()
| Some d -> d in
let target = match Core.Map.find targets target with
let target = match Cgen.Target.find target with
| None -> fatal "invalid target: %s\n%!" target ()
| Some t -> t in
f {file; output; dump; nc; target}

let t f = Term.(const (go f) $ file $ output $ dump $ dump_no_comment $ target)
let t f =
let open Term in
const (go f) $
file $
output $
dump $
dump_no_comment $
target $
Logs_cli.level ~env:log_env ()

let man = List.concat [
man_dump;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(name cgen_main)
(public_name cgen)
(package cgen)
(libraries cgen cmdliner)
(libraries cgen cmdliner logs.cli logs.fmt)
(modules cgen_main cli)
(flags -w -58)
(ocamlopt_flags -O2)
Expand Down
2 changes: 2 additions & 0 deletions src/cgen.opam
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ depends: [
"core" {>= "v0.15"}
"core_kernel" {>= "v0.15"}
"dune" {>= "3.15"}
"fmt"
"graphlib"
"logs"
"menhir"
"monads"
"ocamldiff"
Expand Down
2 changes: 2 additions & 0 deletions src/dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
(core (>= v0.15))
(core_kernel (>= v0.15))
dune
fmt
graphlib
logs
menhir
monads
ocamldiff
Expand Down
Loading