aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CoverageMappingGen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CodeGen/CoverageMappingGen.cpp')
-rw-r--r--lib/CodeGen/CoverageMappingGen.cpp67
1 files changed, 27 insertions, 40 deletions
diff --git a/lib/CodeGen/CoverageMappingGen.cpp b/lib/CodeGen/CoverageMappingGen.cpp
index eca91590e602..eb6edeac4427 100644
--- a/lib/CodeGen/CoverageMappingGen.cpp
+++ b/lib/CodeGen/CoverageMappingGen.cpp
@@ -47,17 +47,6 @@ public:
Optional<SourceLocation> LocEnd)
: Count(Count), LocStart(LocStart), LocEnd(LocEnd) {}
- SourceMappingRegion(SourceMappingRegion &&Region)
- : Count(std::move(Region.Count)), LocStart(std::move(Region.LocStart)),
- LocEnd(std::move(Region.LocEnd)) {}
-
- SourceMappingRegion &operator=(SourceMappingRegion &&RHS) {
- Count = std::move(RHS.Count);
- LocStart = std::move(RHS.LocStart);
- LocEnd = std::move(RHS.LocEnd);
- return *this;
- }
-
const Counter &getCounter() const { return Count; }
void setCounter(Counter C) { Count = C; }
@@ -66,7 +55,7 @@ public:
void setStartLoc(SourceLocation Loc) { LocStart = Loc; }
- const SourceLocation &getStartLoc() const {
+ SourceLocation getStartLoc() const {
assert(LocStart && "Region has no start location");
return *LocStart;
}
@@ -75,7 +64,7 @@ public:
void setEndLoc(SourceLocation Loc) { LocEnd = Loc; }
- const SourceLocation &getEndLoc() const {
+ SourceLocation getEndLoc() const {
assert(LocEnd && "Region has no end location");
return *LocEnd;
}
@@ -174,7 +163,7 @@ public:
unsigned Depth = 0;
for (SourceLocation Parent = getIncludeOrExpansionLoc(Loc);
- !Parent.isInvalid(); Parent = getIncludeOrExpansionLoc(Parent))
+ Parent.isValid(); Parent = getIncludeOrExpansionLoc(Parent))
++Depth;
FileLocs.push_back(std::make_pair(Loc, Depth));
}
@@ -255,7 +244,7 @@ public:
assert(Region.hasEndLoc() && "incomplete region");
SourceLocation LocStart = Region.getStartLoc();
- assert(!SM.getFileID(LocStart).isInvalid() && "region in invalid file");
+ assert(SM.getFileID(LocStart).isValid() && "region in invalid file");
auto CovFileID = getCoverageFileID(LocStart);
// Ignore regions that don't have a file, such as builtin macros.
@@ -413,8 +402,8 @@ struct CounterCoverageMappingBuilder
SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
- assert(!EndLoc.isInvalid() &&
- "File exit was not handled before popRegions");
+ if (EndLoc.isInvalid())
+ llvm::report_fatal_error("File exit not handled before popRegions");
}
Region.setEndLoc(EndLoc);
@@ -426,7 +415,7 @@ struct CounterCoverageMappingBuilder
MostRecentLocation = getIncludeOrExpansionLoc(EndLoc);
assert(SM.isWrittenInSameFile(Region.getStartLoc(), EndLoc));
- SourceRegions.push_back(std::move(Region));
+ SourceRegions.push_back(Region);
}
RegionStack.pop_back();
}
@@ -496,12 +485,12 @@ struct CounterCoverageMappingBuilder
llvm::SmallSet<SourceLocation, 8> StartLocs;
Optional<Counter> ParentCounter;
- for (auto I = RegionStack.rbegin(), E = RegionStack.rend(); I != E; ++I) {
- if (!I->hasStartLoc())
+ for (SourceMappingRegion &I : llvm::reverse(RegionStack)) {
+ if (!I.hasStartLoc())
continue;
- SourceLocation Loc = I->getStartLoc();
+ SourceLocation Loc = I.getStartLoc();
if (!isNestedIn(Loc, ParentFile)) {
- ParentCounter = I->getCounter();
+ ParentCounter = I.getCounter();
break;
}
@@ -510,11 +499,11 @@ struct CounterCoverageMappingBuilder
// correct count. We avoid creating redundant regions by stopping once
// we've seen this region.
if (StartLocs.insert(Loc).second)
- SourceRegions.emplace_back(I->getCounter(), Loc,
+ SourceRegions.emplace_back(I.getCounter(), Loc,
getEndOfFileOrMacro(Loc));
Loc = getIncludeOrExpansionLoc(Loc);
}
- I->setStartLoc(getPreciseTokenLocEnd(Loc));
+ I.setStartLoc(getPreciseTokenLocEnd(Loc));
}
if (ParentCounter) {
@@ -580,7 +569,7 @@ struct CounterCoverageMappingBuilder
}
void VisitStmt(const Stmt *S) {
- if (!S->getLocStart().isInvalid())
+ if (S->getLocStart().isValid())
extendRegion(S);
for (const Stmt *Child : S->children())
if (Child)
@@ -796,7 +785,7 @@ struct CounterCoverageMappingBuilder
else
pushRegion(Count, getStart(S));
- if (const CaseStmt *CS = dyn_cast<CaseStmt>(S)) {
+ if (const auto *CS = dyn_cast<CaseStmt>(S)) {
Visit(CS->getLHS());
if (const Expr *RHS = CS->getRHS())
Visit(RHS);
@@ -842,7 +831,6 @@ struct CounterCoverageMappingBuilder
}
void VisitCXXCatchStmt(const CXXCatchStmt *S) {
- extendRegion(S);
propagateCounts(getRegionCounter(S), S->getHandlerBlock());
}
@@ -891,7 +879,7 @@ static bool isMachO(const CodeGenModule &CGM) {
}
static StringRef getCoverageSection(const CodeGenModule &CGM) {
- return isMachO(CGM) ? "__DATA,__llvm_covmap" : "__llvm_covmap";
+ return llvm::getInstrProfCoverageSectionName(isMachO(CGM));
}
static void dump(llvm::raw_ostream &OS, StringRef FunctionName,
@@ -922,24 +910,23 @@ static void dump(llvm::raw_ostream &OS, StringRef FunctionName,
}
void CoverageMappingModuleGen::addFunctionMappingRecord(
- llvm::GlobalVariable *FunctionName, StringRef FunctionNameValue,
- uint64_t FunctionHash, const std::string &CoverageMapping) {
+ llvm::GlobalVariable *NamePtr, StringRef NameValue,
+ uint64_t FuncHash, const std::string &CoverageMapping) {
llvm::LLVMContext &Ctx = CGM.getLLVMContext();
- auto *Int32Ty = llvm::Type::getInt32Ty(Ctx);
- auto *Int64Ty = llvm::Type::getInt64Ty(Ctx);
- auto *Int8PtrTy = llvm::Type::getInt8PtrTy(Ctx);
if (!FunctionRecordTy) {
- llvm::Type *FunctionRecordTypes[] = {Int8PtrTy, Int32Ty, Int32Ty, Int64Ty};
+ #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) LLVMType,
+ llvm::Type *FunctionRecordTypes[] = {
+ #include "llvm/ProfileData/InstrProfData.inc"
+ };
FunctionRecordTy =
llvm::StructType::get(Ctx, makeArrayRef(FunctionRecordTypes),
/*isPacked=*/true);
}
+ #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Init,
llvm::Constant *FunctionRecordVals[] = {
- llvm::ConstantExpr::getBitCast(FunctionName, Int8PtrTy),
- llvm::ConstantInt::get(Int32Ty, FunctionNameValue.size()),
- llvm::ConstantInt::get(Int32Ty, CoverageMapping.size()),
- llvm::ConstantInt::get(Int64Ty, FunctionHash)};
+ #include "llvm/ProfileData/InstrProfData.inc"
+ };
FunctionRecords.push_back(llvm::ConstantStruct::get(
FunctionRecordTy, makeArrayRef(FunctionRecordVals)));
CoverageMappings += CoverageMapping;
@@ -961,7 +948,7 @@ void CoverageMappingModuleGen::addFunctionMappingRecord(
Expressions, Regions);
if (Reader.read())
return;
- dump(llvm::outs(), FunctionNameValue, Expressions, Regions);
+ dump(llvm::outs(), NameValue, Expressions, Regions);
}
}
@@ -1023,7 +1010,7 @@ void CoverageMappingModuleGen::emit() {
auto CovData = new llvm::GlobalVariable(CGM.getModule(), CovDataTy, true,
llvm::GlobalValue::InternalLinkage,
CovDataVal,
- "__llvm_coverage_mapping");
+ llvm::getCoverageMappingVarName());
CovData->setSection(getCoverageSection(CGM));
CovData->setAlignment(8);