mirror of https://github.com/llvm/circt.git
[LLHD] Use free variants of isa/cast/dyn_cast
Refer to https://mlir.llvm.org/deprecation/
This commit is contained in:
parent
93e2cb71a2
commit
8867f7b867
|
@ -144,12 +144,12 @@ def LLHD_SigArraySliceOp : LLHD_Op<"sig.array_slice",
|
|||
unsigned getResultWidth() { return getLLHDTypeWidth(getResult().getType()); }
|
||||
unsigned getInputWidth() { return getLLHDTypeWidth(getInput().getType()); }
|
||||
hw::ArrayType getInputArrayType() {
|
||||
return getInput().getType().cast<llhd::SigType>().getUnderlyingType()
|
||||
.cast<hw::ArrayType>();
|
||||
return llvm::cast<hw::ArrayType>(llvm::cast<llhd::SigType>(
|
||||
getInput().getType()).getUnderlyingType());
|
||||
}
|
||||
hw::ArrayType getResultArrayType() {
|
||||
return getResult().getType().cast<llhd::SigType>().getUnderlyingType()
|
||||
.cast<hw::ArrayType>();
|
||||
return llvm::cast<hw::ArrayType>(llvm::cast<llhd::SigType>(
|
||||
getResult().getType()).getUnderlyingType());
|
||||
}
|
||||
}];
|
||||
let hasFolder = true;
|
||||
|
@ -195,12 +195,12 @@ def LLHD_PtrArraySliceOp : LLHD_Op<"ptr.array_slice",
|
|||
unsigned getResultWidth() { return getLLHDTypeWidth(getResult().getType()); }
|
||||
unsigned getInputWidth() { return getLLHDTypeWidth(getInput().getType()); }
|
||||
hw::ArrayType getInputArrayType() {
|
||||
return getInput().getType().cast<llhd::PtrType>().getUnderlyingType()
|
||||
.cast<hw::ArrayType>();
|
||||
return llvm::cast<hw::ArrayType>(llvm::cast<llhd::PtrType>(
|
||||
getInput().getType()).getUnderlyingType());
|
||||
}
|
||||
hw::ArrayType getResultArrayType() {
|
||||
return getResult().getType().cast<llhd::PtrType>().getUnderlyingType()
|
||||
.cast<hw::ArrayType>();
|
||||
return llvm::cast<hw::ArrayType>(llvm::cast<llhd::PtrType>(
|
||||
getResult().getType()).getUnderlyingType());
|
||||
}
|
||||
}];
|
||||
let hasFolder = true;
|
||||
|
@ -233,8 +233,8 @@ def LLHD_SigArrayGetOp : LLHD_Op<"sig.array_get",
|
|||
|
||||
let extraClassDeclaration = [{
|
||||
hw::ArrayType getArrayType() {
|
||||
return getInput().getType().cast<llhd::SigType>()
|
||||
.getUnderlyingType().cast<hw::ArrayType>();
|
||||
return llvm::cast<hw::ArrayType>(llvm::cast<llhd::SigType>(
|
||||
getInput().getType()).getUnderlyingType());
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
@ -265,8 +265,8 @@ def LLHD_PtrArrayGetOp : LLHD_Op<"ptr.array_get",
|
|||
|
||||
let extraClassDeclaration = [{
|
||||
hw::ArrayType getArrayType() {
|
||||
return getInput().getType().cast<llhd::PtrType>()
|
||||
.getUnderlyingType().cast<hw::ArrayType>();
|
||||
return llvm::cast<hw::ArrayType>(llvm::cast<llhd::PtrType>(
|
||||
getInput().getType()).getUnderlyingType());
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
@ -299,8 +299,8 @@ def LLHD_SigStructExtractOp : LLHD_Op<"sig.struct_extract", [Pure,
|
|||
|
||||
let extraClassDeclaration = [{
|
||||
hw::StructType getStructType() {
|
||||
return getInput().getType().cast<llhd::SigType>().getUnderlyingType()
|
||||
.cast<hw::StructType>();
|
||||
return llvm::cast<hw::StructType>(llvm::cast<llhd::SigType>(
|
||||
getInput().getType()).getUnderlyingType());
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
@ -329,8 +329,8 @@ def LLHD_PtrStructExtractOp : LLHD_Op<"ptr.struct_extract", [Pure,
|
|||
|
||||
let extraClassDeclaration = [{
|
||||
hw::StructType getStructType() {
|
||||
return getInput().getType().cast<llhd::PtrType>().getUnderlyingType()
|
||||
.cast<hw::StructType>();
|
||||
return llvm::cast<hw::StructType>(llvm::cast<llhd::PtrType>(
|
||||
getInput().getType()).getUnderlyingType());
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ include "LLHDTypesImpl.td"
|
|||
|
||||
// LLHD Time Type
|
||||
def LLHD_TimeType : DialectType<LLHD_Dialect,
|
||||
CPred<"$_self.isa<TimeType>()">, "LLHD time type", "TimeType">,
|
||||
CPred<"llvm::isa<TimeType>($_self)">, "LLHD time type", "TimeType">,
|
||||
BuildableType<"TimeType::get($_builder.getContext())">;
|
||||
|
||||
// Legal underlying types for signals and pointers.
|
||||
|
@ -73,15 +73,15 @@ def LLHD_AnyUnderlyingType :
|
|||
|
||||
// LLHD sig type
|
||||
class LLHD_SigType<list<Type> allowedTypes>
|
||||
: ContainerType<AnyTypeOf<allowedTypes>, CPred<"$_self.isa<SigType>()">,
|
||||
"$_self.cast<SigType>().getUnderlyingType()", "LLHD sig type">;
|
||||
: ContainerType<AnyTypeOf<allowedTypes>, CPred<"llvm::isa<SigType>($_self)">,
|
||||
"llvm::cast<SigType>($_self).getUnderlyingType()", "LLHD sig type">;
|
||||
|
||||
def LLHD_AnySigType : LLHD_SigType<[LLHD_AnyUnderlyingType]>;
|
||||
|
||||
// LLHD ptr type
|
||||
class LLHD_PtrType<list<Type> allowedTypes>
|
||||
: ContainerType<AnyTypeOf<allowedTypes>, CPred<"$_self.isa<PtrType>()">,
|
||||
"$_self.cast<PtrType>().getUnderlyingType()", "LLHD pointer type">;
|
||||
: ContainerType<AnyTypeOf<allowedTypes>, CPred<"llvm::isa<PtrType>($_self)">,
|
||||
"llvm::cast<PtrType>($_self).getUnderlyingType()", "LLHD pointer type">;
|
||||
|
||||
def LLHD_AnyPtrType : LLHD_PtrType<[LLHD_AnyUnderlyingType]>;
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ def LLHD_VarOp : LLHD_Op<"var", [
|
|||
def LLHD_LoadOp : LLHD_Op<"load", [
|
||||
TypesMatchWith<
|
||||
"type of 'result' and underlying type of 'pointer' have to match.",
|
||||
"pointer", "result", "$_self.cast<PtrType>().getUnderlyingType()">
|
||||
"pointer", "result", "llvm::cast<PtrType>($_self).getUnderlyingType()">
|
||||
]> {
|
||||
let summary = "Load a value.";
|
||||
let description = [{
|
||||
|
@ -72,7 +72,7 @@ def LLHD_LoadOp : LLHD_Op<"load", [
|
|||
def LLHD_StoreOp : LLHD_Op<"store", [
|
||||
TypesMatchWith<
|
||||
"type of 'value' and underlying type of 'pointer' have to match.",
|
||||
"pointer", "value", "$_self.cast<PtrType>().getUnderlyingType()">
|
||||
"pointer", "value", "llvm::cast<PtrType>($_self).getUnderlyingType()">
|
||||
]> {
|
||||
let summary = "Store a value.";
|
||||
let description = [{
|
||||
|
|
|
@ -55,7 +55,7 @@ def LLHD_SigOp : LLHD_Op<"sig", [
|
|||
def LLHD_PrbOp : LLHD_Op<"prb", [
|
||||
TypesMatchWith<
|
||||
"type of 'result' and underlying type of 'signal' have to match.",
|
||||
"signal", "result", "$_self.cast<SigType>().getUnderlyingType()">
|
||||
"signal", "result", "llvm::cast<SigType>($_self).getUnderlyingType()">
|
||||
]> {
|
||||
let summary = "Probe a signal.";
|
||||
let description = [{
|
||||
|
@ -128,7 +128,7 @@ def LLHD_OutputOp : LLHD_Op<"output", [
|
|||
def LLHD_DrvOp : LLHD_Op<"drv", [
|
||||
TypesMatchWith<
|
||||
"type of 'value' and underlying type of 'signal' have to match.",
|
||||
"signal", "value", "$_self.cast<SigType>().getUnderlyingType()">
|
||||
"signal", "value", "llvm::cast<SigType>($_self).getUnderlyingType()">
|
||||
]> {
|
||||
let summary = "Drive a value into a signal.";
|
||||
let description = [{
|
||||
|
@ -286,19 +286,22 @@ def LLHD_RegOp : LLHD_Op<"reg", [
|
|||
|
||||
bool hasGate(unsigned index) {
|
||||
assert(index < getGateMask().getValue().size() && "Index out of range.");
|
||||
return getGateMask().getValue()[index].cast<IntegerAttr>().getInt() != 0;
|
||||
return llvm::cast<IntegerAttr>(
|
||||
getGateMask().getValue()[index]).getInt() != 0;
|
||||
}
|
||||
|
||||
Value getGateAt(unsigned index) {
|
||||
assert(index < getGateMask().getValue().size() && "Index out of range.");
|
||||
if (!hasGate(index)) return Value();
|
||||
return
|
||||
getGates()[getGateMask().getValue()[index].cast<IntegerAttr>().getInt()-1];
|
||||
getGates()[llvm::cast<IntegerAttr>(
|
||||
getGateMask().getValue()[index]).getInt()-1];
|
||||
}
|
||||
|
||||
RegMode getRegModeAt(unsigned index) {
|
||||
assert(index < getModes().getValue().size() && "Index out of range.");
|
||||
return (RegMode)getModes().getValue()[index].cast<IntegerAttr>().getInt();
|
||||
return (RegMode) llvm::cast<IntegerAttr>(
|
||||
getModes().getValue()[index]).getInt();
|
||||
}
|
||||
}];
|
||||
|
||||
|
|
|
@ -27,16 +27,14 @@ MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(LLHD, llhd, circt::llhd::LLHDDialect)
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Check if a type is a time type.
|
||||
bool llhdTypeIsATimeType(MlirType type) { return unwrap(type).isa<TimeType>(); }
|
||||
bool llhdTypeIsATimeType(MlirType type) { return isa<TimeType>(unwrap(type)); }
|
||||
|
||||
/// Check if a type is a signal type.
|
||||
bool llhdTypeIsASignalType(MlirType type) {
|
||||
return unwrap(type).isa<SigType>();
|
||||
}
|
||||
bool llhdTypeIsASignalType(MlirType type) { return isa<SigType>(unwrap(type)); }
|
||||
|
||||
/// Check if a type is a pointer type.
|
||||
bool llhdTypeIsAPointerType(MlirType type) {
|
||||
return unwrap(type).isa<PtrType>();
|
||||
return isa<PtrType>(unwrap(type));
|
||||
}
|
||||
|
||||
/// Create a time type.
|
||||
|
@ -56,12 +54,12 @@ MlirType llhdPointerTypeGet(MlirType element) {
|
|||
|
||||
/// Get the inner type of a signal.
|
||||
MlirType llhdSignalTypeGetElementType(MlirType type) {
|
||||
return wrap(unwrap(type).cast<SigType>().getUnderlyingType());
|
||||
return wrap(cast<SigType>(unwrap(type)).getUnderlyingType());
|
||||
}
|
||||
|
||||
/// Get the inner type of a pointer.
|
||||
MlirType llhdPointerTypeGetElementType(MlirType type) {
|
||||
return wrap(unwrap(type).cast<PtrType>().getUnderlyingType());
|
||||
return wrap(cast<PtrType>(unwrap(type)).getUnderlyingType());
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -70,7 +68,7 @@ MlirType llhdPointerTypeGetElementType(MlirType type) {
|
|||
|
||||
/// Check if an attribute is a time attribute.
|
||||
bool llhdAttrIsATimeAttr(MlirAttribute attr) {
|
||||
return unwrap(attr).isa<TimeAttr>();
|
||||
return isa<TimeAttr>(unwrap(attr));
|
||||
}
|
||||
|
||||
/// Create a time attribute.
|
||||
|
@ -83,20 +81,20 @@ MlirAttribute llhdTimeAttrGet(MlirContext ctx, MlirStringRef timeUnit,
|
|||
|
||||
/// Get the time unit of a time attribute.
|
||||
MlirStringRef llhdTimeAttrGetTimeUnit(MlirAttribute attr) {
|
||||
return wrap(unwrap(attr).cast<TimeAttr>().getTimeUnit());
|
||||
return wrap(cast<TimeAttr>(unwrap(attr)).getTimeUnit());
|
||||
}
|
||||
|
||||
/// Get the seconds component of a time attribute.
|
||||
uint64_t llhdTimeAttrGetSeconds(MlirAttribute attr) {
|
||||
return unwrap(attr).cast<TimeAttr>().getTime();
|
||||
return cast<TimeAttr>(unwrap(attr)).getTime();
|
||||
}
|
||||
|
||||
/// Get the delta component of a time attribute.
|
||||
uint64_t llhdTimeAttrGetDelta(MlirAttribute attr) {
|
||||
return unwrap(attr).cast<TimeAttr>().getDelta();
|
||||
return cast<TimeAttr>(unwrap(attr)).getDelta();
|
||||
}
|
||||
|
||||
/// Get the epsilon component of a time attribute.
|
||||
uint64_t llhdTimeAttrGetEpsilon(MlirAttribute attr) {
|
||||
return unwrap(attr).cast<TimeAttr>().getEpsilon();
|
||||
return cast<TimeAttr>(unwrap(attr)).getEpsilon();
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ struct ConvertHWModule : public OpConversionPattern<HWModuleOp> {
|
|||
// Ensure the input and output types have all been converted already. This
|
||||
// is handled separately by the upstream FunctionLikeTypeConversionPattern.
|
||||
if (!llvm::all_of(entityTypes,
|
||||
[](Type type) { return type.isa<SigType>(); }))
|
||||
[](Type type) { return isa<SigType>(type); }))
|
||||
return rewriter.notifyMatchFailure(module, "Not all ports had SigType");
|
||||
|
||||
// Create the entity. Note that LLHD does not support parameterized
|
||||
|
@ -118,7 +118,7 @@ struct ConvertOutput : public OpConversionPattern<hw::OutputOp> {
|
|||
continue;
|
||||
|
||||
// If the source has a signal type, connect it.
|
||||
if (auto sigTy = src.getType().dyn_cast<SigType>()) {
|
||||
if (auto sigTy = dyn_cast<SigType>(src.getType())) {
|
||||
rewriter.create<llhd::ConnectOp>(output.getLoc(), dest, src);
|
||||
continue;
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ struct ConvertInstance : public OpConversionPattern<InstanceOp> {
|
|||
for (auto arg : adaptor.getOperands()) {
|
||||
// Connect signals directly.
|
||||
auto argType = arg.getType();
|
||||
if (argType.isa<SigType>()) {
|
||||
if (isa<SigType>(argType)) {
|
||||
arguments.push_back(arg);
|
||||
continue;
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ struct ConvertInstance : public OpConversionPattern<InstanceOp> {
|
|||
// done, the materializer can insert buffers with no delay and have them
|
||||
// collected in a canonicalization later where appropriate.
|
||||
// See github.com/llvm/circt/pull/988 for a discussion.
|
||||
if (!argType.isa<IntegerType>())
|
||||
if (!isa<IntegerType>(argType))
|
||||
return rewriter.notifyMatchFailure(instance, [&](Diagnostic &diag) {
|
||||
diag << "argument type " << argType << " is not supported";
|
||||
});
|
||||
|
@ -199,7 +199,7 @@ struct ConvertInstance : public OpConversionPattern<InstanceOp> {
|
|||
SmallVector<Value, 4> resultValues;
|
||||
for (auto result : instance.getResults()) {
|
||||
auto resultType = result.getType();
|
||||
if (!resultType.isa<IntegerType>())
|
||||
if (!isa<IntegerType>(resultType))
|
||||
return rewriter.notifyMatchFailure(instance, [&](Diagnostic &diag) {
|
||||
diag << "result type " << resultType << " is not supported";
|
||||
});
|
||||
|
|
|
@ -245,12 +245,11 @@ static void persistValue(LLVM::LLVMDialect *dialect, Location loc,
|
|||
const TypeConverter *converter,
|
||||
ConversionPatternRewriter &rewriter, Type stateTy,
|
||||
int &i, Value state, Value persist) {
|
||||
auto elemTy = stateTy.cast<LLVM::LLVMStructType>()
|
||||
.getBody()[3]
|
||||
.cast<LLVM::LLVMStructType>()
|
||||
auto elemTy = cast<LLVM::LLVMStructType>(
|
||||
cast<LLVM::LLVMStructType>(stateTy).getBody()[3])
|
||||
.getBody()[i];
|
||||
|
||||
if (auto arg = persist.dyn_cast<BlockArgument>()) {
|
||||
if (auto arg = dyn_cast<BlockArgument>(persist)) {
|
||||
rewriter.setInsertionPointToStart(arg.getParentBlock());
|
||||
} else {
|
||||
rewriter.setInsertionPointAfter(persist.getDefiningOp());
|
||||
|
@ -262,11 +261,11 @@ static void persistValue(LLVM::LLVMDialect *dialect, Location loc,
|
|||
auto gep0 = gepPersistenceState(dialect, loc, rewriter, stateTy, i, state);
|
||||
|
||||
Value toStore;
|
||||
if (auto ptr = persist.getType().dyn_cast<PtrType>()) {
|
||||
if (auto ptr = dyn_cast<PtrType>(persist.getType())) {
|
||||
// Unwrap the pointer and store it's value.
|
||||
auto elemTy = converter->convertType(ptr.getUnderlyingType());
|
||||
toStore = rewriter.create<LLVM::LoadOp>(loc, elemTy, convPersist);
|
||||
} else if (persist.getType().isa<SigType>()) {
|
||||
} else if (isa<SigType>(persist.getType())) {
|
||||
// Unwrap and store the signal struct.
|
||||
toStore = rewriter.create<LLVM::LoadOp>(loc, getLLVMSigType(dialect),
|
||||
convPersist);
|
||||
|
@ -281,7 +280,7 @@ static void persistValue(LLVM::LLVMDialect *dialect, Location loc,
|
|||
// use with it, whenever it is in a different block.
|
||||
for (auto &use : llvm::make_early_inc_range(persist.getUses())) {
|
||||
auto user = use.getOwner();
|
||||
if (persist.getType().isa<PtrType>() && user != toStore.getDefiningOp() &&
|
||||
if (isa<PtrType>(persist.getType()) && user != toStore.getDefiningOp() &&
|
||||
user != convPersist.getDefiningOp() &&
|
||||
persist.getParentBlock() == user->getBlock()) {
|
||||
// Redirect uses of the pointer in the same block to the pointer in the
|
||||
|
@ -304,7 +303,7 @@ static void persistValue(LLVM::LLVMDialect *dialect, Location loc,
|
|||
gepPersistenceState(dialect, loc, rewriter, stateTy, i, state);
|
||||
// Use the pointer in the state struct directly for pointer and signal
|
||||
// types.
|
||||
if (persist.getType().isa<PtrType, SigType>()) {
|
||||
if (isa<PtrType, SigType>(persist.getType())) {
|
||||
use.set(gep1);
|
||||
} else {
|
||||
auto load1 = rewriter.create<LLVM::LoadOp>(loc, elemTy, gep1);
|
||||
|
@ -507,8 +506,8 @@ static Value recursiveCloneInit(OpBuilder &initBuilder, IRMapping &mapping,
|
|||
/// Check if the given type is either of LLHD's ArrayType, StructType, or LLVM
|
||||
/// array or struct type.
|
||||
static bool isArrayOrStruct(Type type) {
|
||||
return type.isa<LLVM::LLVMArrayType, LLVM::LLVMStructType, hw::ArrayType,
|
||||
hw::StructType>();
|
||||
return isa<LLVM::LLVMArrayType, LLVM::LLVMStructType, hw::ArrayType,
|
||||
hw::StructType>(type);
|
||||
}
|
||||
|
||||
/// Shift an integer signal pointer to obtain a view of the underlying value as
|
||||
|
@ -1017,11 +1016,10 @@ struct InstOpConversion : public ConvertToLLVMPattern {
|
|||
|
||||
// Zero-initialize reg state entries.
|
||||
for (size_t i = 0,
|
||||
e = regStateTy.cast<LLVM::LLVMStructType>().getBody().size();
|
||||
e = cast<LLVM::LLVMStructType>(regStateTy).getBody().size();
|
||||
i < e; ++i) {
|
||||
size_t f = regStateTy.cast<LLVM::LLVMStructType>()
|
||||
.getBody()[i]
|
||||
.cast<LLVM::LLVMArrayType>()
|
||||
size_t f = cast<LLVM::LLVMArrayType>(
|
||||
cast<LLVM::LLVMStructType>(regStateTy).getBody()[i])
|
||||
.getNumElements();
|
||||
for (size_t j = 0; j < f; ++j) {
|
||||
auto regGep = initBuilder.create<LLVM::GEPOp>(
|
||||
|
@ -1085,7 +1083,7 @@ struct InstOpConversion : public ConvertToLLVMPattern {
|
|||
// Get the amount of bytes required to represent an integer underlying
|
||||
// type. Use the whole size of the type if not an integer.
|
||||
Value passSize;
|
||||
if (auto intTy = underlyingTy.dyn_cast<IntegerType>()) {
|
||||
if (auto intTy = dyn_cast<IntegerType>(underlyingTy)) {
|
||||
auto byteWidth = llvm::divideCeil(intTy.getWidth(), 8);
|
||||
passSize = initBuilder.create<LLVM::ConstantOp>(
|
||||
op.getLoc(), i64Ty, rewriter.getI64IntegerAttr(byteWidth));
|
||||
|
@ -1102,7 +1100,7 @@ struct InstOpConversion : public ConvertToLLVMPattern {
|
|||
.getResult();
|
||||
|
||||
// Add structured underlying type information.
|
||||
if (auto arrayTy = underlyingTy.dyn_cast<LLVM::LLVMArrayType>()) {
|
||||
if (auto arrayTy = dyn_cast<LLVM::LLVMArrayType>(underlyingTy)) {
|
||||
auto numElements = initBuilder.create<LLVM::ConstantOp>(
|
||||
op.getLoc(), i32Ty,
|
||||
rewriter.getI32IntegerAttr(arrayTy.getNumElements()));
|
||||
|
@ -1120,7 +1118,7 @@ struct InstOpConversion : public ConvertToLLVMPattern {
|
|||
op.getLoc(), std::nullopt, SymbolRefAttr::get(addSigElemFunc),
|
||||
ArrayRef<Value>({initStatePtr, sigIndex, toInt, numElements}));
|
||||
} else if (auto structTy =
|
||||
underlyingTy.dyn_cast<LLVM::LLVMStructType>()) {
|
||||
dyn_cast<LLVM::LLVMStructType>(underlyingTy)) {
|
||||
auto null = initBuilder.create<LLVM::ZeroOp>(op.getLoc(), voidPtrTy);
|
||||
for (size_t i = 0, e = structTy.getBody().size(); i < e; ++i) {
|
||||
// Get pointer offset.
|
||||
|
@ -1296,7 +1294,7 @@ struct PrbOpConversion : public ConvertToLLVMPattern {
|
|||
auto sigDetail = getSignalDetail(rewriter, &getDialect(), op->getLoc(),
|
||||
transformed.getSignal());
|
||||
|
||||
if (resTy.isa<IntegerType>()) {
|
||||
if (isa<IntegerType>(resTy)) {
|
||||
// Get the amount of bytes to load. An extra byte is always loaded to
|
||||
// cover the case where a subsignal spans halfway in the last byte.
|
||||
int resWidth = resTy.getIntOrFloatBitWidth();
|
||||
|
@ -1315,7 +1313,7 @@ struct PrbOpConversion : public ConvertToLLVMPattern {
|
|||
return success();
|
||||
}
|
||||
|
||||
if (resTy.isa<hw::ArrayType, hw::StructType>()) {
|
||||
if (isa<hw::ArrayType, hw::StructType>(resTy)) {
|
||||
rewriter.replaceOpWithNewOp<LLVM::LoadOp>(op, finalTy, sigDetail[0]);
|
||||
|
||||
return success();
|
||||
|
|
|
@ -68,10 +68,10 @@ void LLHDDialect::initialize() {
|
|||
|
||||
Operation *LLHDDialect::materializeConstant(OpBuilder &builder, Attribute value,
|
||||
Type type, Location loc) {
|
||||
if (auto timeAttr = value.dyn_cast<TimeAttr>())
|
||||
if (auto timeAttr = dyn_cast<TimeAttr>(value))
|
||||
return builder.create<llhd::ConstantTimeOp>(loc, type, timeAttr);
|
||||
|
||||
if (auto intAttr = value.dyn_cast<IntegerAttr>())
|
||||
if (auto intAttr = dyn_cast<IntegerAttr>(value))
|
||||
return builder.create<hw::ConstantOp>(loc, type, intAttr);
|
||||
|
||||
return nullptr;
|
||||
|
|
|
@ -41,15 +41,15 @@ static Attribute constFoldUnaryOp(ArrayRef<Attribute> operands,
|
|||
if (!operands[0])
|
||||
return {};
|
||||
|
||||
if (auto val = operands[0].dyn_cast<AttrElementT>()) {
|
||||
if (auto val = dyn_cast<AttrElementT>(operands[0])) {
|
||||
return AttrElementT::get(val.getType(), calculate(val.getValue()));
|
||||
} else if (auto val = operands[0].dyn_cast<SplatElementsAttr>()) {
|
||||
} else if (auto val = dyn_cast<SplatElementsAttr>(operands[0])) {
|
||||
// Operand is a splat so we can avoid expanding the value out and
|
||||
// just fold based on the splat value.
|
||||
auto elementResult = calculate(val.getSplatValue<ElementValueT>());
|
||||
return DenseElementsAttr::get(val.getType(), elementResult);
|
||||
}
|
||||
if (auto val = operands[0].dyn_cast<ElementsAttr>()) {
|
||||
if (auto val = dyn_cast<ElementsAttr>(operands[0])) {
|
||||
// Operand is ElementsAttr-derived; perform an element-wise fold by
|
||||
// expanding the values.
|
||||
auto valIt = val.getValues<ElementValueT>().begin();
|
||||
|
@ -72,37 +72,37 @@ static Attribute constFoldTernaryOp(ArrayRef<Attribute> operands,
|
|||
if (!operands[0] || !operands[1] || !operands[2])
|
||||
return {};
|
||||
|
||||
if (operands[0].isa<AttrElementT>() && operands[1].isa<AttrElementT>() &&
|
||||
operands[2].isa<AttrElementT>()) {
|
||||
auto fst = operands[0].cast<AttrElementT>();
|
||||
auto snd = operands[1].cast<AttrElementT>();
|
||||
auto trd = operands[2].cast<AttrElementT>();
|
||||
if (isa<AttrElementT>(operands[0]) && isa<AttrElementT>(operands[1]) &&
|
||||
isa<AttrElementT>(operands[2])) {
|
||||
auto fst = cast<AttrElementT>(operands[0]);
|
||||
auto snd = cast<AttrElementT>(operands[1]);
|
||||
auto trd = cast<AttrElementT>(operands[2]);
|
||||
|
||||
return AttrElementT::get(
|
||||
fst.getType(),
|
||||
calculate(fst.getValue(), snd.getValue(), trd.getValue()));
|
||||
}
|
||||
if (operands[0].isa<SplatElementsAttr>() &&
|
||||
operands[1].isa<SplatElementsAttr>() &&
|
||||
operands[2].isa<SplatElementsAttr>()) {
|
||||
if (isa<SplatElementsAttr>(operands[0]) &&
|
||||
isa<SplatElementsAttr>(operands[1]) &&
|
||||
isa<SplatElementsAttr>(operands[2])) {
|
||||
// Operands are splats so we can avoid expanding the values out and
|
||||
// just fold based on the splat value.
|
||||
auto fst = operands[0].cast<SplatElementsAttr>();
|
||||
auto snd = operands[1].cast<SplatElementsAttr>();
|
||||
auto trd = operands[2].cast<SplatElementsAttr>();
|
||||
auto fst = cast<SplatElementsAttr>(operands[0]);
|
||||
auto snd = cast<SplatElementsAttr>(operands[1]);
|
||||
auto trd = cast<SplatElementsAttr>(operands[2]);
|
||||
|
||||
auto elementResult = calculate(fst.getSplatValue<ElementValueT>(),
|
||||
snd.getSplatValue<ElementValueT>(),
|
||||
trd.getSplatValue<ElementValueT>());
|
||||
return DenseElementsAttr::get(fst.getType(), elementResult);
|
||||
}
|
||||
if (operands[0].isa<ElementsAttr>() && operands[1].isa<ElementsAttr>() &&
|
||||
operands[2].isa<ElementsAttr>()) {
|
||||
if (isa<ElementsAttr>(operands[0]) && isa<ElementsAttr>(operands[1]) &&
|
||||
isa<ElementsAttr>(operands[2])) {
|
||||
// Operands are ElementsAttr-derived; perform an element-wise fold by
|
||||
// expanding the values.
|
||||
auto fst = operands[0].cast<ElementsAttr>();
|
||||
auto snd = operands[1].cast<ElementsAttr>();
|
||||
auto trd = operands[2].cast<ElementsAttr>();
|
||||
auto fst = cast<ElementsAttr>(operands[0]);
|
||||
auto snd = cast<ElementsAttr>(operands[1]);
|
||||
auto trd = cast<ElementsAttr>(operands[2]);
|
||||
|
||||
auto fstIt = fst.getValues<ElementValueT>().begin();
|
||||
auto sndIt = snd.getValues<ElementValueT>().begin();
|
||||
|
@ -130,23 +130,23 @@ struct constant_int_all_ones_matcher {
|
|||
} // anonymous namespace
|
||||
|
||||
unsigned circt::llhd::getLLHDTypeWidth(Type type) {
|
||||
if (auto sig = type.dyn_cast<llhd::SigType>())
|
||||
if (auto sig = dyn_cast<llhd::SigType>(type))
|
||||
type = sig.getUnderlyingType();
|
||||
else if (auto ptr = type.dyn_cast<llhd::PtrType>())
|
||||
else if (auto ptr = dyn_cast<llhd::PtrType>(type))
|
||||
type = ptr.getUnderlyingType();
|
||||
if (auto array = type.dyn_cast<hw::ArrayType>())
|
||||
if (auto array = dyn_cast<hw::ArrayType>(type))
|
||||
return array.getNumElements();
|
||||
if (auto tup = type.dyn_cast<hw::StructType>())
|
||||
if (auto tup = dyn_cast<hw::StructType>(type))
|
||||
return tup.getElements().size();
|
||||
return type.getIntOrFloatBitWidth();
|
||||
}
|
||||
|
||||
Type circt::llhd::getLLHDElementType(Type type) {
|
||||
if (auto sig = type.dyn_cast<llhd::SigType>())
|
||||
if (auto sig = dyn_cast<llhd::SigType>(type))
|
||||
type = sig.getUnderlyingType();
|
||||
else if (auto ptr = type.dyn_cast<llhd::PtrType>())
|
||||
else if (auto ptr = dyn_cast<llhd::PtrType>(type))
|
||||
type = ptr.getUnderlyingType();
|
||||
if (auto array = type.dyn_cast<hw::ArrayType>())
|
||||
if (auto array = dyn_cast<hw::ArrayType>(type))
|
||||
return array.getElementType();
|
||||
return type;
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ static OpFoldResult foldSigPtrExtractOp(Op op, ArrayRef<Attribute> operands) {
|
|||
|
||||
// llhd.sig.extract(input, 0) with inputWidth == resultWidth => input
|
||||
if (op.getResultWidth() == op.getInputWidth() &&
|
||||
operands[1].cast<IntegerAttr>().getValue().isZero())
|
||||
cast<IntegerAttr>(operands[1]).getValue().isZero())
|
||||
return op.getInput();
|
||||
|
||||
return nullptr;
|
||||
|
@ -210,7 +210,7 @@ static OpFoldResult foldSigPtrArraySliceOp(Op op,
|
|||
|
||||
// llhd.sig.array_slice(input, 0) with inputWidth == resultWidth => input
|
||||
if (op.getResultWidth() == op.getInputWidth() &&
|
||||
operands[1].cast<IntegerAttr>().getValue().isZero())
|
||||
cast<IntegerAttr>(operands[1]).getValue().isZero())
|
||||
return op.getInput();
|
||||
|
||||
return nullptr;
|
||||
|
@ -267,15 +267,11 @@ static LogicalResult inferReturnTypesOfStructExtractOp(
|
|||
MLIRContext *context, std::optional<Location> loc, ValueRange operands,
|
||||
DictionaryAttr attrs, mlir::OpaqueProperties properties,
|
||||
mlir::RegionRange regions, SmallVectorImpl<Type> &results) {
|
||||
Type type = operands[0]
|
||||
.getType()
|
||||
.cast<SigPtrType>()
|
||||
.getUnderlyingType()
|
||||
.template cast<hw::StructType>()
|
||||
.getFieldType(attrs.getNamed("field")
|
||||
->getValue()
|
||||
.cast<StringAttr>()
|
||||
.getValue());
|
||||
Type type =
|
||||
cast<hw::StructType>(
|
||||
cast<SigPtrType>(operands[0].getType()).getUnderlyingType())
|
||||
.getFieldType(
|
||||
cast<StringAttr>(attrs.getNamed("field")->getValue()).getValue());
|
||||
if (!type) {
|
||||
context->getDiagEngine().emit(loc.value_or(UnknownLoc()),
|
||||
DiagnosticSeverity::Error)
|
||||
|
@ -472,7 +468,7 @@ LogicalResult llhd::EntityOp::verify() {
|
|||
|
||||
// Check that all block arguments are of signal type
|
||||
for (size_t i = 0; i < numArgs; ++i)
|
||||
if (!getArgument(i).getType().isa<llhd::SigType>())
|
||||
if (!isa<llhd::SigType>(getArgument(i).getType()))
|
||||
return emitError("usage of invalid argument type. Got ")
|
||||
<< getArgument(i).getType() << ", expected LLHD signal type";
|
||||
|
||||
|
@ -489,7 +485,7 @@ LogicalResult circt::llhd::EntityOp::verifyType() {
|
|||
|
||||
// Check that all operands are of signal type
|
||||
for (Type inputType : type.getInputs())
|
||||
if (!inputType.isa<llhd::SigType>())
|
||||
if (!isa<llhd::SigType>(inputType))
|
||||
return emitOpError("usage of invalid argument type. Got ")
|
||||
<< inputType << ", expected LLHD signal type";
|
||||
|
||||
|
@ -557,7 +553,7 @@ LogicalResult circt::llhd::ProcOp::verifyType() {
|
|||
|
||||
// Check that all operands are of signal type
|
||||
for (int i = 0, e = getNumArguments(); i < e; ++i) {
|
||||
if (!getArgument(i).getType().isa<llhd::SigType>()) {
|
||||
if (!isa<llhd::SigType>(getArgument(i).getType())) {
|
||||
return emitOpError("usage of invalid argument type, was ")
|
||||
<< getArgument(i).getType() << ", expected LLHD signal type";
|
||||
}
|
||||
|
@ -784,16 +780,15 @@ LogicalResult llhd::InstOp::verify() {
|
|||
|
||||
// Check input types
|
||||
for (size_t i = 0, e = module.getNumInputPorts(); i != e; ++i) {
|
||||
if (getOperand(i).getType().cast<llhd::SigType>().getUnderlyingType() !=
|
||||
if (cast<llhd::SigType>(getOperand(i).getType()).getUnderlyingType() !=
|
||||
module.getInputTypes()[i])
|
||||
return emitOpError("input type mismatch");
|
||||
}
|
||||
|
||||
// Check output types
|
||||
for (size_t i = 0, e = module.getNumOutputPorts(); i != e; ++i) {
|
||||
if (getOperand(module.getNumInputPorts() + i)
|
||||
.getType()
|
||||
.cast<llhd::SigType>()
|
||||
if (cast<llhd::SigType>(
|
||||
getOperand(module.getNumInputPorts() + i).getType())
|
||||
.getUnderlyingType() != module.getOutputTypes()[i])
|
||||
return emitOpError("output type mismatch");
|
||||
}
|
||||
|
@ -921,7 +916,7 @@ void llhd::RegOp::print(OpAsmPrinter &printer) {
|
|||
printer << " " << getSignal();
|
||||
for (size_t i = 0, e = getValues().size(); i < e; ++i) {
|
||||
std::optional<llhd::RegMode> mode = llhd::symbolizeRegMode(
|
||||
getModes().getValue()[i].cast<IntegerAttr>().getInt());
|
||||
cast<IntegerAttr>(getModes().getValue()[i]).getInt());
|
||||
if (!mode) {
|
||||
emitError("invalid RegMode");
|
||||
return;
|
||||
|
@ -979,7 +974,7 @@ LogicalResult llhd::RegOp::verify() {
|
|||
unsigned counter = 0;
|
||||
unsigned prevElement = 0;
|
||||
for (Attribute maskElem : getGateMask().getValue()) {
|
||||
int64_t val = maskElem.cast<IntegerAttr>().getInt();
|
||||
int64_t val = cast<IntegerAttr>(maskElem).getInt();
|
||||
if (val < 0)
|
||||
return emitError("Element in 'gateMask' must not be negative!");
|
||||
if (val == 0)
|
||||
|
@ -1000,7 +995,7 @@ LogicalResult llhd::RegOp::verify() {
|
|||
for (auto val : getValues()) {
|
||||
if (val.getType() != getSignal().getType() &&
|
||||
val.getType() !=
|
||||
getSignal().getType().cast<llhd::SigType>().getUnderlyingType()) {
|
||||
cast<llhd::SigType>(getSignal().getType()).getUnderlyingType()) {
|
||||
return emitOpError(
|
||||
"type of each 'value' has to be either the same as the "
|
||||
"type of 'signal' or the underlying type of 'signal'");
|
||||
|
|
|
@ -276,7 +276,7 @@ void Engine::walkEntity(EntityOp entity, Instance &child) {
|
|||
|
||||
for (size_t i = 0, e = args.size(); i < e; ++i) {
|
||||
// The signal comes from an instance's argument.
|
||||
if (auto blockArg = args[i].dyn_cast<BlockArgument>()) {
|
||||
if (auto blockArg = dyn_cast<BlockArgument>(args[i])) {
|
||||
auto detail = child.sensitivityList[blockArg.getArgNumber()];
|
||||
detail.instIndex = i;
|
||||
newChild.sensitivityList.push_back(detail);
|
||||
|
|
|
@ -73,7 +73,7 @@ void EarlyCodeMotionPass::runOnOperation() {
|
|||
for (Value operand : op.getOperands()) {
|
||||
SmallVector<Block *, 8> dominationSet;
|
||||
Block *instBlock = nullptr;
|
||||
if (BlockArgument arg = operand.dyn_cast<BlockArgument>()) {
|
||||
if (BlockArgument arg = dyn_cast<BlockArgument>(operand)) {
|
||||
instBlock = arg.getParentBlock();
|
||||
} else {
|
||||
instBlock = operand.getDefiningOp()->getBlock();
|
||||
|
|
|
@ -134,8 +134,7 @@ void MemoryToBlockArgumentPass::runOnOperation() {
|
|||
for (Block *jp : joinPoints) {
|
||||
// Add a block argument for the variable at each join point
|
||||
BlockArgument phi = jp->addArgument(
|
||||
var.getType().cast<llhd::PtrType>().getUnderlyingType(),
|
||||
var.getLoc());
|
||||
cast<llhd::PtrType>(var.getType()).getUnderlyingType(), var.getLoc());
|
||||
|
||||
// Add a load at the end of every predecessor and pass the loaded value as
|
||||
// the block argument
|
||||
|
@ -144,7 +143,7 @@ void MemoryToBlockArgumentPass::runOnOperation() {
|
|||
builder.setInsertionPoint(pred->getTerminator());
|
||||
Value load = builder.create<llhd::LoadOp>(
|
||||
pred->getTerminator()->getLoc(),
|
||||
var.getType().cast<llhd::PtrType>().getUnderlyingType(), var);
|
||||
cast<llhd::PtrType>(var.getType()).getUnderlyingType(), var);
|
||||
// Add the loaded value as additional block argument
|
||||
addBlockOperandToTerminator(pred->getTerminator(), jp, load);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ static LogicalResult checkSignalsAreObserved(OperandRange obs, Value value) {
|
|||
// last point where it could have been observed. As we've already checked
|
||||
// that, we can fail here. This includes for example llhd.sig
|
||||
if (llvm::none_of(op->getOperands(), [](Value arg) {
|
||||
return arg.getType().isa<llhd::SigType>();
|
||||
return isa<llhd::SigType>(arg.getType());
|
||||
}))
|
||||
return failure();
|
||||
|
||||
|
@ -49,7 +49,7 @@ static LogicalResult checkSignalsAreObserved(OperandRange obs, Value value) {
|
|||
// they are covered by that probe. As soon as we find a signal that is not
|
||||
// observed no matter how far we backtrack, we fail.
|
||||
return success(llvm::all_of(op->getOperands(), [&](Value arg) {
|
||||
return !arg.getType().isa<llhd::SigType>() ||
|
||||
return !isa<llhd::SigType>(arg.getType()) ||
|
||||
succeeded(checkSignalsAreObserved(obs, arg));
|
||||
}));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue