[RTG] Sequences are always private (#8792)

This commit is contained in:
Martin Erhart 2025-07-29 17:45:52 +01:00 committed by GitHub
parent 964cc8be4f
commit 01a53d4552
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 51 additions and 1 deletions

View File

@ -46,7 +46,7 @@ def ConstantOp : RTGOp<"constant", [
def SequenceOp : RTGOp<"sequence", [
IsolatedFromAbove,
Symbol,
DeclareOpInterfaceMethods<Symbol, ["getVisibility", "setVisibility"]>,
SingleBlock,
NoTerminator,
HasParent<"mlir::ModuleOp">,

View File

@ -108,6 +108,15 @@ void SequenceOp::print(OpAsmPrinter &p) {
p.printRegion(getBodyRegion(), /*printEntryBlockArgs=*/false);
}
mlir::SymbolTable::Visibility SequenceOp::getVisibility() {
return mlir::SymbolTable::Visibility::Private;
}
void SequenceOp::setVisibility(mlir::SymbolTable::Visibility visibility) {
// Do nothing, always private.
assert(false && "cannot change visibility of sequence");
}
//===----------------------------------------------------------------------===//
// GetSequenceOp
//===----------------------------------------------------------------------===//

View File

@ -0,0 +1,6 @@
// RUN: circt-opt --symbol-dce %s | FileCheck %s
// CHECK-NOT: @seq1
rtg.sequence @seq1() {
rtg.comment "to be removed"
}

View File

@ -1,5 +1,6 @@
add_circt_unittest(CIRCTRTGTests
MaterializerTest.cpp
OpTests.cpp
)
target_link_libraries(CIRCTRTGTests

View File

@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "circt/Dialect/RTG/IR/RTGDialect.h"
#include "circt/Dialect/RTG/IR/RTGOps.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "gtest/gtest.h"
using namespace mlir;
using namespace circt;
using namespace rtg;
namespace {
TEST(SequenceTests, Visibility) {
MLIRContext context;
context.loadDialect<RTGDialect>();
Location loc(UnknownLoc::get(&context));
auto moduleOp = ModuleOp::create(loc);
OpBuilder builder = OpBuilder::atBlockBegin(moduleOp.getBody());
auto sequence =
SequenceOp::create(builder, loc, "seq", SequenceType::get(&context, {}));
ASSERT_TRUE(sequence.isPrivate());
ASSERT_TRUE(sequence.canDiscardOnUseEmpty());
}
} // namespace