[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:
Andrew Lenharth 2023-09-06 15:22:58 -05:00 committed by GitHub
parent 28bd7f1521
commit 1d36f60ce6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 9 additions and 43 deletions

View File

@ -52,9 +52,6 @@ void modifyModulePorts(Operation *op,
// 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.
bool isAnyModuleOrInstance(Operation *module);

View File

@ -35,8 +35,7 @@ Operation *getReferencedModule(const HWSymbolCache *cache,
Operation *instanceOp,
mlir::FlatSymbolRefAttr moduleName);
/// Verify that the instance refers to a valid HW module as determined by the
/// 'hw::isAnyModule' function.
/// Verify that the instance refers to a valid HW module.
LogicalResult verifyReferencedModule(Operation *instanceOp,
SymbolTableCollection &symbolTable,
mlir::FlatSymbolRefAttr moduleName,

View File

@ -13,20 +13,6 @@
include "mlir/IR/EnumAttr.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
//===----------------------------------------------------------------------===//

View File

@ -498,14 +498,9 @@ OpFoldResult ParamValueOp::fold(FoldAdaptor adaptor) {
// 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.
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
@ -523,8 +518,6 @@ FunctionType hw::getModuleType(Operation *moduleOrInstance) {
if (auto mod = dyn_cast<HWModuleLike>(moduleOrInstance))
return mod.getHWModuleType().getFuncType();
assert(isAnyModule(moduleOrInstance) &&
"must be called on instance or module");
return cast<mlir::FunctionOpInterface>(moduleOrInstance)
.getFunctionType()
.cast<FunctionType>();
@ -1096,7 +1089,7 @@ void HWModuleOp::print(OpAsmPrinter &p) {
}
static LogicalResult verifyModuleCommon(HWModuleLike module) {
assert(isAnyModule(module) &&
assert(isa<HWModuleLike>(module) &&
"verifier hook should only be called on modules");
auto moduleType = module.getHWModuleType();

View File

@ -34,7 +34,7 @@ LogicalResult instance_like_impl::verifyReferencedModule(
<< moduleName.getValue() << "'";
// It must be some sort of module.
if (!hw::isAnyModule(module))
if (!isa<HWModuleLike>(module))
return instanceOp->emitError("symbol reference '")
<< moduleName.getValue() << "' isn't a module";

View File

@ -390,8 +390,7 @@ LogicalResult InstanceOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
<< getModuleName() << "'";
// It must be some sort of module.
if (!hw::isAnyModule(module) &&
!isa<MSFTModuleOp, MSFTModuleExternOp>(module))
if (!isa<hw::HWModuleLike>(module))
return emitError("symbol reference '")
<< getModuleName() << "' isn't a module";
return success();

View File

@ -305,7 +305,7 @@ static StringRef getOperandName(OpOperand &oper, const SymbolCache &syms,
if (auto inst = dyn_cast<InstanceOp>(op)) {
Operation *modOp = syms.getDefinition(inst.getModuleNameAttr());
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);
return mod.getInputName(oper.getOperandNumber());
}

View File

@ -53,7 +53,7 @@ InstanceOpLowering::matchAndRewrite(InstanceOp msftInst, OpAdaptor adaptor,
if (!referencedModule)
return rewriter.notifyMatchFailure(msftInst,
"Could not find referenced module");
if (!hw::isAnyModule(referencedModule))
if (!isa<hw::HWModuleLike>(referencedModule))
return rewriter.notifyMatchFailure(
msftInst, "Referenced module was not an HW module");

View File

@ -14,11 +14,6 @@ using namespace mlir;
using namespace circt;
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> seq;
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)) {
Operation *modOp = syms.getDefinition(inst.getModuleNameAttr());
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>();
auto mod = cast<hw::HWModuleLike>(modOp);
buff.clear();
@ -73,7 +68,7 @@ void PassCommon::getAndSortModules(ModuleOp topMod,
LogicalResult PassCommon::verifyInstances(mlir::ModuleOp mod) {
WalkResult r = mod.walk([&](InstanceOp inst) {
Operation *modOp = topLevelSyms.getDefinition(inst.getModuleNameAttr());
if (!isAnyModule(modOp))
if (!isa<hw::HWModuleLike>(modOp))
return WalkResult::interrupt();
hw::ModulePortInfo ports = cast<hw::PortList>(modOp).getPortList();

View File

@ -26,9 +26,6 @@
namespace circt {
namespace msft {
/// TODO: Migrate these to some sort of OpInterface shared with hw.
bool isAnyModule(Operation *module);
/// Utility for creating {0, 1, 2, ..., size}.
SmallVector<unsigned> makeSequentialRange(unsigned size);