Skip to content
This repository was archived by the owner on Jun 21, 2024. It is now read-only.

Inlining loads in the native code#251

Merged
kayceesrk merged 5 commits intoocaml-multicore:masterfrom
anmolsahoo25:change-cloadmut-inline-record
Jun 28, 2019
Merged

Inlining loads in the native code#251
kayceesrk merged 5 commits intoocaml-multicore:masterfrom
anmolsahoo25:change-cloadmut-inline-record

Conversation

@anmolsahoo25
Copy link
Copy Markdown
Contributor

@anmolsahoo25 anmolsahoo25 commented Jun 10, 2019

This PR aims to fix #237. Atomic.get is a library function that provides atomic reads across domains. On x86, these atomic reads emit an external function call - caml_atomic_load. This function loads a value and emits a read_barrier to prevent re-ordering from happening.

The external call is unnecessary, and on x86, can be translated to plain loads.

TODO:

  • Extend Patomic_load with an immediate_or_pointer field
  • Modify Cload and Cloadmut to use inline records instead of tuples
  • Extend Cload and Cloadmut with is_atomic field
  • Translate Patomic_load to Cload {} or Cload {}
  • Emit Iloadmut instead of caml_atomic_load

Changes

Extending Patomic_load with an immediate_or_pointer field

Patomic_load is a lambda op, which has been extended with a field to denote whether that load is to a value or an immediate.

| Patomic_load

to

| Patomic_load of {immediate_or_pointer : immediate_or_pointer}

Changing Cload and Cloadmut to use records instead of tuples

Cload and Cloadmut are two cmm operations defined as -

| Cload of memory_chunk * Asttypes.mutable_flag
| Cloadmut

This has now been modified to be -

| Cload of {memory_chunk: memory_chunk; mutability: Asttypes.mutable_flag; is_atomic: bool}
| Cloadmut of {is_atomic:bool}

All occurring values and usage in pattern matching has been updated to the new representation

Emitting Cload or Cloadmut from Patomic_load

The cmmgen.ml file emits cmm from lambda expressions. For this, the pattern match has been modified as -

| Patomic_load ->
     Cop (Cextcall("caml_atomic_load", typ_val, true, None), [transl env arg], dbg)

to

  | Patomic_load {immediate_or_pointer} ->
      let ptr = transl env arg
      in
      ( match immediate_or_pointer with
        | Immediate -> Cop (Cload {memory_chunk=Word_int ; mutability=Mutable ; is_atomic=true} , [ptr; Cconst_int 0], dbg)
        | Pointer -> Cop (Cloadmut {is_atomic=true}, [ptr; Cconst_int 0], dbg) )

Emit Iloadmut instead of caml_atomic_load

In selectgen.ml, the Cload and Cloadmut are translated to iload and iloadmut. In x86, the is_atomic param is ignored.

Changed the representation of the cmm-op Cloadmut to be
a record from a tuple.

Replaced all occurences of values of type Cloadmut and
pattern matching on Cloadmut to make use of the
record representation
@anmolsahoo25 anmolsahoo25 force-pushed the change-cloadmut-inline-record branch from 2613930 to 2787e67 Compare June 26, 2019 09:58
Cloadmut has been extended with is_atomic flag to be used further
in the emit-mlp stage to set-up read barriers on atomic accesses
Patomic_load has been modified with immediate_or_pointer field
to use while emitting asm for atomic loads
Patomic_load was emitting an extcall to caml_atomic_load.
Now depending on the immediate_or_pointer parameter, it emits
Cload or Cloadmut which gets lowered to assembly rather than
extcall
@anmolsahoo25 anmolsahoo25 force-pushed the change-cloadmut-inline-record branch from 2787e67 to 6e0089c Compare June 26, 2019 10:16
Changed the record syntax in mutiple places
@kayceesrk
Copy link
Copy Markdown
Contributor

Awesome. I'll merge it once the CI passes.

@kayceesrk kayceesrk merged commit 8fbacb1 into ocaml-multicore:master Jun 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Atomic.get should be inlined on x86

2 participants