llvm-project/mlir/lib/TableGen/SideEffects.cpp
River Riddle 0ddba0bd59 [mlir][SideEffects] Replace HasNoSideEffect with the memory effect interfaces.
HasNoSideEffect can now be implemented using the MemoryEffectInterface, removing the need to check multiple things for the same information. This also removes an easy foot-gun for users as 'Operation::hasNoSideEffect' would ignore operations that dynamically, or recursively, have no side effects. This also leads to an immediate improvement in some of the existing users, such as DCE, now that they have access to more information.

Differential Revision: https://reviews.llvm.org/D76036
2020-03-12 14:26:15 -07:00

52 lines
1.7 KiB
C++

//===- SideEffects.cpp - SideEffect classes -------------------------------===//
//
// Part of the MLIR Project, 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 "mlir/TableGen/SideEffects.h"
#include "llvm/TableGen/Record.h"
using namespace mlir;
using namespace mlir::tblgen;
//===----------------------------------------------------------------------===//
// SideEffect
//===----------------------------------------------------------------------===//
StringRef SideEffect::getName() const {
return def->getValueAsString("effect");
}
StringRef SideEffect::getBaseEffectName() const {
return def->getValueAsString("baseEffectName");
}
StringRef SideEffect::getResource() const {
auto value = def->getValueAsString("resource");
return value.empty() ? "::mlir::SideEffects::DefaultResource" : value;
}
bool SideEffect::classof(const Operator::VariableDecorator *var) {
return var->getDef().isSubClassOf("SideEffect");
}
//===----------------------------------------------------------------------===//
// SideEffectsTrait
//===----------------------------------------------------------------------===//
Operator::var_decorator_range SideEffectTrait::getEffects() const {
auto *listInit = dyn_cast<llvm::ListInit>(def->getValueInit("effects"));
return {listInit->begin(), listInit->end()};
}
StringRef SideEffectTrait::getBaseEffectName() const {
return def->getValueAsString("baseEffectName");
}
bool SideEffectTrait::classof(const OpTrait *t) {
return t->getDef().isSubClassOf("SideEffectsTraitBase");
}