Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | llvm::JITSymbol findSymbol(const std::string &Name, | ||||
return llvm::JITSymbol(122, llvm::JITSymbolFlags::None); | return llvm::JITSymbol(122, llvm::JITSymbolFlags::None); | ||||
} | } | ||||
void expectFindSymbol(const std::string &Name, bool ExportedSymbolsOnly) { | void expectFindSymbol(const std::string &Name, bool ExportedSymbolsOnly) { | ||||
MockName = Name; | MockName = Name; | ||||
MockBool = ExportedSymbolsOnly; | MockBool = ExportedSymbolsOnly; | ||||
} | } | ||||
void verifyFindSymbol(llvm::JITSymbol Returned) { | void verifyFindSymbol(llvm::JITSymbol Returned) { | ||||
EXPECT_EQ("findSymbol", LastCalled); | EXPECT_EQ("findSymbol", LastCalled); | ||||
EXPECT_EQ(cantFail(MockSymbol.getAddress()), | EXPECT_EQ(llvm_cantFail(MockSymbol.getAddress()), | ||||
cantFail(Returned.getAddress())) | llvm_cantFail(Returned.getAddress())) | ||||
<< "Return should pass through"; | << "Return should pass through"; | ||||
resetExpectations(); | resetExpectations(); | ||||
} | } | ||||
llvm::JITSymbol findSymbolIn(VModuleKey K, const std::string &Name, | llvm::JITSymbol findSymbolIn(VModuleKey K, const std::string &Name, | ||||
bool ExportedSymbolsOnly) { | bool ExportedSymbolsOnly) { | ||||
EXPECT_EQ(MockKey, K) << "VModuleKey should pass through"; | EXPECT_EQ(MockKey, K) << "VModuleKey should pass through"; | ||||
EXPECT_EQ(MockName, Name) << "Name should pass through"; | EXPECT_EQ(MockName, Name) << "Name should pass through"; | ||||
EXPECT_EQ(MockBool, ExportedSymbolsOnly) << "Flag should pass through"; | EXPECT_EQ(MockBool, ExportedSymbolsOnly) << "Flag should pass through"; | ||||
LastCalled = "findSymbolIn"; | LastCalled = "findSymbolIn"; | ||||
MockSymbol = llvm::JITSymbol(122, llvm::JITSymbolFlags::None); | MockSymbol = llvm::JITSymbol(122, llvm::JITSymbolFlags::None); | ||||
return llvm::JITSymbol(122, llvm::JITSymbolFlags::None); | return llvm::JITSymbol(122, llvm::JITSymbolFlags::None); | ||||
} | } | ||||
void expectFindSymbolIn(VModuleKey K, const std::string &Name, | void expectFindSymbolIn(VModuleKey K, const std::string &Name, | ||||
bool ExportedSymbolsOnly) { | bool ExportedSymbolsOnly) { | ||||
MockKey = K; | MockKey = K; | ||||
MockName = Name; | MockName = Name; | ||||
MockBool = ExportedSymbolsOnly; | MockBool = ExportedSymbolsOnly; | ||||
} | } | ||||
void verifyFindSymbolIn(llvm::JITSymbol Returned) { | void verifyFindSymbolIn(llvm::JITSymbol Returned) { | ||||
EXPECT_EQ("findSymbolIn", LastCalled); | EXPECT_EQ("findSymbolIn", LastCalled); | ||||
EXPECT_EQ(cantFail(MockSymbol.getAddress()), | EXPECT_EQ(llvm_cantFail(MockSymbol.getAddress()), | ||||
cantFail(Returned.getAddress())) | llvm_cantFail(Returned.getAddress())) | ||||
<< "Return should pass through"; | << "Return should pass through"; | ||||
resetExpectations(); | resetExpectations(); | ||||
} | } | ||||
llvm::Error emitAndFinalize(VModuleKey K) { | llvm::Error emitAndFinalize(VModuleKey K) { | ||||
EXPECT_EQ(MockKey, K) << "VModuleKey should pass through"; | EXPECT_EQ(MockKey, K) << "VModuleKey should pass through"; | ||||
LastCalled = "emitAndFinalize"; | LastCalled = "emitAndFinalize"; | ||||
return llvm::Error::success(); | return llvm::Error::success(); | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | LegacyObjectTransformLayer<MockBaseLayer, | ||||
++(*Obj); | ++(*Obj); | ||||
return Obj; | return Obj; | ||||
}); | }); | ||||
// Test addObject with T1 (allocating) | // Test addObject with T1 (allocating) | ||||
auto K1 = ES.allocateVModule(); | auto K1 = ES.allocateVModule(); | ||||
auto Obj1 = std::make_shared<MockObjectFile>(211); | auto Obj1 = std::make_shared<MockObjectFile>(211); | ||||
M.expectAddObject(K1, Obj1); | M.expectAddObject(K1, Obj1); | ||||
cantFail(T1.addObject(K1, std::move(Obj1))); | llvm_cantFail(T1.addObject(K1, std::move(Obj1))); | ||||
M.verifyAddObject(); | M.verifyAddObject(); | ||||
// Test addObjectSet with T2 (mutating) | // Test addObjectSet with T2 (mutating) | ||||
auto K2 = ES.allocateVModule(); | auto K2 = ES.allocateVModule(); | ||||
auto Obj2 = std::make_shared<MockObjectFile>(222); | auto Obj2 = std::make_shared<MockObjectFile>(222); | ||||
M.expectAddObject(K2, Obj2); | M.expectAddObject(K2, Obj2); | ||||
cantFail(T2.addObject(K2, Obj2)); | llvm_cantFail(T2.addObject(K2, Obj2)); | ||||
M.verifyAddObject(); | M.verifyAddObject(); | ||||
EXPECT_EQ(223, *Obj2) << "Expected mutation"; | EXPECT_EQ(223, *Obj2) << "Expected mutation"; | ||||
// Test removeObjectSet | // Test removeObjectSet | ||||
M.expectRemoveObject(K2); | M.expectRemoveObject(K2); | ||||
cantFail(T1.removeObject(K2)); | llvm_cantFail(T1.removeObject(K2)); | ||||
M.verifyRemoveObject(); | M.verifyRemoveObject(); | ||||
// Test findSymbol | // Test findSymbol | ||||
std::string Name = "foo"; | std::string Name = "foo"; | ||||
bool ExportedOnly = true; | bool ExportedOnly = true; | ||||
M.expectFindSymbol(Name, ExportedOnly); | M.expectFindSymbol(Name, ExportedOnly); | ||||
llvm::JITSymbol Sym1 = T2.findSymbol(Name, ExportedOnly); | llvm::JITSymbol Sym1 = T2.findSymbol(Name, ExportedOnly); | ||||
M.verifyFindSymbol(std::move(Sym1)); | M.verifyFindSymbol(std::move(Sym1)); | ||||
// Test findSymbolIn | // Test findSymbolIn | ||||
Name = "bar"; | Name = "bar"; | ||||
ExportedOnly = false; | ExportedOnly = false; | ||||
M.expectFindSymbolIn(K1, Name, ExportedOnly); | M.expectFindSymbolIn(K1, Name, ExportedOnly); | ||||
llvm::JITSymbol Sym2 = T1.findSymbolIn(K1, Name, ExportedOnly); | llvm::JITSymbol Sym2 = T1.findSymbolIn(K1, Name, ExportedOnly); | ||||
M.verifyFindSymbolIn(std::move(Sym2)); | M.verifyFindSymbolIn(std::move(Sym2)); | ||||
// Test emitAndFinalize | // Test emitAndFinalize | ||||
M.expectEmitAndFinalize(K1); | M.expectEmitAndFinalize(K1); | ||||
cantFail(T2.emitAndFinalize(K1)); | llvm_cantFail(T2.emitAndFinalize(K1)); | ||||
M.verifyEmitAndFinalize(); | M.verifyEmitAndFinalize(); | ||||
// Test mapSectionAddress | // Test mapSectionAddress | ||||
char Buffer[24]; | char Buffer[24]; | ||||
llvm::JITTargetAddress MockAddress = 255; | llvm::JITTargetAddress MockAddress = 255; | ||||
M.expectMapSectionAddress(K1, Buffer, MockAddress); | M.expectMapSectionAddress(K1, Buffer, MockAddress); | ||||
T1.mapSectionAddress(K1, Buffer, MockAddress); | T1.mapSectionAddress(K1, Buffer, MockAddress); | ||||
M.verifyMapSectionAddress(); | M.verifyMapSectionAddress(); | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | auto NullCompiler = [](llvm::Module &) { | ||||
return std::unique_ptr<llvm::MemoryBuffer>(nullptr); | return std::unique_ptr<llvm::MemoryBuffer>(nullptr); | ||||
}; | }; | ||||
LegacyIRCompileLayer<decltype(TransformLayer), decltype(NullCompiler)> | LegacyIRCompileLayer<decltype(TransformLayer), decltype(NullCompiler)> | ||||
CompileLayer(llvm::AcknowledgeORCv1Deprecation, TransformLayer, | CompileLayer(llvm::AcknowledgeORCv1Deprecation, TransformLayer, | ||||
NullCompiler); | NullCompiler); | ||||
// Make sure that the calls from LegacyIRCompileLayer to LegacyObjectTransformLayer | // Make sure that the calls from LegacyIRCompileLayer to LegacyObjectTransformLayer | ||||
// compile. | // compile. | ||||
cantFail(CompileLayer.addModule(ES.allocateVModule(), | llvm_cantFail(CompileLayer.addModule(ES.allocateVModule(), | ||||
std::unique_ptr<llvm::Module>())); | std::unique_ptr<llvm::Module>())); | ||||
// Make sure that the calls from LegacyObjectTransformLayer to ObjectLinkingLayer | // Make sure that the calls from LegacyObjectTransformLayer to ObjectLinkingLayer | ||||
// compile. | // compile. | ||||
VModuleKey DummyKey = ES.allocateVModule(); | VModuleKey DummyKey = ES.allocateVModule(); | ||||
cantFail(TransformLayer.emitAndFinalize(DummyKey)); | llvm_cantFail(TransformLayer.emitAndFinalize(DummyKey)); | ||||
TransformLayer.findSymbolIn(DummyKey, Name, false); | TransformLayer.findSymbolIn(DummyKey, Name, false); | ||||
TransformLayer.findSymbol(Name, true); | TransformLayer.findSymbol(Name, true); | ||||
TransformLayer.mapSectionAddress(DummyKey, nullptr, 0); | TransformLayer.mapSectionAddress(DummyKey, nullptr, 0); | ||||
cantFail(TransformLayer.removeObject(DummyKey)); | llvm_cantFail(TransformLayer.removeObject(DummyKey)); | ||||
} | } | ||||
} | } |