Skip to content

Commit d9006f2

Browse files
author
Andres Wearden
committed
commit to push final changes
1 parent 035dd72 commit d9006f2

File tree

7 files changed

+17
-350
lines changed

7 files changed

+17
-350
lines changed

llvm/include/llvm/ProfileData/InstrProf.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -513,12 +513,12 @@ 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-
//ANDRES Function
516+
517517
StringRef getObjectFilename() {return ObjectFilename;}
518518
void setObjectFilename(StringRef ObjectFilename) {this->ObjectFilename = ObjectFilename;}
519519
StringRef getArchitecture() {return Architecture;}
520520
void setArchitecture(StringRef Architecture) {this->Architecture = Architecture;}
521-
//ANDRES Function
521+
522522
private:
523523
StringRef ObjectFilename;
524524
StringRef Architecture;
@@ -646,16 +646,15 @@ class InstrProfSymtab {
646646

647647
uint64_t HashValue = IndexedInstrProf::ComputeHash(SymbolName);
648648
std::string HashStr(std::to_string(HashValue));
649-
// llvm::errs() << "HELLLOOOOOOOOO" << "\n";
649+
//if ObjectFilename is not empty from the --object-aware-hashing flag, add ObjectFilename to hash context
650650
if(!ObjectFilename.empty()){
651651
std::string CombinedStr = HashStr + ":" + ObjectFilename.str();
652-
llvm::errs() << CombinedStr << "\n";
653652
StringRef HashRef = CombinedStr;
654653
HashValue = IndexedInstrProf::ComputeHash(HashRef);
655654
}
656655
auto Ins = NameTab.insert(SymbolName);
657656
if (Ins.second) {
658-
MD5NameMap.push_back(std::make_pair(HashValue /*IndexedInstrProf::ComputeHash(HashRef)*/, Ins.first->getKey()));
657+
MD5NameMap.push_back(std::make_pair(HashValue, Ins.first->getKey()));
659658
Sorted = false;
660659
}
661660
return Error::success();
@@ -792,13 +791,8 @@ StringRef InstrProfSymtab::getFuncOrVarName(uint64_t MD5Hash) {
792791
}
793792
auto Result = llvm::lower_bound(MD5NameMap, MD5Hash, [](const std::pair<uint64_t, StringRef> &LHS, uint64_t RHS) { return LHS.first < RHS; });
794793

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";
799794
if (Result != MD5NameMap.end() && Result->first == MD5Hash)
800795
return Result->second;
801-
llvm::errs() << "MISMATCH HERE" << "\n";
802796
return StringRef();
803797
}
804798

llvm/include/llvm/ProfileData/InstrProfReader.h

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

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

168168
std::unique_ptr<InstrProfSymtab> Symtab;

llvm/lib/ProfileData/Coverage/CoverageMapping.cpp

Lines changed: 3 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -825,157 +825,6 @@ class MCDCDecisionRecorder {
825825

826826
} // namespace
827827

828-
// Error CoverageMapping::loadFunctionRecord(
829-
// const CoverageMappingRecord &Record,
830-
// const std::optional<std::reference_wrapper<IndexedInstrProfReader>>
831-
// &ProfileReader, StringRef Arch) {
832-
// StringRef OrigFuncName = Record.FunctionName;
833-
// if (OrigFuncName.empty())
834-
// return make_error<CoverageMapError>(coveragemap_error::malformed,
835-
// "record function name is empty");
836-
837-
// if (Record.Filenames.empty())
838-
// OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName);
839-
// else
840-
// OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]);
841-
842-
// CounterMappingContext Ctx(Record.Expressions);
843-
844-
// uint64_t FuncArchHash = Record.FunctionHash;
845-
// if(!Arch.empty()){
846-
// std::string HashStr = std::to_string(Record.FunctionHash) + ":" + Arch.str();
847-
// llvm::StringRef HashRef(HashStr);
848-
// FuncArchHash = IndexedInstrProf::ComputeHash(HashRef);
849-
// }
850-
851-
// std::vector<uint64_t> Counts;
852-
// if (ProfileReader) {
853-
// if (Error E = ProfileReader.value().get().getFunctionCounts(
854-
// Record.FunctionName, FuncArchHash, Counts)) {
855-
// instrprof_error IPE = std::get<0>(InstrProfError::take(std::move(E)));
856-
// if (IPE == instrprof_error::hash_mismatch) {
857-
// FuncHashMismatches.emplace_back(std::string(Record.FunctionName),
858-
// FuncArchHash);
859-
// return Error::success();
860-
// }
861-
// if (IPE != instrprof_error::unknown_function)
862-
// return make_error<InstrProfError>(IPE);
863-
// Counts.assign(getMaxCounterID(Ctx, Record) + 1, 0);
864-
// }
865-
// } else {
866-
// Counts.assign(getMaxCounterID(Ctx, Record) + 1, 0);
867-
// }
868-
// Ctx.setCounts(Counts);
869-
870-
// bool IsVersion11 =
871-
// ProfileReader && ProfileReader.value().get().getVersion() <
872-
// IndexedInstrProf::ProfVersion::Version12;
873-
874-
// BitVector Bitmap;
875-
// if (ProfileReader) {
876-
// if (Error E = ProfileReader.value().get().getFunctionBitmap(
877-
// Record.FunctionName, FuncArchHash, Bitmap)) {
878-
// instrprof_error IPE = std::get<0>(InstrProfError::take(std::move(E)));
879-
// if (IPE == instrprof_error::hash_mismatch) {
880-
// FuncHashMismatches.emplace_back(std::string(Record.FunctionName),
881-
// FuncArchHash);
882-
// return Error::success();
883-
// }
884-
// if (IPE != instrprof_error::unknown_function)
885-
// return make_error<InstrProfError>(IPE);
886-
// Bitmap = BitVector(getMaxBitmapSize(Record, IsVersion11));
887-
// }
888-
// } else {
889-
// Bitmap = BitVector(getMaxBitmapSize(Record, false));
890-
// }
891-
// Ctx.setBitmap(std::move(Bitmap));
892-
893-
// assert(!Record.MappingRegions.empty() && "Function has no regions");
894-
895-
// // This coverage record is a zero region for a function that's unused in
896-
// // some TU, but used in a different TU. Ignore it. The coverage maps from the
897-
// // the other TU will either be loaded (providing full region counts) or they
898-
// // won't (in which case we don't unintuitively report functions as uncovered
899-
// // when they have non-zero counts in the profile).
900-
// if (Record.MappingRegions.size() == 1 &&
901-
// Record.MappingRegions[0].Count.isZero() && Counts[0] > 0)
902-
// return Error::success();
903-
904-
// MCDCDecisionRecorder MCDCDecisions;
905-
// FunctionRecord Function(OrigFuncName, Record.Filenames);
906-
// for (const auto &Region : Record.MappingRegions) {
907-
// // MCDCDecisionRegion should be handled first since it overlaps with
908-
// // others inside.
909-
// if (Region.Kind == CounterMappingRegion::MCDCDecisionRegion) {
910-
// MCDCDecisions.registerDecision(Region);
911-
// continue;
912-
// }
913-
// Expected<int64_t> ExecutionCount = Ctx.evaluate(Region.Count);
914-
// if (auto E = ExecutionCount.takeError()) {
915-
// consumeError(std::move(E));
916-
// return Error::success();
917-
// }
918-
// Expected<int64_t> AltExecutionCount = Ctx.evaluate(Region.FalseCount);
919-
// if (auto E = AltExecutionCount.takeError()) {
920-
// consumeError(std::move(E));
921-
// return Error::success();
922-
// }
923-
// Function.pushRegion(Region, *ExecutionCount, *AltExecutionCount);
924-
925-
// // Record ExpansionRegion.
926-
// if (Region.Kind == CounterMappingRegion::ExpansionRegion) {
927-
// MCDCDecisions.recordExpansion(Region);
928-
// continue;
929-
// }
930-
931-
// // Do nothing unless MCDCBranchRegion.
932-
// if (Region.Kind != CounterMappingRegion::MCDCBranchRegion)
933-
// continue;
934-
935-
// auto Result = MCDCDecisions.processBranch(Region);
936-
// if (!Result) // Any Decision doesn't complete.
937-
// continue;
938-
939-
// auto MCDCDecision = Result->first;
940-
// auto &MCDCBranches = Result->second;
941-
942-
// // Since the bitmap identifies the executed test vectors for an MC/DC
943-
// // DecisionRegion, all of the information is now available to process.
944-
// // This is where the bulk of the MC/DC progressing takes place.
945-
// Expected<MCDCRecord> Record =
946-
// Ctx.evaluateMCDCRegion(*MCDCDecision, MCDCBranches, IsVersion11);
947-
// if (auto E = Record.takeError()) {
948-
// consumeError(std::move(E));
949-
// return Error::success();
950-
// }
951-
952-
// // Save the MC/DC Record so that it can be visualized later.
953-
// Function.pushMCDCRecord(std::move(*Record));
954-
// }
955-
956-
// // Don't create records for (filenames, function) pairs we've already seen.
957-
// auto FilenamesHash = hash_combine_range(Record.Filenames);
958-
// if (!RecordProvenance[FilenamesHash].insert(hash_value(OrigFuncName)).second)
959-
// return Error::success();
960-
961-
// Functions.push_back(std::move(Function));
962-
963-
// // Performance optimization: keep track of the indices of the function records
964-
// // which correspond to each filename. This can be used to substantially speed
965-
// // up queries for coverage info in a file.
966-
// unsigned RecordIndex = Functions.size() - 1;
967-
// for (StringRef Filename : Record.Filenames) {
968-
// auto &RecordIndices = FilenameHash2RecordIndices[hash_value(Filename)];
969-
// // Note that there may be duplicates in the filename set for a function
970-
// // record, because of e.g. macro expansions in the function in which both
971-
// // the macro and the function are defined in the same file.
972-
// if (RecordIndices.empty() || RecordIndices.back() != RecordIndex)
973-
// RecordIndices.push_back(RecordIndex);
974-
// }
975-
976-
// return Error::success();
977-
// }
978-
979828
Error CoverageMapping::loadFunctionRecord(
980829
const CoverageMappingRecord &Record,
981830
const std::optional<std::reference_wrapper<IndexedInstrProfReader>>
@@ -1200,7 +1049,6 @@ Error CoverageMapping::loadFromReaders(
12001049
&ProfileReader,
12011050
CoverageMapping &Coverage, StringRef Arch, StringRef ObjectFilename, bool ShowArchExecutables, bool MergeBinaryCoverage) {
12021051

1203-
// Coverage.setArchitecture(Arch);
12041052
assert(!Coverage.SingleByteCoverage || !ProfileReader ||
12051053
*Coverage.SingleByteCoverage ==
12061054
ProfileReader.value().get().hasSingleByteCoverage());
@@ -1308,9 +1156,6 @@ Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load(
13081156
return Arches[Idx];
13091157
};
13101158

1311-
//I beleive there is an error in this area of code, it's iterating through all arch's of the object files
1312-
// but its only filling *Coverage with last architecture it gets to
1313-
13141159
SmallVector<object::BuildID> FoundBinaryIDs;
13151160
for (const auto &File : llvm::enumerate(ObjectFilenames)) {
13161161
if (Error E = loadFromFile(File.value(), GetArch(File.index()),
@@ -1320,9 +1165,6 @@ Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load(
13201165
return std::move(E);
13211166
}
13221167

1323-
//I beleive there is an error in this area of code, it's iterating through all arch's of the object files
1324-
// but its only filling *Coverage with last architecture it gets to
1325-
13261168
if (BIDFetcher) {
13271169
std::vector<object::BuildID> ProfileBinaryIDs;
13281170
if (ProfileReader)
@@ -1561,7 +1403,6 @@ class SegmentBuilder {
15611403
}
15621404

15631405
/// Combine counts of regions which cover the same area.
1564-
//[(3:12, 10:1), (4:1, 6:7), (6:7, 8:1)]
15651406
static ArrayRef<CountedRegion>
15661407
combineRegions(MutableArrayRef<CountedRegion> Regions) {
15671408
if (Regions.empty())
@@ -1576,8 +1417,6 @@ class SegmentBuilder {
15761417
++Active;
15771418
if (Active != I){
15781419
*Active = *I;
1579-
// Active->ExecutionCount = 1;
1580-
// Active->Kind = CounterMappingRegion::CodeRegion;
15811420
}
15821421
continue;
15831422
}
@@ -1608,14 +1447,16 @@ class SegmentBuilder {
16081447

16091448
sortNestedRegions(Regions);
16101449

1450+
1451+
//check to see if a skipped region from executable A is within a CodeRegion from executable B,
1452+
//promote to CodeRegion if skipped region does not show up on any other executable.
16111453
for(auto *I = Regions.begin(); I != Regions.end(); ++I){
16121454
bool FoundMatchInOtherBinary = false;
16131455
for(auto *J = I + 1; J != Regions.end(); ++J){
16141456
if(I->ObjectFilename != J->ObjectFilename &&
16151457
J->Kind == CounterMappingRegion::SkippedRegion
16161458
&& I->Kind != CounterMappingRegion::SkippedRegion &&
16171459
J->startLoc() >= I->startLoc() && J->endLoc() <= I->endLoc()){
1618-
// llvm::errs() << "(" << to_string(J->startLoc().first) << ", " << to_string(J->endLoc().first) << ")" << "\n";
16191460
for(auto *K = J + 1; K != Regions.end(); ++K){
16201461
if(K->ObjectFilename == I->ObjectFilename &&
16211462
J->startLoc() == K->startLoc() && J->endLoc() == K->endLoc()){
@@ -1686,12 +1527,7 @@ static SmallBitVector gatherFileIDs(StringRef SourceFile,
16861527
static std::optional<unsigned>
16871528
findMainViewFileID(const FunctionRecord &Function) {
16881529
SmallBitVector IsNotExpandedFile(Function.Filenames.size(), true);
1689-
uint64_t counter = 0;
16901530
for (const auto &CR : Function.CountedRegions){
1691-
// counter++;
1692-
// if(counter == 245){
1693-
// llvm::errs() << counter << "\n";
1694-
// }
16951531
if (CR.Kind == CounterMappingRegion::ExpansionRegion)
16961532
IsNotExpandedFile[CR.ExpandedFileID] = false;
16971533
}
@@ -1726,14 +1562,6 @@ CoverageData CoverageMapping::getCoverageForFile(StringRef Filename, bool ShowAr
17261562
// DenseSet<CountedRegion> DeDuplicationSet;
17271563
ArrayRef<unsigned> RecordIndices =
17281564
getImpreciseRecordIndicesForFilename(Filename);
1729-
// for (unsigned RecordIndex : RecordIndices) {
1730-
// const FunctionRecord &Function = AllFunctionRegions[RecordIndex];
1731-
// for(const auto &I : Function.CountedRegions){
1732-
// llvm::errs() << "(" << to_string(I.startLoc().first) << ", " << to_string(I.endLoc().first) << ")" << "\n";
1733-
// }
1734-
// }
1735-
// ArrayRef<unsigned> RecordIndices =
1736-
// getImpreciseRecordIndicesForFilename(Filename);
17371565
for (unsigned RecordIndex : RecordIndices) {
17381566
const FunctionRecord &Function = !MergeBinaryCoverage ? Functions[RecordIndex] : AllFunctionRegions[RecordIndex];
17391567
auto MainFileID = findMainViewFileID(Filename, Function);

llvm/lib/ProfileData/InstrProf.cpp

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -574,49 +574,6 @@ Error InstrProfSymtab::addVTableWithName(GlobalVariable &VTable,
574574
return Error::success();
575575
}
576576

577-
// Error readAndDecodeStrings(StringRef NameStrings,
578-
// std::function<Error(StringRef)> NameCallback, const std::string &Architecture) {
579-
// const uint8_t *P = NameStrings.bytes_begin();
580-
// const uint8_t *EndP = NameStrings.bytes_end();
581-
// while (P < EndP) {
582-
// uint32_t N;
583-
// uint64_t UncompressedSize = decodeULEB128(P, &N);
584-
// P += N;
585-
// uint64_t CompressedSize = decodeULEB128(P, &N);
586-
// P += N;
587-
// const bool IsCompressed = (CompressedSize != 0);
588-
// SmallVector<uint8_t, 128> UncompressedNameStrings;
589-
// StringRef NameStrings;
590-
// if (IsCompressed) {
591-
// if (!llvm::compression::zlib::isAvailable())
592-
// return make_error<InstrProfError>(instrprof_error::zlib_unavailable);
593-
594-
// if (Error E = compression::zlib::decompress(ArrayRef(P, CompressedSize),
595-
// UncompressedNameStrings,
596-
// UncompressedSize)) {
597-
// consumeError(std::move(E));
598-
// return make_error<InstrProfError>(instrprof_error::uncompress_failed);
599-
// }
600-
// P += CompressedSize;
601-
// NameStrings = toStringRef(UncompressedNameStrings);
602-
// } else {
603-
// NameStrings =
604-
// StringRef(reinterpret_cast<const char *>(P), UncompressedSize);
605-
// P += UncompressedSize;
606-
// }
607-
// // Now parse the name strings.
608-
// SmallVector<StringRef, 0> Names;
609-
// NameStrings.split(Names, getInstrProfNameSeparator());
610-
// for (StringRef &Name : Names){
611-
// if (Error E = NameCallback(Name))
612-
// return E;
613-
// }
614-
// while (P < EndP && *P == 0)
615-
// P++;
616-
// }
617-
// return Error::success();
618-
// }
619-
620577
Error readAndDecodeStrings(StringRef NameStrings,
621578
std::function<Error(StringRef)> NameCallback, StringRef ObjectFilename) {
622579
const uint8_t *P = NameStrings.bytes_begin();
@@ -665,8 +622,7 @@ Error InstrProfSymtab::create(StringRef NameStrings) {
665622
}
666623

667624
Error InstrProfSymtab::create(StringRef FuncNameStrings,
668-
StringRef VTableNameStrings) {
669-
// const std::string &Architecture = getArchitecture();
625+
StringRef VTableNameStrings) {
670626
if (Error E = readAndDecodeStrings(FuncNameStrings, std::bind(&InstrProfSymtab::addFuncName, this, std::placeholders::_1)))
671627
return E;
672628

0 commit comments

Comments
 (0)