Skip to content

Commit e875efa

Browse files
committed
[Coverage] Clean up a few classes, NFC
Run clang-format, delete some dead code, and fix a few naming inconsistencies.
1 parent c7e05cb commit e875efa

File tree

4 files changed

+28
-44
lines changed

4 files changed

+28
-44
lines changed

include/swift/SIL/SILCoverageMap.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222
#include "swift/SIL/SILAllocated.h"
2323
#include "swift/SIL/SILFunction.h"
2424
#include "swift/SIL/SILPrintContext.h"
25-
#include "llvm/ADT/ilist_node.h"
2625
#include "llvm/ADT/ilist.h"
26+
#include "llvm/ADT/ilist_node.h"
2727
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
2828

2929
namespace llvm {
3030
namespace coverage {
3131
struct CounterExpression;
3232
struct Counter;
33-
}
34-
}
33+
} // namespace coverage
34+
} // namespace llvm
3535

3636
namespace swift {
3737

@@ -133,7 +133,7 @@ class SILCoverageMap : public llvm::ilist_node<SILCoverageMap>,
133133
void dump() const;
134134
};
135135

136-
} // end swift namespace
136+
} // namespace swift
137137

138138
namespace llvm {
139139

@@ -142,8 +142,8 @@ namespace llvm {
142142
//===----------------------------------------------------------------------===//
143143

144144
template <>
145-
struct ilist_traits<::swift::SILCoverageMap> :
146-
public ilist_default_traits<::swift::SILCoverageMap> {
145+
struct ilist_traits<::swift::SILCoverageMap>
146+
: public ilist_default_traits<::swift::SILCoverageMap> {
147147
typedef ::swift::SILCoverageMap SILCoverageMap;
148148

149149
public:
@@ -153,6 +153,6 @@ public ilist_default_traits<::swift::SILCoverageMap> {
153153
void createNode(const SILCoverageMap &);
154154
};
155155

156-
} // end llvm namespace
156+
} // namespace llvm
157157

158158
#endif // SWIFT_SIL_SILCOVERAGEMAP_H

include/swift/SIL/SILModule.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -453,20 +453,6 @@ class SILModule {
453453
using coverage_map_const_iterator = CoverageMapListType::const_iterator;
454454
CoverageMapListType &getCoverageMapList() { return coverageMaps; }
455455
const CoverageMapListType &getCoverageMapList() const { return coverageMaps; }
456-
coverage_map_iterator coverage_map_begin() { return coverageMaps.begin(); }
457-
coverage_map_iterator coverage_map_end() { return coverageMaps.end(); }
458-
coverage_map_const_iterator coverage_map_begin() const {
459-
return coverageMaps.begin();
460-
}
461-
coverage_map_const_iterator coverage_map_end() const {
462-
return coverageMaps.end();
463-
}
464-
iterator_range<coverage_map_iterator> getCoverageMaps() {
465-
return {coverageMaps.begin(), coverageMaps.end()};
466-
}
467-
iterator_range<coverage_map_const_iterator> getCoverageMaps() const {
468-
return {coverageMaps.begin(), coverageMaps.end()};
469-
}
470456

471457
llvm::yaml::Output *getOptRecordStream() { return OptRecordStream.get(); }
472458
void setOptRecordStream(std::unique_ptr<llvm::yaml::Output> &&Stream,

include/swift/SIL/SILProfiler.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/AST/Stmt.h"
2323
#include "swift/Basic/ProfileCounter.h"
2424
#include "swift/SIL/FormalLinkage.h"
25+
#include "swift/SIL/SILAllocated.h"
2526
#include "llvm/ADT/DenseMap.h"
2627

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

4647
std::string PGOFuncName;
4748

48-
uint64_t FunctionHash = 0;
49+
uint64_t PGOFuncHash = 0;
4950

5051
unsigned NumRegionCounters = 0;
5152

5253
llvm::DenseMap<ASTNode, unsigned> RegionCounterMap;
5354

54-
llvm::DenseMap<ASTNode, ProfileCounter> PGORegionLoadedCounterMap;
55+
llvm::DenseMap<ASTNode, ProfileCounter> RegionLoadedCounterMap;
5556

56-
llvm::DenseMap<ASTNode, ASTNode> PGORegionCondToParentMap;
57+
llvm::DenseMap<ASTNode, ASTNode> RegionCondToParentMap;
5758

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

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

8081
/// Get the function hash.
81-
uint64_t getPGOFuncHash() const { return FunctionHash; }
82+
uint64_t getPGOFuncHash() const { return PGOFuncHash; }
8283

8384
/// Get the number of region counters.
8485
unsigned getNumRegionCounters() const { return NumRegionCounters; }

lib/SIL/SILProfiler.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "swift/SIL/SILProfiler.h"
1314
#include "swift/AST/ASTWalker.h"
1415
#include "swift/AST/Decl.h"
1516
#include "swift/Parse/Lexer.h"
1617
#include "swift/SIL/SILModule.h"
17-
#include "swift/SIL/SILProfiler.h"
1818
#include "llvm/IR/GlobalValue.h"
1919
#include "llvm/IR/Intrinsics.h"
2020
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
@@ -52,8 +52,8 @@ static void walkFunctionForProfiling(AbstractFunctionDecl *Root,
5252

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

163-
CounterExpr(Kind K, const CounterExpr &LHS)
164-
: K(K), LHS(&LHS) {
163+
CounterExpr(Kind K, const CounterExpr &LHS) : K(K), LHS(&LHS) {
165164
assert((K == Kind::Ref) && "only valid for Ref");
166165
}
167166

@@ -281,9 +280,9 @@ struct PGOMapping : public ASTWalker {
281280

282281
PGOMapping(llvm::DenseMap<ASTNode, ProfileCounter> &LoadedCounterMap,
283282
llvm::Expected<llvm::InstrProfRecord> &LoadedCounts,
284-
llvm::DenseMap<ASTNode, ASTNode> &PGORegionCondToParentMap)
283+
llvm::DenseMap<ASTNode, ASTNode> &RegionCondToParentMap)
285284
: NextCounter(0), LoadedCounterMap(LoadedCounterMap),
286-
LoadedCounts(LoadedCounts), CondToParentMap(PGORegionCondToParentMap) {}
285+
LoadedCounts(LoadedCounts), CondToParentMap(RegionCondToParentMap) {}
287286

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

578-
//RegionStack.emplace_back(ASTNode(), *Count, getEndLoc(Scope), None);
579577
RegionStack.emplace_back(ASTNode(), *Count, getEndLoc(Scope), None);
580578
}
581579

@@ -766,7 +764,7 @@ struct CoverageMapping : public ASTWalker {
766764

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

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

846844
return E;
847845
}
848-
849846
};
850847

851848
} // end anonymous namespace
@@ -896,7 +893,7 @@ void SILProfiler::assignRegionCounters() {
896893

897894
NumRegionCounters = Mapper.NextCounter;
898895
// TODO: Mapper needs to calculate a function hash as it goes.
899-
FunctionHash = 0x0;
896+
PGOFuncHash = 0x0;
900897

901898
if (EmitCoverageMapping) {
902899
CoverageMapping Coverage(SM);
@@ -905,11 +902,11 @@ void SILProfiler::assignRegionCounters() {
905902
M, CurrentFuncName,
906903
!llvm::GlobalValue::isLocalLinkage(
907904
getEquivalentPGOLinkage(CurrentFuncLinkage)),
908-
FunctionHash, RegionCounterMap, CurrentFileName);
905+
PGOFuncHash, RegionCounterMap, CurrentFileName);
909906
}
910907

911908
if (llvm::IndexedInstrProfReader *IPR = M.getPGOReader()) {
912-
auto LoadedCounts = IPR->getInstrProfRecord(PGOFuncName, FunctionHash);
909+
auto LoadedCounts = IPR->getInstrProfRecord(PGOFuncName, PGOFuncHash);
913910
if (auto E = LoadedCounts.takeError()) {
914911
llvm::handleAllErrors(std::move(E), [](const llvm::InstrProfError &Err) {
915912
Err.log(llvm::dbgs());
@@ -918,8 +915,8 @@ void SILProfiler::assignRegionCounters() {
918915
llvm::dbgs() << PGOFuncName << "\n";
919916
return;
920917
}
921-
PGOMapping pgoMapper(PGORegionLoadedCounterMap, LoadedCounts,
922-
PGORegionCondToParentMap);
918+
PGOMapping pgoMapper(RegionLoadedCounterMap, LoadedCounts,
919+
RegionCondToParentMap);
923920
walkForProfiling(Root, pgoMapper);
924921
}
925922
}
@@ -928,8 +925,8 @@ ProfileCounter SILProfiler::getExecutionCount(ASTNode Node) {
928925
if (!Node || !M.getPGOReader() || !hasRegionCounters()) {
929926
return ProfileCounter();
930927
}
931-
auto it = PGORegionLoadedCounterMap.find(Node);
932-
if (it == PGORegionLoadedCounterMap.end()) {
928+
auto it = RegionLoadedCounterMap.find(Node);
929+
if (it == RegionLoadedCounterMap.end()) {
933930
return ProfileCounter();
934931
}
935932
return it->getSecond();
@@ -939,8 +936,8 @@ Optional<ASTNode> SILProfiler::getPGOParent(ASTNode Node) {
939936
if (!Node || !M.getPGOReader() || !hasRegionCounters()) {
940937
return None;
941938
}
942-
auto it = PGORegionCondToParentMap.find(Node);
943-
if (it == PGORegionCondToParentMap.end()) {
939+
auto it = RegionCondToParentMap.find(Node);
940+
if (it == RegionCondToParentMap.end()) {
944941
return None;
945942
}
946943
return it->getSecond();

0 commit comments

Comments
 (0)