Description
Potential improvements:
- Enable
pragma Restrictions (No_Exceptions)
- Enable
pragma Restrictions (No_Secondary_Stack)
The code size will be calculated by the size of the .text section of the generated binary minus the size of the .text section of a reference binary that is built from an empty main procedure.
Important compiler switches:
-ffunction-sections
,-fdata-sections
,-Wl,-gc-sections
-Os
-gnatp
-fno-inline
/-gnatd.8
(for GNAT 22.1, not needed for 23.0w)-fno-early-inlining
Improvements in the code generator:
-
Group case statements with identical branches into a single case
-
Group if-else statements with identical branches into a single expression
-
Replace case statements that use exceptions with assertions (at least if many/all branches are equal)
-
Replace case statements that generate boolean values with single boolean expressions
-
Rewrite case statements in expression functions that return case based enum values as regular functions with single returns
-
Remove code duplications in
RFLX_Generic_Types
(mergeInsert
functions)
(Part 1)
- Remove exceptions and enforce
pragma Restrictions (No_Exceptions)
- Inline
Set_Field_Value_*
intoSet_*
- Simplify
Incomplete_Message
andInitialized
by using quantified expressions (no effect on binary size, but maybe positive effect on proof time) - Simplify
Valid_Length
- Simplify
Path_Condition
- Improve
Field_Size
- Split first part of
Set_*
functions - Defer dereferencing of buffer pointers for
Extract
andInsert
- Simplify
Composite_Field
(Part 2)
- Remove duplicated finalization code for session states
(Part 3)
- Use common integer type (e.g., U64) in context for representing field values to prevent need for variant records (i.e.
Field_Dependent_Value
) and therefore case statements
(Part 4)
- Improve setters for scalar fields (Improve binary size of generated code #908 (comment))
(Part 5)
- Move
Has_Buffer
ofVerify
into precondition
(Part 6)
- Replace
RFLX_Exception
variable with gotos. Currently this variable is used to stay inside a block and callUpdate
on the buffer at the end of that block before jumping via the goto. However it seems to be more size efficient to call theUpdate
and jump directly. - Replace the pattern
Available_Field (Ctx, Field) >= Field_Size (Ctx, Field)
with separate function.
(Part 7)
- Some scalar fields that do not affect the path through the message (e.g. long lists of flags) should be settable with less checks.
- For message aggregates:
- Check
Available_Space
once (Message.size
must consider message path) - Do not check
Valid_Next
- Check
- For message aggregates:
(Ideas for messages)
- Remove unnecessary deferred exceptions (blocked by Switch to newer SPARK wavefront in CI #955)
- Merge
Field_Condition
andSuccessor
- Use
Successor
forValid_Predecessor
(Improve binary size of generated code #908 (comment)) - Add precalculation of predecessor to
Valid_Predecessor
? (decreases provability, as transformation of expression function into function necessary) - Compile with
-gnatD
(don't ask my why this works)
(Ideas for sessions)
- Optimize consecutive message field assignments #1120
- Optimize sequence comprehension 'Head #1115
- Optimize messages if only fields are used #1114
(Rejected ideas)
-
Add(no effect when using 23.0w)Inline_Always
toRFLX.RFLX_Generic_Types.(Insert|Insert_LE|Extract|Extract_LE)
- Split
,Get_Field_Value
Set_Field_Value
andinto separate functions (negative impact forVerify
Get_Field_Value
andVerify
) -
Refactor(negative impact)Successor
andValid_Predecessor
-
Remove duplication in(slight negative impact on binary size)Valid
,Invalid
andIncomplete
for fields and cursors -
Remove duplications in(no impact on binary size)Field_Condition
,Path_Condition
and(Structural_|)Valid_Message
by addingLink_Condition
function -
Add precalculation ofVal.Fld
toSet