-
Notifications
You must be signed in to change notification settings - Fork 156
[CIR][NFC] Add helper functions for CIR visibility #1652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@@ -126,6 +127,43 @@ template <typename Int> inline bool isValidCIRAtomicOrderingCABI(Int I) { | |||
I <= (Int)cir::MemOrder::SequentiallyConsistent; | |||
} | |||
|
|||
/// This function is used to deduce the MLIR visibility of a CIR symbol based on | |||
/// CIR linkage and visibility. | |||
static inline mlir::SymbolTable::Visibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: I'm not sure whether this is the best place to put this function. Let me know if I should move it somewhere else.
@@ -485,7 +486,8 @@ CIRGenModule::getOrCreateStaticVarDecl(const VarDecl &D, | |||
cir::GlobalOp GV = builder.createVersionedGlobal( | |||
getModule(), getLoc(D.getLocation()), Name, LTy, false, Linkage, AS); | |||
// TODO(cir): infer visibility from linkage in global op builder. | |||
GV.setVisibility(getMLIRVisibilityFromCIRLinkage(Linkage)); | |||
GV.setVisibility( | |||
cir::deduceMLIRVisibility(Linkage, cir::VisibilityKind::Default)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion is a bit more simple and somewhat different: GV.setLinkage and Fn.setLinkage should call GV.setVisibility under the hood, no need to involve visibility kind. If you make linkage into an interface, than you don't need to implement in both places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comment! I was trying to do that in future PRs, but I ran into some issues when dealing with FuncOp
(#1029 (comment))
d2c4ab8
to
8f89224
Compare
This PR contains 2 changes:
CIRGlobalValueInterface
, which is implemented byGlobalOp
andFuncOp
with linkage and CIR visibility. The getters/setters are analogous to existing getters/setters for linkage and symbol visibility.more notes in #1029 (comment)