[llvm-branch-commits] [clang] [CIR] Delete the unused cir::VisibilityAttr (PR #220881)
Henrich Lauko via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Sep 3 04:31:05 PDT 2026
https://github.com/xlauko created https://github.com/llvm/llvm-project/pull/220881
CIR_VisibilityAttr had no users. `cir.global` and `cir.func` carry visibility
as `DefaultValuedProp<EnumProp<CIR_VisibilityKind>>:$global_visibility`, a
property rather than an attribute, so nothing ever built or printed the
attribute and no test mentioned it.
Its only consumer was CIRGenModule::getGlobalVisibilityAttrFromDecl, itself
never called. That in turn was the only caller of
getGlobalVisibilityKindFromClangVisibility, so all three go away together.
The nearly identical getCIRVisibilityKind survives and does have a caller.
It maps clang::Visibility rather than clang::VisibilityAttr::VisibilityType,
so a future caller wiring visibility into the property has a starting point,
and git history has the rest.
CIR_VisibilityKind stays. It is the enum the property is built from.
Incidentally this removes one of the two attributes overriding their
assembly format to a bare `$value`.
---
Stacked on #220880. Based on `users/xlauko/cir-enum-03-lang-address-space`, so the diff shown is this commit alone.
>From 0ee293c46d92ecfb139e1b79657fcc69cfc1d83b Mon Sep 17 00:00:00 2001
From: Henrich Lauko <hlauko at nvidia.com>
Date: Thu, 3 Sep 2026 11:29:23 +0000
Subject: [PATCH] [CIR] Delete the unused cir::VisibilityAttr
CIR_VisibilityAttr had no users. `cir.global` and `cir.func` carry visibility
as `DefaultValuedProp<EnumProp<CIR_VisibilityKind>>:$global_visibility`, a
property rather than an attribute, so nothing ever built or printed the
attribute and no test mentioned it.
Its only consumer was CIRGenModule::getGlobalVisibilityAttrFromDecl, itself
never called. That in turn was the only caller of
getGlobalVisibilityKindFromClangVisibility, so all three go away together.
The nearly identical getCIRVisibilityKind survives and does have a caller.
It maps clang::Visibility rather than clang::VisibilityAttr::VisibilityType,
so a future caller wiring visibility into the property has a starting point,
and git history has the rest.
CIR_VisibilityKind stays. It is the enum the property is built from.
Incidentally this removes one of the two attributes overriding their
assembly format to a bare `$value`.
---
.../include/clang/CIR/Dialect/IR/CIRAttrs.td | 29 +------------------
clang/lib/CIR/CodeGen/CIRGenModule.cpp | 26 -----------------
clang/lib/CIR/CodeGen/CIRGenModule.h | 3 --
3 files changed, 1 insertion(+), 57 deletions(-)
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index f047cf284255c..f88ffa1ff7c0d 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -1289,7 +1289,7 @@ def CIR_ConstComplexAttr : CIR_ValueLikeAttr<"ConstComplex", "const_complex"> {
}
//===----------------------------------------------------------------------===//
-// VisibilityAttr
+// VisibilityKind
//===----------------------------------------------------------------------===//
def CIR_VisibilityKind : CIR_I32EnumAttr<"VisibilityKind", "C/C++ visibility", [
@@ -1300,33 +1300,6 @@ def CIR_VisibilityKind : CIR_I32EnumAttr<"VisibilityKind", "C/C++ visibility", [
let genSpecializedAttr = 0;
}
-def CIR_VisibilityAttr : CIR_EnumAttr<CIR_VisibilityKind, "visibility"> {
- let summary = "Visibility attribute";
- let description = [{
- Visibility attributes.
- }];
-
- let cppClassName = "VisibilityAttr";
-
- let skipDefaultBuilders = 1;
- let builders = [
- AttrBuilder<(ins CArg<"VisibilityKind",
- "cir::VisibilityKind::Default">:$value), [{
- return $_get($_ctxt, value);
- }]>
- ];
-
- let assemblyFormat = [{
- $value
- }];
-
- let extraClassDeclaration = [{
- bool isDefault() const { return getValue() == VisibilityKind::Default; };
- bool isHidden() const { return getValue() == VisibilityKind::Hidden; };
- bool isProtected() const { return getValue() == VisibilityKind::Protected; };
- }];
-}
-
//===----------------------------------------------------------------------===//
// GloblCtorAttr
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 0cb2164f4c0ef..320eccaa7388e 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -3855,32 +3855,6 @@ CIRGenModule::getMLIRVisibilityFromCIRLinkage(cir::GlobalLinkageKind glk) {
llvm_unreachable("linkage should be handled above!");
}
-cir::VisibilityKind CIRGenModule::getGlobalVisibilityKindFromClangVisibility(
- clang::VisibilityAttr::VisibilityType visibility) {
- switch (visibility) {
- case clang::VisibilityAttr::VisibilityType::Default:
- return cir::VisibilityKind::Default;
- case clang::VisibilityAttr::VisibilityType::Hidden:
- return cir::VisibilityKind::Hidden;
- case clang::VisibilityAttr::VisibilityType::Protected:
- return cir::VisibilityKind::Protected;
- }
- llvm_unreachable("unexpected visibility value");
-}
-
-cir::VisibilityAttr
-CIRGenModule::getGlobalVisibilityAttrFromDecl(const Decl *decl) {
- const clang::VisibilityAttr *va = decl->getAttr<clang::VisibilityAttr>();
- cir::VisibilityAttr cirVisibility =
- cir::VisibilityAttr::get(&getMLIRContext());
- if (va) {
- cirVisibility = cir::VisibilityAttr::get(
- &getMLIRContext(),
- getGlobalVisibilityKindFromClangVisibility(va->getVisibility()));
- }
- return cirVisibility;
-}
-
void CIRGenModule::release() {
emitDeferred();
emitVTablesOpportunistically();
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.h b/clang/lib/CIR/CodeGen/CIRGenModule.h
index cf82906d6e6c0..5646db9503dc6 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.h
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.h
@@ -877,9 +877,6 @@ class CIRGenModule : public CIRGenTypeCache {
static mlir::SymbolTable::Visibility
getMLIRVisibilityFromCIRLinkage(cir::GlobalLinkageKind GLK);
- static cir::VisibilityKind getGlobalVisibilityKindFromClangVisibility(
- clang::VisibilityAttr::VisibilityType visibility);
- cir::VisibilityAttr getGlobalVisibilityAttrFromDecl(const Decl *decl);
cir::GlobalLinkageKind getFunctionLinkage(GlobalDecl gd);
static mlir::SymbolTable::Visibility getMLIRVisibility(cir::GlobalOp op);
cir::GlobalLinkageKind getCIRLinkageForDeclarator(const DeclaratorDecl *dd,
More information about the llvm-branch-commits
mailing list