-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[NFCI][Globals] In GlobalObjects::setSectionPrefix, do conditional update if existing prefix is not equivalent to the new one. Returns whether prefix changed. #158460
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
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
887e270
[NFCI][Globals]Add GlobalObjects::updateSectionPrefix and change setS…
mingmingl-llvm 314696a
run clang format
mingmingl-llvm b894f77
incorporate review feedback
mingmingl-llvm eb55b81
fix typo
mingmingl-llvm 1df1bf5
merge update inside set, and update callsites to make use of return v…
mingmingl-llvm 381d31d
fix typo
mingmingl-llvm 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
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,81 @@ | ||
//===- GlobalObjectTest.cpp - Global object unit tests --------------------===// | ||
// | ||
// 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/IR/GlobalObject.h" | ||
#include "llvm/AsmParser/Parser.h" | ||
#include "llvm/IR/Module.h" | ||
#include "llvm/Support/SourceMgr.h" | ||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
using namespace llvm; | ||
namespace { | ||
using testing::Eq; | ||
using testing::Optional; | ||
using testing::StrEq; | ||
|
||
static std::unique_ptr<Module> parseIR(LLVMContext &C, const char *IR) { | ||
SMDiagnostic Err; | ||
std::unique_ptr<Module> Mod = parseAssemblyString(IR, Err, C); | ||
if (!Mod) | ||
Err.print("GlobalObjectTests", errs()); | ||
return Mod; | ||
} | ||
|
||
static LLVMContext C; | ||
static std::unique_ptr<Module> M; | ||
|
||
class GlobalObjectTest : public testing::Test { | ||
public: | ||
static void SetUpTestSuite() { | ||
M = parseIR(C, R"( | ||
@foo = global i32 3, !section_prefix !0 | ||
@bar = global i32 0 | ||
!0 = !{!"section_prefix", !"hot"} | ||
)"); | ||
} | ||
}; | ||
|
||
TEST_F(GlobalObjectTest, SectionPrefix) { | ||
GlobalVariable *Foo = M->getGlobalVariable("foo"); | ||
|
||
// Initial section prefix is hot. | ||
ASSERT_NE(Foo, nullptr); | ||
ASSERT_THAT(Foo->getSectionPrefix(), Optional(StrEq("hot"))); | ||
|
||
// No actual update. | ||
EXPECT_FALSE(Foo->updateSectionPrefix("hot")); | ||
|
||
// Update prefix from hot to unlikely. | ||
Foo->setSectionPrefix("unlikely"); | ||
EXPECT_THAT(Foo->getSectionPrefix(), Optional(StrEq("unlikely"))); | ||
|
||
// Set prefix to empty is the same as clear. | ||
Foo->setSectionPrefix(""); | ||
// Test that section prefix is cleared. | ||
EXPECT_THAT(Foo->getSectionPrefix(), Eq(std::nullopt)); | ||
|
||
GlobalVariable *Bar = M->getGlobalVariable("bar"); | ||
|
||
// Initial section prefix is empty. | ||
ASSERT_NE(Bar, nullptr); | ||
ASSERT_THAT(Bar->getSectionPrefix(), Eq(std::nullopt)); | ||
|
||
// Teset that update method returns false since Bar doesn't have prefix | ||
// metadata. | ||
EXPECT_FALSE(Bar->updateSectionPrefix("")); | ||
snehasish marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
// Update from empty to hot. | ||
EXPECT_TRUE(Bar->updateSectionPrefix("hot")); | ||
EXPECT_THAT(Bar->getSectionPrefix(), Optional(StrEq("hot"))); | ||
|
||
// Teset that update method returns true and section prefix is cleared. | ||
|
||
EXPECT_TRUE(Bar->updateSectionPrefix("")); | ||
EXPECT_THAT(Bar->getSectionPrefix(), Eq(std::nullopt)); | ||
} | ||
} // namespace |
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.