10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
13
+ #include " swift/SIL/SILProfiler.h"
13
14
#include " swift/AST/ASTWalker.h"
14
15
#include " swift/AST/Decl.h"
15
16
#include " swift/Parse/Lexer.h"
16
17
#include " swift/SIL/SILModule.h"
17
- #include " swift/SIL/SILProfiler.h"
18
18
#include " llvm/IR/GlobalValue.h"
19
19
#include " llvm/IR/Intrinsics.h"
20
20
#include " llvm/ProfileData/Coverage/CoverageMapping.h"
@@ -52,8 +52,8 @@ static void walkFunctionForProfiling(AbstractFunctionDecl *Root,
52
52
53
53
// We treat class initializers as part of the constructor for profiling.
54
54
if (auto *CD = dyn_cast<ConstructorDecl>(Root)) {
55
- auto *NominalType = CD-> getDeclContext ()
56
- ->getAsNominalTypeOrNominalTypeExtensionContext ();
55
+ auto *NominalType =
56
+ CD-> getDeclContext () ->getAsNominalTypeOrNominalTypeExtensionContext ();
57
57
for (auto *Member : NominalType->getMembers ()) {
58
58
// Find pattern binding declarations that have initializers.
59
59
if (auto *PBD = dyn_cast<PatternBindingDecl>(Member))
@@ -160,8 +160,7 @@ class CounterExpr {
160
160
assert (K == Kind::Node && " only valid for Node" );
161
161
}
162
162
163
- CounterExpr (Kind K, const CounterExpr &LHS)
164
- : K(K), LHS(&LHS) {
163
+ CounterExpr (Kind K, const CounterExpr &LHS) : K(K), LHS(&LHS) {
165
164
assert ((K == Kind::Ref) && " only valid for Ref" );
166
165
}
167
166
@@ -281,9 +280,9 @@ struct PGOMapping : public ASTWalker {
281
280
282
281
PGOMapping (llvm::DenseMap<ASTNode, ProfileCounter> &LoadedCounterMap,
283
282
llvm::Expected<llvm::InstrProfRecord> &LoadedCounts,
284
- llvm::DenseMap<ASTNode, ASTNode> &PGORegionCondToParentMap )
283
+ llvm::DenseMap<ASTNode, ASTNode> &RegionCondToParentMap )
285
284
: NextCounter(0 ), LoadedCounterMap(LoadedCounterMap),
286
- LoadedCounts (LoadedCounts), CondToParentMap(PGORegionCondToParentMap ) {}
285
+ LoadedCounts (LoadedCounts), CondToParentMap(RegionCondToParentMap ) {}
287
286
288
287
unsigned getParentCounter () const {
289
288
if (Parent.isNull ())
@@ -575,7 +574,6 @@ struct CoverageMapping : public ASTWalker {
575
574
if (ControlFlowAdjust)
576
575
Count = &createCounter (CounterExpr::Sub (*Count, *ControlFlowAdjust));
577
576
578
- // RegionStack.emplace_back(ASTNode(), *Count, getEndLoc(Scope), None);
579
577
RegionStack.emplace_back (ASTNode (), *Count, getEndLoc (Scope), None);
580
578
}
581
579
@@ -766,7 +764,7 @@ struct CoverageMapping : public ASTWalker {
766
764
767
765
} else if (auto *RWS = dyn_cast<RepeatWhileStmt>(S)) {
768
766
assert (RepeatWhileStack.back () == RWS && " Malformed repeat-while stack" );
769
- (void ) RWS;
767
+ (void )RWS;
770
768
RepeatWhileStack.pop_back ();
771
769
772
770
} else if (auto *CS = dyn_cast<ContinueStmt>(S)) {
@@ -845,7 +843,6 @@ struct CoverageMapping : public ASTWalker {
845
843
846
844
return E;
847
845
}
848
-
849
846
};
850
847
851
848
} // end anonymous namespace
@@ -896,7 +893,7 @@ void SILProfiler::assignRegionCounters() {
896
893
897
894
NumRegionCounters = Mapper.NextCounter ;
898
895
// TODO: Mapper needs to calculate a function hash as it goes.
899
- FunctionHash = 0x0 ;
896
+ PGOFuncHash = 0x0 ;
900
897
901
898
if (EmitCoverageMapping) {
902
899
CoverageMapping Coverage (SM);
@@ -905,11 +902,11 @@ void SILProfiler::assignRegionCounters() {
905
902
M, CurrentFuncName,
906
903
!llvm::GlobalValue::isLocalLinkage (
907
904
getEquivalentPGOLinkage (CurrentFuncLinkage)),
908
- FunctionHash , RegionCounterMap, CurrentFileName);
905
+ PGOFuncHash , RegionCounterMap, CurrentFileName);
909
906
}
910
907
911
908
if (llvm::IndexedInstrProfReader *IPR = M.getPGOReader ()) {
912
- auto LoadedCounts = IPR->getInstrProfRecord (PGOFuncName, FunctionHash );
909
+ auto LoadedCounts = IPR->getInstrProfRecord (PGOFuncName, PGOFuncHash );
913
910
if (auto E = LoadedCounts.takeError ()) {
914
911
llvm::handleAllErrors (std::move (E), [](const llvm::InstrProfError &Err) {
915
912
Err.log (llvm::dbgs ());
@@ -918,8 +915,8 @@ void SILProfiler::assignRegionCounters() {
918
915
llvm::dbgs () << PGOFuncName << " \n " ;
919
916
return ;
920
917
}
921
- PGOMapping pgoMapper (PGORegionLoadedCounterMap , LoadedCounts,
922
- PGORegionCondToParentMap );
918
+ PGOMapping pgoMapper (RegionLoadedCounterMap , LoadedCounts,
919
+ RegionCondToParentMap );
923
920
walkForProfiling (Root, pgoMapper);
924
921
}
925
922
}
@@ -928,8 +925,8 @@ ProfileCounter SILProfiler::getExecutionCount(ASTNode Node) {
928
925
if (!Node || !M.getPGOReader () || !hasRegionCounters ()) {
929
926
return ProfileCounter ();
930
927
}
931
- auto it = PGORegionLoadedCounterMap .find (Node);
932
- if (it == PGORegionLoadedCounterMap .end ()) {
928
+ auto it = RegionLoadedCounterMap .find (Node);
929
+ if (it == RegionLoadedCounterMap .end ()) {
933
930
return ProfileCounter ();
934
931
}
935
932
return it->getSecond ();
@@ -939,8 +936,8 @@ Optional<ASTNode> SILProfiler::getPGOParent(ASTNode Node) {
939
936
if (!Node || !M.getPGOReader () || !hasRegionCounters ()) {
940
937
return None;
941
938
}
942
- auto it = PGORegionCondToParentMap .find (Node);
943
- if (it == PGORegionCondToParentMap .end ()) {
939
+ auto it = RegionCondToParentMap .find (Node);
940
+ if (it == RegionCondToParentMap .end ()) {
944
941
return None;
945
942
}
946
943
return it->getSecond ();
0 commit comments