Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure type conversion materialization callbacks return values of the correct type #7583

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/Conversion/DCToHW/DCToHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ class ESITypeConverter : public TypeConverter {
if (inputs.size() != 1)
return std::nullopt;

return inputs[0];
return builder
.create<UnrealizedConversionCastOp>(loc, resultType, inputs[0])
->getResult(0);
});

addSourceMaterialization(
Expand All @@ -128,7 +130,9 @@ class ESITypeConverter : public TypeConverter {
if (inputs.size() != 1)
return std::nullopt;

return inputs[0];
return builder
.create<UnrealizedConversionCastOp>(loc, resultType, inputs[0])
->getResult(0);
});
}
};
Expand Down
8 changes: 6 additions & 2 deletions lib/Conversion/HWArithToHW/HWArithToHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,9 @@ HWArithToHWTypeConverter::HWArithToHWTypeConverter() {
mlir::Location loc) -> std::optional<mlir::Value> {
if (inputs.size() != 1)
return std::nullopt;
return inputs[0];
return builder
.create<UnrealizedConversionCastOp>(loc, resultType, inputs[0])
->getResult(0);
});

addSourceMaterialization(
Expand All @@ -402,7 +404,9 @@ HWArithToHWTypeConverter::HWArithToHWTypeConverter() {
mlir::Location loc) -> std::optional<mlir::Value> {
if (inputs.size() != 1)
return std::nullopt;
return inputs[0];
return builder
.create<UnrealizedConversionCastOp>(loc, resultType, inputs[0])
->getResult(0);
});
}

Expand Down
8 changes: 6 additions & 2 deletions lib/Conversion/HandshakeToDC/HandshakeToDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ class DCTypeConverter : public TypeConverter {
if (vt && !vt.getInnerType())
return pack(builder, inputs.front());

return inputs[0];
return builder
.create<UnrealizedConversionCastOp>(loc, resultType, inputs[0])
->getResult(0);
});

addSourceMaterialization(
Expand All @@ -112,7 +114,9 @@ class DCTypeConverter : public TypeConverter {
if (vt && !vt.getInnerType())
return pack(builder, inputs.front());

return inputs[0];
return builder
.create<UnrealizedConversionCastOp>(loc, resultType, inputs[0])
->getResult(0);
});
}
};
Expand Down
8 changes: 6 additions & 2 deletions lib/Conversion/HandshakeToHW/HandshakeToHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ class ESITypeConverter : public TypeConverter {
mlir::Location loc) -> std::optional<mlir::Value> {
if (inputs.size() != 1)
return std::nullopt;
return inputs[0];
return builder
.create<UnrealizedConversionCastOp>(loc, resultType, inputs[0])
->getResult(0);
});

addSourceMaterialization(
Expand All @@ -80,7 +82,9 @@ class ESITypeConverter : public TypeConverter {
mlir::Location loc) -> std::optional<mlir::Value> {
if (inputs.size() != 1)
return std::nullopt;
return inputs[0];
return builder
.create<UnrealizedConversionCastOp>(loc, resultType, inputs[0])
->getResult(0);
});
}
};
Expand Down
8 changes: 6 additions & 2 deletions lib/Conversion/LTLToCore/LTLToCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ void LowerLTLToCorePass::runOnOperation() {
mlir::Location loc) -> std::optional<mlir::Value> {
if (inputs.size() != 1)
return std::nullopt;
return inputs[0];
return builder
.create<UnrealizedConversionCastOp>(loc, resultType, inputs[0])
->getResult(0);
});

converter.addSourceMaterialization(
Expand All @@ -147,7 +149,9 @@ void LowerLTLToCorePass::runOnOperation() {
mlir::Location loc) -> std::optional<mlir::Value> {
if (inputs.size() != 1)
return std::nullopt;
return inputs[0];
return builder
.create<UnrealizedConversionCastOp>(loc, resultType, inputs[0])
->getResult(0);
});

// Create the operation rewrite patters
Expand Down
4 changes: 3 additions & 1 deletion lib/Conversion/MooreToCore/MooreToCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,9 @@ static void populateTypeConversion(TypeConverter &typeConverter) {
mlir::Location loc) -> std::optional<mlir::Value> {
if (inputs.size() != 1)
return std::nullopt;
return inputs[0];
return builder
.create<UnrealizedConversionCastOp>(loc, resultType, inputs[0])
->getResult(0);
});
}

Expand Down
10 changes: 8 additions & 2 deletions lib/Conversion/SeqToSV/SeqToSV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,10 @@ struct SeqToSVTypeConverter : public TypeConverter {
mlir::Location loc) -> std::optional<mlir::Value> {
if (inputs.size() != 1)
return std::nullopt;
return inputs[0];
return builder
.create<mlir::UnrealizedConversionCastOp>(loc, resultType,
inputs[0])
->getResult(0);
});

addSourceMaterialization(
Expand All @@ -372,7 +375,10 @@ struct SeqToSVTypeConverter : public TypeConverter {
mlir::Location loc) -> std::optional<mlir::Value> {
if (inputs.size() != 1)
return std::nullopt;
return inputs[0];
return builder
.create<mlir::UnrealizedConversionCastOp>(loc, resultType,
inputs[0])
->getResult(0);
});
}
};
Expand Down
6 changes: 4 additions & 2 deletions lib/Dialect/FIRRTL/Transforms/LowerClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1857,14 +1857,16 @@ static void populateTypeConverter(TypeConverter &converter) {
converter.addTargetMaterialization(
[](OpBuilder &builder, Type type, ValueRange values, Location loc) {
assert(values.size() == 1);
return values[0];
return builder.create<UnrealizedConversionCastOp>(loc, type, values[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment above this says the materialization here is to fold away the casts, which seems unlikely to be what is accomplished by the new version.

Should this just be dropped? (And the other here?)
(I can help answer that later)

Thanks for helping maintain this!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it is also not what is accomplished by the old version. Let me change that comment to make clear what it does.

->getResult(0);
});

// Add a source materialization to fold away unrealized conversion casts.
converter.addSourceMaterialization(
[](OpBuilder &builder, Type type, ValueRange values, Location loc) {
assert(values.size() == 1);
return values[0];
return builder.create<UnrealizedConversionCastOp>(loc, type, values[0])
->getResult(0);
});
}

Expand Down
Loading