-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LTO] Introduce a new class ImportIDTable #106503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kazutakahirata
merged 2 commits into
llvm:main
from
kazutakahirata:cleanup_thinlto_ImportIDTable
Aug 29, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,91 @@ | ||
//===- ImportIDTableTests.cpp - Unit tests for ImportIDTable --------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/Transforms/IPO/FunctionImport.h" | ||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
#include <set> | ||
#include <type_traits> | ||
|
||
using namespace llvm; | ||
|
||
TEST(ImportIDTableTests, Basic) { | ||
FunctionImporter::ImportIDTable Table; | ||
|
||
auto [Def, Decl] = Table.createImportIDs("mod", 123U); | ||
auto [Def2, Decl2] = Table.createImportIDs("stuff", 456U); | ||
|
||
// Def and Decl must be of the same unsigned integer type. | ||
static_assert( | ||
std::is_unsigned_v<FunctionImporter::ImportIDTable::ImportIDTy>); | ||
static_assert(std::is_same_v<FunctionImporter::ImportIDTable::ImportIDTy, | ||
decltype(Def)>); | ||
static_assert(std::is_same_v<FunctionImporter::ImportIDTable::ImportIDTy, | ||
decltype(Decl)>); | ||
|
||
// Check that all IDs are unique. | ||
std::set<FunctionImporter::ImportIDTable::ImportIDTy> IDs = {Def, Decl, Def2, | ||
Decl2}; | ||
EXPECT_THAT(IDs, ::testing::SizeIs(4)); | ||
|
||
// Verify what Def maps to. | ||
auto DefTuple = Table.lookup(Def); | ||
EXPECT_EQ(std::get<0>(DefTuple), StringRef("mod")); | ||
EXPECT_EQ(std::get<1>(DefTuple), 123U); | ||
EXPECT_EQ(std::get<2>(DefTuple), GlobalValueSummary::Definition); | ||
|
||
// Verify what Decl maps to. | ||
auto DeclTuple = Table.lookup(Decl); | ||
EXPECT_EQ(std::get<0>(DeclTuple), StringRef("mod")); | ||
EXPECT_EQ(std::get<1>(DeclTuple), 123U); | ||
EXPECT_EQ(std::get<2>(DeclTuple), GlobalValueSummary::Declaration); | ||
|
||
// Verify what Def2 maps to. | ||
auto Def2Tuple = Table.lookup(Def2); | ||
EXPECT_EQ(std::get<0>(Def2Tuple), StringRef("stuff")); | ||
EXPECT_EQ(std::get<1>(Def2Tuple), 456U); | ||
EXPECT_EQ(std::get<2>(Def2Tuple), GlobalValueSummary::Definition); | ||
|
||
// Verify what Decl2 maps to. | ||
auto Decl2Tuple = Table.lookup(Decl2); | ||
EXPECT_EQ(std::get<0>(Decl2Tuple), StringRef("stuff")); | ||
EXPECT_EQ(std::get<1>(Decl2Tuple), 456U); | ||
EXPECT_EQ(std::get<2>(Decl2Tuple), GlobalValueSummary::Declaration); | ||
kazutakahirata marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
TEST(ImportIDTableTests, Duplicates) { | ||
FunctionImporter::ImportIDTable Table; | ||
|
||
auto [Def1, Decl1] = Table.createImportIDs("mod", 123U); | ||
auto [Def2, Decl2] = Table.createImportIDs("mod", 123U); | ||
|
||
// Verify we get the same IDs back. | ||
EXPECT_EQ(Def1, Def2); | ||
EXPECT_EQ(Decl1, Decl2); | ||
} | ||
|
||
TEST(ImportIDTableTests, Present) { | ||
FunctionImporter::ImportIDTable Table; | ||
|
||
auto [Def, Decl] = Table.createImportIDs("mod", 123U); | ||
auto Result = Table.getImportIDs("mod", 123U); | ||
|
||
// Verify that we get the same IDs back. | ||
ASSERT_NE(Result, std::nullopt); | ||
EXPECT_EQ(Result->first, Def); | ||
EXPECT_EQ(Result->second, Decl); | ||
} | ||
|
||
TEST(ImportIDTableTests, Missing) { | ||
FunctionImporter::ImportIDTable Table; | ||
|
||
auto Result = Table.getImportIDs("mod", 123U); | ||
|
||
// Verify that we get std::nullopt for a non-existent pair. | ||
EXPECT_EQ(Result, std::nullopt); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.