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