Support intrinsic overloading on unnamed types

Authored by jeroen.dobbelaere on Mar 19 2021, 6:34 AM.


Support intrinsic overloading on unnamed types

This patch adds support for intrinsic overloading on unnamed types.

This fixes PR38117 and PR48340 and will also be needed for the Full Restrict Patches (D68484).

The main problem is that the intrinsic overloading name mangling is using 's_s' for unnamed types.
This can result in identical intrinsic mangled names for different function prototypes.

This patch changes this by adding a '.XXXXX' to the intrinsic mangled name when at least one of the types is based on an unnamed type, ensuring that we get a unique name.

Implementation details:

  • The mapping is created on demand and kept in Module.
  • It also checks for existing clashes and recycles potentially existing prototypes and declarations.
  • Because of extra data in Module, Intrinsic::getName needs an extra Module* argument and, for speed, an optional FunctionType* argument.
  • I still kept the original two-argument 'Intrinsic::getName' around which keeps the original behavior (providing the base name).
    • Main reason is that I did not want to change the LLVMIntrinsicGetName version, as I don't know how acceptable such a change is
    • The current situation already has a limitation. So that should not get worse with this patch.
  • Intrinsic::getDeclaration and the verifier are now using the new version.

Other notes:

  • As far as I see, this should not suffer from stability issues. The count is only added for prototypes depending on at least one anonymous struct
  • The initial count starts from 0 for each intrinsic mangled name.
  • In case of name clashes, existing prototypes are remembered and reused when that makes sense.

Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D91250


jeroen.dobbelaereMar 19 2021, 6:34 AM
Differential Revision
D91250: Support intrinsic overloading on unnamed types
rGa5f9cda17333: [mlir] Rename gpu-to-llvm pass implementation file