Skip to content

[Coverage] Clean up a few classes, NFC #13705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions include/swift/SIL/SILCoverageMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
#include "swift/SIL/SILAllocated.h"
#include "swift/SIL/SILFunction.h"
#include "swift/SIL/SILPrintContext.h"
#include "llvm/ADT/ilist_node.h"
#include "llvm/ADT/ilist.h"
#include "llvm/ADT/ilist_node.h"
#include "llvm/ProfileData/Coverage/CoverageMapping.h"

namespace llvm {
namespace coverage {
struct CounterExpression;
struct Counter;
}
}
} // namespace coverage
} // namespace llvm

namespace swift {

Expand Down Expand Up @@ -133,7 +133,7 @@ class SILCoverageMap : public llvm::ilist_node<SILCoverageMap>,
void dump() const;
};

} // end swift namespace
} // namespace swift

namespace llvm {

Expand All @@ -142,8 +142,8 @@ namespace llvm {
//===----------------------------------------------------------------------===//

template <>
struct ilist_traits<::swift::SILCoverageMap> :
public ilist_default_traits<::swift::SILCoverageMap> {
struct ilist_traits<::swift::SILCoverageMap>
: public ilist_default_traits<::swift::SILCoverageMap> {
typedef ::swift::SILCoverageMap SILCoverageMap;

public:
Expand All @@ -153,6 +153,6 @@ public ilist_default_traits<::swift::SILCoverageMap> {
void createNode(const SILCoverageMap &);
};

} // end llvm namespace
} // namespace llvm

#endif // SWIFT_SIL_SILCOVERAGEMAP_H
14 changes: 0 additions & 14 deletions include/swift/SIL/SILModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,20 +453,6 @@ class SILModule {
using coverage_map_const_iterator = CoverageMapListType::const_iterator;
CoverageMapListType &getCoverageMapList() { return coverageMaps; }
const CoverageMapListType &getCoverageMapList() const { return coverageMaps; }
coverage_map_iterator coverage_map_begin() { return coverageMaps.begin(); }
coverage_map_iterator coverage_map_end() { return coverageMaps.end(); }
coverage_map_const_iterator coverage_map_begin() const {
return coverageMaps.begin();
}
coverage_map_const_iterator coverage_map_end() const {
return coverageMaps.end();
}
iterator_range<coverage_map_iterator> getCoverageMaps() {
return {coverageMaps.begin(), coverageMaps.end()};
}
iterator_range<coverage_map_const_iterator> getCoverageMaps() const {
return {coverageMaps.begin(), coverageMaps.end()};
}

llvm::yaml::Output *getOptRecordStream() { return OptRecordStream.get(); }
void setOptRecordStream(std::unique_ptr<llvm::yaml::Output> &&Stream,
Expand Down
9 changes: 5 additions & 4 deletions include/swift/SIL/SILProfiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "swift/AST/Stmt.h"
#include "swift/Basic/ProfileCounter.h"
#include "swift/SIL/FormalLinkage.h"
#include "swift/SIL/SILAllocated.h"
#include "llvm/ADT/DenseMap.h"

namespace swift {
Expand All @@ -45,15 +46,15 @@ class SILProfiler : public SILAllocated<SILProfiler> {

std::string PGOFuncName;

uint64_t FunctionHash = 0;
uint64_t PGOFuncHash = 0;

unsigned NumRegionCounters = 0;

llvm::DenseMap<ASTNode, unsigned> RegionCounterMap;

llvm::DenseMap<ASTNode, ProfileCounter> PGORegionLoadedCounterMap;
llvm::DenseMap<ASTNode, ProfileCounter> RegionLoadedCounterMap;

llvm::DenseMap<ASTNode, ASTNode> PGORegionCondToParentMap;
llvm::DenseMap<ASTNode, ASTNode> RegionCondToParentMap;

std::vector<std::tuple<std::string, uint64_t, std::string>> CoverageData;

Expand All @@ -78,7 +79,7 @@ class SILProfiler : public SILAllocated<SILProfiler> {
StringRef getPGOFuncName() const { return PGOFuncName; }

/// Get the function hash.
uint64_t getPGOFuncHash() const { return FunctionHash; }
uint64_t getPGOFuncHash() const { return PGOFuncHash; }

/// Get the number of region counters.
unsigned getNumRegionCounters() const { return NumRegionCounters; }
Expand Down
35 changes: 16 additions & 19 deletions lib/SIL/SILProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
//
//===----------------------------------------------------------------------===//

#include "swift/SIL/SILProfiler.h"
#include "swift/AST/ASTWalker.h"
#include "swift/AST/Decl.h"
#include "swift/Parse/Lexer.h"
#include "swift/SIL/SILModule.h"
#include "swift/SIL/SILProfiler.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
Expand Down Expand Up @@ -52,8 +52,8 @@ static void walkFunctionForProfiling(AbstractFunctionDecl *Root,

// We treat class initializers as part of the constructor for profiling.
if (auto *CD = dyn_cast<ConstructorDecl>(Root)) {
auto *NominalType = CD->getDeclContext()
->getAsNominalTypeOrNominalTypeExtensionContext();
auto *NominalType =
CD->getDeclContext()->getAsNominalTypeOrNominalTypeExtensionContext();
for (auto *Member : NominalType->getMembers()) {
// Find pattern binding declarations that have initializers.
if (auto *PBD = dyn_cast<PatternBindingDecl>(Member))
Expand Down Expand Up @@ -160,8 +160,7 @@ class CounterExpr {
assert(K == Kind::Node && "only valid for Node");
}

CounterExpr(Kind K, const CounterExpr &LHS)
: K(K), LHS(&LHS) {
CounterExpr(Kind K, const CounterExpr &LHS) : K(K), LHS(&LHS) {
assert((K == Kind::Ref) && "only valid for Ref");
}

Expand Down Expand Up @@ -281,9 +280,9 @@ struct PGOMapping : public ASTWalker {

PGOMapping(llvm::DenseMap<ASTNode, ProfileCounter> &LoadedCounterMap,
llvm::Expected<llvm::InstrProfRecord> &LoadedCounts,
llvm::DenseMap<ASTNode, ASTNode> &PGORegionCondToParentMap)
llvm::DenseMap<ASTNode, ASTNode> &RegionCondToParentMap)
: NextCounter(0), LoadedCounterMap(LoadedCounterMap),
LoadedCounts(LoadedCounts), CondToParentMap(PGORegionCondToParentMap) {}
LoadedCounts(LoadedCounts), CondToParentMap(RegionCondToParentMap) {}

unsigned getParentCounter() const {
if (Parent.isNull())
Expand Down Expand Up @@ -575,7 +574,6 @@ struct CoverageMapping : public ASTWalker {
if (ControlFlowAdjust)
Count = &createCounter(CounterExpr::Sub(*Count, *ControlFlowAdjust));

//RegionStack.emplace_back(ASTNode(), *Count, getEndLoc(Scope), None);
RegionStack.emplace_back(ASTNode(), *Count, getEndLoc(Scope), None);
}

Expand Down Expand Up @@ -766,7 +764,7 @@ struct CoverageMapping : public ASTWalker {

} else if (auto *RWS = dyn_cast<RepeatWhileStmt>(S)) {
assert(RepeatWhileStack.back() == RWS && "Malformed repeat-while stack");
(void) RWS;
(void)RWS;
RepeatWhileStack.pop_back();

} else if (auto *CS = dyn_cast<ContinueStmt>(S)) {
Expand Down Expand Up @@ -845,7 +843,6 @@ struct CoverageMapping : public ASTWalker {

return E;
}

};

} // end anonymous namespace
Expand Down Expand Up @@ -896,7 +893,7 @@ void SILProfiler::assignRegionCounters() {

NumRegionCounters = Mapper.NextCounter;
// TODO: Mapper needs to calculate a function hash as it goes.
FunctionHash = 0x0;
PGOFuncHash = 0x0;

if (EmitCoverageMapping) {
CoverageMapping Coverage(SM);
Expand All @@ -905,11 +902,11 @@ void SILProfiler::assignRegionCounters() {
M, CurrentFuncName,
!llvm::GlobalValue::isLocalLinkage(
getEquivalentPGOLinkage(CurrentFuncLinkage)),
FunctionHash, RegionCounterMap, CurrentFileName);
PGOFuncHash, RegionCounterMap, CurrentFileName);
}

if (llvm::IndexedInstrProfReader *IPR = M.getPGOReader()) {
auto LoadedCounts = IPR->getInstrProfRecord(PGOFuncName, FunctionHash);
auto LoadedCounts = IPR->getInstrProfRecord(PGOFuncName, PGOFuncHash);
if (auto E = LoadedCounts.takeError()) {
llvm::handleAllErrors(std::move(E), [](const llvm::InstrProfError &Err) {
Err.log(llvm::dbgs());
Expand All @@ -918,8 +915,8 @@ void SILProfiler::assignRegionCounters() {
llvm::dbgs() << PGOFuncName << "\n";
return;
}
PGOMapping pgoMapper(PGORegionLoadedCounterMap, LoadedCounts,
PGORegionCondToParentMap);
PGOMapping pgoMapper(RegionLoadedCounterMap, LoadedCounts,
RegionCondToParentMap);
walkForProfiling(Root, pgoMapper);
}
}
Expand All @@ -928,8 +925,8 @@ ProfileCounter SILProfiler::getExecutionCount(ASTNode Node) {
if (!Node || !M.getPGOReader() || !hasRegionCounters()) {
return ProfileCounter();
}
auto it = PGORegionLoadedCounterMap.find(Node);
if (it == PGORegionLoadedCounterMap.end()) {
auto it = RegionLoadedCounterMap.find(Node);
if (it == RegionLoadedCounterMap.end()) {
return ProfileCounter();
}
return it->getSecond();
Expand All @@ -939,8 +936,8 @@ Optional<ASTNode> SILProfiler::getPGOParent(ASTNode Node) {
if (!Node || !M.getPGOReader() || !hasRegionCounters()) {
return None;
}
auto it = PGORegionCondToParentMap.find(Node);
if (it == PGORegionCondToParentMap.end()) {
auto it = RegionCondToParentMap.find(Node);
if (it == RegionCondToParentMap.end()) {
return None;
}
return it->getSecond();
Expand Down