Skip to content

Polymorphism Optimizations #1516

@volsa

Description

@volsa

We currently have to assume every method call to be polymorphic (i.e. resolved at run time rather than compile time) because ST lacks a dedicated keyword similar to C++ to flag only certain methods as virtual. This makes the implementation somewhat inefficient compared to statically resolved function calls in the IR.

For performance optimization there are a few points to note:

  1. C++ has some vtable specific IR syntax (see https://godbolt.org/z/9KKMY1Mfc, @vtable for ...). At the time of coming up with our polymorphism implementation we were aware of that syntax but couldn't find any documentation. Perhaps we should give it another try if it means LLVM can use it to optimize virtual method calls.
  2. We could introduce a final keyword to classes and function blocks, making them not extendable and as a result allowing us to "devirtualize" the method calls. Alternatively make them final by default and introduce another keyword to make them extendable, though that would break compatibility for codesys.
  3. As noted in here feat: Polymorphism (Classes and Function Blocks) #1493 (review), for static analysis Static Class Hierarchy Analysis might be interesting.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions