-
Notifications
You must be signed in to change notification settings - Fork 306
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
[ImportVerilog] add real literal support, refine real type, and add real format support #8020
Draft
chenbo-again
wants to merge
3
commits into
llvm:main
Choose a base branch
from
chenbo-again:real
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -278,6 +278,20 @@ def FormatCharOp : SimOp<"fmt.char", [Pure]> { | |||||
let assemblyFormat = "$value attr-dict `:` qualified(type($value))"; | ||||||
} | ||||||
|
||||||
def FormatFloatOp : SimOp<"fmt.float", [Pure]> { | ||||||
let summary = "Float format specifier"; | ||||||
let description = [{ | ||||||
}]; | ||||||
Comment on lines
+283
to
+284
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
let arguments = (ins AnyFloat:$value); | ||||||
let results = (outs FormatStringType:$result); | ||||||
|
||||||
let hasFolder = true; | ||||||
|
||||||
let assemblyFormat = "$value attr-dict `:` qualified(type($value))"; | ||||||
} | ||||||
|
||||||
|
||||||
def FormatStringConcatOp : SimOp<"fmt.concat", [Pure]> { | ||||||
let summary = "Concatenate format strings"; | ||||||
let description = [{ | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
//===----------------------------------------------------------------------===// | ||
|
||
#include "ImportVerilogInternals.h" | ||
#include "circt/Dialect/Moore/MooreTypes.h" | ||
#include "slang/ast/SystemSubroutine.h" | ||
#include "slang/syntax/AllSyntax.h" | ||
|
||
|
@@ -221,12 +222,32 @@ struct RvalueExprVisitor { | |
// pass them into a binary op. | ||
template <class ConcreteOp> | ||
Value createBinary(Value lhs, Value rhs) { | ||
lhs = context.convertToSimpleBitVector(lhs); | ||
if (!lhs) | ||
return {}; | ||
rhs = context.convertToSimpleBitVector(rhs); | ||
if (!rhs) | ||
return {}; | ||
auto lhsType = lhs.getType(); | ||
auto rhsType = rhs.getType(); | ||
|
||
// The result of using logical or relational operators or the inside operator on real operands shall be a | ||
// single-bit scalar value. | ||
// For other operators, if any operand, except before the ? in the conditional operator, is real, the result is | ||
// real. Otherwise, if any operand, except before the ? in the conditional operator, is shortreal, the result is | ||
// shortreal. | ||
if(isa<moore::RealType>(lhsType) || isa<moore::RealType>(rhsType)) { | ||
if(!isa<moore::RealType>(lhsType)) | ||
lhs = builder.create<moore::ConversionOp>(lhs.getLoc(), moore::RealType::get(context.getContext()), lhs); | ||
if(!isa<moore::RealType>(rhsType)) | ||
rhs = builder.create<moore::ConversionOp>(rhs.getLoc(), moore::RealType::get(context.getContext()), rhs); | ||
} else if(isa<moore::ShortRealType>(lhsType) || isa<moore::ShortRealType>(rhsType)) { | ||
if(!isa<moore::ShortRealType>(lhsType)) | ||
lhs = builder.create<moore::ConversionOp>(lhs.getLoc(), moore::ShortRealType::get(context.getContext()), lhs); | ||
if(!isa<moore::ShortRealType>(rhsType)) | ||
rhs = builder.create<moore::ConversionOp>(rhs.getLoc(), moore::ShortRealType::get(context.getContext()), rhs); | ||
Comment on lines
+228
to
+242
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to limit code <= 80 chars. |
||
} else { | ||
lhs = context.convertToSimpleBitVector(lhs); | ||
if (!lhs) | ||
return {}; | ||
rhs = context.convertToSimpleBitVector(rhs); | ||
if (!rhs) | ||
return {}; | ||
} | ||
return builder.create<ConcreteOp>(loc, lhs, rhs); | ||
} | ||
|
||
|
@@ -879,6 +900,10 @@ struct RvalueExprVisitor { | |
return builder.create<moore::ConcatOp>(loc, slicedOperands); | ||
} | ||
|
||
Value visit(const slang::ast::RealLiteral &expr) { | ||
return builder.create<moore::RealLiteralOp>(loc, builder.getF64FloatAttr(expr.getValue())); | ||
} | ||
|
||
/// Emit an error for all other expressions. | ||
template <typename T> | ||
Value visit(T &&node) { | ||
|
@@ -1243,6 +1268,9 @@ Value Context::materializeConversion(Type type, Value value, bool isSigned, | |
return value; | ||
auto dstPacked = dyn_cast<moore::PackedType>(type); | ||
auto srcPacked = dyn_cast<moore::PackedType>(value.getType()); | ||
if(isa<moore::RealType>(type) || isa<moore::ShortRealType>(type)) { | ||
return builder.create<moore::ConversionOp>(value.getLoc(), type, value); | ||
} | ||
|
||
// Resize the value if needed. | ||
if (dstPacked && srcPacked && dstPacked.getBitSize() && | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.