[llvm] r300352 - [Profile] Make host tool aware of object format when quering prof section names
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 14 10:48:40 PDT 2017
Author: davidxl
Date: Fri Apr 14 12:48:40 2017
New Revision: 300352
URL: http://llvm.org/viewvc/llvm-project?rev=300352&view=rev
Log:
[Profile] Make host tool aware of object format when quering prof section names
Differential Revision: https://reviews.llvm.org/D32073
Modified:
llvm/trunk/include/llvm/ProfileData/InstrProf.h
llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/trunk/lib/ProfileData/Coverage/CoverageMappingReader.cpp
llvm/trunk/lib/ProfileData/InstrProf.cpp
Modified: llvm/trunk/include/llvm/ProfileData/InstrProf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProf.h?rev=300352&r1=300351&r2=300352&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/InstrProf.h (original)
+++ llvm/trunk/include/llvm/ProfileData/InstrProf.h Fri Apr 14 12:48:40 2017
@@ -63,11 +63,21 @@ std::string getInstrProfCountersSectionN
/// the host machine, nor will segment prefix be added.
std::string getInstrProfNameSectionName(const Module *M = nullptr);
+/// Similar to the above, but used by host tool (e.g, coverage) which has
+/// object format information. The section name returned is not prefixed
+/// with segment name.
+std::string getInstrProfNameSectionNameInObject(bool isCoff);
+
/// Return the name of the data section containing per-function control
/// data. If M is null, the target platform is assumed to be the same as
/// the host machine, and the segment prefix will not be added.
std::string getInstrProfDataSectionName(const Module *M = nullptr);
+/// Similar to the above, but used by host tool (e.g, coverage) which has
+/// object format information. The section name returned is not prefixed
+/// with segment name.
+std::string getInstrProfDataSectionNameInObject(bool isCoff);
+
/// Return the name of data section containing pointers to value profile
/// counters/nodes. If M is null, the target platform is assumed to be
/// the same as the host machine, and the segment prefix will not be added.
@@ -92,6 +102,10 @@ inline StringRef getInstrProfValueRangeP
/// Return the name of the section containing function coverage mapping
/// data.
std::string getInstrProfCoverageSectionName(const Module *M = nullptr);
+/// Similar to the above, but used by host tool (e.g, coverage) which has
+/// object format information. The section name returned is not prefixed
+/// with segment name.
+std::string getInstrProfCoverageSectionNameInObject(bool isCoff);
/// Return the name prefix of variables containing instrumented function names.
inline StringRef getInstrProfNameVarPrefix() { return "__profn_"; }
Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=300352&r1=300351&r2=300352&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Fri Apr 14 12:48:40 2017
@@ -132,10 +132,8 @@ getELFKindForNamedSection(StringRef Name
// section(".eh_frame") gcc will produce:
//
// .section .eh_frame,"a", at progbits
-
- // TODO: to support Win->ELF cross compilation with coverage properly,
- // need to pass the module pointer to the following call.
- if (Name == getInstrProfCoverageSectionName())
+
+ if (Name == getInstrProfCoverageSectionNameInObject(false /*not coff*/))
return SectionKind::getMetadata();
if (Name.empty() || Name[0] != '.') return K;
Modified: llvm/trunk/lib/ProfileData/Coverage/CoverageMappingReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/Coverage/CoverageMappingReader.cpp?rev=300352&r1=300351&r2=300352&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/Coverage/CoverageMappingReader.cpp (original)
+++ llvm/trunk/lib/ProfileData/Coverage/CoverageMappingReader.cpp Fri Apr 14 12:48:40 2017
@@ -12,23 +12,24 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/ProfileData/Coverage/CoverageMappingReader.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/Triple.h"
+#include "llvm/ADT/Triple.h"
#include "llvm/Object/Binary.h"
+#include "llvm/Object/COFF.h"
#include "llvm/Object/Error.h"
#include "llvm/Object/MachOUniversal.h"
#include "llvm/Object/ObjectFile.h"
-#include "llvm/ProfileData/Coverage/CoverageMappingReader.h"
#include "llvm/ProfileData/InstrProf.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/Endian.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
@@ -648,15 +649,13 @@ static Error loadBinaryFormat(MemoryBuff
: support::endianness::big;
// Look for the sections that we are interested in.
- // TODO: with the current getInstrProfXXXSectionName interfaces, the
- // the coverage reader host tool is limited to read coverage section on
- // binaries with compatible profile section naming scheme as the host
- // platform. Currently, COFF format binaries have different section
- // naming scheme from the all the rest.
- auto NamesSection = lookupSection(*OF, getInstrProfNameSectionName());
+ bool IsCoff = (dyn_cast<COFFObjectFile>(OF.get()) != nullptr);
+ auto NamesSection =
+ lookupSection(*OF, getInstrProfNameSectionNameInObject(IsCoff));
if (auto E = NamesSection.takeError())
return E;
- auto CoverageSection = lookupSection(*OF, getInstrProfCoverageSectionName());
+ auto CoverageSection =
+ lookupSection(*OF, getInstrProfCoverageSectionNameInObject(IsCoff));
if (auto E = CoverageSection.takeError())
return E;
Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=300352&r1=300351&r2=300352&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProf.cpp Fri Apr 14 12:48:40 2017
@@ -173,8 +173,11 @@ const char *InstrProfSectNamePrefix[] =
#include "llvm/ProfileData/InstrProfData.inc"
};
-std::string getInstrProfSectionName(const Module *M, InstrProfSectKind Kind) {
+std::string getInstrProfSectionName(bool isCoff, InstrProfSectKind Kind) {
+ return isCoff ? InstrProfSectNameCoff[Kind] : InstrProfSectNameCommon[Kind];
+}
+std::string getInstrProfSectionName(const Module *M, InstrProfSectKind Kind) {
if (!M)
return InstrProfSectName[Kind];
@@ -206,10 +209,18 @@ std::string getInstrProfNameSectionName(
return getInstrProfSectionName(M, IPSK_name);
}
+std::string getInstrProfNameSectionNameInObject(bool isCoff) {
+ return getInstrProfSectionName(isCoff, IPSK_name);
+}
+
std::string getInstrProfDataSectionName(const Module *M) {
return getInstrProfSectionName(M, IPSK_data);
}
+std::string getInstrProfDataSectionNameInObject(bool isCoff) {
+ return getInstrProfSectionName(isCoff, IPSK_data);
+}
+
std::string getInstrProfValuesSectionName(const Module *M) {
return getInstrProfSectionName(M, IPSK_vals);
}
@@ -222,6 +233,10 @@ std::string getInstrProfCoverageSectionN
return getInstrProfSectionName(M, IPSK_covmap);
}
+std::string getInstrProfCoverageSectionNameInObject(bool isCoff) {
+ return getInstrProfSectionName(isCoff, IPSK_covmap);
+}
+
void SoftInstrProfErrors::addError(instrprof_error IE) {
if (IE == instrprof_error::success)
return;
More information about the llvm-commits
mailing list