Skip to content

Commit 1d6ae59

Browse files
author
Andres Wearden
committed
saving changes to compare with main branch
1 parent 3a398c1 commit 1d6ae59

File tree

8 files changed

+280
-47
lines changed

8 files changed

+280
-47
lines changed

llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -993,17 +993,24 @@ class CoverageMapping {
993993
std::vector<FunctionRecord> Functions;
994994
DenseMap<size_t, SmallVector<unsigned, 0>> FilenameHash2RecordIndices;
995995
std::vector<std::pair<std::string, uint64_t>> FuncHashMismatches;
996+
StringRef Arch;
996997

997998
std::optional<bool> SingleByteCoverage;
998999

9991000
CoverageMapping() = default;
10001001

10011002
// Load coverage records from readers.
10021003
static Error loadFromReaders(
1003-
ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
1004-
std::optional<std::reference_wrapper<IndexedInstrProfReader>>
1005-
&ProfileReader,
1006-
CoverageMapping &Coverage);
1004+
ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
1005+
std::optional<std::reference_wrapper<IndexedInstrProfReader>>
1006+
&ProfileReader,
1007+
CoverageMapping &Coverage, StringRef Arch);
1008+
1009+
static Error loadFromReaders(
1010+
ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
1011+
std::optional<std::reference_wrapper<IndexedInstrProfReader>>
1012+
&ProfileReader,
1013+
CoverageMapping &Coverage);
10071014

10081015
// Load coverage records from file.
10091016
static Error
@@ -1018,6 +1025,8 @@ class CoverageMapping {
10181025
const CoverageMappingRecord &Record,
10191026
const std::optional<std::reference_wrapper<IndexedInstrProfReader>>
10201027
&ProfileReader);
1028+
1029+
Error loadFunctionRecord(const CoverageMappingRecord &Record, const std::optional<std::reference_wrapper<IndexedInstrProfReader>> &ProfileReader, const std::string &Arch);
10211030

10221031
/// Look up the indices for function records which are at least partially
10231032
/// defined in the specified file. This is guaranteed to return a superset of
@@ -1027,6 +1036,13 @@ class CoverageMapping {
10271036
getImpreciseRecordIndicesForFilename(StringRef Filename) const;
10281037

10291038
public:
1039+
1040+
const StringRef &getArchitecture() const { return Arch; }
1041+
1042+
void setArchitecture(StringRef NewArch){
1043+
Arch = StringRef(NewArch);
1044+
}
1045+
10301046
CoverageMapping(const CoverageMapping &) = delete;
10311047
CoverageMapping &operator=(const CoverageMapping &) = delete;
10321048

@@ -1234,8 +1250,9 @@ uint64_t getFuncNameRef(const FuncRecordTy *Record) {
12341250
/// a hash.
12351251
template <class FuncRecordTy, llvm::endianness Endian>
12361252
Error getFuncNameViaRef(const FuncRecordTy *Record,
1237-
InstrProfSymtab &ProfileNames, StringRef &FuncName) {
1253+
InstrProfSymtab &ProfileNames, StringRef &FuncName, StringRef Arch = "") {
12381254
uint64_t NameRef = getFuncNameRef<FuncRecordTy, Endian>(Record);
1255+
ProfileNames.setArchitecture(Arch.str());
12391256
FuncName = ProfileNames.getFuncOrVarName(NameRef);
12401257
return Error::success();
12411258
}
@@ -1285,7 +1302,7 @@ struct CovMapFunctionRecordV1 {
12851302

12861303
/// Return the PGO name of the function.
12871304
template <llvm::endianness Endian>
1288-
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const {
1305+
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName, StringRef Arch = "") const {
12891306
IntPtrT NameRef = getFuncNameRef<Endian>();
12901307
uint32_t NameS = support::endian::byte_swap<uint32_t, Endian>(NameSize);
12911308
FuncName = ProfileNames.getFuncName(NameRef, NameS);
@@ -1334,7 +1351,7 @@ struct CovMapFunctionRecordV2 {
13341351
}
13351352

13361353
template <llvm::endianness Endian>
1337-
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const {
1354+
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName, StringRef Arch = "") const {
13381355
return accessors::getFuncNameViaRef<ThisT, Endian>(this, ProfileNames,
13391356
FuncName);
13401357
}
@@ -1378,9 +1395,9 @@ struct CovMapFunctionRecordV3 {
13781395
}
13791396

13801397
template <llvm::endianness Endian>
1381-
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const {
1398+
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName, StringRef Arch = "") const {
13821399
return accessors::getFuncNameViaRef<ThisT, Endian>(this, ProfileNames,
1383-
FuncName);
1400+
FuncName, Arch);
13841401
}
13851402

13861403
/// Get the filename set reference.

llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ struct CoverageMappingRecord {
3939
ArrayRef<StringRef> Filenames;
4040
ArrayRef<CounterExpression> Expressions;
4141
ArrayRef<CounterMappingRegion> MappingRegions;
42+
StringRef Arch;
43+
44+
const StringRef &getArchitecture() const { return Arch; }
45+
void setArchitecture(StringRef NewArch){
46+
Arch = StringRef(NewArch);
47+
}
4248
};
4349

4450
/// A file format agnostic iterator over coverage mapping data.
@@ -191,6 +197,7 @@ class LLVM_ABI BinaryCoverageReader : public CoverageMappingReader {
191197
std::vector<StringRef> FunctionsFilenames;
192198
std::vector<CounterExpression> Expressions;
193199
std::vector<CounterMappingRegion> MappingRegions;
200+
StringRef Arch;
194201

195202
// Used to tie the lifetimes of coverage function records to the lifetime of
196203
// this BinaryCoverageReader instance. Needed to support the format change in
@@ -223,7 +230,7 @@ class LLVM_ABI BinaryCoverageReader : public CoverageMappingReader {
223230
StringRef Coverage, FuncRecordsStorage &&FuncRecords,
224231
CoverageMapCopyStorage &&CoverageMap,
225232
std::unique_ptr<InstrProfSymtab> ProfileNamesPtr, uint8_t BytesInAddress,
226-
llvm::endianness Endian, StringRef CompilationDir = "");
233+
llvm::endianness Endian, StringRef CompilationDir = "", StringRef Arch = "");
227234

228235
Error readNextRecord(CoverageMappingRecord &Record) override;
229236
};

llvm/include/llvm/ProfileData/InstrProf.h

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -636,22 +636,23 @@ class InstrProfSymtab {
636636
// Map the MD5 of the symbol name to the name.
637637
Error addSymbolName(StringRef SymbolName) {
638638
StringRef FuncName;
639-
StringRef ArchName;
639+
StringRef ArchName = "";
640640
std::tie(FuncName, ArchName) = SymbolName.split(":");
641641
if (SymbolName.empty())
642642
return make_error<InstrProfError>(instrprof_error::malformed,
643643
"symbol name is empty");
644644

645645
// Insert into NameTab so that MD5NameMap (a vector that will be sorted)
646646
// won't have duplicated entries in the first place.
647-
648647
uint64_t HashValue = IndexedInstrProf::ComputeHash(FuncName);
649-
std::string HashStr = std::to_string(HashValue);
650-
std::string CombinedStr = HashStr + ":" + ArchName.str();
651-
llvm::StringRef HashRef(CombinedStr);
652-
HashValue = IndexedInstrProf::ComputeHash(HashRef);
653-
654-
printf("Hash Value for %.*s: %" PRIu64 "\n", static_cast<int>(SymbolName.size()), SymbolName.data(), HashValue);
648+
llvm::StringRef HashRef(FuncName);
649+
if(!ArchName.empty()){
650+
std::string HashStr = std::to_string(HashValue);
651+
std::string CombinedStr = HashStr + ":" + ArchName.str();
652+
HashRef = CombinedStr;
653+
HashValue = IndexedInstrProf::ComputeHash(HashRef);
654+
}
655+
printf("Hash Value for %.*s %" PRIu64 "\n", static_cast<int>(SymbolName.size()), SymbolName.data(), HashValue);
655656
auto Ins = NameTab.insert(FuncName);
656657
printf("mapped value for %" PRIu64 " hash: %.*s\n", HashValue, static_cast<int>(Ins.first->getKey().size()), Ins.first->getKey().data());
657658
if (Ins.second) {
@@ -786,13 +787,14 @@ StringRef InstrProfSymtab::getFuncOrVarNameIfDefined(uint64_t MD5Hash) {
786787
StringRef InstrProfSymtab::getFuncOrVarName(uint64_t MD5Hash) {
787788
finalizeSymtab();
788789
std::string TempMD5HashStr = std::to_string(MD5Hash);
789-
std::string CombinedHashStr = TempMD5HashStr + ":" + Architecture;
790-
llvm::StringRef CombinedHashRef(CombinedHashStr);
791-
uint64_t NewMD5Hash = IndexedInstrProf::ComputeHash(CombinedHashRef);
792-
auto Result = llvm::lower_bound(MD5NameMap, NewMD5Hash,
793-
[](const std::pair<uint64_t, StringRef> &LHS,
794-
uint64_t RHS) { return LHS.first < RHS; });
795-
if (Result != MD5NameMap.end() && Result->first == NewMD5Hash)
790+
if(!Architecture.empty()){
791+
std::string CombinedHashStr = TempMD5HashStr + ":" + Architecture;
792+
llvm::StringRef CombinedHashRef(CombinedHashStr);
793+
MD5Hash = IndexedInstrProf::ComputeHash(CombinedHashRef);
794+
}
795+
auto Result = llvm::lower_bound(MD5NameMap, MD5Hash, [](const std::pair<uint64_t, StringRef> &LHS, uint64_t RHS) { return LHS.first < RHS; });
796+
llvm::errs() << "Architecture: " << (!Architecture.empty() ? Architecture : "No Specified Architecture") << ": " << Result->second<< ": " << "Result->first: " << Result->first << " vs. MD5hash: " << MD5Hash << "\n";
797+
if (Result != MD5NameMap.end() && Result->first == MD5Hash)
796798
return Result->second;
797799
return StringRef();
798800
}

llvm/include/llvm/ProfileData/InstrProfReader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,10 @@ class LLVM_ABI IndexedInstrProfReader : public InstrProfReader {
875875
create(const Twine &Path, vfs::FileSystem &FS,
876876
const Twine &RemappingPath = "");
877877

878+
static Expected<std::unique_ptr<IndexedInstrProfReader>>
879+
create(const Twine &Path, vfs::FileSystem &FS,
880+
const std::string &Arch, const Twine &RemappingPath = "");
881+
878882
static Expected<std::unique_ptr<IndexedInstrProfReader>>
879883
create(std::unique_ptr<MemoryBuffer> Buffer,
880884
std::unique_ptr<MemoryBuffer> RemappingBuffer = nullptr);

0 commit comments

Comments
 (0)