Skip to content

Implement argument dealiasing #197

@asl

Description

@asl

After p4lang/p4c#5318 we might be in perfect position to simplify / optimize copy-in / copy-out semantics before inlining. This would eliminate variables for copy-in / copy-out values

Essentially we can check if the extern / action / function call arguments alias each other. E.g. for the following code:

      p4hir.scope {
        %int_egress_port_tx_utilization_header_field_ref = p4hir.struct_extract_ref %arg1["int_egress_port_tx_utilization_header"] : <!headers>
        %hdr_out_arg = p4hir.variable ["hdr_out_arg"] : <!int_egress_port_tx_utilization_header_t>
        p4hir.call_method @packet_in::@extract<[!int_egress_port_tx_utilization_header_t]> of %arg0 : !packet_in (%hdr_out_arg) : (!p4hir.ref<!int_egress_port_tx_utilization_header_t>) -> ()
        %val = p4hir.read %hdr_out_arg : <!int_egress_port_tx_utilization_header_t>
        p4hir.assign %val, %int_egress_port_tx_utilization_header_field_ref : <!int_egress_port_tx_utilization_header_t>
      }

We can eliminate hdr_out_arg and pass reference to a header field directly. For this we need:

  • Identify set of variables used to hold inout / out arguments along with corresponding source / destination arguments
  • Ensure that source / destination arguments do not alias each other (to exclude e.g. foo(s, s.field) cases)
  • Ensure that copy-in / copy-out variables has one (for inouts) or zero (for outs) write before call and exactly one read after the call
  • And Check for out/inout bindings aliased with uses p4c#5318 ensures that there are no "side" channels (though after Make actions / functions / controls isolated #195 we can do same kind of check pretty trivial as well – yay to isolation, all external uses are explicit!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions