@@ -37,14 +37,19 @@ using namespace llvm;
37
37
38
38
enum ProfileFormat { PF_None = 0 , PF_Text, PF_Binary, PF_GCC };
39
39
40
- static void exitWithError ( Twine Message, std::string Whence = " " ,
41
- std::string Hint = " " ) {
42
- errs () << " error: " ;
40
+ static void warn (StringRef Prefix, Twine Message, std::string Whence = " " ,
41
+ std::string Hint = " " ) {
42
+ errs () << Prefix ;
43
43
if (!Whence.empty ())
44
44
errs () << Whence << " : " ;
45
45
errs () << Message << " \n " ;
46
46
if (!Hint.empty ())
47
47
errs () << Hint << " \n " ;
48
+ }
49
+
50
+ static void exitWithError (Twine Message, std::string Whence = " " ,
51
+ std::string Hint = " " ) {
52
+ warn (" error: " , Message, Whence, Hint);
48
53
::exit (1 );
49
54
}
50
55
@@ -129,6 +134,22 @@ struct WriterContext {
129
134
ErrLock (ErrLock), WriterErrorCodes(WriterErrorCodes) {}
130
135
};
131
136
137
+ // / Determine whether an error is fatal for profile merging.
138
+ static bool isFatalError (instrprof_error IPE) {
139
+ switch (IPE) {
140
+ default :
141
+ return true ;
142
+ case instrprof_error::success:
143
+ case instrprof_error::eof:
144
+ case instrprof_error::unknown_function:
145
+ case instrprof_error::hash_mismatch:
146
+ case instrprof_error::count_mismatch:
147
+ case instrprof_error::counter_overflow:
148
+ case instrprof_error::value_site_count_mismatch:
149
+ return false ;
150
+ }
151
+ }
152
+
132
153
// / Load an input into a writer context.
133
154
static void loadInput (const WeightedFile &Input, WriterContext *WC) {
134
155
std::unique_lock<std::mutex> CtxGuard{WC->Lock };
@@ -177,8 +198,13 @@ static void loadInput(const WeightedFile &Input, WriterContext *WC) {
177
198
FuncName, firstTime);
178
199
});
179
200
}
180
- if (Reader->hasError ())
181
- WC->Err = Reader->getError ();
201
+ if (Reader->hasError ()) {
202
+ if (Error E = Reader->getError ()) {
203
+ instrprof_error IPE = InstrProfError::take (std::move (E));
204
+ if (isFatalError (IPE))
205
+ WC->Err = make_error<InstrProfError>(IPE);
206
+ }
207
+ }
182
208
}
183
209
184
210
// / Merge the \p Src writer context into \p Dst.
@@ -262,10 +288,20 @@ static void mergeInstrProfile(const WeightedFileVector &Inputs,
262
288
}
263
289
264
290
// Handle deferred hard errors encountered during merging.
265
- for (std::unique_ptr<WriterContext> &WC : Contexts)
266
- if (WC->Err )
291
+ for (std::unique_ptr<WriterContext> &WC : Contexts) {
292
+ if (!WC->Err )
293
+ continue ;
294
+ if (!WC->Err .isA <InstrProfError>())
267
295
exitWithError (std::move (WC->Err ), WC->ErrWhence );
268
296
297
+ instrprof_error IPE = InstrProfError::take (std::move (WC->Err ));
298
+ if (isFatalError (IPE))
299
+ exitWithError (make_error<InstrProfError>(IPE), WC->ErrWhence );
300
+ else
301
+ warn (" warning: " , toString (make_error<InstrProfError>(IPE)),
302
+ WC->ErrWhence );
303
+ }
304
+
269
305
InstrProfWriter &Writer = Contexts[0 ]->Writer ;
270
306
if (OutputFormat == PF_Text) {
271
307
if (Error E = Writer.writeText (Output))
0 commit comments