[OpaquePtr] Support forward references in textual IR
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 25 Jun 2021 20:14:37 +0000 (22:14 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 29 Jun 2021 18:10:31 +0000 (20:10 +0200)
commitf8aaec19e674c44bfffd2b31611ad1eecc4698bd
tree29d6613d2aec33814c348048ee0110838cf61202
parent913229983633cd4c19b9e5534018f9a42e274b30
[OpaquePtr] Support forward references in textual IR

Currently, LLParser will create a Function/GlobalVariable forward
reference based on the desired pointer type and then modify it when
it is declared. With opaque pointers, we generally do not know the
correct type to use until we see the declaration.

Solve this by creating the forward reference with a dummy type, and
then performing a RAUW with the correct Function/GlobalVariable when
it is declared. The approach is adopted from
https://github.com/TNorthover/llvm-project/commit/b5b55963f62038319fa7a8b1b232226ba1d8ef3c.

This results in a change to the use list order, which is why we see
test changes on some module passes that are not stable under use list
reordering.

Differential Revision: https://reviews.llvm.org/D104950
15 files changed:
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/IR/AsmWriter.cpp
llvm/test/CodeGen/WebAssembly/add-prototypes-conflict.ll
llvm/test/Other/force-opaque-ptrs.ll
llvm/test/Transforms/Attributor/IPConstantProp/PR16052.ll
llvm/test/Transforms/Attributor/misc.ll
llvm/test/Transforms/FunctionSpecialization/function-specialization3.ll
llvm/test/Transforms/FunctionSpecialization/function-specialization4.ll
llvm/test/Transforms/LowerTypeTests/function-weak.ll
llvm/test/Transforms/LowerTypeTests/icall-branch-funnel.ll
llvm/test/Transforms/OpenMP/parallel_deletion_remarks.ll
llvm/test/Transforms/WholeProgramDevirt/branch-funnel.ll
llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll
llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-check.ll
llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll