summaryrefslogtreecommitdiff
path: root/clang/lib/CIR/CodeGen/CIRGenModule.h
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CIR/CodeGen/CIRGenModule.h')
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenModule.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.h b/clang/lib/CIR/CodeGen/CIRGenModule.h
index 073e8d96b773..1fc116d98a85 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.h
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.h
@@ -159,6 +159,13 @@ public:
bool isConstant = false,
mlir::Operation *insertPoint = nullptr);
+ /// Add a global constructor or destructor to the module.
+ /// The priority is optional, if not specified, the default priority is used.
+ void addGlobalCtor(cir::FuncOp ctor,
+ std::optional<int> priority = std::nullopt);
+ void addGlobalDtor(cir::FuncOp dtor,
+ std::optional<int> priority = std::nullopt);
+
bool shouldZeroInitPadding() const {
// In C23 (N3096) $6.7.10:
// """
@@ -256,6 +263,26 @@ public:
mlir::Attribute getAddrOfRTTIDescriptor(mlir::Location loc, QualType ty,
bool forEH = false);
+ static mlir::SymbolTable::Visibility getMLIRVisibility(Visibility v) {
+ switch (v) {
+ case DefaultVisibility:
+ return mlir::SymbolTable::Visibility::Public;
+ case HiddenVisibility:
+ return mlir::SymbolTable::Visibility::Private;
+ case ProtectedVisibility:
+ // The distinction between ProtectedVisibility and DefaultVisibility is
+ // that symbols with ProtectedVisibility, while visible to the dynamic
+ // linker like DefaultVisibility, are guaranteed to always dynamically
+ // resolve to a symbol in the current shared object. There is currently no
+ // equivalent MLIR visibility, so we fall back on the fact that the symbol
+ // is visible.
+ return mlir::SymbolTable::Visibility::Public;
+ }
+ llvm_unreachable("unknown visibility!");
+ }
+
+ llvm::DenseMap<mlir::Attribute, cir::GlobalOp> constantStringMap;
+
/// Return a constant array for the given string.
mlir::Attribute getConstantArrayFromStringLiteral(const StringLiteral *e);
@@ -402,12 +429,23 @@ public:
void setFunctionAttributes(GlobalDecl gd, cir::FuncOp f,
bool isIncompleteFunction, bool isThunk);
+ /// Set extra attributes (inline, etc.) for a function.
+ void setCIRFunctionAttributesForDefinition(const clang::FunctionDecl *fd,
+ cir::FuncOp f);
+
void emitGlobalDefinition(clang::GlobalDecl gd,
mlir::Operation *op = nullptr);
void emitGlobalFunctionDefinition(clang::GlobalDecl gd, mlir::Operation *op);
void emitGlobalVarDefinition(const clang::VarDecl *vd,
bool isTentative = false);
+ /// Emit the function that initializes the specified global
+ void emitCXXGlobalVarDeclInit(const VarDecl *varDecl, cir::GlobalOp addr,
+ bool performInit);
+
+ void emitCXXGlobalVarDeclInitFunc(const VarDecl *vd, cir::GlobalOp addr,
+ bool performInit);
+
void emitGlobalOpenACCDecl(const clang::OpenACCConstructDecl *cd);
// C++ related functions.
@@ -448,6 +486,17 @@ public:
cir::FuncType funcType,
const clang::FunctionDecl *funcDecl);
+ /// Create a CIR function with builtin attribute set.
+ cir::FuncOp createCIRBuiltinFunction(mlir::Location loc, llvm::StringRef name,
+ cir::FuncType ty,
+ const clang::FunctionDecl *fd);
+
+ cir::FuncOp createRuntimeFunction(cir::FuncType ty, llvm::StringRef name,
+ mlir::ArrayAttr = {}, bool isLocal = false,
+ bool assumeConvergent = false);
+
+ static constexpr const char *builtinCoroId = "__builtin_coro_id";
+
/// Given a builtin id for a function like "__builtin_fabsf", return a
/// Function* for "fabsf".
cir::FuncOp getBuiltinLibFunction(const FunctionDecl *fd, unsigned builtinID);