Compositional C11 Program Transformation Mark Batty - Mike - - PowerPoint PPT Presentation

compositional c11 program transformation
SMART_READER_LITE
LIVE PREVIEW

Compositional C11 Program Transformation Mark Batty - Mike - - PowerPoint PPT Presentation

Compositional C11 Program Transformation Mark Batty - Mike Dodds - Alexey Gotsman Imperial Concurrency Workshop, July 2015 @miike Overview The C11 model is (arguably) broken: we omit problem features, most importantly no RLX.


slide-1
SLIDE 1

Mark Batty - Mike Dodds - Alexey Gotsman

Compositional C11 Program Transformation

Imperial Concurrency Workshop, July 2015

@miike

slide-2
SLIDE 2

Overview

  • Context: relaxed memory, axiomatic semantics,

fragment of C11 / C++11.

  • Immediate aim: program transformation, eg

compiler optimisations.

  • Approach: summarise context interactions using

a set of histories (denotational-ish).

  • Under construction!

The C11 model is (arguably) broken: we omit problem features, most importantly no RLX.

slide-3
SLIDE 3

Overview

  • 1. Objective: compositional transformation
  • 2. C11 semantics primer
  • 3. Defining execution histories
  • 4. Cutting down contexts
slide-4
SLIDE 4

Fragments and Contexts

C(−) Context (program with hole) P Program fragment + = C(P) Whole program C

  • whole program

JCK

  • semantics (defined by a set of executions)
slide-5
SLIDE 5

Motivation: Compiler Optimisations

P1 P2

  • replace one fragment with another

Is this a sound transformation on C11?

Assume operations are release-acquire unless

  • therwise mentioned

r=read(x); r=read(x); r=read(x);

P2 : P1 :

slide-6
SLIDE 6

Motivation: Compiler Optimisations

P1 P2

  • replace one fragment with another

all contexts executions of transformed program executions

  • f prior

program equivalent

  • bserved

behaviour Soundness: ∀C. ∀X2 ∈ JC(P2)K. ∃X1 ∈ JC(P1)K. obsv(X2) = obsv(X1)

slide-7
SLIDE 7

Approach

  • summarises of all possible interactions

(…a kind of denotation) JPKd Adequacy: JP2Kd ⊆ JP1Kd = ⇒ ∀C. ∀X2 ∈ JC(P2)K. ∃X1 ∈ JC(P1)K. obsv(X2) = obsv(X1) Thus: JP2Kd ⊆ JP1Kd = ⇒ P1 P2 is sound

slide-8
SLIDE 8

Approach

We’d also like finiteness: P is loop-free code = ⇒ is finite

(…possibly with symbolic values?)

JPKd This would support e.g. automated checking

slide-9
SLIDE 9
  • 1. Objective: compositional transformation
  • 2. C11 semantics primer
  • 3. Defining execution histories
  • 4. Cutting down contexts
slide-10
SLIDE 10

C11 concurrency semantics

Executions: multiple partial orders on memory actions. memory actions read- writes hA, rf, hb, moi 2 JCK happens before per-location coherence

slide-11
SLIDE 11

C11 concurrency semantics (II)

C11 semantics is very non-compositional:

  • 1. Generate whole-program execution candidates.
  • 2. Filter on the basis of validity axioms.

Validity forbids eg: write(x,v) write(x,v’) read(x,v)

hb hb rf

forbidden!

slide-12
SLIDE 12

Observable behaviour

P

write(x,5) write(y,2) write(y,1) read(y,1)

rf?

thread 1 thread 2

slide-13
SLIDE 13

Observable behaviour

P

write(x,5) write(y,2) read(x) write(y,1) read(y,1)

hb hb hb rf rf? hb

thread 1 thread 2

slide-14
SLIDE 14

Observable behaviour

P

write(x,5) write(y,2) write(y,1) read(y,1)

hb hb hb rf?

read(x)

thread 1 thread 2

slide-15
SLIDE 15

C11 Challenges

  • 1. Semantics is whole-program and axiomatic.
  • 2. No notion of a global state
  • 3. Unclear when orders can be observed
slide-16
SLIDE 16
  • 1. Objective: compositional transformation
  • 2. C11 semantics primer
  • 3. Defining execution histories
  • 4. Cutting down contexts
slide-17
SLIDE 17

Inspiration

Idea: treat code transformation as library abstraction

slide-18
SLIDE 18

Intuition

C(P)

execution

slide-19
SLIDE 19

execution

Intuition

P C(−)

slide-20
SLIDE 20

execution

Intuition

P C(−)

‘History’ Projection of hb relation to interface actions

slide-21
SLIDE 21

Interface actions

return call

read(x,7) write(y,4)

slide-22
SLIDE 22

Interface actions

return call

History includes context reads / writes to locations accessed in code block

write(x,5) read(x,7) write(y,4) write(y,7) read(y,9) read(x,9) write(y,8) read(z,7) write(z,8) read(z,8)

slide-23
SLIDE 23

History

return call

In history

slide-24
SLIDE 24

History

return call

In history Don’t record internal actions in history

read(x,5) write(x,5)

rf

Not in history

slide-25
SLIDE 25

History

return call

write(x,5)

Don’t record internal actions in history

slide-26
SLIDE 26

History

return call

In history

write(x,5) read(x,5)

rf

slide-27
SLIDE 27

History

return call

read(x,5)

slide-28
SLIDE 28

History

return call

read(x) read(y)

rf

write(y) write(x)

rf

Some internal order matters!

slide-29
SLIDE 29

History

return call

read(y) write(x)

Some internal order matters!

slide-30
SLIDE 30

History

return call

write(x) read(x)

rf

write(x) read(x)

rf

In history as a deny Prohibits a hb order Some internal order matters!

slide-31
SLIDE 31

History

return call

read(x) read(x)

Some internal order matters!

slide-32
SLIDE 32

Building JPKd

To build : JPKd

  • 1. Generate executions in for a limited

collection of contexts.

  • 2. Extract the history from each execution.

JPK

JPKd : P(History)

Interface actions hb projection (‘guarantee’)

History: P(Action) × P(Action × Action) × P(Action × Action)

forbidden hb (‘deny’)

slide-33
SLIDE 33

Validating the example

return call

read(x); read(x); read(x);

P2 : P1 : Show : JP2Kd ⊆ JP1Kd

write(x); read(x);

rf

read(x);

rf

In history

P2 P1

slide-34
SLIDE 34
  • 1. Objective: compositional transformation
  • 2. C11 semantics primer
  • 3. Defining execution histories
  • 4. Cutting down contexts
slide-35
SLIDE 35

Which contexts matter?

∀C. ∀X2 ∈ JC(P2)K. ∃X1 ∈ JC(P1)K. obsv(X2) = obsv(X1) all contexts?

slide-36
SLIDE 36

Which contexts matter?

return call

write(x,5) read(x,7) write(y,4) write(y,7) read(y,9) read(x,9) write(y,8) read(z,7) write(z,8) read(z,8)

Drop non-interface context actions

slide-37
SLIDE 37

Which contexts matter?

return call

write(x) read(x)

rf

read(x)

rf

Drop duplicate interface reads

slide-38
SLIDE 38

Which contexts matter?

return call

write(x) read(x)

rf

write(x)

Drop interface reads from interface writes

slide-39
SLIDE 39

Which contexts matter?

return call

write(x)

Drop interface writes with siblings in modification-order

write(x) write(x) read(x) write(x)

rf mo mo mo

slide-40
SLIDE 40

Which contexts matter?

P is loop-free code = ⇒ is finite JPKd {X ∈ JPK | cut(X)} is finite = ⇒ cut(X)

⇐ ⇒ “only interface actions” “only rf-distinguished reads” “only mo-distinguished writes” ∧ ∧

slide-41
SLIDE 41

Current status

  • Proved adequacy for a fragment of C11.

(release-acquire, NA, working on SC)

  • Validated a collection of optimisations.
  • Finiteness theorem (mostly done).
  • Full abstraction (in progress).
  • Checking tool (planning stages).
slide-42
SLIDE 42

Towards a compositional semantics?

Would like to define parallel composition: Would (maybe) like full abstraction: ∀C. ∀X2 ∈ JC(P2)K. ∃X1 ∈ JC(P1)K. obsv(X2) = obsv(X1) = ⇒ JP2Kd ⊆ JP1Kd JP1kP2Kd

def

= JP1Kd JP2Kd