Skip to content

Commit

Permalink
Remove some unused members from HierarchyOverrideNode -- these were a…
Browse files Browse the repository at this point in the history
…dded to support configurations but ended up not being needed
  • Loading branch information
MikePopoloski committed Mar 22, 2024
1 parent 1869b93 commit d36dfc8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 43 deletions.
12 changes: 3 additions & 9 deletions include/slang/ast/Compilation.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,10 @@ struct SLANG_EXPORT HierarchyOverrideNode {
/// the first element of which is the value to set the parameter to and the second
/// is the source defparam doing the overriding, if any (can be null).
flat_hash_map<const syntax::SyntaxNode*, std::pair<ConstantValue, const syntax::SyntaxNode*>>
overridesBySyntax;
paramOverrides;

/// A map of parameters to override, keyed by name.
flat_hash_map<std::string_view, ConstantValue> overridesByName;

/// A map of child scopes that also contain overrides, keyed by syntax.
flat_hash_map<InstancePath::Entry, HierarchyOverrideNode> childrenBySyntax;

/// A map of child scopes that also contain overrides, keyed by name.
flat_hash_map<std::string_view, HierarchyOverrideNode> childrenByName;
/// A map of child scopes that also contain overrides.
flat_hash_map<InstancePath::Entry, HierarchyOverrideNode> childNodes;

/// A list of bind directives to apply in this scope.
std::vector<BindDirectiveInfo> binds;
Expand Down
17 changes: 6 additions & 11 deletions source/ast/Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,8 @@ const RootSymbol& Compilation::getRoot(bool skipDefParamsAndBinds) {
if (!param.isTypeParam && param.hasSyntax) {
auto it = cliOverrides.find(param.name);
if (it != cliOverrides.end()) {
hierarchyOverrides.childrenBySyntax[*def.getSyntax()]
.overridesBySyntax.emplace(param.valueDecl,
std::pair{*it->second, nullptr});
hierarchyOverrides.childNodes[*def.getSyntax()].paramOverrides.emplace(
param.valueDecl, std::pair{*it->second, nullptr});
}
}
}
Expand All @@ -550,14 +549,10 @@ const RootSymbol& Compilation::getRoot(bool skipDefParamsAndBinds) {
for (auto [result, _] : topDefs) {
auto& def = result.definition->as<DefinitionSymbol>();
HierarchyOverrideNode* hierarchyOverrideNode = nullptr;
if (auto sit = hierarchyOverrides.childrenBySyntax.find(*def.getSyntax());
sit != hierarchyOverrides.childrenBySyntax.end()) {
if (auto sit = hierarchyOverrides.childNodes.find(*def.getSyntax());
sit != hierarchyOverrides.childNodes.end()) {
hierarchyOverrideNode = &sit->second;
}
else if (auto nit = hierarchyOverrides.childrenByName.find(def.name);
nit != hierarchyOverrides.childrenByName.end()) {
hierarchyOverrideNode = &nit->second;
}

auto& instance = InstanceSymbol::createDefault(*this, def, hierarchyOverrideNode,
result.configRoot, result.configRule);
Expand Down Expand Up @@ -2196,7 +2191,7 @@ void Compilation::resolveDefParamsAndBinds() {
auto getNodeFor = [](const InstancePath& path, Compilation& c) {
HierarchyOverrideNode* node = &c.hierarchyOverrides;
for (auto& entry : path.entries)
node = &node->childrenBySyntax[entry];
node = &node->childNodes[entry];
return node;
};

Expand All @@ -2208,7 +2203,7 @@ void Compilation::resolveDefParamsAndBinds() {
SLANG_ASSERT(entry.defparamSyntax);

auto node = getNodeFor(entry.path, c);
auto [it, inserted] = node->overridesBySyntax.emplace(
auto [it, inserted] = node->paramOverrides.emplace(
entry.targetSyntax, std::pair{entry.value, entry.defparamSyntax});

if (!inserted && isFinal) {
Expand Down
22 changes: 7 additions & 15 deletions source/ast/symbols/InstanceSymbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,10 @@ class InstanceBuilder {

const HierarchyOverrideNode* overrideNode = nullptr;
if (parentOverrideNode) {
if (auto sit = parentOverrideNode->childrenBySyntax.find(syntax);
sit != parentOverrideNode->childrenBySyntax.end()) {
if (auto sit = parentOverrideNode->childNodes.find(syntax);
sit != parentOverrideNode->childNodes.end()) {
overrideNode = &sit->second;
}
else if (auto nit = parentOverrideNode->childrenByName.find(
syntax.decl->name.valueText());
nit != parentOverrideNode->childrenByName.end()) {
overrideNode = &nit->second;
}
}

auto dims = syntax.decl->dimensions;
Expand Down Expand Up @@ -207,8 +202,8 @@ class InstanceBuilder {
for (uint32_t i = 0; i < range.width(); i++) {
const HierarchyOverrideNode* childOverrides = nullptr;
if (overrideNode) {
auto nodeIt = overrideNode->childrenBySyntax.find(i);
if (nodeIt != overrideNode->childrenBySyntax.end())
auto nodeIt = overrideNode->childNodes.find(i);
if (nodeIt != overrideNode->childNodes.end())
childOverrides = &nodeIt->second;
}

Expand Down Expand Up @@ -256,8 +251,8 @@ const HierarchyOverrideNode* findParentOverrideNode(const Scope& scope) {
if (sym.kind == SymbolKind::GenerateBlock &&
parentScope->asSymbol().kind == SymbolKind::GenerateBlockArray) {

auto it = node->childrenBySyntax.find(sym.as<GenerateBlockSymbol>().constructIndex);
if (it == node->childrenBySyntax.end())
auto it = node->childNodes.find(sym.as<GenerateBlockSymbol>().constructIndex);
if (it == node->childNodes.end())
return nullptr;

return &it->second;
Expand All @@ -266,10 +261,7 @@ const HierarchyOverrideNode* findParentOverrideNode(const Scope& scope) {
auto syntax = sym.getSyntax();
SLANG_ASSERT(syntax);

if (auto it = node->childrenBySyntax.find(*syntax); it != node->childrenBySyntax.end())
return &it->second;

if (auto it = node->childrenByName.find(sym.name); it != node->childrenByName.end())
if (auto it = node->childNodes.find(*syntax); it != node->childNodes.end())
return &it->second;

return nullptr;
Expand Down
10 changes: 2 additions & 8 deletions source/ast/symbols/ParameterBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,11 @@ const ParameterSymbolBase& ParameterBuilder::createParam(
// Note that we ignore the override node if this is from a configuration,
// as the LRM says config overrides take precedence over defparams.
if (auto paramSyntax = param->getSyntax(); overrideNode && paramSyntax && !isFromConfig) {
if (auto it = overrideNode->overridesBySyntax.find(paramSyntax);
it != overrideNode->overridesBySyntax.end()) {
if (auto it = overrideNode->paramOverrides.find(paramSyntax);
it != overrideNode->paramOverrides.end()) {
param->setValue(comp, it->second.first, /* needsCoercion */ true);
return *param;
}

if (auto it = overrideNode->overridesByName.find(param->name);
it != overrideNode->overridesByName.end()) {
param->setValue(comp, it->second, /* needsCoercion */ true);
return *param;
}
}

if (!param->isLocalParam()) {
Expand Down

0 comments on commit d36dfc8

Please sign in to comment.