@@ -703,32 +703,11 @@ bool swift::performLLVM(const IRGenOptions &Opts,
703703 assert (Opts.OutputKind == IRGenOutputKind::Module && " no output specified" );
704704 }
705705
706- std::string OptRemarksRecordFile;
707- if (Opts.AnnotateCondFailMessage && !OutputFilename.empty ()) {
708- OptRemarksRecordFile = std::string (OutputFilename);
709- OptRemarksRecordFile.append (" .opt.yaml" );
710- }
711-
712706 auto &Ctxt = Module->getContext ();
713707 std::unique_ptr<llvm::DiagnosticHandler> OldDiagnosticHandler =
714708 Ctxt.getDiagnosticHandler ();
715709 Ctxt.setDiagnosticHandler (std::make_unique<SwiftDiagnosticHandler>(Opts));
716710
717- llvm::Expected<std::unique_ptr<llvm::ToolOutputFile>> OptRecordFileOrErr =
718- setupLLVMOptimizationRemarks (Ctxt, OptRemarksRecordFile.c_str (), " annotation-remarks" , " yaml" ,
719- false /* RemarksWithHotness*/ ,
720- 0 /* RemarksHotnessThreshold*/ );
721-
722- if (Error E = OptRecordFileOrErr.takeError ()) {
723- diagnoseSync (Diags, DiagMutex, SourceLoc (), diag::error_opening_output,
724- StringRef (OptRemarksRecordFile.c_str ()),
725- toString (std::move (E)));
726- return true ;
727- }
728-
729- std::unique_ptr<llvm::ToolOutputFile> OptRecordFile =
730- std::move (*OptRecordFileOrErr);
731-
732711 performLLVMOptimizations (Opts, Diags, DiagMutex, Module, TargetMachine,
733712 OutputFile ? &OutputFile->getOS () : nullptr );
734713
@@ -759,10 +738,8 @@ bool swift::performLLVM(const IRGenOptions &Opts,
759738 }
760739
761740 auto res = compileAndWriteLLVM (Module, TargetMachine, Opts, Stats, Diags,
762- *OutputFile, DiagMutex,
763- CASIDFile ? CASIDFile.get () : nullptr );
764- if (OptRecordFile)
765- OptRecordFile->keep ();
741+ *OutputFile, DiagMutex,
742+ CASIDFile ? CASIDFile.get () : nullptr );
766743
767744 Ctxt.setDiagnosticHandler (std::move (OldDiagnosticHandler));
768745
@@ -1166,7 +1143,7 @@ static void embedBitcode(llvm::Module *M, const IRGenOptions &Opts)
11661143 NewUsed->setSection (" llvm.metadata" );
11671144}
11681145
1169- static void initLLVMModule (const IRGenModule &IGM, SILModule &SIL) {
1146+ static void initLLVMModule (IRGenModule &IGM, SILModule &SIL) {
11701147 auto *Module = IGM.getModule ();
11711148 assert (Module && " Expected llvm:Module for IR generation!" );
11721149
@@ -1208,8 +1185,19 @@ static void initLLVMModule(const IRGenModule &IGM, SILModule &SIL) {
12081185 " standard-library" ),
12091186 llvm::ConstantAsMetadata::get (Value)}));
12101187
1211- if (auto *streamer = SIL.getSILRemarkStreamer ()) {
1212- streamer->intoLLVMContext (Module->getContext ());
1188+ if (auto *SILstreamer = SIL.getSILRemarkStreamer ()) {
1189+ // Install RemarkStreamer into LLVM and keep the remarks file alive. This is
1190+ // required even if no LLVM remarks are enabled, because the AsmPrinter
1191+ // serializes meta information about the remarks into the object file.
1192+ IGM.RemarkStream = SILstreamer->releaseStream ();
1193+ SILstreamer->intoLLVMContext (Context);
1194+ auto &RS = *IGM.getLLVMContext ().getMainRemarkStreamer ();
1195+ if (IGM.getOptions ().AnnotateCondFailMessage ) {
1196+ Context.setLLVMRemarkStreamer (
1197+ std::make_unique<llvm::LLVMRemarkStreamer>(RS));
1198+ // FIXME: add a frontend flag to enable all LLVM remarks
1199+ cantFail (RS.setFilter (" annotation-remarks" ));
1200+ }
12131201 }
12141202}
12151203
0 commit comments