1 | //===- SideEffects.cpp - SideEffect classes -------------------------------===// |
2 | // |
3 | // Part of the MLIR Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "mlir/TableGen/SideEffects.h" |
10 | #include "llvm/ADT/Twine.h" |
11 | #include "llvm/TableGen/Record.h" |
12 | |
13 | using namespace mlir; |
14 | using namespace mlir::tblgen; |
15 | |
16 | //===----------------------------------------------------------------------===// |
17 | // SideEffect |
18 | //===----------------------------------------------------------------------===// |
19 | |
20 | StringRef SideEffect::getName() const { |
21 | return def->getValueAsString(FieldName: "effect" ); |
22 | } |
23 | |
24 | StringRef SideEffect::getBaseEffectName() const { |
25 | return def->getValueAsString(FieldName: "baseEffectName" ); |
26 | } |
27 | |
28 | std::string SideEffect::getInterfaceTrait() const { |
29 | StringRef trait = def->getValueAsString(FieldName: "interfaceTrait" ); |
30 | StringRef cppNamespace = def->getValueAsString(FieldName: "cppNamespace" ); |
31 | return cppNamespace.empty() ? trait.str() |
32 | : (cppNamespace + "::" + trait).str(); |
33 | } |
34 | |
35 | StringRef SideEffect::getResource() const { |
36 | return def->getValueAsString(FieldName: "resource" ); |
37 | } |
38 | |
39 | int64_t SideEffect::getStage() const { return def->getValueAsInt(FieldName: "stage" ); } |
40 | |
41 | bool SideEffect::getEffectOnfullRegion() const { |
42 | return def->getValueAsBit(FieldName: "effectOnFullRegion" ); |
43 | } |
44 | |
45 | bool SideEffect::classof(const Operator::VariableDecorator *var) { |
46 | return var->getDef().isSubClassOf(Name: "SideEffect" ); |
47 | } |
48 | |
49 | //===----------------------------------------------------------------------===// |
50 | // SideEffectsTrait |
51 | //===----------------------------------------------------------------------===// |
52 | |
53 | Operator::var_decorator_range SideEffectTrait::getEffects() const { |
54 | auto *listInit = dyn_cast<llvm::ListInit>(Val: def->getValueInit(FieldName: "effects" )); |
55 | return {listInit->begin(), listInit->end()}; |
56 | } |
57 | |
58 | StringRef SideEffectTrait::getBaseEffectName() const { |
59 | return def->getValueAsString(FieldName: "baseEffectName" ); |
60 | } |
61 | |
62 | bool SideEffectTrait::classof(const Trait *t) { |
63 | return t->getDef().isSubClassOf(Name: "SideEffectsTraitBase" ); |
64 | } |
65 | |