Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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: 8 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ use_repo(ac_types_ext, "ac_datatypes")
z3_ext = use_extension("//dependency_support/z3:extension.bzl", "z3_extension")
use_repo(z3_ext, "z3")

# busperf analyzer (used in //xls/experimental/busperf)
busperf_ext = use_extension("//dependency_support/busperf:extension.bzl", "busperf_extension")
use_repo(busperf_ext, "busperf")

# Hermetic Rust toolchain for building busperf (needs wasm32-unknown-unknown)
rust_toolchain_ext = use_extension("//dependency_support/busperf:extension.bzl", "rust_toolchain_extension")
use_repo(rust_toolchain_ext, "busperf_rust_toolchain")

bitwuzla_ext = use_extension("//dependency_support/bitwuzla:extension.bzl", "bitwuzla_extension")
use_repo(bitwuzla_ext, "bitwuzla", "cadical", "symfpu")

Expand Down
51 changes: 51 additions & 0 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions dependency_support/busperf/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2026 The XLS Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
36 changes: 36 additions & 0 deletions dependency_support/busperf/bundled.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2026 The XLS Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package(default_visibility = ["//visibility:public"])

genrule(
name = "busperf_bin",
srcs = glob(["**"]),
outs = ["busperf"],
cmd = """
cargo="$$PWD/$(location @busperf_rust_toolchain//:cargo/bin/cargo)"
toolchain_root="$$(dirname $$(dirname $$(dirname "$$cargo")))"
export CARGO_HOME="$$toolchain_root/cargo"
export RUSTUP_HOME="$$toolchain_root/rustup"
manifest="$(location Cargo.toml)"
"$$cargo" build --release --manifest-path="$$manifest" \
--target-dir="$$PWD/target" --bin busperf
cp "$$PWD/target/release/busperf" $@
chmod +x $@
""",
executable = True,
local = True,
tags = ["manual", "requires-network"],
tools = ["@busperf_rust_toolchain//:cargo/bin/cargo"],
)
83 changes: 83 additions & 0 deletions dependency_support/busperf/extension.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright 2026 The XLS Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Module extension for busperf."""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

def _busperf_extension_impl(
module_ctx): # @unused
http_archive(
name = "busperf",
urls = ["https://github.com/antmicro/busperf/archive/a62c4c7c6cb3edb090a6b17f0c6edf18fcb4ebb1.tar.gz"],
integrity = "sha256-tfu+WqRT05t2SsMy6DjY+142ZlkqbzMc9fWIfzzpsI4=",
strip_prefix = "busperf-a62c4c7c6cb3edb090a6b17f0c6edf18fcb4ebb1",
build_file = Label("//dependency_support/busperf:bundled.BUILD.bazel"),
)

busperf_extension = module_extension(
implementation = _busperf_extension_impl,
)

def _rust_toolchain_repository_impl(repository_ctx):
# Self-contained rustup toolchain, with wasm32-unknown-unknown for
# busperf's HTML report build.
#
# TODO: temporary workaround, easiest way to get the wasm build working.
# Should be replaced with a proper rules_rust build.
rustup_init = repository_ctx.path("rustup-init")
repository_ctx.download(
url = "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init",
output = rustup_init,
executable = True,
)

rustup_home = repository_ctx.path("rustup")
cargo_home = repository_ctx.path("cargo")
result = repository_ctx.execute(
[
str(rustup_init),
"-y",
"--no-modify-path",
"--profile",
"minimal",
"--default-toolchain",
"stable",
"--target",
"wasm32-unknown-unknown",
],
environment = {
"RUSTUP_HOME": str(rustup_home),
"CARGO_HOME": str(cargo_home),
},
timeout = 1800,
)
if result.return_code != 0:
fail("rustup-init failed:\n" + result.stdout + result.stderr)

repository_ctx.file("BUILD.bazel", """\
exports_files(["cargo/bin/cargo"])
""")

rust_toolchain_repository = repository_rule(
implementation = _rust_toolchain_repository_impl,
)

def _rust_toolchain_extension_impl(
module_ctx): # @unused
rust_toolchain_repository(name = "busperf_rust_toolchain")

rust_toolchain_extension = module_extension(
implementation = _rust_toolchain_extension_impl,
)
1 change: 1 addition & 0 deletions dependency_support/com_google_absl/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package(default_visibility = ["//visibility:public"])
2 changes: 2 additions & 0 deletions xls/codegen/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,12 @@ cc_library(
deps = [
":codegen_pass",
":module_signature",
":module_signature_cc_proto",
":signature_generator",
"//xls/common/status:status_macros",
"//xls/ir",
"//xls/passes:pass_base",
"@abseil-cpp//absl/base",
"@abseil-cpp//absl/log",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
Expand Down
39 changes: 39 additions & 0 deletions xls/codegen/signature_generation_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,53 @@

#include "xls/codegen/signature_generation_pass.h"

#include "absl/base/casts.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_format.h"
#include "xls/codegen/codegen_pass.h"
#include "xls/codegen/module_signature.h"
#include "xls/codegen/module_signature.pb.h"
#include "xls/codegen/signature_generator.h"
#include "xls/common/status/status_macros.h"
#include "xls/ir/block.h"
#include "xls/ir/instantiation.h"
#include "xls/ir/package.h"
#include "xls/passes/pass_base.h"

namespace xls::verilog {
namespace {

// Returns `block`'s signature with `block_signature` embedded recursively.
ModuleSignatureProto ResolveEmbeddedSignature(Block* block) {
ModuleSignatureProto proto = *block->GetSignature();
for (InstantiationProto& instantiation : *proto.mutable_instantiations()) {
if (!instantiation.has_block_instantiation()) {
continue;
}
BlockInstantiationProto* block_instantiation =
instantiation.mutable_block_instantiation();
for (const ::xls::Instantiation* child_instantiation :
block->GetInstantiations()) {
if (child_instantiation->kind() != ::xls::InstantiationKind::kBlock ||
child_instantiation->name() != block_instantiation->instance_name()) {
continue;
}
Block* child_block =
absl::down_cast<const BlockInstantiation*>(child_instantiation)
->instantiated_block();
if (child_block->GetSignature().has_value()) {
*block_instantiation->mutable_block_signature() =
ResolveEmbeddedSignature(child_block);
}
break;
}
}
return proto;
}

} // namespace

absl::StatusOr<bool> SignatureGenerationPass::RunInternal(
Package* package, const CodegenPassOptions& options, PassResults* results,
Expand All @@ -45,6 +80,10 @@ absl::StatusOr<bool> SignatureGenerationPass::RunInternal(
block->SetSignature(signature.proto());
changed = true;
}
// All blocks now have their own signature; embed children recursively.
for (auto& [block, metadata] : context.metadata()) {
block->SetSignature(ResolveEmbeddedSignature(block));
}
return changed;
}

Expand Down
33 changes: 33 additions & 0 deletions xls/codegen_v_1_5/signature_generation_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,35 @@ absl::StatusOr<verilog::ModuleSignature> GenerateSignature(
return b.Build();
}

// Returns `block`'s signature with `block_signature` embedded recursively.
verilog::ModuleSignatureProto ResolveEmbeddedSignature(Block* block) {
verilog::ModuleSignatureProto proto = *block->GetSignature();
for (verilog::InstantiationProto& instantiation :
*proto.mutable_instantiations()) {
if (!instantiation.has_block_instantiation()) {
continue;
}
verilog::BlockInstantiationProto* block_instantiation =
instantiation.mutable_block_instantiation();
for (const ::xls::Instantiation* child_instantiation :
block->GetInstantiations()) {
if (child_instantiation->kind() != ::xls::InstantiationKind::kBlock ||
child_instantiation->name() != block_instantiation->instance_name()) {
continue;
}
Block* child_block =
absl::down_cast<const BlockInstantiation*>(child_instantiation)
->instantiated_block();
if (child_block->GetSignature().has_value()) {
*block_instantiation->mutable_block_signature() =
ResolveEmbeddedSignature(child_block);
}
break;
}
}
return proto;
}

} // namespace

absl::StatusOr<bool> SignatureGenerationPass::RunInternal(
Expand All @@ -272,6 +301,10 @@ absl::StatusOr<bool> SignatureGenerationPass::RunInternal(
block->SetSignature(signature.proto());
changed = true;
}
// All blocks now have their own signature; embed children recursively.
for (const std::unique_ptr<Block>& block : package->blocks()) {
block->SetSignature(ResolveEmbeddedSignature(block.get()));
}
return changed;
}

Expand Down
Loading