forked from EPFL-LAP/dynamatic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperationNames.cpp
57 lines (48 loc) · 1.83 KB
/
OperationNames.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
//===- OperationNames.cpp - Canonicalize Handshake ops ----------*- C++ -*-===//
//
// Dynamatic is 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
//
//===----------------------------------------------------------------------===//
//
// Implements the pass that only deal with operation names.
//
//===----------------------------------------------------------------------===//
#include "dynamatic/Transforms/OperationNames.h"
#include "dynamatic/Analysis/NameAnalysis.h"
#include "mlir/IR/BuiltinAttributes.h"
using namespace dynamatic;
namespace {
/// Simple driver for the pass that names all operations in the IR.
struct NameAllOperationsPass
: public dynamatic::impl::NameAllOperationsBase<NameAllOperationsPass> {
void runOnOperation() override {
NameAnalysis &analysis = getAnalysis<NameAnalysis>();
if (!analysis.isAnalysisValid())
return signalPassFailure();
if (!analysis.areAllOpsNamed())
analysis.nameAllUnnamedOps();
markAnalysesPreserved<NameAnalysis>();
};
};
/// Simple driver for the pass that removes all operation names from the IR.
struct RemoveOperationNamesPass
: public dynamatic::impl::RemoveOperationNamesBase<
RemoveOperationNamesPass> {
void runOnOperation() override {
getOperation()->walk([&](Operation *op) {
if (op->hasAttrOfType<mlir::StringAttr>(NameAnalysis::ATTR_NAME))
op->removeAttr(NameAnalysis::ATTR_NAME);
});
};
};
} // namespace
std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
dynamatic::createNameAllOperations() {
return std::make_unique<NameAllOperationsPass>();
}
std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
dynamatic::createRemoveOperationNames() {
return std::make_unique<RemoveOperationNamesPass>();
}