DEV Community

Avelyn Hyunjeong Choi
Avelyn Hyunjeong Choi

Posted on

Project Stage2 - Part II

In this blog, I will be designing how an automatic ifunc implementation within the GCC compiler could work from the user's point of view.

What options should the user specify on the command line to indicate that they want automatic ifunc capability to be applied during the compilation?

-> User can specify -fifunc on the command line, which triggers the GCC compiler to perform automatic ifunc resolution.

How should the user specify the list of architecture variants they want to target?

-> User should use -march-variants=<arch1>,<arch2>... on the command line. For example, it can be used like below.

-march-variants=armv8-a,armv8-a+sve,armv8-a+sve2
Enter fullscreen mode Exit fullscreen mode

What constraints need to be applied to the list of architecture variants? (i.e., how do we figure out if the architecture variants can be combined into a sane executable)?

-> List of constraints to ensure that specified variants can be combined into a functional executable:

  • Compatibility: Each architecture variant should be compatible with the others.
  • Target Hardware Support: The target hardware must support the architecture variants specified by the user.
  • Runtime Support: The runtime environment should also support the specified architecture variants.
  • Consistency with Instruction Set Architecture (ISA): Specified architecture variants should be consistent with the ISA.

When some of these constraints are not met, it can lead to an incoherent executable.

To which functions should the automatic ifunc capability be added? Should the user specify the functions to be affected? If so, how? (What should the source code syntax look like?)

-> user can explicitly specify which function should have automatic ifunc capability by using a source code annotation as below.

__attribute__((ifunc("resolver_function")))
void target_function() {}
Enter fullscreen mode Exit fullscreen mode

If the functions should be selected automatically, what should the selection criteria be? And should the user be able to tune the selection criteria, and if so, how?

-> Selection Criteria:

  • Function Size: Smaller functions are preferable for optimization.
  • Frequency of Function Calls: Functions called more often during execution are better candidates.
  • Performance Guidelines: Potential functions can be selected based on rules applied to make informed decisions for optimizing the code.

-> Tuning the selection criteria:

  • users can tune the automatic function selection criteria by specifying the criteria on the command line as below.
-ffunc-selection-criteria=<c1>,<c2>,...

// example
-ffunc-selection-criteria=performance,size
Enter fullscreen mode Exit fullscreen mode

What diagnostics should be produced during the compilation process?

-> Possible Feedback About Potential Errors or Important Information:

  • Incompatible Architecture Variants Warning: Users will receive a warning if the specified architecture variants are not compatible with each other.

  • Check Hardware Support: Users will be alerted if the target hardware does not support the specified architecture variants.

  • Check Runtime Support: Users will be warned if the specified architecture variants are not supported by the runtime environment.

  • Failure to Apply Automatic Ifunc Capability: Users will encounter an error if the compiler fails to resolve ifunc for a function.

  • Information About the List of Architecture Variants Specified by the User: Users will be informed about the architecture variants they specified.

  • Information About Function Selection: Users will receive information about which functions were selected for ifunc capability.

  • Information About Selection Criteria: Users will be informed about the list of selection criteria they tuned.

Explain your design decisions in detail, clearly presenting the case for each decision and why you feel it's the best option.

1. -fifunc option for Automatic Ifunc Resolution

  • The -f prefix is commonly used in the design of GCC, making the -fifunc option consistent with existing conventions in GCC.
  • The option name is straightforward and meaningful.
  • Users can seamlessly integrate automatic ifunc capability into the compilation process with the -fifunc option.

2. -march-variants=<arch1>,<arch2>... option for Specifying Targeted Architecture Variants

  • The -march-variants option is consistent with the existing GCC syntax, specifically -march.
  • Users can easily specify multiple target architecture variants using a comma-separated list.
  • This design is adaptable for other platforms as well.

3. Constraints

  • Avoiding unpredictable outcomes is achievable by considering compatibility, hardware and runtime support, and maintaining consistency with the Instruction Set Architecture (ISA).

4. Manual Specification by User

  • The use of __attribute__((ifunc("resolver_function"))) is consistent with the existing conventions of GCC.
  • Users have direct control over ifunc behaviors through manual specification.

5. Automatic Function Selection Criteria

  • The ffunc-selection-criteria is intuitive and consistent with existing GCC options.
  • Allowing users to adjust the selection criteria provides flexibility.
  • If a user does not specify any selection criteria, default criteria will be used.

Top comments (0)