-
Notifications
You must be signed in to change notification settings - Fork 608
/
TranslateExecutables.cpp
117 lines (98 loc) · 4.32 KB
/
TranslateExecutables.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2020 The IREE Authors
//
// Licensed 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 <memory>
#include <utility>
#include "iree/compiler/Dialect/HAL/IR/HALDialect.h"
#include "iree/compiler/Dialect/HAL/IR/HALOps.h"
#include "iree/compiler/Dialect/HAL/Target/TargetBackend.h"
#include "iree/compiler/Dialect/HAL/Target/TargetRegistry.h"
#include "iree/compiler/Dialect/HAL/Transforms/Passes.h"
#include "iree/compiler/Utils/TracingUtils.h"
#include "llvm/ADT/StringSet.h"
#include "mlir/Dialect/Bufferization/IR/Bufferization.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/Diagnostics.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"
namespace mlir::iree_compiler::IREE::HAL {
#define GEN_PASS_DEF_TRANSLATEEXECUTABLESPASS
#define GEN_PASS_DEF_TRANSLATETARGETEXECUTABLEVARIANTSPASS
#include "iree/compiler/Dialect/HAL/Transforms/Passes.h.inc"
namespace {
//===----------------------------------------------------------------------===//
// --iree-hal-translate-target-executable-variants
//===----------------------------------------------------------------------===//
struct TranslateTargetExecutableVariantsPass
: public IREE::HAL::impl::TranslateTargetExecutableVariantsPassBase<
TranslateTargetExecutableVariantsPass> {
using IREE::HAL::impl::TranslateTargetExecutableVariantsPassBase<
TranslateTargetExecutableVariantsPass>::
TranslateTargetExecutableVariantsPassBase;
void getDependentDialects(DialectRegistry ®istry) const override {
registry.insert<IREE::HAL::HALDialect>();
registry.insert<bufferization::BufferizationDialect>();
auto targetBackend = targetRegistry->getTargetBackend(target);
if (targetBackend) {
targetBackend->getDependentDialects(registry);
}
}
void runOnOperation() override {
auto variantOp = getOperation();
if (variantOp.getTarget().getBackend().getValue() != target)
return;
if (variantOp.isExternal())
return;
auto targetBackend = targetRegistry->getTargetBackend(target);
if (!targetBackend) {
variantOp.emitError() << "unregistered target backend '" << target << "'";
return signalPassFailure();
}
OpPassManager passManager(variantOp.getOperationName());
targetBackend->buildTranslationPassPipeline(variantOp.getTargetAttr(),
passManager);
if (failed(runPipeline(passManager, variantOp))) {
variantOp.emitError() << "failed to run translation of source "
"executable to target executable for backend "
<< variantOp.getTarget();
return signalPassFailure();
}
}
};
//===----------------------------------------------------------------------===//
// --iree-hal-translate-executables
//===----------------------------------------------------------------------===//
struct TranslateExecutablesPass
: public IREE::HAL::impl::TranslateExecutablesPassBase<
TranslateExecutablesPass> {
using IREE::HAL::impl::TranslateExecutablesPassBase<
TranslateExecutablesPass>::TranslateExecutablesPassBase;
void getDependentDialects(DialectRegistry ®istry) const override {
registry.insert<IREE::HAL::HALDialect>();
registry.insert<bufferization::BufferizationDialect>();
auto targetBackends = targetRegistry->getTargetBackends(
targetRegistry->getRegisteredTargetBackends());
for (auto &targetBackend : targetBackends) {
targetBackend->getDependentDialects(registry);
}
}
void runOnOperation() override {
auto executableOp = getOperation();
OpPassManager passManager(executableOp.getOperationName());
for (const auto &targetName : gatherExecutableTargetNames(executableOp)) {
passManager.addNestedPass<IREE::HAL::ExecutableVariantOp>(
IREE::HAL::createTranslateTargetExecutableVariantsPass(
{targetRegistry, targetName}));
}
IREE_COMPILER_TRACE_MESSAGE_DYNAMIC(INFO, executableOp.getSymName().str());
if (failed(runPipeline(passManager, executableOp))) {
llvm::errs() << "failed to translate executables\n";
return signalPassFailure();
}
}
};
} // namespace
} // namespace mlir::iree_compiler::IREE::HAL