@@ -1343,32 +1343,36 @@ cir::GlobalOp CIRGenModule::getGlobalForStringLiteral(const StringLiteral *s,
1343
1343
1344
1344
mlir::Attribute c = getConstantArrayFromStringLiteral (s);
1345
1345
1346
- if (getLangOpts ().WritableStrings ) {
1347
- errorNYI (s->getSourceRange (),
1348
- " getGlobalForStringLiteral: Writable strings" );
1349
- }
1350
-
1351
- // Mangle the string literal if that's how the ABI merges duplicate strings.
1352
- // Don't do it if they are writable, since we don't want writes in one TU to
1353
- // affect strings in another.
1354
- if (getCXXABI ().getMangleContext ().shouldMangleStringLiteral (s) &&
1355
- !getLangOpts ().WritableStrings ) {
1356
- errorNYI (s->getSourceRange (),
1357
- " getGlobalForStringLiteral: mangle string literals" );
1358
- }
1359
-
1360
- // Unlike LLVM IR, CIR doesn't automatically unique names for globals, so
1361
- // we need to do that explicitly.
1362
- std::string uniqueName = getUniqueGlobalName (name.str ());
1363
- mlir::Location loc = getLoc (s->getSourceRange ());
1364
- auto typedC = llvm::cast<mlir::TypedAttr>(c);
1365
- cir::GlobalOp gv =
1366
- generateStringLiteral (loc, typedC, cir::GlobalLinkageKind::PrivateLinkage,
1367
- *this , uniqueName, alignment);
1368
- setDSOLocal (static_cast <mlir::Operation *>(gv));
1346
+ cir::GlobalOp gv;
1347
+ if (!getLangOpts ().WritableStrings && constantStringMap.count (c)) {
1348
+ gv = constantStringMap[c];
1349
+ // The bigger alignment always wins.
1350
+ if (!gv.getAlignment () ||
1351
+ uint64_t (alignment.getQuantity ()) > *gv.getAlignment ())
1352
+ gv.setAlignmentAttr (getSize (alignment));
1353
+ } else {
1354
+ // Mangle the string literal if that's how the ABI merges duplicate strings.
1355
+ // Don't do it if they are writable, since we don't want writes in one TU to
1356
+ // affect strings in another.
1357
+ if (getCXXABI ().getMangleContext ().shouldMangleStringLiteral (s) &&
1358
+ !getLangOpts ().WritableStrings ) {
1359
+ errorNYI (s->getSourceRange (),
1360
+ " getGlobalForStringLiteral: mangle string literals" );
1361
+ }
1369
1362
1370
- assert (!cir::MissingFeatures::sanitizers ());
1363
+ // Unlike LLVM IR, CIR doesn't automatically unique names for globals, so
1364
+ // we need to do that explicitly.
1365
+ std::string uniqueName = getUniqueGlobalName (name.str ());
1366
+ mlir::Location loc = getLoc (s->getSourceRange ());
1367
+ auto typedC = llvm::cast<mlir::TypedAttr>(c);
1368
+ gv = generateStringLiteral (loc, typedC,
1369
+ cir::GlobalLinkageKind::PrivateLinkage, *this ,
1370
+ uniqueName, alignment);
1371
+ setDSOLocal (static_cast <mlir::Operation *>(gv));
1372
+ constantStringMap[c] = gv;
1371
1373
1374
+ assert (!cir::MissingFeatures::sanitizers ());
1375
+ }
1372
1376
return gv;
1373
1377
}
1374
1378
@@ -2065,6 +2069,15 @@ CIRGenModule::createCIRFunction(mlir::Location loc, StringRef name,
2065
2069
return func;
2066
2070
}
2067
2071
2072
+ cir::FuncOp
2073
+ CIRGenModule::createCIRBuiltinFunction (mlir::Location loc, StringRef name,
2074
+ cir::FuncType ty,
2075
+ const clang::FunctionDecl *fd) {
2076
+ cir::FuncOp fnOp = createCIRFunction (loc, name, ty, fd);
2077
+ fnOp.setBuiltin (true );
2078
+ return fnOp;
2079
+ }
2080
+
2068
2081
mlir::SymbolTable::Visibility
2069
2082
CIRGenModule::getMLIRVisibility (cir::GlobalOp op) {
2070
2083
// MLIR doesn't accept public symbols declarations (only
0 commit comments