Skip to content

Commit 035dd72

Browse files
author
Andres Wearden
committed
llvm-lit test cases pass
1 parent ebcd68e commit 035dd72

File tree

13 files changed

+100
-170
lines changed

13 files changed

+100
-170
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ class CoverageMapping {
10311031
ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
10321032
std::optional<std::reference_wrapper<IndexedInstrProfReader>>
10331033
&ProfileReader,
1034-
CoverageMapping &Coverage, StringRef Arch, StringRef ObjectFilename = "", bool ShowArchExecutables = false);
1034+
CoverageMapping &Coverage, StringRef Arch, StringRef ObjectFilename = "", bool ShowArchExecutables = false, bool MergeBinaryCoverage = false);
10351035

10361036
static Error loadFromReaders(
10371037
ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
@@ -1046,13 +1046,13 @@ class CoverageMapping {
10461046
&ProfileReader,
10471047
CoverageMapping &Coverage, bool &DataFound,
10481048
SmallVectorImpl<object::BuildID> *FoundBinaryIDs = nullptr, StringRef ObjectFilename = "",
1049-
bool ShowArchExecutables = false);
1049+
bool ShowArchExecutables = false, bool MergeBinaryCoverage = false);
10501050

10511051
/// Add a function record corresponding to \p Record.
10521052
Error loadFunctionRecord(
10531053
const CoverageMappingRecord &Record,
10541054
const std::optional<std::reference_wrapper<IndexedInstrProfReader>>
1055-
&ProfileReader, StringRef ObjectFilename = "", bool ShowArchExecutables = false);
1055+
&ProfileReader, StringRef ObjectFilename = "", bool ShowArchExecutables = false, bool MergeBinaryCoverage = false);
10561056

10571057
Error loadFunctionRecord(const CoverageMappingRecord &Record,
10581058
const std::optional<std::reference_wrapper<IndexedInstrProfReader>> &ProfileReader,
@@ -1090,7 +1090,7 @@ class CoverageMapping {
10901090
std::optional<StringRef> ProfileFilename, vfs::FileSystem &FS,
10911091
ArrayRef<StringRef> Arches = {}, StringRef CompilationDir = "",
10921092
const object::BuildIDFetcher *BIDFetcher = nullptr,
1093-
bool CheckBinaryIDs = false, bool ShowArchExecutables = false);
1093+
bool CheckBinaryIDs = false, bool ShowArchExecutables = false, bool MergeBinaryCoverage = false);
10941094

10951095
/// The number of functions that couldn't have their profiles mapped.
10961096
///
@@ -1115,7 +1115,7 @@ class CoverageMapping {
11151115
/// The given filename must be the name as recorded in the coverage
11161116
/// information. That is, only names returned from getUniqueSourceFiles will
11171117
/// yield a result.
1118-
LLVM_ABI CoverageData getCoverageForFile(StringRef Filename, bool ShowArchExecutables = false) const;
1118+
LLVM_ABI CoverageData getCoverageForFile(StringRef Filename, bool ShowArchExecutables = false, bool MergeBinaryCoverage = false) const;
11191119

11201120
/// Get the coverage for a particular function.
11211121
LLVM_ABI CoverageData
@@ -1280,9 +1280,9 @@ uint64_t getFuncNameRef(const FuncRecordTy *Record) {
12801280
/// a hash.
12811281
template <class FuncRecordTy, llvm::endianness Endian>
12821282
Error getFuncNameViaRef(const FuncRecordTy *Record,
1283-
InstrProfSymtab &ProfileNames, StringRef &FuncName, StringRef Arch = "") {
1283+
InstrProfSymtab &ProfileNames, StringRef &FuncName, StringRef ObjectFilename = "") {
12841284
uint64_t NameRef = getFuncNameRef<FuncRecordTy, Endian>(Record);
1285-
ProfileNames.setArchitecture(Arch.str());
1285+
ProfileNames.setObjectFilename(ObjectFilename);
12861286
FuncName = ProfileNames.getFuncOrVarName(NameRef);
12871287
return Error::success();
12881288
}
@@ -1425,9 +1425,9 @@ struct CovMapFunctionRecordV3 {
14251425
}
14261426

14271427
template <llvm::endianness Endian>
1428-
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName, StringRef Arch = "") const {
1428+
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName, StringRef ObjectFilename = "") const {
14291429
return accessors::getFuncNameViaRef<ThisT, Endian>(this, ProfileNames,
1430-
FuncName, Arch);
1430+
FuncName, ObjectFilename);
14311431
}
14321432

14331433
/// Get the filename set reference.

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,16 @@ struct CoverageMappingRecord {
4040
ArrayRef<CounterExpression> Expressions;
4141
ArrayRef<CounterMappingRegion> MappingRegions;
4242
StringRef Arch;
43+
StringRef ObjectFilename;
4344

4445
const StringRef &getArchitecture() const { return Arch; }
4546
void setArchitecture(StringRef NewArch){
4647
Arch = StringRef(NewArch);
4748
}
49+
const StringRef &getObjectFilename() const { return ObjectFilename; }
50+
void setObjectFilename(StringRef ObjectFilename){
51+
this->ObjectFilename = StringRef(ObjectFilename);
52+
}
4853
};
4954

5055
/// A file format agnostic iterator over coverage mapping data.
@@ -223,14 +228,14 @@ class LLVM_ABI BinaryCoverageReader : public CoverageMappingReader {
223228
create(MemoryBufferRef ObjectBuffer, StringRef Arch,
224229
SmallVectorImpl<std::unique_ptr<MemoryBuffer>> &ObjectFileBuffers,
225230
StringRef CompilationDir = "",
226-
SmallVectorImpl<object::BuildIDRef> *BinaryIDs = nullptr);
231+
SmallVectorImpl<object::BuildIDRef> *BinaryIDs = nullptr, StringRef ObjectFilename = "");
227232

228233
static Expected<std::unique_ptr<BinaryCoverageReader>>
229234
createCoverageReaderFromBuffer(
230235
StringRef Coverage, FuncRecordsStorage &&FuncRecords,
231236
CoverageMapCopyStorage &&CoverageMap,
232237
std::unique_ptr<InstrProfSymtab> ProfileNamesPtr, uint8_t BytesInAddress,
233-
llvm::endianness Endian, StringRef CompilationDir = "", StringRef Arch = "");
238+
llvm::endianness Endian, StringRef CompilationDir = "", StringRef Arch = "", StringRef ObjectFilename = "");
234239

235240
Error readNextRecord(CoverageMappingRecord &Record) override;
236241
};

llvm/include/llvm/ProfileData/InstrProf.h

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ LLVM_ABI bool needsComdatForCounter(const GlobalObject &GV, const Module &M);
369369
/// InstrProf.h:getInstrProfNameSeparator). This method decodes the string and
370370
/// calls `NameCallback` for each substring.
371371
LLVM_ABI Error readAndDecodeStrings(
372-
StringRef NameStrings, std::function<Error(StringRef)> NameCallback, StringRef Architecture = "");
372+
StringRef NameStrings, std::function<Error(StringRef)> NameCallback, StringRef ObjectFilename = "");
373373

374374

375375
/// An enum describing the attributes of an instrumented profile.
@@ -513,12 +513,14 @@ class InstrProfSymtab {
513513
// suffixes that begins with "." except ".__uniq." are stripped.
514514
// FIXME: Unify this with `FunctionSamples::getCanonicalFnName`.
515515
LLVM_ABI static StringRef getCanonicalName(StringRef PGOName);
516-
517516
//ANDRES Function
517+
StringRef getObjectFilename() {return ObjectFilename;}
518+
void setObjectFilename(StringRef ObjectFilename) {this->ObjectFilename = ObjectFilename;}
518519
StringRef getArchitecture() {return Architecture;}
519-
void setArchitecture(StringRef Arch) {Architecture = Arch;}
520+
void setArchitecture(StringRef Architecture) {this->Architecture = Architecture;}
520521
//ANDRES Function
521522
private:
523+
StringRef ObjectFilename;
522524
StringRef Architecture;
523525
using AddrIntervalMap =
524526
IntervalMap<uint64_t, uint64_t, 4, IntervalMapHalfOpenInfo<uint64_t>>;
@@ -643,20 +645,19 @@ class InstrProfSymtab {
643645
// won't have duplicated entries in the first place.
644646

645647
uint64_t HashValue = IndexedInstrProf::ComputeHash(SymbolName);
646-
llvm::StringRef HashRef(SymbolName);
647-
if(!Architecture.empty()){
648-
std::string HashStr = std::to_string(HashValue);
649-
std::string CombinedStr = HashStr + ":" + Architecture.str();
650-
HashRef = CombinedStr;
648+
std::string HashStr(std::to_string(HashValue));
649+
// llvm::errs() << "HELLLOOOOOOOOO" << "\n";
650+
if(!ObjectFilename.empty()){
651+
std::string CombinedStr = HashStr + ":" + ObjectFilename.str();
652+
llvm::errs() << CombinedStr << "\n";
653+
StringRef HashRef = CombinedStr;
651654
HashValue = IndexedInstrProf::ComputeHash(HashRef);
652655
}
653656
auto Ins = NameTab.insert(SymbolName);
654657
if (Ins.second) {
655658
MD5NameMap.push_back(std::make_pair(HashValue /*IndexedInstrProf::ComputeHash(HashRef)*/, Ins.first->getKey()));
656659
Sorted = false;
657660
}
658-
for(int I = 0; I < int(MD5NameMap.size()); ++I){
659-
}
660661
return Error::success();
661662
}
662663

@@ -784,19 +785,20 @@ StringRef InstrProfSymtab::getFuncOrVarNameIfDefined(uint64_t MD5Hash) {
784785
StringRef InstrProfSymtab::getFuncOrVarName(uint64_t MD5Hash) {
785786
finalizeSymtab();
786787
std::string TempMD5HashStr = std::to_string(MD5Hash);
787-
if(!Architecture.empty()){
788-
std::string CombinedHashStr = TempMD5HashStr + ":" + Architecture.str();
788+
if(!ObjectFilename.empty()){
789+
std::string CombinedHashStr = TempMD5HashStr + ":" + ObjectFilename.str();
789790
llvm::StringRef CombinedHashRef(CombinedHashStr);
790791
MD5Hash = IndexedInstrProf::ComputeHash(CombinedHashRef);
791792
}
792793
auto Result = llvm::lower_bound(MD5NameMap, MD5Hash, [](const std::pair<uint64_t, StringRef> &LHS, uint64_t RHS) { return LHS.first < RHS; });
793794

794-
// for(auto name : MD5NameMap){
795-
// llvm::errs() << "Function Name " << name.second << " Result->first: " << name.first << "\n";
796-
// }
797-
// llvm::errs() << "Function Name " << Result->second << " Result->first: " << Result->first << " vs. " << MD5Hash << "\n";
795+
for(auto name : MD5NameMap){
796+
llvm::errs() << "Function Name " << name.second << " Result->first: " << name.first << "\n";
797+
}
798+
llvm::errs() << "Function Name " << Result->second << " Result->first: " << Result->first << " vs. " << MD5Hash << "\n";
798799
if (Result != MD5NameMap.end() && Result->first == MD5Hash)
799800
return Result->second;
801+
llvm::errs() << "MISMATCH HERE" << "\n";
800802
return StringRef();
801803
}
802804

llvm/include/llvm/ProfileData/InstrProfReader.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ class InstrProfReader {
162162
LLVM_ABI void accumulateCounts(CountSumOrPercent &Sum, bool IsCS);
163163

164164
protected:
165-
//ANDRES Storing Architecture Information as a string
166-
std::string Architecture;
165+
//ANDRES Storing ObjectFilename Information as a string
166+
std::string ObjectFilename;
167167

168168
std::unique_ptr<InstrProfSymtab> Symtab;
169169
/// A list of temporal profile traces.
@@ -213,19 +213,19 @@ class InstrProfReader {
213213
const object::BuildIDFetcher *BIDFetcher = nullptr,
214214
const InstrProfCorrelator::ProfCorrelatorKind BIDFetcherCorrelatorKind =
215215
InstrProfCorrelator::ProfCorrelatorKind::NONE,
216-
std::function<void(Error)> Warn = nullptr, StringRef Architecture = "");
216+
std::function<void(Error)> Warn = nullptr, StringRef ObjectFilename = "");
217217

218218
LLVM_ABI static Expected<std::unique_ptr<InstrProfReader>> create(
219219
std::unique_ptr<MemoryBuffer> Buffer,
220220
const InstrProfCorrelator *Correlator = nullptr,
221221
const object::BuildIDFetcher *BIDFetcher = nullptr,
222222
const InstrProfCorrelator::ProfCorrelatorKind BIDFetcherCorrelatorKind =
223223
InstrProfCorrelator::ProfCorrelatorKind::NONE,
224-
std::function<void(Error)> Warn = nullptr, StringRef Architecture = "");
224+
std::function<void(Error)> Warn = nullptr, StringRef ObjectFilename = "");
225225

226-
StringRef getArchitecture() {return Architecture;}
226+
StringRef getObjectFilename() {return ObjectFilename;}
227227

228-
void setArchitecture(StringRef Arch) {Architecture = Arch;}
228+
void setObjectFilename(StringRef ObjectFilename) {this->ObjectFilename = ObjectFilename;}
229229
/// \param Weight for raw profiles use this as the temporal profile trace
230230
/// weight
231231
/// \returns a list of temporal profile traces.
@@ -877,7 +877,7 @@ class LLVM_ABI IndexedInstrProfReader : public InstrProfReader {
877877

878878
static Expected<std::unique_ptr<IndexedInstrProfReader>>
879879
create(const Twine &Path, vfs::FileSystem &FS,
880-
const std::string &Arch, const Twine &RemappingPath = "");
880+
const std::string &ObjectFilename, const Twine &RemappingPath = "");
881881

882882
static Expected<std::unique_ptr<IndexedInstrProfReader>>
883883
create(std::unique_ptr<MemoryBuffer> Buffer,

llvm/include/llvm/ProfileData/InstrProfWriter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class InstrProfWriter {
113113
/// for this function and the hash and number of counts match, each counter is
114114
/// summed. Optionally scale counts by \p Weight.
115115
LLVM_ABI void addRecord(NamedInstrProfRecord &&I, uint64_t Weight,
116-
function_ref<void(Error)> Warn, StringRef Architecture = "");
116+
function_ref<void(Error)> Warn, StringRef ObjectFilename = "");
117117
// void addRecord(NamedInstrProfRecord &&I, uint64_t Weight, function_ref<void(Error)> Warn);
118118
void addRecord(NamedInstrProfRecord &&I, function_ref<void(Error)> Warn) {
119119
addRecord(std::move(I), 1, Warn);
@@ -225,7 +225,7 @@ class InstrProfWriter {
225225

226226
private:
227227
void addRecord(StringRef Name, uint64_t Hash, InstrProfRecord &&I,
228-
uint64_t Weight, function_ref<void(Error)> Warn, StringRef Architecture = "");
228+
uint64_t Weight, function_ref<void(Error)> Warn, StringRef ObjectFilename = "");
229229
bool shouldEncodeData(const ProfilingData &PD);
230230
/// Add \p Trace using reservoir sampling.
231231
void addTemporalProfileTrace(TemporalProfTraceTy Trace);

0 commit comments

Comments
 (0)