Skip to content

Commit

Permalink
[RemoveDIs] Update some unittests to the new format (llvm#90476)
Browse files Browse the repository at this point in the history
This patch updates the unittests that can be changed to the new format
after llvm#89799 (which changes the default format everywhere) to avoid a
loss in coverage for the (new) default debug info format.
  • Loading branch information
OCHyams authored May 7, 2024
1 parent 1de0535 commit 1530f31
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 143 deletions.
42 changes: 7 additions & 35 deletions llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@ extern cl::opt<cl::boolOrDefault> PreserveInputDbgFormat;
extern bool WriteNewDbgInfoFormatToBitcode;
extern cl::opt<bool> WriteNewDbgInfoFormat;

// Backup all of the existing settings that may be modified when
// PreserveInputDbgFormat=true, so that when the test is finished we return them
// (and the "preserve" setting) to their original values.
static auto SaveDbgInfoFormat() {
return make_scope_exit(
[OldPreserveInputDbgFormat = PreserveInputDbgFormat.getValue(),
OldUseNewDbgInfoFormat = UseNewDbgInfoFormat.getValue(),
OldWriteNewDbgInfoFormatToBitcode = WriteNewDbgInfoFormatToBitcode,
OldWriteNewDbgInfoFormat = WriteNewDbgInfoFormat.getValue()] {
PreserveInputDbgFormat = OldPreserveInputDbgFormat;
UseNewDbgInfoFormat = OldUseNewDbgInfoFormat;
WriteNewDbgInfoFormatToBitcode = OldWriteNewDbgInfoFormatToBitcode;
WriteNewDbgInfoFormat = OldWriteNewDbgInfoFormat;
});
}

static std::unique_ptr<Module> makeLLVMModule(LLVMContext &Context,
StringRef ModuleStr) {
SMDiagnostic Err;
Expand Down Expand Up @@ -1328,25 +1312,19 @@ TEST(IRInstructionMapper, CallBrInstIllegal) {
ASSERT_GT(UnsignedVec[0], Mapper.IllegalInstrNumber);
}

// Checks that an debuginfo intrinsics are mapped to be invisible. Since they
// Checks that an debuginfo records are mapped to be invisible. Since they
// do not semantically change the program, they can be recognized as similar.
// FIXME: PreserveInputDbgFormat is set to true because this test contains
// malformed debug info that cannot be converted to the new debug info format;
// this test should be updated later to use valid debug info.
TEST(IRInstructionMapper, DebugInfoInvisible) {
StringRef ModuleString = R"(
define i32 @f(i32 %a, i32 %b) {
then:
%0 = add i32 %a, %b
call void @llvm.dbg.value(metadata !0)
%1 = add i32 %a, %b
%0 = add i32 %a, %b
#dbg_value(i32 0, !0, !0, !0)
%1 = add i32 %a, %b
ret i32 0
}
declare void @llvm.dbg.value(metadata)
!0 = distinct !{!"test\00", i32 10})";
auto SettingGuard = SaveDbgInfoFormat();
PreserveInputDbgFormat = cl::boolOrDefault::BOU_TRUE;
LLVMContext Context;
std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString);

Expand Down Expand Up @@ -1941,22 +1919,19 @@ TEST(IRSimilarityCandidate, CheckRegionsDifferentTypes) {
ASSERT_FALSE(longSimCandCompare(InstrList));
}

// Check that debug instructions do not impact similarity. They are marked as
// Check that debug records do not impact similarity. They are marked as
// invisible.
// FIXME: PreserveInputDbgFormat is set to true because this test contains
// malformed debug info that cannot be converted to the new debug info format;
// this test should be updated later to use valid debug info.
TEST(IRSimilarityCandidate, IdenticalWithDebug) {
StringRef ModuleString = R"(
define i32 @f(i32 %a, i32 %b) {
bb0:
%0 = add i32 %a, %b
call void @llvm.dbg.value(metadata !0)
#dbg_value(i32 0, !0, !0, !0)
%1 = add i32 %b, %a
ret i32 0
bb1:
%2 = add i32 %a, %b
call void @llvm.dbg.value(metadata !1)
#dbg_value(i32 1, !1, !1, !1)
%3 = add i32 %b, %a
ret i32 0
bb2:
Expand All @@ -1965,11 +1940,8 @@ TEST(IRSimilarityCandidate, IdenticalWithDebug) {
ret i32 0
}
declare void @llvm.dbg.value(metadata)
!0 = distinct !{!"test\00", i32 10}
!1 = distinct !{!"test\00", i32 11})";
auto SettingGuard = SaveDbgInfoFormat();
PreserveInputDbgFormat = cl::boolOrDefault::BOU_TRUE;
LLVMContext Context;
std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString);

Expand Down
Loading

0 comments on commit 1530f31

Please sign in to comment.