@@ -703,32 +703,11 @@ bool swift::performLLVM(const IRGenOptions &Opts,
703
703
assert (Opts.OutputKind == IRGenOutputKind::Module && " no output specified" );
704
704
}
705
705
706
- std::string OptRemarksRecordFile;
707
- if (Opts.AnnotateCondFailMessage && !OutputFilename.empty ()) {
708
- OptRemarksRecordFile = std::string (OutputFilename);
709
- OptRemarksRecordFile.append (" .opt.yaml" );
710
- }
711
-
712
706
auto &Ctxt = Module->getContext ();
713
707
std::unique_ptr<llvm::DiagnosticHandler> OldDiagnosticHandler =
714
708
Ctxt.getDiagnosticHandler ();
715
709
Ctxt.setDiagnosticHandler (std::make_unique<SwiftDiagnosticHandler>(Opts));
716
710
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
-
732
711
performLLVMOptimizations (Opts, Diags, DiagMutex, Module, TargetMachine,
733
712
OutputFile ? &OutputFile->getOS () : nullptr );
734
713
@@ -759,10 +738,8 @@ bool swift::performLLVM(const IRGenOptions &Opts,
759
738
}
760
739
761
740
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 );
766
743
767
744
Ctxt.setDiagnosticHandler (std::move (OldDiagnosticHandler));
768
745
@@ -1166,7 +1143,7 @@ static void embedBitcode(llvm::Module *M, const IRGenOptions &Opts)
1166
1143
NewUsed->setSection (" llvm.metadata" );
1167
1144
}
1168
1145
1169
- static void initLLVMModule (const IRGenModule &IGM, SILModule &SIL) {
1146
+ static void initLLVMModule (IRGenModule &IGM, SILModule &SIL) {
1170
1147
auto *Module = IGM.getModule ();
1171
1148
assert (Module && " Expected llvm:Module for IR generation!" );
1172
1149
@@ -1208,8 +1185,19 @@ static void initLLVMModule(const IRGenModule &IGM, SILModule &SIL) {
1208
1185
" standard-library" ),
1209
1186
llvm::ConstantAsMetadata::get (Value)}));
1210
1187
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
+ }
1213
1201
}
1214
1202
}
1215
1203
0 commit comments