mirror of https://github.com/llvm/circt.git
[NFC] Replace isAnyModule with an isa test. (#6057)
This accepts slightly different operations in a couple places (more permissive), but I don't think this is a problem for any of the pipelines.
This commit is contained in:
parent
28bd7f1521
commit
1d36f60ce6
|
@ -52,9 +52,6 @@ void modifyModulePorts(Operation *op,
|
||||||
|
|
||||||
// Helpers for working with modules.
|
// Helpers for working with modules.
|
||||||
|
|
||||||
/// Return true if this is an hw.module, external module, generated module etc.
|
|
||||||
bool isAnyModule(Operation *module);
|
|
||||||
|
|
||||||
/// Return true if isAnyModule or instance.
|
/// Return true if isAnyModule or instance.
|
||||||
bool isAnyModuleOrInstance(Operation *module);
|
bool isAnyModuleOrInstance(Operation *module);
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,7 @@ Operation *getReferencedModule(const HWSymbolCache *cache,
|
||||||
Operation *instanceOp,
|
Operation *instanceOp,
|
||||||
mlir::FlatSymbolRefAttr moduleName);
|
mlir::FlatSymbolRefAttr moduleName);
|
||||||
|
|
||||||
/// Verify that the instance refers to a valid HW module as determined by the
|
/// Verify that the instance refers to a valid HW module.
|
||||||
/// 'hw::isAnyModule' function.
|
|
||||||
LogicalResult verifyReferencedModule(Operation *instanceOp,
|
LogicalResult verifyReferencedModule(Operation *instanceOp,
|
||||||
SymbolTableCollection &symbolTable,
|
SymbolTableCollection &symbolTable,
|
||||||
mlir::FlatSymbolRefAttr moduleName,
|
mlir::FlatSymbolRefAttr moduleName,
|
||||||
|
|
|
@ -13,20 +13,6 @@
|
||||||
include "mlir/IR/EnumAttr.td"
|
include "mlir/IR/EnumAttr.td"
|
||||||
include "mlir/IR/OpAsmInterface.td"
|
include "mlir/IR/OpAsmInterface.td"
|
||||||
|
|
||||||
/// Ensure symbol is one of the hw module.* types
|
|
||||||
def isModuleSymbol : AttrConstraint<
|
|
||||||
CPred<
|
|
||||||
"hw::isAnyModule(::mlir::SymbolTable::lookupNearestSymbolFrom("
|
|
||||||
"&$_op, $_self.cast<::mlir::FlatSymbolRefAttr>().getValue()))"
|
|
||||||
>, "is module like">;
|
|
||||||
|
|
||||||
/// Ensure symbol is one of the sv macro.* types
|
|
||||||
def isMacroSymbol : AttrConstraint<
|
|
||||||
CPred<
|
|
||||||
"sv::isAnyMacro(::mlir::SymbolTable::lookupNearestSymbolFrom("
|
|
||||||
"&$_op, $_self.cast<::mlir::FlatSymbolRefAttr>().getValue()))"
|
|
||||||
>, "is macro like">;
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Control flow like-operations
|
// Control flow like-operations
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
|
@ -498,14 +498,9 @@ OpFoldResult ParamValueOp::fold(FoldAdaptor adaptor) {
|
||||||
// HWModuleOp
|
// HWModuleOp
|
||||||
//===----------------------------------------------------------------------===/
|
//===----------------------------------------------------------------------===/
|
||||||
|
|
||||||
/// Return true if this is an hw.module, external module, generated module etc.
|
|
||||||
bool hw::isAnyModule(Operation *module) {
|
|
||||||
return isa<HWModuleOp, HWModuleExternOp, HWModuleGeneratedOp>(module);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return true if isAnyModule or instance.
|
/// Return true if isAnyModule or instance.
|
||||||
bool hw::isAnyModuleOrInstance(Operation *moduleOrInstance) {
|
bool hw::isAnyModuleOrInstance(Operation *moduleOrInstance) {
|
||||||
return isAnyModule(moduleOrInstance) || isa<InstanceOp>(moduleOrInstance);
|
return isa<HWModuleLike, InstanceOp>(moduleOrInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the signature for a module as a function type from the module itself
|
/// Return the signature for a module as a function type from the module itself
|
||||||
|
@ -523,8 +518,6 @@ FunctionType hw::getModuleType(Operation *moduleOrInstance) {
|
||||||
if (auto mod = dyn_cast<HWModuleLike>(moduleOrInstance))
|
if (auto mod = dyn_cast<HWModuleLike>(moduleOrInstance))
|
||||||
return mod.getHWModuleType().getFuncType();
|
return mod.getHWModuleType().getFuncType();
|
||||||
|
|
||||||
assert(isAnyModule(moduleOrInstance) &&
|
|
||||||
"must be called on instance or module");
|
|
||||||
return cast<mlir::FunctionOpInterface>(moduleOrInstance)
|
return cast<mlir::FunctionOpInterface>(moduleOrInstance)
|
||||||
.getFunctionType()
|
.getFunctionType()
|
||||||
.cast<FunctionType>();
|
.cast<FunctionType>();
|
||||||
|
@ -1096,7 +1089,7 @@ void HWModuleOp::print(OpAsmPrinter &p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static LogicalResult verifyModuleCommon(HWModuleLike module) {
|
static LogicalResult verifyModuleCommon(HWModuleLike module) {
|
||||||
assert(isAnyModule(module) &&
|
assert(isa<HWModuleLike>(module) &&
|
||||||
"verifier hook should only be called on modules");
|
"verifier hook should only be called on modules");
|
||||||
|
|
||||||
auto moduleType = module.getHWModuleType();
|
auto moduleType = module.getHWModuleType();
|
||||||
|
|
|
@ -34,7 +34,7 @@ LogicalResult instance_like_impl::verifyReferencedModule(
|
||||||
<< moduleName.getValue() << "'";
|
<< moduleName.getValue() << "'";
|
||||||
|
|
||||||
// It must be some sort of module.
|
// It must be some sort of module.
|
||||||
if (!hw::isAnyModule(module))
|
if (!isa<HWModuleLike>(module))
|
||||||
return instanceOp->emitError("symbol reference '")
|
return instanceOp->emitError("symbol reference '")
|
||||||
<< moduleName.getValue() << "' isn't a module";
|
<< moduleName.getValue() << "' isn't a module";
|
||||||
|
|
||||||
|
|
|
@ -390,8 +390,7 @@ LogicalResult InstanceOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
|
||||||
<< getModuleName() << "'";
|
<< getModuleName() << "'";
|
||||||
|
|
||||||
// It must be some sort of module.
|
// It must be some sort of module.
|
||||||
if (!hw::isAnyModule(module) &&
|
if (!isa<hw::HWModuleLike>(module))
|
||||||
!isa<MSFTModuleOp, MSFTModuleExternOp>(module))
|
|
||||||
return emitError("symbol reference '")
|
return emitError("symbol reference '")
|
||||||
<< getModuleName() << "' isn't a module";
|
<< getModuleName() << "' isn't a module";
|
||||||
return success();
|
return success();
|
||||||
|
|
|
@ -305,7 +305,7 @@ static StringRef getOperandName(OpOperand &oper, const SymbolCache &syms,
|
||||||
if (auto inst = dyn_cast<InstanceOp>(op)) {
|
if (auto inst = dyn_cast<InstanceOp>(op)) {
|
||||||
Operation *modOp = syms.getDefinition(inst.getModuleNameAttr());
|
Operation *modOp = syms.getDefinition(inst.getModuleNameAttr());
|
||||||
if (modOp) { // If modOp isn't in the cache, it's probably a new module;
|
if (modOp) { // If modOp isn't in the cache, it's probably a new module;
|
||||||
assert(isAnyModule(modOp) && "Instance must point to a module");
|
assert(isa<hw::HWModuleLike>(modOp) && "Instance must point to a module");
|
||||||
auto mod = cast<hw::HWModuleLike>(modOp);
|
auto mod = cast<hw::HWModuleLike>(modOp);
|
||||||
return mod.getInputName(oper.getOperandNumber());
|
return mod.getInputName(oper.getOperandNumber());
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ InstanceOpLowering::matchAndRewrite(InstanceOp msftInst, OpAdaptor adaptor,
|
||||||
if (!referencedModule)
|
if (!referencedModule)
|
||||||
return rewriter.notifyMatchFailure(msftInst,
|
return rewriter.notifyMatchFailure(msftInst,
|
||||||
"Could not find referenced module");
|
"Could not find referenced module");
|
||||||
if (!hw::isAnyModule(referencedModule))
|
if (!isa<hw::HWModuleLike>(referencedModule))
|
||||||
return rewriter.notifyMatchFailure(
|
return rewriter.notifyMatchFailure(
|
||||||
msftInst, "Referenced module was not an HW module");
|
msftInst, "Referenced module was not an HW module");
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,6 @@ using namespace mlir;
|
||||||
using namespace circt;
|
using namespace circt;
|
||||||
using namespace msft;
|
using namespace msft;
|
||||||
|
|
||||||
bool circt::msft::isAnyModule(Operation *module) {
|
|
||||||
return isa<MSFTModuleOp, MSFTModuleExternOp>(module) ||
|
|
||||||
hw::isAnyModule(module);
|
|
||||||
}
|
|
||||||
|
|
||||||
SmallVector<unsigned> circt::msft::makeSequentialRange(unsigned size) {
|
SmallVector<unsigned> circt::msft::makeSequentialRange(unsigned size) {
|
||||||
SmallVector<unsigned> seq;
|
SmallVector<unsigned> seq;
|
||||||
for (size_t i = 0; i < size; ++i)
|
for (size_t i = 0; i < size; ++i)
|
||||||
|
@ -32,7 +27,7 @@ StringRef circt::msft::getValueName(Value v, const SymbolCache &syms,
|
||||||
if (auto inst = dyn_cast_or_null<InstanceOp>(defOp)) {
|
if (auto inst = dyn_cast_or_null<InstanceOp>(defOp)) {
|
||||||
Operation *modOp = syms.getDefinition(inst.getModuleNameAttr());
|
Operation *modOp = syms.getDefinition(inst.getModuleNameAttr());
|
||||||
if (modOp) { // If modOp isn't in the cache, it's probably a new module;
|
if (modOp) { // If modOp isn't in the cache, it's probably a new module;
|
||||||
assert(isAnyModule(modOp) && "Instance must point to a module");
|
assert(isa<hw::HWModuleLike>(modOp) && "Instance must point to a module");
|
||||||
OpResult instResult = v.cast<OpResult>();
|
OpResult instResult = v.cast<OpResult>();
|
||||||
auto mod = cast<hw::HWModuleLike>(modOp);
|
auto mod = cast<hw::HWModuleLike>(modOp);
|
||||||
buff.clear();
|
buff.clear();
|
||||||
|
@ -73,7 +68,7 @@ void PassCommon::getAndSortModules(ModuleOp topMod,
|
||||||
LogicalResult PassCommon::verifyInstances(mlir::ModuleOp mod) {
|
LogicalResult PassCommon::verifyInstances(mlir::ModuleOp mod) {
|
||||||
WalkResult r = mod.walk([&](InstanceOp inst) {
|
WalkResult r = mod.walk([&](InstanceOp inst) {
|
||||||
Operation *modOp = topLevelSyms.getDefinition(inst.getModuleNameAttr());
|
Operation *modOp = topLevelSyms.getDefinition(inst.getModuleNameAttr());
|
||||||
if (!isAnyModule(modOp))
|
if (!isa<hw::HWModuleLike>(modOp))
|
||||||
return WalkResult::interrupt();
|
return WalkResult::interrupt();
|
||||||
|
|
||||||
hw::ModulePortInfo ports = cast<hw::PortList>(modOp).getPortList();
|
hw::ModulePortInfo ports = cast<hw::PortList>(modOp).getPortList();
|
||||||
|
|
|
@ -26,9 +26,6 @@
|
||||||
namespace circt {
|
namespace circt {
|
||||||
namespace msft {
|
namespace msft {
|
||||||
|
|
||||||
/// TODO: Migrate these to some sort of OpInterface shared with hw.
|
|
||||||
bool isAnyModule(Operation *module);
|
|
||||||
|
|
||||||
/// Utility for creating {0, 1, 2, ..., size}.
|
/// Utility for creating {0, 1, 2, ..., size}.
|
||||||
SmallVector<unsigned> makeSequentialRange(unsigned size);
|
SmallVector<unsigned> makeSequentialRange(unsigned size);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue