mirror of https://github.com/llvm/circt.git
[HW] Added methods to operate on in and inout ports (#4023)
Co-authored-by: Fabian Schuiki <fabian@schuiki.ch>
This commit is contained in:
parent
be732e05fe
commit
9ef4ead820
|
@ -87,6 +87,9 @@ def HWModuleOp : HWModuleOpBase<"module",
|
||||||
return getAllModulePortInfos(*this);
|
return getAllModulePortInfos(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the number of in or inout ports.
|
||||||
|
size_t getNumInOrInoutPorts() { return getArgumentTypes().size(); }
|
||||||
|
|
||||||
/// Return the PortInfo for the specified input or inout port.
|
/// Return the PortInfo for the specified input or inout port.
|
||||||
PortInfo getInOrInoutPort(size_t i) {
|
PortInfo getInOrInoutPort(size_t i) {
|
||||||
return getModuleInOrInoutPort(*this, i);
|
return getModuleInOrInoutPort(*this, i);
|
||||||
|
@ -97,6 +100,29 @@ def HWModuleOp : HWModuleOpBase<"module",
|
||||||
return getModuleOutputPort(*this, i);
|
return getModuleOutputPort(*this, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Append an input with a given name and type to the port list.
|
||||||
|
/// If the name is not unique, a unique name is created and returned.
|
||||||
|
std::pair<StringAttr, BlockArgument>
|
||||||
|
appendInput(const Twine &name, Type ty) {
|
||||||
|
return insertInput(getNumInOrInoutPorts(), name, ty);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<StringAttr, BlockArgument>
|
||||||
|
appendInput(StringAttr name, Type ty) {
|
||||||
|
return insertInput(getNumInOrInoutPorts(), name.getValue(), ty);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Insert an input with a given name and type into the port list.
|
||||||
|
/// The input is added at the specified index.
|
||||||
|
std::pair<StringAttr, BlockArgument>
|
||||||
|
insertInput(unsigned index, StringAttr name, Type ty);
|
||||||
|
|
||||||
|
std::pair<StringAttr, BlockArgument>
|
||||||
|
insertInput(unsigned index, const Twine &name, Type ty) {
|
||||||
|
::mlir::StringAttr nameAttr = ::mlir::StringAttr::get(getContext(), name);
|
||||||
|
return insertInput(index, nameAttr, ty);
|
||||||
|
}
|
||||||
|
|
||||||
/// Inserts a list of output ports into the port list at a specific
|
/// Inserts a list of output ports into the port list at a specific
|
||||||
/// location, shifting all subsequent ports. Rewrites the output op
|
/// location, shifting all subsequent ports. Rewrites the output op
|
||||||
/// to return the associated values.
|
/// to return the associated values.
|
||||||
|
|
|
@ -17,10 +17,13 @@
|
||||||
#include "circt/Dialect/HW/HWSymCache.h"
|
#include "circt/Dialect/HW/HWSymCache.h"
|
||||||
#include "circt/Dialect/HW/HWVisitors.h"
|
#include "circt/Dialect/HW/HWVisitors.h"
|
||||||
#include "circt/Dialect/HW/ModuleImplementation.h"
|
#include "circt/Dialect/HW/ModuleImplementation.h"
|
||||||
|
#include "circt/Support/Namespace.h"
|
||||||
#include "mlir/IR/Builders.h"
|
#include "mlir/IR/Builders.h"
|
||||||
#include "mlir/IR/FunctionImplementation.h"
|
#include "mlir/IR/FunctionImplementation.h"
|
||||||
#include "mlir/IR/PatternMatch.h"
|
#include "mlir/IR/PatternMatch.h"
|
||||||
|
#include "llvm/ADT/BitVector.h"
|
||||||
#include "llvm/ADT/SmallPtrSet.h"
|
#include "llvm/ADT/SmallPtrSet.h"
|
||||||
|
#include "llvm/ADT/StringSet.h"
|
||||||
|
|
||||||
using namespace circt;
|
using namespace circt;
|
||||||
using namespace hw;
|
using namespace hw;
|
||||||
|
@ -1133,6 +1136,25 @@ LogicalResult HWModuleOp::verify() { return verifyModuleCommon(*this); }
|
||||||
|
|
||||||
LogicalResult HWModuleExternOp::verify() { return verifyModuleCommon(*this); }
|
LogicalResult HWModuleExternOp::verify() { return verifyModuleCommon(*this); }
|
||||||
|
|
||||||
|
std::pair<StringAttr, BlockArgument>
|
||||||
|
HWModuleOp::insertInput(unsigned index, StringAttr name, Type ty) {
|
||||||
|
// Find a unique name for the wire.
|
||||||
|
Namespace ns;
|
||||||
|
for (auto port : getAllPorts())
|
||||||
|
ns.newName(port.name.getValue());
|
||||||
|
auto nameAttr = StringAttr::get(getContext(), ns.newName(name.getValue()));
|
||||||
|
|
||||||
|
// Create a new port for the host clock.
|
||||||
|
PortInfo port;
|
||||||
|
port.name = nameAttr;
|
||||||
|
port.direction = PortDirection::INPUT;
|
||||||
|
port.type = ty;
|
||||||
|
insertPorts({std::make_pair(index, port)}, {});
|
||||||
|
|
||||||
|
// Add a new argument.
|
||||||
|
return {nameAttr, getBody().getArgument(index)};
|
||||||
|
}
|
||||||
|
|
||||||
void HWModuleOp::insertOutputs(unsigned index,
|
void HWModuleOp::insertOutputs(unsigned index,
|
||||||
ArrayRef<std::pair<StringAttr, Value>> outputs) {
|
ArrayRef<std::pair<StringAttr, Value>> outputs) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue