8000 [3/8] ECO: Add XLSGraph representation and XLS IR-to-graph lowering by copybara-service[bot] · Pull Request #5588 · google/xls · GitHub
[go: up one dir, main page]

Skip to content
Draft
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
161 changes: 161 additions & 0 deletions xls/contrib/eco/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Copyright 2025 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.

load("@protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
load("@protobuf//bazel:proto_library.bzl", "proto_library")
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_test.bzl", "cc_test")

package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//xls:xls_internal"],
features = [
"layering_check",
"parse_headers",
],
licenses = ["notice"], # Apache 2.0
)

proto_library(
name = "ir_patch_proto",
srcs = ["ir_patch.proto"],
deps = [
"//xls/ir:xls_type_proto",
"//xls/ir:xls_value_proto",
],
)

cc_library(
name = "patch_ir_lib",
srcs = ["patch_ir.cc"],
hdrs = ["patch_ir.h"],
deps = [
":ir_patch_cc_proto",
"//xls/common/file:filesystem",
"//xls/common/status:status_macros",
"//xls/estimators/delay_model:delay_estimator",
"//xls/ir",
"//xls/ir:bits",
"//xls/ir:format_strings",
"//xls/ir:node_util",
"//xls/ir:op",
"//xls/ir:source_location",
"//xls/ir:type",
"//xls/ir:value",
"//xls/ir:value_utils",
"//xls/ir:xls_type_cc_proto",
"//xls/ir:xls_value_cc_proto",
"//xls/scheduling:pipeline_schedule",
"//xls/scheduling:pipeline_schedule_cc_proto",
"//xls/scheduling:run_pipeline_schedule",
"//xls/scheduling:scheduling_options",
"//xls/tools:codegen_flags",
"//xls/tools:scheduling_options_flags",
"//xls/tools:scheduling_options_flags_cc_proto",
"@abseil-cpp//absl/algorithm:container",
"@abseil-cpp//absl/base:core_headers",
"@abseil-cpp//absl/container:flat_hash_map",
"@abseil-cpp//absl/container:flat_hash_set",
"@abseil-cpp//absl/flags:flag",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/types:span",
],
)

cc_binary(
name = "patch_ir_main",
srcs = ["patch_ir_main.cc"],
deps = [
":ir_patch_cc_proto",
":patch_ir_lib",
"//xls/common:exit_status",
"//xls/common:init_xls",
"//xls/common/file:filesystem",
"//xls/common/status:status_macros",
"//xls/ir",
"//xls/ir:ir_parser",
"//xls/scheduling:pipeline_schedule",
"//xls/scheduling:pipeline_schedule_cc_proto",
"//xls/scheduling:scheduling_options",
"@abseil-cpp//absl/flags:flag",
"@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
],
)

cc_proto_library(
name = "ir_patch_cc_proto",
deps = [":ir_patch_proto"],
)

# Graph Edit Distance (GED) and Maximum Common Subgraph (MCS) implementation

cc_library(
name = "graph",
srcs = ["graph.cc"],
hdrs = ["graph.h"],
deps = [
"//xls/ir:op",
"//xls/ir:xls_type_cc_proto",
"//xls/ir:xls_value_cc_proto",
"//xls/visualization/ir_viz:visualization_cc_proto",
"@abseil-cpp//absl/algorithm:container",
"@abseil-cpp//absl/container:flat_hash_map",
"@abseil-cpp//absl/container:flat_hash_set",
"@abseil-cpp//absl/log",
"@abseil-cpp//absl/strings",
],
)

cc_library(
name = "xls_ir_to_graph",
srcs = ["xls_ir_to_graph.cc"],
hdrs = ["xls_ir_to_graph.h"],
deps = [
":graph",
"//xls/common/file:filesystem",
"//xls/common/status:ret_check",
"//xls/common/status:status_macros",
"//xls/ir",
"//xls/ir:format_strings",
"//xls/ir:ir_parser",
"//xls/ir:op",
"//xls/visualization/ir_viz:node_attribute_visitor",
"@abseil-cpp//absl/algorithm:container",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
],
)

cc_test(
name = "xls_ir_to_graph_test",
size = "small",
srcs = ["xls_ir_to_graph_test.cc"],
deps = [
":graph",
":xls_ir_to_graph",
"//xls/common:xls_gunit_main",
"//xls/common/status:matchers",
"//xls/ir",
"//xls/ir:ir_parser",
"//xls/ir:op",
"@abseil-cpp//absl/status:statusor",
"@googletest//:gtest",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
#include "xls/codegen/module_signature.h"
#include "xls/common/exit_status.h"
#include "xls/common/file/filesystem.h"
#include "xls/common/init_xls.h"
Expand All @@ -38,13 +37,18 @@
#include "xls/ir/ir_parser.h"
#include "xls/ir/verifier.h"
#include "xls/scheduling/pipeline_schedule.h"
#include "xls/scheduling/pipeline_schedule.pb.h"
#include "xls/tools/codegen.h"
#include "xls/tools/codegen_flags.h"
#include "xls/tools/codegen_flags.pb.h"
#include "xls/tools/scheduling_options_flags.h"
#include "xls/tools/scheduling_options_flags.pb.h"

ABSL_FLAG(std::string, input_schedule_path, "",
"Path to the IR file to patch."); // NOLINT

namespace xls {
namespace {

static constexpr std::string_view kUsage = R"(
Generates Verilog RTL from a given IR file and a schedule proto. Writes a Verilog file and a module
signature describing the module interface to a specified location. Example
Expand All @@ -60,10 +64,7 @@ Emit a feed-forward pipelined module:
--input_schedule_path=SCHEDULE_FILE \
IR_FILE
)";
ABSL_FLAG(std::string, input_schedule_path, "",
"Path to the IR file to patch."); // NOLINT
namespace xls {
namespace {

absl::Status RealMain(std::string_view ir_path) {
auto timeout = StartTimeoutTimer();
if (ir_path == "-") {
Expand Down Expand Up @@ -156,7 +157,7 @@ absl::Status RealMain(std::string_view ir_path) {

int main(int argc, char** argv) {
std::vector<std::string_view> positional_arguments =
xls::InitXls(kUsage, argc, argv);
xls::InitXls(xls::kUsage, argc, argv);

if (positional_arguments.size() != 1) {
LOG(QFATAL) << absl::StreamFormat("Expected invocation: %s IR_FILE",
Expand Down
Loading
Loading
0