|
| 1 | +//===---------- TypeExpansionAnalysis.cpp - Type Expansion Analysis -------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See http://swift.org/LICENSE.txt for license information |
| 9 | +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#define DEBUG_TYPE "typeexpansion-analysis" |
1 | 14 | #include "swift/SILAnalysis/TypeExpansionAnalysis.h"
|
2 | 15 | #include "swift/SIL/SILInstruction.h"
|
3 | 16 | #include "swift/SIL/SILModule.h"
|
4 | 17 | #include "llvm/Support/Debug.h"
|
5 | 18 |
|
6 |
| -#define DEBUG_TYPE "typeexpansion-analysis" |
7 |
| - |
8 | 19 | using namespace swift;
|
9 | 20 |
|
10 |
| -// The MemoryBehavior Cache must not grow beyond this size. |
| 21 | +// The TypeExpansion Cache must not grow beyond this size. |
11 | 22 | // We limit the size of the MB cache to 2**12 because we want to limit the
|
12 | 23 | // memory usage of this cache.
|
13 | 24 | static const int TypeExpansionAnalysisMaxCacheSize = 4096;
|
14 | 25 |
|
15 |
| -const ProjectionPathList & |
16 |
| -TypeExpansionAnalysis::getTypeLeafExpansion(SILType B, SILModule *Mod) { |
| 26 | +const ProjectionPathList & |
| 27 | +TypeExpansionAnalysis::getTypeExpansionProjectionPaths(SILType B, SILModule *Mod, |
| 28 | + TEKind Kind) { |
| 29 | + // Which cache we should be looking up. |
| 30 | + bool IsLeaf = Kind == TEKind::TELeaf; |
| 31 | + TypeExpansionMap &Cache = IsLeaf ? TELeafCache : TENodeCache; |
| 32 | + |
17 | 33 | // Check whether we have the type expansion.
|
18 |
| - if (LeafTECache.find(B) != LeafTECache.end()) { |
19 |
| - return LeafTECache.find(B)->second; |
| 34 | + auto Iter = Cache.find(B); |
| 35 | + if (Iter != Cache.end()) { |
| 36 | + return Iter->second; |
20 | 37 | }
|
21 | 38 |
|
22 | 39 | // Flush the cache if the size of the cache is too large.
|
23 |
| - if (LeafTECache.size() > TypeExpansionAnalysisMaxCacheSize) { |
24 |
| - LeafTECache.clear(); |
| 40 | + if (Cache.size() > TypeExpansionAnalysisMaxCacheSize) { |
| 41 | + Cache.clear(); |
25 | 42 | }
|
26 | 43 |
|
27 |
| - // Need to build the type expansion. |
28 |
| - LeafTECache[B] = ProjectionPathList(); |
29 |
| - ProjectionPath::expandTypeIntoLeafProjectionPaths(B, Mod, LeafTECache[B]); |
30 |
| - return LeafTECache[B]; |
31 |
| -} |
32 |
| - |
33 |
| -const ProjectionPathList & |
34 |
| -TypeExpansionAnalysis::getTypeNodeExpansion(SILType B, SILModule *Mod) { |
35 |
| - // Check whether we have the type expansion. |
36 |
| - if (NodeTECache.find(B) != NodeTECache.end()) { |
37 |
| - return NodeTECache.find(B)->second; |
38 |
| - } |
39 |
| - |
40 |
| - // Flush the cache if the size of the cache is too large. |
41 |
| - if (NodeTECache.size() > TypeExpansionAnalysisMaxCacheSize) { |
42 |
| - NodeTECache.clear(); |
| 44 | + // Build the type expansion for the leaf nodes. |
| 45 | + if (IsLeaf) { |
| 46 | + ProjectionPath::expandTypeIntoLeafProjectionPaths(B, Mod, Cache[B]); |
| 47 | + return Cache[B]; |
43 | 48 | }
|
44 | 49 |
|
45 |
| - // Need to build the type expansion. |
46 |
| - NodeTECache[B] = ProjectionPathList(); |
47 |
| - ProjectionPath::expandTypeIntoNodeProjectionPaths(B, Mod, NodeTECache[B]); |
48 |
| - return NodeTECache[B]; |
| 50 | + // Build the type expansion for the internal and leaf nodes. |
| 51 | + ProjectionPath::expandTypeIntoNodeProjectionPaths(B, Mod, Cache[B]); |
| 52 | + return Cache[B]; |
49 | 53 | }
|
50 | 54 |
|
51 | 55 | SILAnalysis *swift::createTypeExpansionAnalysis(SILModule *M) {
|
|
0 commit comments