aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CIR/CodeGen/CIRGenModule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CIR/CodeGen/CIRGenModule.cpp')
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenModule.cpp61
1 files changed, 37 insertions, 24 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 2bd2729..8485564 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -1343,32 +1343,36 @@ cir::GlobalOp CIRGenModule::getGlobalForStringLiteral(const StringLiteral *s,
mlir::Attribute c = getConstantArrayFromStringLiteral(s);
- if (getLangOpts().WritableStrings) {
- errorNYI(s->getSourceRange(),
- "getGlobalForStringLiteral: Writable strings");
- }
-
- // Mangle the string literal if that's how the ABI merges duplicate strings.
- // Don't do it if they are writable, since we don't want writes in one TU to
- // affect strings in another.
- if (getCXXABI().getMangleContext().shouldMangleStringLiteral(s) &&
- !getLangOpts().WritableStrings) {
- errorNYI(s->getSourceRange(),
- "getGlobalForStringLiteral: mangle string literals");
- }
-
- // Unlike LLVM IR, CIR doesn't automatically unique names for globals, so
- // we need to do that explicitly.
- std::string uniqueName = getUniqueGlobalName(name.str());
- mlir::Location loc = getLoc(s->getSourceRange());
- auto typedC = llvm::cast<mlir::TypedAttr>(c);
- cir::GlobalOp gv =
- generateStringLiteral(loc, typedC, cir::GlobalLinkageKind::PrivateLinkage,
- *this, uniqueName, alignment);
- setDSOLocal(static_cast<mlir::Operation *>(gv));
+ cir::GlobalOp gv;
+ if (!getLangOpts().WritableStrings && constantStringMap.count(c)) {
+ gv = constantStringMap[c];
+ // The bigger alignment always wins.
+ if (!gv.getAlignment() ||
+ uint64_t(alignment.getQuantity()) > *gv.getAlignment())
+ gv.setAlignmentAttr(getSize(alignment));
+ } else {
+ // Mangle the string literal if that's how the ABI merges duplicate strings.
+ // Don't do it if they are writable, since we don't want writes in one TU to
+ // affect strings in another.
+ if (getCXXABI().getMangleContext().shouldMangleStringLiteral(s) &&
+ !getLangOpts().WritableStrings) {
+ errorNYI(s->getSourceRange(),
+ "getGlobalForStringLiteral: mangle string literals");
+ }
- assert(!cir::MissingFeatures::sanitizers());
+ // Unlike LLVM IR, CIR doesn't automatically unique names for globals, so
+ // we need to do that explicitly.
+ std::string uniqueName = getUniqueGlobalName(name.str());
+ mlir::Location loc = getLoc(s->getSourceRange());
+ auto typedC = llvm::cast<mlir::TypedAttr>(c);
+ gv = generateStringLiteral(loc, typedC,
+ cir::GlobalLinkageKind::PrivateLinkage, *this,
+ uniqueName, alignment);
+ setDSOLocal(static_cast<mlir::Operation *>(gv));
+ constantStringMap[c] = gv;
+ assert(!cir::MissingFeatures::sanitizers());
+ }
return gv;
}
@@ -2065,6 +2069,15 @@ CIRGenModule::createCIRFunction(mlir::Location loc, StringRef name,
return func;
}
+cir::FuncOp
+CIRGenModule::createCIRBuiltinFunction(mlir::Location loc, StringRef name,
+ cir::FuncType ty,
+ const clang::FunctionDecl *fd) {
+ cir::FuncOp fnOp = createCIRFunction(loc, name, ty, fd);
+ fnOp.setBuiltin(true);
+ return fnOp;
+}
+
mlir::SymbolTable::Visibility
CIRGenModule::getMLIRVisibility(cir::GlobalOp op) {
// MLIR doesn't accept public symbols declarations (only