Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[llvm-reduce] Reduce metadata references.
The ReduceMetadata pass before this patch removed metadata on a per-MDNode (or NamedMDNode) basis. Either all references to an MDNode are kept, or all of them are removed. However, MDNodes are uniqued, meaning that references to MDNodes with the same data become references to the same MDNodes. As a consequence, e.g. tbaa references to the same type will all have the same MDNode reference and hence make it impossible to reduce only keeping metadata on those memory access for which they are interesting. Moreover, MDNodes can also be referenced by some intrinsics or other MDNodes. These references were not considered for removal leading to the possibility that MDNodes are not actually removed even if selected to be removed by the oracle. This patch changes ReduceMetadata to reduces based on removable metadata references instead. MDNodes without references implicitly dropped anyway. References by intrinsic calls should be removed by ReduceOperands or ReduceInstructions. References in other MDNodes cannot be removed as it would violate the immutability of MDNodes. Additionally, ReduceMetadata pass before this patch used `setMetadata(I, NULL)` to remove references, where `I` is the index in the array returned by `getAllMetadata`. However, `setMetadata` expects a MDKind (such as `MD_tbaa`) as first argument. `getAllMetadata` does not return those in consecutive order (otherwise it would not need to be a `std::pair` with `first` representing the MDKind). Reviewed By: aeubanks, swamulism Differential Revision: https://reviews.llvm.org/D110534
- Loading branch information
1 parent
26db178
commit d9562a8
Showing
2 changed files
with
79 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
; RUN: llvm-reduce %s -o %t --delta-passes=metadata --test FileCheck --test-arg %s --test-arg --check-prefix=EXCITING --test-arg --input-file | ||
; RUN: FileCheck %s --input-file %t --check-prefix=REDUCED | ||
|
||
; All exciting stuff must remain in the reduced file. | ||
; EXCITING-DAG: ExcitingGlobal = global i32 0, !md !0 | ||
; EXCITING-DAG: define void @ExcitingFunc() !md !0 | ||
; EXCITING-DAG: store i32 0, i32* @ExcitingGlobal, align 4, !md !0 | ||
; EXCITING-DAG: !ExcitingNamedMD = !{!0} | ||
|
||
; Boring stuff's metadata must have been removed. | ||
; REDUCED-NOT: Boring{{.*}} !md !0 | ||
; REDUCED-NOT: !md !0 {{.*}}Boring | ||
|
||
|
||
@ExcitingGlobal = global i32 0, !md !0 | ||
@BoringGlobal = global i32 0, !md !0 | ||
|
||
define void @ExcitingFunc() !md !0 { | ||
store i32 0, i32* @ExcitingGlobal, align 4, !md !0 | ||
store i32 0, i32* @BoringGlobal, align 4, !md !0 | ||
ret void | ||
} | ||
|
||
declare !md !0 void @BoringFunc() | ||
|
||
!ExcitingNamedMD = !{!0} | ||
!BoringNamedMD = !{!0} | ||
|
||
!0 = !{!"my metadata"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters