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

[slang] Introduce net aliases bits duplication checks #1045

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

likeamahoney
Copy link
Contributor

Introduce 2 new net alias bit checks from SystemVerilog LRM section 10.11:

  • check that net aliased to itself
  • check that aliased bits specified more than once at module instance scope

@likeamahoney
Copy link
Contributor Author

I think with it LRM section 10.11 is done

Copy link

codecov bot commented Jul 4, 2024

Codecov Report

Attention: Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.

Project coverage is 94.71%. Comparing base (13e2f12) to head (a404093).
Report is 323 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1045      +/-   ##
==========================================
+ Coverage   93.76%   94.71%   +0.94%     
==========================================
  Files         189      191       +2     
  Lines       47139    47695     +556     
==========================================
+ Hits        44201    45172     +971     
+ Misses       2938     2523     -415     
Files Coverage Δ
include/slang/ast/SemanticFacts.h 84.21% <ø> (-4.68%) ⬇️
include/slang/ast/symbols/ValueSymbol.h 100.00% <100.00%> (ø)
source/ast/ASTContext.cpp 97.74% <100.00%> (+1.29%) ⬆️
source/ast/symbols/ValueSymbol.cpp 97.95% <100.00%> (-0.03%) ⬇️
source/ast/symbols/MemberSymbols.cpp 97.49% <94.44%> (+4.40%) ⬆️

... and 172 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 13e2f12...a404093. Read the comment docs.

@likeamahoney likeamahoney force-pushed the feature/net-alias-duplication-check branch from 49d4723 to 16b72d5 Compare July 12, 2024 15:05
// Store any net alias bits to check it's possible intersections.
// Since alias statements can appear anywhere module instance statements can appears
// good option is to store aliased bits info in the module instance scope.
mutable AliasMap* aliasedBits;
Copy link
Owner

Choose a reason for hiding this comment

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

It seems unnecessary to have an alias map allocated for every instance. The rules about net alias overlap are global, so it seems fine to have just one alias map stored in the Compilation object that all aliases can access. Then you don't need a custom allocator for it either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reimplemented all in order to last commentary

@@ -2196,7 +2196,6 @@ NetAliasSymbol& NetAliasSymbol::fromSyntax(const ASTContext& parentContext,
if (!netType.isError()) {
SmallVector<const IdentifierNameSyntax*> implicitNetNames;
Expression::findPotentiallyImplicitNets(*expr, context, implicitNetNames);

Copy link
Owner

Choose a reason for hiding this comment

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

Random newline deletion seems unrelated to the rest of the diff

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

if (const auto* sym = processExpr(expr)) {
const auto& eSelExpr = expr.template as<ElementSelectExpression>();
// If value can't be evaluated that means it is unbounded
const auto evalVal = toInt(context.tryEval(eSelExpr.selector()));
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this is correct in all cases. An example is when there is multiple selections of a multi-dimensional array. It's actually pretty tricky to figure out the statically assigned bits of an arbitrary expression -- that's essentially what the ValueDriver code in ValueSymbol.cpp is doing to be able to issue multi-driven errors. It occurs to me that it may make more sense to use that code to implement the net alias check. You could add a new flag to AssignFlags that says it's a net alias and do the check for overlap there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great Idea! The solution was reimplemented according to it!

@likeamahoney likeamahoney force-pushed the feature/net-alias-duplication-check branch from 16b72d5 to 4dd5370 Compare July 16, 2024 12:18
Copy link
Owner

@MikePopoloski MikePopoloski left a comment

Choose a reason for hiding this comment

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

Ok yeah, this is way better. I left some additional comments to help simplify this a bit more.

@@ -7,6 +7,8 @@
//------------------------------------------------------------------------------
#include "slang/ast/symbols/ValueSymbol.h"

#include <iostream>
Copy link
Owner

Choose a reason for hiding this comment

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

The iostream include isn't needed right?

@@ -136,7 +136,8 @@ void ASTContext::setAttributes(const Expression& expr,

void ASTContext::addDriver(const ValueSymbol& symbol, const Expression& longestStaticPrefix,
bitmask<AssignFlags> assignFlags) const {
if (flags.has(ASTFlags::NotADriver) || scope->isUninstantiated())
if ((flags.has(ASTFlags::NotADriver) && !assignFlags.has(AssignFlags::NetAlias)) ||
Copy link
Owner

Choose a reason for hiding this comment

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

I think you can get rid of this change if you simply don't use the NotADriver flag when binding the net alias expressions

@@ -2119,16 +2124,18 @@ std::span<const Expression* const> NetAliasSymbol::getNetReferences() const {
auto syntax = getSyntax();
SLANG_ASSERT(scope && syntax);

// TODO: there should be a global check somewhere that any given bit
// of a net isn't aliased to the same target signal bit multiple times.
bitwidth_t bitWidth = 0;
bool issuedError = false;
SmallVector<const Expression*> buffer;
ASTContext context(*scope, LookupLocation::after(*this),
ASTFlags::NonProcedural | ASTFlags::NotADriver);
Copy link
Owner

Choose a reason for hiding this comment

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

Down here, you can remove the NotADriver


for (auto exprSyntax : syntax->as<NetAliasSyntax>().nets) {
for (auto exprSyntax : nets) {
auto& netRef = Expression::bind(*exprSyntax, context);
if (!netRef.requireLValue(context))
Copy link
Owner

Choose a reason for hiding this comment

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

And then here pass your new AssignFlag and then you won't need the additional addDriver call below I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants