Skip to content
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

Look for child targets in TargetOperationPass #86

Merged
merged 2 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions include/HAL/TargetOperationPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,20 @@ class TargetOperationPass : public mlir::OperationPass<OpT> {
auto target = targetInfo.getValue()->getTarget(
&mlir::OperationPass<OpT>::getContext());
if (!target) {
llvm::errs() << "Error: failed to get target '" << TargetT::name
<< "':\n";
llvm::errs() << target.takeError();
mlir::OperationPass<OpT>::signalPassFailure();
return nullptr;
// look for a child target that matches
for (auto childName : TargetT::childNames)
if ((targetInfo =
registry::TargetSystemRegistry::lookupPluginInfo(childName)) &&
(target = targetInfo.getValue()->getTarget(
&mlir::OperationPass<OpT>::getContext())))
break;
if (!target) {
llvm::errs() << "Error: failed to get target '" << TargetT::name
<< "':\n";
llvm::errs() << target.takeError();
mlir::OperationPass<OpT>::signalPassFailure();
return nullptr;
}
}

auto *castedTarget = dynamic_cast<TargetT *>(target.get());
Expand Down
3 changes: 3 additions & 0 deletions mock_target/MockTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ int qssc::targets::mock::init() {
return registered ? 0 : -1;
}

const std::vector<std::string> MockSystem::childNames = {"MockChild1",
"MockChild2"};

MockConfig::MockConfig(llvm::StringRef configurationPath)
: SystemConfiguration() {
std::ifstream configStream(configurationPath.str());
Expand Down
1 change: 1 addition & 0 deletions mock_target/MockTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class MockConfig : public qssc::hal::SystemConfiguration {
class MockSystem : public qssc::hal::TargetSystem {
public:
static constexpr auto name = "mock";
static const std::vector<std::string> childNames;
explicit MockSystem(std::unique_ptr<MockConfig> config);
static llvm::Error registerTargetPasses();
static llvm::Error registerTargetPipelines();
Expand Down