[llvm] f380066 - [JITLink] Remove redundant local variable definitions from a unit test.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 19 18:29:45 PDT 2021
Author: Lang Hames
Date: 2021-03-19T18:29:36-07:00
New Revision: f3800664611976e4ccae234d8881a65725358260
URL: https://github.com/llvm/llvm-project/commit/f3800664611976e4ccae234d8881a65725358260
DIFF: https://github.com/llvm/llvm-project/commit/f3800664611976e4ccae234d8881a65725358260.diff
LOG: [JITLink] Remove redundant local variable definitions from a unit test.
Added:
Modified:
llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
index 799284d38cb7..24c0a75ac53f 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
@@ -479,6 +479,16 @@ class Symbol {
/// Returns the size of this symbol.
JITTargetAddress getSize() const { return Size; }
+ /// Set the size of this symbol.
+ void setSize(JITTargetAddress Size) {
+ assert(Base && "Cannot set size for null Symbol");
+ assert((Size == 0 || Base->isDefined()) &&
+ "Non-zero size can only be set for defined symbols");
+ assert((Offset + Size <= static_cast<const Block &>(*Base).getSize()) &&
+ "Symbol size cannot extend past the end of its containing block");
+ this->Size = Size;
+ }
+
/// Returns true if this symbol is backed by a zero-fill block.
/// This method may only be called on defined symbols.
bool isSymbolZeroFill() const { return getBlock().isZeroFill(); }
@@ -1014,6 +1024,24 @@ class LinkGraph {
ExternalSymbols.insert(&Sym);
}
+ /// Turn an external symbol into a defined one by attaching it to a block.
+ void makeDefined(Symbol &Sym, Block &Content, JITTargetAddress Offset,
+ JITTargetAddress Size, Linkage L, Scope S, bool IsLive) {
+ assert(!Sym.isDefined() && !Sym.isAbsolute() &&
+ "Sym is not an external symbol");
+ assert(ExternalSymbols.count(&Sym) && "Symbol is not in the externals set");
+ ExternalSymbols.erase(&Sym);
+ Addressable &OldBase = *Sym.Base;
+ Sym.setBlock(Content);
+ Sym.setOffset(Offset);
+ Sym.setSize(Size);
+ Sym.setLinkage(L);
+ Sym.setScope(S);
+ Sym.setLive(IsLive);
+ Content.getSection().addSymbol(Sym);
+ destroyAddressable(OldBase);
+ }
+
/// Removes an external symbol. Also removes the underlying Addressable.
void removeExternalSymbol(Symbol &Sym) {
assert(!Sym.isDefined() && !Sym.isAbsolute() &&
diff --git a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
index 810a2fd0e1f3..6e00550cf242 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
+++ b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
@@ -101,14 +101,97 @@ TEST(LinkGraphTest, BlockAndSymbolIteration) {
EXPECT_TRUE(llvm::count(G.defined_symbols(), &S4));
}
-TEST(LinkGraphTest, SplitBlock) {
- // Check that the LinkGraph::splitBlock test works as expected.
+TEST(LinkGraphTest, MakeExternal) {
+ // Check that we can make a defined symbol external.
+ LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little,
+ getGenericEdgeKindName);
+ auto &Sec = G.createSection("__data", RWFlags);
+
+ // Create an initial block.
+ auto &B1 = G.createContentBlock(Sec, BlockContent, 0x1000, 8, 0);
+
+ // Add a symbol to the block.
+ auto &S1 = G.addDefinedSymbol(B1, 0, "S1", 4, Linkage::Strong, Scope::Default,
+ false, false);
+
+ EXPECT_TRUE(S1.isDefined()) << "Symbol should be defined";
+ EXPECT_FALSE(S1.isExternal()) << "Symbol should not be external";
+ EXPECT_FALSE(S1.isAbsolute()) << "Symbol should not be absolute";
+ EXPECT_TRUE(&S1.getBlock()) << "Symbol should have a non-null block";
+ EXPECT_EQ(S1.getAddress(), 0x1000U) << "Unexpected symbol address";
+
+ EXPECT_EQ(
+ std::distance(G.defined_symbols().begin(), G.defined_symbols().end()), 1U)
+ << "Unexpected number of defined symbols";
+ EXPECT_EQ(
+ std::distance(G.external_symbols().begin(), G.external_symbols().end()),
+ 0U)
+ << "Unexpected number of external symbols";
+
+ // Make S1 external, confirm that the its flags are updated and that it is
+ // moved from the defined symbols to the externals list.
+ G.makeExternal(S1);
+
+ EXPECT_FALSE(S1.isDefined()) << "Symbol should not be defined";
+ EXPECT_TRUE(S1.isExternal()) << "Symbol should be external";
+ EXPECT_FALSE(S1.isAbsolute()) << "Symbol should not be absolute";
+ EXPECT_EQ(S1.getAddress(), 0U) << "Unexpected symbol address";
+
+ EXPECT_EQ(
+ std::distance(G.defined_symbols().begin(), G.defined_symbols().end()), 0U)
+ << "Unexpected number of defined symbols";
+ EXPECT_EQ(
+ std::distance(G.external_symbols().begin(), G.external_symbols().end()),
+ 1U)
+ << "Unexpected number of external symbols";
+}
+
+TEST(LinkGraphTest, MakeDefined) {
+ // Check that we can make an external symbol defined.
+ LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little,
+ getGenericEdgeKindName);
+ auto &Sec = G.createSection("__data", RWFlags);
- const char BlockContentBytes[] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
- 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B,
- 0x1C, 0x1D, 0x1E, 0x1F, 0x00};
- StringRef BlockContent(BlockContentBytes);
+ // Create an initial block.
+ auto &B1 = G.createContentBlock(Sec, BlockContent, 0x1000, 8, 0);
+
+ // Add an external symbol.
+ auto &S1 = G.addExternalSymbol("S1", 4, Linkage::Strong);
+
+ EXPECT_FALSE(S1.isDefined()) << "Symbol should not be defined";
+ EXPECT_TRUE(S1.isExternal()) << "Symbol should be external";
+ EXPECT_FALSE(S1.isAbsolute()) << "Symbol should not be absolute";
+ EXPECT_EQ(S1.getAddress(), 0U) << "Unexpected symbol address";
+ EXPECT_EQ(
+ std::distance(G.defined_symbols().begin(), G.defined_symbols().end()), 0U)
+ << "Unexpected number of defined symbols";
+ EXPECT_EQ(
+ std::distance(G.external_symbols().begin(), G.external_symbols().end()),
+ 1U)
+ << "Unexpected number of external symbols";
+
+ // Make S1 defined, confirm that its flags are updated and that it is
+ // moved from the defined symbols to the externals list.
+ G.makeDefined(S1, B1, 0, 4, Linkage::Strong, Scope::Default, false);
+
+ EXPECT_TRUE(S1.isDefined()) << "Symbol should be defined";
+ EXPECT_FALSE(S1.isExternal()) << "Symbol should not be external";
+ EXPECT_FALSE(S1.isAbsolute()) << "Symbol should not be absolute";
+ EXPECT_TRUE(&S1.getBlock()) << "Symbol should have a non-null block";
+ EXPECT_EQ(S1.getAddress(), 0x1000U) << "Unexpected symbol address";
+
+ EXPECT_EQ(
+ std::distance(G.defined_symbols().begin(), G.defined_symbols().end()), 1U)
+ << "Unexpected number of defined symbols";
+ EXPECT_EQ(
+ std::distance(G.external_symbols().begin(), G.external_symbols().end()),
+ 0U)
+ << "Unexpected number of external symbols";
+}
+
+TEST(LinkGraphTest, SplitBlock) {
+ // Check that the LinkGraph::splitBlock test works as expected.
LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, support::little,
getGenericEdgeKindName);
auto &Sec = G.createSection("__data", RWFlags);
More information about the llvm-commits
mailing list