@@ -2041,7 +2041,7 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
20412041 case PCK_Unknown:
20422042 llvm_unreachable (" unexpected pragma comment kind" );
20432043 case PCK_Linker:
2044- assert (! MissingFeatures::emitModuleLinkOptions () && " NYI " );
2044+ appendLinkerOptions (PCD-> getArg () );
20452045 break ;
20462046 case PCK_Lib:
20472047 assert (!MissingFeatures::elfDependentLibraries () && " NYI" );
@@ -3341,6 +3341,18 @@ CIRGenModule::GetAddrOfGlobal(GlobalDecl gd, ForDefinition_t isForDefinition) {
33413341 .getDefiningOp ();
33423342}
33433343
3344+ void CIRGenModule::emitModuleLinkOptions () {
3345+ assert (!MissingFeatures::emitModuleLinkOptions ());
3346+
3347+ // Add the linker options metadata flag.
3348+ llvm::SmallVector<mlir::Attribute, 16 > args;
3349+ for (const auto &opt : linkerOptionsMetadata) {
3350+ args.push_back (opt);
3351+ }
3352+ mlir::ArrayAttr arr = builder.getArrayAttr (args);
3353+ getBuilder ().create <cir::LinkerOptionsOp>(theModule->getLoc (), arr);
3354+ }
3355+
33443356void CIRGenModule::Release () {
33453357 assert (!MissingFeatures::emitModuleInitializers ());
33463358 emitDeferred (getCodeGenOpts ().ClangIRBuildDeferredThreshold );
@@ -3392,9 +3404,9 @@ void CIRGenModule::Release() {
33923404 assert (!MissingFeatures::emitLLVMUsed ());
33933405 assert (!MissingFeatures::sanStats ());
33943406
3395- if (codeGenOpts.Autolink && (astContext. getLangOpts (). Modules ||
3396- ! MissingFeatures:: linkerOptionsMetadata ())) {
3397- assert (! MissingFeatures:: emitModuleLinkOptions () );
3407+ if (codeGenOpts.Autolink &&
3408+ (astContext. getLangOpts (). Modules || ! linkerOptionsMetadata. empty ())) {
3409+ emitModuleLinkOptions ();
33983410 }
33993411
34003412 // On ELF we pass the dependent library specifiers directly to the linker
@@ -4229,6 +4241,11 @@ void CIRGenModule::emitGlobalAnnotations() {
42294241 deferredAnnotations.clear ();
42304242}
42314243
4244+ void CIRGenModule::appendLinkerOptions (StringRef Opts) {
4245+ linkerOptionsMetadata.push_back (
4246+ mlir::StringAttr::get (&getMLIRContext (), Opts));
4247+ }
4248+
42324249cir::TBAAAttr CIRGenModule::getTBAATypeInfo (QualType qTy) {
42334250 if (!tbaa) {
42344251 return nullptr ;
0 commit comments