Skip to content

Commit d0acddb

Browse files
Revert "[StaticDataLayout][PGO]Implement reader and writer change for data access profiles" (#141157)
Reverts #139997 Sanitizer failures (https://lab.llvm.org/buildbot/#/builders/94/builds/7373) Will fix forward later.
1 parent c47260e commit d0acddb

File tree

14 files changed

+32
-313
lines changed

14 files changed

+32
-313
lines changed

llvm/include/llvm/ProfileData/DataAccessProf.h

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
#ifndef LLVM_PROFILEDATA_DATAACCESSPROF_H_
1818
#define LLVM_PROFILEDATA_DATAACCESSPROF_H_
1919

20+
#include "llvm/ADT/DenseMap.h"
2021
#include "llvm/ADT/DenseMapInfoVariant.h"
2122
#include "llvm/ADT/MapVector.h"
23+
#include "llvm/ADT/STLExtras.h"
2224
#include "llvm/ADT/SetVector.h"
2325
#include "llvm/ADT/SmallVector.h"
2426
#include "llvm/ADT/StringRef.h"
@@ -33,15 +35,12 @@
3335

3436
namespace llvm {
3537

36-
namespace memprof {
38+
namespace data_access_prof {
3739

3840
/// The location of data in the source code. Used by profile lookup API.
3941
struct SourceLocation {
4042
SourceLocation(StringRef FileNameRef, uint32_t Line)
4143
: FileName(FileNameRef.str()), Line(Line) {}
42-
43-
// Empty constructor is used in yaml conversion.
44-
SourceLocation() {}
4544
/// The filename where the data is located.
4645
std::string FileName;
4746
/// The line number in the source code.
@@ -54,8 +53,6 @@ namespace internal {
5453
// which strings are owned by `DataAccessProfData`. Used by `DataAccessProfData`
5554
// to represent data locations internally.
5655
struct SourceLocationRef {
57-
SourceLocationRef(StringRef FileNameRef, uint32_t Line)
58-
: FileName(FileNameRef), Line(Line) {}
5956
// The filename where the data is located.
6057
StringRef FileName;
6158
// The line number in the source code.
@@ -103,21 +100,18 @@ using SymbolHandle = std::variant<std::string, uint64_t>;
103100
/// The data access profiles for a symbol.
104101
struct DataAccessProfRecord {
105102
public:
106-
DataAccessProfRecord(SymbolHandleRef SymHandleRef, uint64_t AccessCount,
107-
ArrayRef<internal::SourceLocationRef> LocRefs)
108-
: AccessCount(AccessCount) {
103+
DataAccessProfRecord(SymbolHandleRef SymHandleRef,
104+
ArrayRef<internal::SourceLocationRef> LocRefs) {
109105
if (std::holds_alternative<StringRef>(SymHandleRef)) {
110106
SymHandle = std::get<StringRef>(SymHandleRef).str();
111107
} else
112108
SymHandle = std::get<uint64_t>(SymHandleRef);
113109

114110
for (auto Loc : LocRefs)
115-
Locations.emplace_back(Loc.FileName, Loc.Line);
111+
Locations.push_back(SourceLocation(Loc.FileName, Loc.Line));
116112
}
117-
// Empty constructor is used in yaml conversion.
118-
DataAccessProfRecord() {}
119113
SymbolHandle SymHandle;
120-
uint64_t AccessCount;
114+
121115
// The locations of data in the source code. Optional.
122116
SmallVector<SourceLocation> Locations;
123117
};
@@ -214,7 +208,7 @@ class DataAccessProfData {
214208
llvm::SetVector<StringRef> KnownColdSymbols;
215209
};
216210

217-
} // namespace memprof
211+
} // namespace data_access_prof
218212
} // namespace llvm
219213

220214
#endif // LLVM_PROFILEDATA_DATAACCESSPROF_H_

llvm/include/llvm/ProfileData/IndexedMemProfData.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@
1515
#ifndef LLVM_PROFILEDATA_INDEXEDMEMPROFDATA_H
1616
#define LLVM_PROFILEDATA_INDEXEDMEMPROFDATA_H
1717

18-
#include "llvm/ProfileData/DataAccessProf.h"
1918
#include "llvm/ProfileData/InstrProf.h"
2019
#include "llvm/ProfileData/MemProf.h"
2120

22-
#include <functional>
23-
#include <optional>
24-
2521
namespace llvm {
2622
namespace memprof {
2723
struct IndexedMemProfData {
@@ -86,10 +82,8 @@ struct IndexedMemProfData {
8682
} // namespace memprof
8783

8884
// Write the MemProf data to OS.
89-
Error writeMemProf(
90-
ProfOStream &OS, memprof::IndexedMemProfData &MemProfData,
91-
memprof::IndexedVersion MemProfVersionRequested, bool MemProfFullSchema,
92-
std::unique_ptr<memprof::DataAccessProfData> DataAccessProfileData);
93-
85+
Error writeMemProf(ProfOStream &OS, memprof::IndexedMemProfData &MemProfData,
86+
memprof::IndexedVersion MemProfVersionRequested,
87+
bool MemProfFullSchema);
9488
} // namespace llvm
9589
#endif

llvm/include/llvm/ProfileData/InstrProfReader.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "llvm/ADT/StringRef.h"
1919
#include "llvm/IR/ProfileSummary.h"
2020
#include "llvm/Object/BuildID.h"
21-
#include "llvm/ProfileData/DataAccessProf.h"
2221
#include "llvm/ProfileData/InstrProf.h"
2322
#include "llvm/ProfileData/InstrProfCorrelator.h"
2423
#include "llvm/ProfileData/MemProf.h"
@@ -704,13 +703,10 @@ class IndexedMemProfReader {
704703
const unsigned char *CallStackBase = nullptr;
705704
// The number of elements in the radix tree array.
706705
unsigned RadixTreeSize = 0;
707-
/// The data access profiles, deserialized from binary data.
708-
std::unique_ptr<memprof::DataAccessProfData> DataAccessProfileData;
709706

710707
Error deserializeV2(const unsigned char *Start, const unsigned char *Ptr);
711708
Error deserializeRadixTreeBased(const unsigned char *Start,
712-
const unsigned char *Ptr,
713-
memprof::IndexedVersion Version);
709+
const unsigned char *Ptr);
714710

715711
public:
716712
IndexedMemProfReader() = default;

llvm/include/llvm/ProfileData/InstrProfWriter.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "llvm/ADT/StringMap.h"
2020
#include "llvm/IR/GlobalValue.h"
2121
#include "llvm/Object/BuildID.h"
22-
#include "llvm/ProfileData/DataAccessProf.h"
2322
#include "llvm/ProfileData/IndexedMemProfData.h"
2423
#include "llvm/ProfileData/InstrProf.h"
2524
#include "llvm/Support/Error.h"
@@ -82,8 +81,6 @@ class InstrProfWriter {
8281
// Whether to generated random memprof hotness for testing.
8382
bool MemprofGenerateRandomHotness;
8483

85-
std::unique_ptr<memprof::DataAccessProfData> DataAccessProfileData;
86-
8784
public:
8885
// For memprof testing, random hotness can be assigned to the contexts if
8986
// MemprofGenerateRandomHotness is enabled. The random seed can be either
@@ -125,9 +122,6 @@ class InstrProfWriter {
125122
// Add a binary id to the binary ids list.
126123
void addBinaryIds(ArrayRef<llvm::object::BuildID> BIs);
127124

128-
void addDataAccessProfData(
129-
std::unique_ptr<memprof::DataAccessProfData> DataAccessProfile);
130-
131125
/// Merge existing function counts from the given writer.
132126
void mergeRecordsFromWriter(InstrProfWriter &&IPW,
133127
function_ref<void(Error)> Warn);

llvm/include/llvm/ProfileData/MemProfReader.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,6 @@ class YAMLMemProfReader final : public MemProfReader {
229229
create(std::unique_ptr<MemoryBuffer> Buffer);
230230

231231
void parse(StringRef YAMLData);
232-
233-
std::unique_ptr<memprof::DataAccessProfData> takeDataAccessProfData() {
234-
return std::move(DataAccessProfileData);
235-
}
236-
237-
private:
238-
// Called by `parse` to set data access profiles after parsing them from Yaml
239-
// files.
240-
void
241-
setDataAccessProfileData(std::unique_ptr<memprof::DataAccessProfData> Data) {
242-
DataAccessProfileData = std::move(Data);
243-
}
244-
245-
std::unique_ptr<memprof::DataAccessProfData> DataAccessProfileData;
246232
};
247233
} // namespace memprof
248234
} // namespace llvm

llvm/include/llvm/ProfileData/MemProfYAML.h

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define LLVM_PROFILEDATA_MEMPROFYAML_H_
33

44
#include "llvm/ADT/SmallVector.h"
5-
#include "llvm/ProfileData/DataAccessProf.h"
65
#include "llvm/ProfileData/MemProf.h"
76
#include "llvm/Support/Format.h"
87
#include "llvm/Support/YAMLTraits.h"
@@ -21,24 +20,9 @@ struct GUIDMemProfRecordPair {
2120
MemProfRecord Record;
2221
};
2322

24-
// Helper struct to yamlify memprof::DataAccessProfData. The struct
25-
// members use owned strings. This is for simplicity and assumes that most real
26-
// world use cases do look-ups and regression test scale is small.
27-
struct YamlDataAccessProfData {
28-
std::vector<memprof::DataAccessProfRecord> Records;
29-
std::vector<uint64_t> KnownColdStrHashes;
30-
std::vector<std::string> KnownColdSymbols;
31-
32-
bool isEmpty() const {
33-
return Records.empty() && KnownColdStrHashes.empty() &&
34-
KnownColdSymbols.empty();
35-
}
36-
};
37-
3823
// The top-level data structure, only used with YAML for now.
3924
struct AllMemProfData {
4025
std::vector<GUIDMemProfRecordPair> HeapProfileRecords;
41-
YamlDataAccessProfData YamlifiedDataAccessProfiles;
4226
};
4327
} // namespace memprof
4428

@@ -222,52 +206,9 @@ template <> struct MappingTraits<memprof::GUIDMemProfRecordPair> {
222206
}
223207
};
224208

225-
template <> struct MappingTraits<memprof::SourceLocation> {
226-
static void mapping(IO &Io, memprof::SourceLocation &Loc) {
227-
Io.mapOptional("FileName", Loc.FileName);
228-
Io.mapOptional("Line", Loc.Line);
229-
}
230-
};
231-
232-
template <> struct MappingTraits<memprof::DataAccessProfRecord> {
233-
static void mapping(IO &Io, memprof::DataAccessProfRecord &Rec) {
234-
if (Io.outputting()) {
235-
if (std::holds_alternative<std::string>(Rec.SymHandle)) {
236-
Io.mapOptional("Symbol", std::get<std::string>(Rec.SymHandle));
237-
} else {
238-
Io.mapOptional("Hash", std::get<uint64_t>(Rec.SymHandle));
239-
}
240-
} else {
241-
std::string SymName;
242-
uint64_t Hash = 0;
243-
Io.mapOptional("Symbol", SymName);
244-
Io.mapOptional("Hash", Hash);
245-
if (!SymName.empty()) {
246-
Rec.SymHandle = SymName;
247-
} else {
248-
Rec.SymHandle = Hash;
249-
}
250-
}
251-
252-
Io.mapOptional("Locations", Rec.Locations);
253-
}
254-
};
255-
256-
template <> struct MappingTraits<memprof::YamlDataAccessProfData> {
257-
static void mapping(IO &Io, memprof::YamlDataAccessProfData &Data) {
258-
Io.mapOptional("SampledRecords", Data.Records);
259-
Io.mapOptional("KnownColdSymbols", Data.KnownColdSymbols);
260-
Io.mapOptional("KnownColdStrHashes", Data.KnownColdStrHashes);
261-
}
262-
};
263-
264209
template <> struct MappingTraits<memprof::AllMemProfData> {
265210
static void mapping(IO &Io, memprof::AllMemProfData &Data) {
266211
Io.mapRequired("HeapProfileRecords", Data.HeapProfileRecords);
267-
// Map data access profiles if reading input, or if writing output &&
268-
// the struct is populated.
269-
if (!Io.outputting() || !Data.YamlifiedDataAccessProfiles.isEmpty())
270-
Io.mapOptional("DataAccessProfiles", Data.YamlifiedDataAccessProfiles);
271212
}
272213
};
273214

@@ -293,7 +234,5 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::AllocationInfo)
293234
LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::CallSiteInfo)
294235
LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::GUIDMemProfRecordPair)
295236
LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::GUIDHex64) // Used for CalleeGuids
296-
LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::DataAccessProfRecord)
297-
LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::SourceLocation)
298237

299238
#endif // LLVM_PROFILEDATA_MEMPROFYAML_H_

llvm/lib/ProfileData/DataAccessProf.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <sys/types.h>
1212

1313
namespace llvm {
14-
namespace memprof {
14+
namespace data_access_prof {
1515

1616
// If `Map` has an entry keyed by `Str`, returns the entry iterator. Otherwise,
1717
// creates an owned copy of `Str`, adds a map entry for it and returns the
@@ -48,8 +48,7 @@ DataAccessProfData::getProfileRecord(const SymbolHandleRef SymbolID) const {
4848

4949
auto It = Records.find(Key);
5050
if (It != Records.end()) {
51-
return DataAccessProfRecord(Key, It->second.AccessCount,
52-
It->second.Locations);
51+
return DataAccessProfRecord(Key, It->second.Locations);
5352
}
5453

5554
return std::nullopt;
@@ -262,5 +261,5 @@ Error DataAccessProfData::deserializeRecords(const unsigned char *&Ptr) {
262261
}
263262
return Error::success();
264263
}
265-
} // namespace memprof
264+
} // namespace data_access_prof
266265
} // namespace llvm

0 commit comments

Comments
 (0)