================
@@ -2702,9 +2702,77 @@ static bool shouldAssumeDSOLocal(const CIRGenModule &cgm,
return false;
}
-void CIRGenModule::setGlobalVisibility(mlir::Operation *gv,
+static void setGlobalVisibilityHelper(const CIRGenModule &cgm,
+ cir::CIRGlobalValueInterface gv,
+ cir::VisibilityKind visibility) {
+ gv.setGlobalVisibility(cir::VisibilityKind::Default);
+ // Also update MLIR symbol visibility to match linkage
+ if (auto globalOp = dyn_cast<cir::GlobalOp>(gv.getOperation()))
+ mlir::SymbolTable::setSymbolVisibility(globalOp,
+ cgm.getMLIRVisibility(globalOp));
+ else if (auto funcOp = dyn_cast<cir::FuncOp>(gv.getOperation()))
+ mlir::SymbolTable::setSymbolVisibility(
+ funcOp, cgm.getMLIRVisibilityFromCIRLinkage(funcOp.getLinkage()));
+}
+
+void CIRGenModule::setGlobalVisibility(cir::CIRGlobalValueInterface gv,
const NamedDecl *d) const {
- assert(!cir::MissingFeatures::opGlobalVisibility());
+ // Internal definitions always have default visibility.
+ if (gv.hasLocalLinkage()) {
+ setGlobalVisibilityHelper(*this, gv, cir::VisibilityKind::Default);
+ return;
+ }
+ if (!d)
+ return;
+
+ // Set visibility for definitions, and for declarations if requested globally
+ // or set explicitly.
+ LinkageInfo lv = d->getLinkageAndVisibility();
+
+ // OpenMP declare target variables must be visible to the host so they can
+ // be registered. We require protected visibility unless the variable has
+ // the DT_nohost modifier and does not need to be registered.
+ if (getASTContext().getLangOpts().OpenMP &&
+ getASTContext().getLangOpts().OpenMPIsTargetDevice && isa<VarDecl>(d) &&
+ d->hasAttr<OMPDeclareTargetDeclAttr>() &&
+ d->getAttr<OMPDeclareTargetDeclAttr>()->getDevType() !=
+ OMPDeclareTargetDeclAttr::DT_NoHost &&
+ lv.getVisibility() == HiddenVisibility) {
+ gv.setGlobalVisibility(cir::VisibilityKind::Protected);
----------------
ZakyHermawan wrote:
can't write tests for OpenMP because of NYI, and for
```cpp
if (lv.isVisibilityExplicit() || getLangOpts().SetVisibilityForExternDecls ||
!gv.isDeclarationForLinker())
```
is triggered by tests in `attribute-visibility.c` (no need to write additional
tests, i guess)
https://github.com/llvm/llvm-project/pull/195257
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits