This is a Coq formalization of OOPSLA'18 LLVM memory model.
Compile with Coq 8.8.1 please.
-
Definition of memory:
Ir.Memory.t
in Memory.vIr.Memory.t
meanst
inModule Memory
inModule Ir
.
-
Well-formedness of a memory:
Ir.Memory.wf
in Memory.v -
Definition of a memory block:
Ir.MemBlock.t
in Memory.v -
Well-formedness of a memory block:
Ir.MemBlock.wf
in Memory.v -
Definition of dereferenceability:
Ir.deref
in LoadStore.v -
Semantics of load/store:
Ir.load_val
/Ir.store_val
in LoadStore.v -
Definition of twin state, observedness, guessed pointer, etc: TwinExecution.v
-
Definition of IR syntax: Lang.v
- Phi node:
Ir.PhiNode.t
(or 't' inModule PhiNode
inModule Ir
) - Instruction:
Ir.Inst.t
- Terminator:
Ir.Terminator.t
- Basic block:
Ir.BasicBlock.t
- Function:
Ir.IRFunction.t
- Module:
Ir.IRModule.t
- Note: for simplicity, function call and return instruction is not included in our language.
- Phi node:
-
Definition of small-step semantics of IR instructions: SmallStep.v
-
Definition of a program state:
Ir.Config.t
in State.v -
Well-formedness of a program state:
Ir.Config.wf
in State.v -
Definition of an event:
event
in Behaviors.v -
Definition of a program behavior:
Ir.program_behavior
in Behaviors.v -
Definition of refinement :
Ir.refines
in Refinement.v- It is showed that refinement is reflexive as well as transitive.
-
Small-step of instructions preserve wellformedness of state: SmallStepWf.v
- Theorem
sstep_wf
shows that if input state is well-formed, and executing small step on the state successesfully made output state, the output state is also well-formed.
- Theorem
-
Proof of a property of a guessed address (sec. 4.11): TwinExecutionProof.v
- Theorem
malloc_creates_twin_state
states that malloc either returns a NULL pointer, or it creates a twin state. - Theorem
twin_execution
states that 'twin-state-ness' is preserved if the block is not observed and no memory access through a guessed pointer is made. - Theorem
access_from_guessed_pointer_fails
states that if a guessed pointer accesses a block at state st1, then the access fails at twin state st2.
- Theorem
-
Reordering of interested instructions: Reordering.v
- This proves that ptrtoint/inttoptr/getelementptr/icmp eq/icmp ule/psub can be freely reordered with respect to malloc/free.
-
Correctness of GVN on pointer equality (sec. 5): GVN1.v, GVN2.v, GVN3.v, GVN4.v
- GVN1.v proves that replacing p with q is valid if q is NULL or the result of an integer-to-pointer cast.
- It defines a notion of
physicalized_ptr p q
, meaning that either (informally)q = (int*)(uintptr_t)p
holds, orp = gep [inbounds] p0
andq = gep [inbounds] q0
that satisfiesphysicalized_ptr p0 q0
. - Theorem
physicalized_ptr_spec
shows that ificmp eq p, q
evaluates to true, and q is a vanilla physical pointer, thenphysicalized_ptr p q
holds. - Theorems
*_refines
show that for all operations that take pointer as operand, refinement holds ifp
is replaced withq
.
- It defines a notion of
- GVN2.v proves that replacing p with q is valid if p and q are logical pointers, and both are either dereferenceable or they point to the same block.
- It shows that if p and q satisfies the condition, and
icmp eq p, q
evaluates to true, p and q have same value.
- It shows that if p and q satisfies the condition, and
- GVN3.v proves that replacing p with q is valid if p and q are both computed by the gep inbounds with same base pointer.
- It shows that if p and q satisfies the condition, and
icmp eq p, q
evaluates to true, p and q have same value.
- It shows that if p and q satisfies the condition, and
- GVN4.v proves that replacing p with q is valid if either p or q is computed by a series of gep inbounds with positive offsets, based on the same base pointer.
- It defines a notion of
gepinbs p q p0
, meaning that p and q are series of gep inbounds with positive offsets, based on p0. - Theorem
gepinbs_after_icmpeq_true
shows that, ificmp eq p q
evaluates to true, andgepinbs p q p0
holds for any pointer p0, either p and q are equal orphys_minmaxI p1 p2
holds.phys_minmaxI p1 p2
means that p1 and p2 are physical pointers withp1.I
andp2.I
having same min/max value. - Later on, GVN4.v shows that if
phys_minmaxI p1 p2
holds, then replacing p1 with p2 is valid (refinement holds) for all instructions which take pointer as operand.
- It defines a notion of
- GVN1.v proves that replacing p with q is valid if q is NULL or the result of an integer-to-pointer cast.