Support intrinsic overloading on unnamed types
authorJeroen Dobbelaere <jeroen.dobbelaere@synopsys.com>
Fri, 19 Mar 2021 13:34:25 +0000 (14:34 +0100)
committerJeroen Dobbelaere <jeroen.dobbelaere@synopsys.com>
Fri, 19 Mar 2021 13:34:25 +0000 (14:34 +0100)
commit04790d9cfba35073d56047544502c387c5657bb1
tree159536511b7af6ad5c3f7895d909c6a360b1fadb
parenta5f9cda17333530de3d78282d10f53abfaa00906
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
llvm/docs/LangRef.rst
llvm/include/llvm/IR/Intrinsics.h
llvm/include/llvm/IR/Module.h
llvm/lib/IR/Function.cpp
llvm/lib/IR/Module.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Linker/IRMover.cpp
llvm/test/Bitcode/intrinsics-with-unnamed-types.ll [new file with mode: 0644]
llvm/test/Linker/intrinsics-with-unnamed-types.ll [new file with mode: 0644]
llvm/test/Transforms/LoopVectorize/X86/pr48340.ll [new file with mode: 0644]