summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp3
-rw-r--r--llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp8
-rw-r--r--llvm/lib/ProfileData/InstrProf.cpp90
-rw-r--r--llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp40
-rw-r--r--llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp4
5 files changed, 36 insertions, 109 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 8ce4dfd4ecc..34892680ace 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -133,7 +133,8 @@ getELFKindForNamedSection(StringRef Name, SectionKind K) {
//
// .section .eh_frame,"a",@progbits
- if (Name == getInstrProfCoverageSectionNameInObject(false /*not coff*/))
+ if (Name == getInstrProfSectionName(IPSK_covmap, Triple::ELF,
+ /*AddSegmentInfo=*/false))
return SectionKind::getMetadata();
if (Name.empty() || Name[0] != '.') return K;
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
index dab602afd25..a34f359cd54 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -649,13 +649,15 @@ static Error loadBinaryFormat(MemoryBufferRef ObjectBuffer,
: support::endianness::big;
// Look for the sections that we are interested in.
- bool IsCoff = (dyn_cast<COFFObjectFile>(OF.get()) != nullptr);
+ auto ObjFormat = OF->getTripleObjectFormat();
auto NamesSection =
- lookupSection(*OF, getInstrProfNameSectionNameInObject(IsCoff));
+ lookupSection(*OF, getInstrProfSectionName(IPSK_name, ObjFormat,
+ /*AddSegmentInfo=*/false));
if (auto E = NamesSection.takeError())
return E;
auto CoverageSection =
- lookupSection(*OF, getInstrProfCoverageSectionNameInObject(IsCoff));
+ lookupSection(*OF, getInstrProfSectionName(IPSK_covmap, ObjFormat,
+ /*AddSegmentInfo=*/false));
if (auto E = CoverageSection.takeError())
return E;
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index a8f5b7f3d0e..64a65ccc11a 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -138,103 +138,45 @@ const std::error_category &llvm::instrprof_category() {
namespace {
-enum InstrProfSectKind {
-#define INSTR_PROF_SECT_ENTRY(Kind, SectName, SectNameCommon, SectNameCoff, \
- Prefix) \
- Kind,
-#include "llvm/ProfileData/InstrProfData.inc"
-};
-
-const char *InstrProfSectName[] = {
-#define INSTR_PROF_SECT_ENTRY(Kind, SectName, SectNameCommon, SectNameCoff, \
- Prefix) \
- SectName,
-#include "llvm/ProfileData/InstrProfData.inc"
-};
-
const char *InstrProfSectNameCommon[] = {
-#define INSTR_PROF_SECT_ENTRY(Kind, SectName, SectNameCommon, SectNameCoff, \
- Prefix) \
+#define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) \
SectNameCommon,
#include "llvm/ProfileData/InstrProfData.inc"
};
const char *InstrProfSectNameCoff[] = {
-#define INSTR_PROF_SECT_ENTRY(Kind, SectName, SectNameCommon, SectNameCoff, \
- Prefix) \
+#define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) \
SectNameCoff,
#include "llvm/ProfileData/InstrProfData.inc"
};
const char *InstrProfSectNamePrefix[] = {
-#define INSTR_PROF_SECT_ENTRY(Kind, SectName, SectNameCommon, SectNameCoff, \
- Prefix) \
+#define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) \
Prefix,
#include "llvm/ProfileData/InstrProfData.inc"
};
-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];
-
- bool AddSegment = Triple(M->getTargetTriple()).isOSBinFormatMachO();
- std::string SectName;
- if (Triple(M->getTargetTriple()).isOSBinFormatCOFF())
- SectName = InstrProfSectNameCoff[Kind];
- else
- SectName = InstrProfSectNameCommon[Kind];
-
- if (AddSegment) {
- SectName = InstrProfSectNamePrefix[Kind] + SectName;
- if (Kind == IPSK_data) {
- SectName += ",regular,live_support";
- }
- }
- return SectName;
-}
-
} // namespace
namespace llvm {
-std::string getInstrProfCountersSectionName(const Module *M) {
- return getInstrProfSectionName(M, IPSK_cnts);
-}
-
-std::string getInstrProfNameSectionName(const Module *M) {
- 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 getInstrProfSectionName(InstrProfSectKind IPSK,
+ Triple::ObjectFormatType OF,
+ bool AddSegmentInfo) {
+ std::string SectName;
-std::string getInstrProfValuesSectionName(const Module *M) {
- return getInstrProfSectionName(M, IPSK_vals);
-}
+ if (OF == Triple::MachO && AddSegmentInfo)
+ SectName = InstrProfSectNamePrefix[IPSK];
-std::string getInstrProfVNodesSectionName(const Module *M) {
- return getInstrProfSectionName(M, IPSK_vnodes);
-}
+ if (OF == Triple::COFF)
+ SectName += InstrProfSectNameCoff[IPSK];
+ else
+ SectName += InstrProfSectNameCommon[IPSK];
-std::string getInstrProfCoverageSectionName(const Module *M) {
- return getInstrProfSectionName(M, IPSK_covmap);
-}
+ if (OF == Triple::MachO && IPSK == IPSK_data && AddSegmentInfo)
+ SectName += ",regular,live_support";
-std::string getInstrProfCoverageSectionNameInObject(bool isCoff) {
- return getInstrProfSectionName(isCoff, IPSK_covmap);
+ return SectName;
}
void SoftInstrProfErrors::addError(instrprof_error IE) {
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
index c47467f1a84..d91ac6ac788 100644
--- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -140,30 +140,6 @@ llvm::createInstrProfilingLegacyPass(const InstrProfOptions &Options) {
return new InstrProfilingLegacyPass(Options);
}
-bool InstrProfiling::isMachO() const {
- return Triple(M->getTargetTriple()).isOSBinFormatMachO();
-}
-
-/// Get the section name for the counter variables.
-std::string InstrProfiling::getCountersSection() const {
- return getInstrProfCountersSectionName(M);
-}
-
-/// Get the section name for the name variables.
-std::string InstrProfiling::getNameSection() const {
- return getInstrProfNameSectionName(M);
-}
-
-/// Get the section name for the profile data variables.
-std::string InstrProfiling::getDataSection() const {
- return getInstrProfDataSectionName(M);
-}
-
-/// Get the section name for the coverage mapping data.
-std::string InstrProfiling::getCoverageSection() const {
- return getInstrProfCoverageSectionName(M);
-}
-
static InstrProfIncrementInst *castToIncrementInst(Instruction *Instr) {
InstrProfIncrementInst *Inc = dyn_cast<InstrProfIncrementInstStep>(Instr);
if (Inc)
@@ -182,6 +158,7 @@ bool InstrProfiling::run(Module &M, const TargetLibraryInfo &TLI) {
UsedVars.clear();
getMemOPSizeRangeFromOption(MemOPSizeRange, MemOPSizeRangeStart,
MemOPSizeRangeLast);
+ TT = Triple(M.getTargetTriple());
// We did not know how many value sites there would be inside
// the instrumented function. This is counting the number of instrumented
@@ -442,7 +419,8 @@ InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) {
Constant::getNullValue(CounterTy),
getVarName(Inc, getInstrProfCountersVarPrefix()));
CounterPtr->setVisibility(NamePtr->getVisibility());
- CounterPtr->setSection(getCountersSection());
+ CounterPtr->setSection(
+ getInstrProfSectionName(IPSK_cnts, TT.getObjectFormat()));
CounterPtr->setAlignment(8);
CounterPtr->setComdat(ProfileVarsComdat);
@@ -462,7 +440,8 @@ InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) {
Constant::getNullValue(ValuesTy),
getVarName(Inc, getInstrProfValuesVarPrefix()));
ValuesVar->setVisibility(NamePtr->getVisibility());
- ValuesVar->setSection(getInstrProfValuesSectionName(M));
+ ValuesVar->setSection(
+ getInstrProfSectionName(IPSK_vals, TT.getObjectFormat()));
ValuesVar->setAlignment(8);
ValuesVar->setComdat(ProfileVarsComdat);
ValuesPtrExpr =
@@ -495,7 +474,7 @@ InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) {
ConstantStruct::get(DataTy, DataVals),
getVarName(Inc, getInstrProfDataVarPrefix()));
Data->setVisibility(NamePtr->getVisibility());
- Data->setSection(getDataSection());
+ Data->setSection(getInstrProfSectionName(IPSK_data, TT.getObjectFormat()));
Data->setAlignment(INSTR_PROF_DATA_ALIGNMENT);
Data->setComdat(ProfileVarsComdat);
@@ -557,7 +536,8 @@ void InstrProfiling::emitVNodes() {
auto *VNodesVar = new GlobalVariable(
*M, VNodesTy, false, GlobalValue::PrivateLinkage,
Constant::getNullValue(VNodesTy), getInstrProfVNodesVarName());
- VNodesVar->setSection(getInstrProfVNodesSectionName(M));
+ VNodesVar->setSection(
+ getInstrProfSectionName(IPSK_vnodes, TT.getObjectFormat()));
UsedVars.push_back(VNodesVar);
}
@@ -580,7 +560,8 @@ void InstrProfiling::emitNameData() {
GlobalValue::PrivateLinkage, NamesVal,
getInstrProfNamesVarName());
NamesSize = CompressedNameStr.size();
- NamesVar->setSection(getNameSection());
+ NamesVar->setSection(
+ getInstrProfSectionName(IPSK_name, TT.getObjectFormat()));
UsedVars.push_back(NamesVar);
for (auto *NamePtr : ReferencedNames)
@@ -676,7 +657,6 @@ void InstrProfiling::emitInitialization() {
GlobalVariable *ProfileNameVar = new GlobalVariable(
*M, ProfileNameConst->getType(), true, GlobalValue::WeakAnyLinkage,
ProfileNameConst, INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_NAME_VAR));
- Triple TT(M->getTargetTriple());
if (TT.supportsCOMDAT()) {
ProfileNameVar->setLinkage(GlobalValue::ExternalLinkage);
ProfileNameVar->setComdat(M->getOrInsertComdat(
diff --git a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
index b6255f651fd..9260217bd5e 100644
--- a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
@@ -280,7 +280,9 @@ static bool shouldInstrumentReadWriteFromAddress(const Module *M, Value *Addr) {
if (GV->hasSection()) {
StringRef SectionName = GV->getSection();
// Check if the global is in the PGO counters section.
- if (SectionName.endswith(getInstrProfCountersSectionName(M)))
+ auto OF = Triple(M->getTargetTriple()).getObjectFormat();
+ if (SectionName.endswith(
+ getInstrProfSectionName(IPSK_cnts, OF, /*AddSegmentInfo=*/false)))
return false;
}
OpenPOWER on IntegriCloud