Skip to content

Commit 78d993a

Browse files
authored
Merge pull request #13709 from apple/revert-13705-master
Revert "[Coverage] Clean up a few classes, NFC"
2 parents 38be0b7 + 7c49bc9 commit 78d993a

File tree

4 files changed

+44
-28
lines changed

4 files changed

+44
-28
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.h"
2625
#include "llvm/ADT/ilist_node.h"
26+
#include "llvm/ADT/ilist.h"
2727
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
2828

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

3636
namespace swift {
3737

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

136-
} // namespace swift
136+
} // end swift namespace
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 @@ struct ilist_traits<::swift::SILCoverageMap>
153153
void createNode(const SILCoverageMap &);
154154
};
155155

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

158158
#endif // SWIFT_SIL_SILCOVERAGEMAP_H

include/swift/SIL/SILModule.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,20 @@ 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+
}
456470

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

include/swift/SIL/SILProfiler.h

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

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

4746
std::string PGOFuncName;
4847

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

5150
unsigned NumRegionCounters = 0;
5251

5352
llvm::DenseMap<ASTNode, unsigned> RegionCounterMap;
5453

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

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

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

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

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

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

lib/SIL/SILProfiler.cpp

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

13-
#include "swift/SIL/SILProfiler.h"
1413
#include "swift/AST/ASTWalker.h"
1514
#include "swift/AST/Decl.h"
1615
#include "swift/Parse/Lexer.h"
1716
#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 =
56-
CD->getDeclContext()->getAsNominalTypeOrNominalTypeExtensionContext();
55+
auto *NominalType = CD->getDeclContext()
56+
->getAsNominalTypeOrNominalTypeExtensionContext();
5757
for (auto *Member : NominalType->getMembers()) {
5858
// Find pattern binding declarations that have initializers.
5959
if (auto *PBD = dyn_cast<PatternBindingDecl>(Member))
@@ -160,7 +160,8 @@ class CounterExpr {
160160
assert(K == Kind::Node && "only valid for Node");
161161
}
162162

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

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

281282
PGOMapping(llvm::DenseMap<ASTNode, ProfileCounter> &LoadedCounterMap,
282283
llvm::Expected<llvm::InstrProfRecord> &LoadedCounts,
283-
llvm::DenseMap<ASTNode, ASTNode> &RegionCondToParentMap)
284+
llvm::DenseMap<ASTNode, ASTNode> &PGORegionCondToParentMap)
284285
: NextCounter(0), LoadedCounterMap(LoadedCounterMap),
285-
LoadedCounts(LoadedCounts), CondToParentMap(RegionCondToParentMap) {}
286+
LoadedCounts(LoadedCounts), CondToParentMap(PGORegionCondToParentMap) {}
286287

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

578+
//RegionStack.emplace_back(ASTNode(), *Count, getEndLoc(Scope), None);
577579
RegionStack.emplace_back(ASTNode(), *Count, getEndLoc(Scope), None);
578580
}
579581

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

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

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

844846
return E;
845847
}
848+
846849
};
847850

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

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

898901
if (EmitCoverageMapping) {
899902
CoverageMapping Coverage(SM);
@@ -902,11 +905,11 @@ void SILProfiler::assignRegionCounters() {
902905
M, CurrentFuncName,
903906
!llvm::GlobalValue::isLocalLinkage(
904907
getEquivalentPGOLinkage(CurrentFuncLinkage)),
905-
PGOFuncHash, RegionCounterMap, CurrentFileName);
908+
FunctionHash, RegionCounterMap, CurrentFileName);
906909
}
907910

908911
if (llvm::IndexedInstrProfReader *IPR = M.getPGOReader()) {
909-
auto LoadedCounts = IPR->getInstrProfRecord(PGOFuncName, PGOFuncHash);
912+
auto LoadedCounts = IPR->getInstrProfRecord(PGOFuncName, FunctionHash);
910913
if (auto E = LoadedCounts.takeError()) {
911914
llvm::handleAllErrors(std::move(E), [](const llvm::InstrProfError &Err) {
912915
Err.log(llvm::dbgs());
@@ -915,8 +918,8 @@ void SILProfiler::assignRegionCounters() {
915918
llvm::dbgs() << PGOFuncName << "\n";
916919
return;
917920
}
918-
PGOMapping pgoMapper(RegionLoadedCounterMap, LoadedCounts,
919-
RegionCondToParentMap);
921+
PGOMapping pgoMapper(PGORegionLoadedCounterMap, LoadedCounts,
922+
PGORegionCondToParentMap);
920923
walkForProfiling(Root, pgoMapper);
921924
}
922925
}
@@ -925,8 +928,8 @@ ProfileCounter SILProfiler::getExecutionCount(ASTNode Node) {
925928
if (!Node || !M.getPGOReader() || !hasRegionCounters()) {
926929
return ProfileCounter();
927930
}
928-
auto it = RegionLoadedCounterMap.find(Node);
929-
if (it == RegionLoadedCounterMap.end()) {
931+
auto it = PGORegionLoadedCounterMap.find(Node);
932+
if (it == PGORegionLoadedCounterMap.end()) {
930933
return ProfileCounter();
931934
}
932935
return it->getSecond();
@@ -936,8 +939,8 @@ Optional<ASTNode> SILProfiler::getPGOParent(ASTNode Node) {
936939
if (!Node || !M.getPGOReader() || !hasRegionCounters()) {
937940
return None;
938941
}
939-
auto it = RegionCondToParentMap.find(Node);
940-
if (it == RegionCondToParentMap.end()) {
942+
auto it = PGORegionCondToParentMap.find(Node);
943+
if (it == PGORegionCondToParentMap.end()) {
941944
return None;
942945
}
943946
return it->getSecond();

0 commit comments

Comments
 (0)