@@ -77,6 +77,8 @@ class InstrProfReader {
77
77
78
78
virtual bool isIRLevelProfile () const = 0;
79
79
80
+ virtual bool hasCSIRLevelProfile () const = 0;
81
+
80
82
// / Return the PGO symtab. There are three different readers:
81
83
// / Raw, Text, and Indexed profile readers. The first two types
82
84
// / of readers are used only by llvm-profdata tool, while the indexed
@@ -142,6 +144,7 @@ class TextInstrProfReader : public InstrProfReader {
142
144
// / Iterator over the profile data.
143
145
line_iterator Line;
144
146
bool IsIRLevelProfile = false ;
147
+ bool HasCSIRLevelProfile = false ;
145
148
146
149
Error readValueProfileData (InstrProfRecord &Record);
147
150
@@ -156,6 +159,8 @@ class TextInstrProfReader : public InstrProfReader {
156
159
157
160
bool isIRLevelProfile () const override { return IsIRLevelProfile; }
158
161
162
+ bool hasCSIRLevelProfile () const override { return HasCSIRLevelProfile; }
163
+
159
164
// / Read the header.
160
165
Error readHeader () override ;
161
166
@@ -212,6 +217,10 @@ class RawInstrProfReader : public InstrProfReader {
212
217
return (Version & VARIANT_MASK_IR_PROF) != 0 ;
213
218
}
214
219
220
+ bool hasCSIRLevelProfile () const override {
221
+ return (Version & VARIANT_MASK_CSIR_PROF) != 0 ;
222
+ }
223
+
215
224
InstrProfSymtab &getSymtab () override {
216
225
assert (Symtab.get ());
217
226
return *Symtab.get ();
@@ -341,6 +350,7 @@ struct InstrProfReaderIndexBase {
341
350
virtual void setValueProfDataEndianness (support::endianness Endianness) = 0;
342
351
virtual uint64_t getVersion () const = 0;
343
352
virtual bool isIRLevelProfile () const = 0;
353
+ virtual bool hasCSIRLevelProfile () const = 0;
344
354
virtual Error populateSymtab (InstrProfSymtab &) = 0;
345
355
};
346
356
@@ -385,6 +395,10 @@ class InstrProfReaderIndex : public InstrProfReaderIndexBase {
385
395
return (FormatVersion & VARIANT_MASK_IR_PROF) != 0 ;
386
396
}
387
397
398
+ bool hasCSIRLevelProfile () const override {
399
+ return (FormatVersion & VARIANT_MASK_CSIR_PROF) != 0 ;
400
+ }
401
+
388
402
Error populateSymtab (InstrProfSymtab &Symtab) override {
389
403
return Symtab.create (HashTable->keys ());
390
404
}
@@ -412,13 +426,16 @@ class IndexedInstrProfReader : public InstrProfReader {
412
426
std::unique_ptr<InstrProfReaderRemapper> Remapper;
413
427
// / Profile summary data.
414
428
std::unique_ptr<ProfileSummary> Summary;
429
+ // / Context sensitive profile summary data.
430
+ std::unique_ptr<ProfileSummary> CS_Summary;
415
431
// Index to the current record in the record array.
416
432
unsigned RecordIndex;
417
433
418
434
// Read the profile summary. Return a pointer pointing to one byte past the
419
435
// end of the summary data if it exists or the input \c Cur.
436
+ // \c UseCS indicates whether to use the context-sensitive profile summary.
420
437
const unsigned char *readSummary (IndexedInstrProf::ProfVersion Version,
421
- const unsigned char *Cur);
438
+ const unsigned char *Cur, bool UseCS );
422
439
423
440
public:
424
441
IndexedInstrProfReader (
@@ -432,6 +449,9 @@ class IndexedInstrProfReader : public InstrProfReader {
432
449
// / Return the profile version.
433
450
uint64_t getVersion () const { return Index->getVersion (); }
434
451
bool isIRLevelProfile () const override { return Index->isIRLevelProfile (); }
452
+ bool hasCSIRLevelProfile () const override {
453
+ return Index->hasCSIRLevelProfile ();
454
+ }
435
455
436
456
// / Return true if the given buffer is in an indexed instrprof format.
437
457
static bool hasFormat (const MemoryBuffer &DataBuffer);
@@ -450,7 +470,16 @@ class IndexedInstrProfReader : public InstrProfReader {
450
470
std::vector<uint64_t > &Counts);
451
471
452
472
// / Return the maximum of all known function counts.
453
- uint64_t getMaximumFunctionCount () { return Summary->getMaxFunctionCount (); }
473
+ // / \c UseCS indicates whether to use the context-sensitive count.
474
+ uint64_t getMaximumFunctionCount (bool UseCS) {
475
+ if (UseCS) {
476
+ assert (CS_Summary && " No context sensitive profile summary" );
477
+ return CS_Summary->getMaxFunctionCount ();
478
+ } else {
479
+ assert (Summary && " No profile summary" );
480
+ return Summary->getMaxFunctionCount ();
481
+ }
482
+ }
454
483
455
484
// / Factory method to create an indexed reader.
456
485
static Expected<std::unique_ptr<IndexedInstrProfReader>>
@@ -469,7 +498,19 @@ class IndexedInstrProfReader : public InstrProfReader {
469
498
// to be used by llvm-profdata (for dumping). Avoid using this when
470
499
// the client is the compiler.
471
500
InstrProfSymtab &getSymtab () override ;
472
- ProfileSummary &getSummary () { return *(Summary.get ()); }
501
+
502
+ // / Return the profile summary.
503
+ // / \c UseCS indicates whether to use the context-sensitive summary.
504
+ // TODO: removed the defualt parameter.
505
+ ProfileSummary &getSummary (bool UseCS = false ) {
506
+ if (UseCS) {
507
+ assert (CS_Summary && " No context sensitive summary" );
508
+ return *(CS_Summary.get ());
509
+ } else {
510
+ assert (Summary && " No profile summary" );
511
+ return *(Summary.get ());
512
+ }
513
+ }
473
514
};
474
515
475
516
} // end namespace llvm
0 commit comments