1// Copyright 2020 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5const UNCLASSIFIED_CATEGORY = 'unclassified';
6const UNCLASSIFIED_CATEGORY_NAME = 'Unclassified';
7
8// Categories for zones.
9export const CATEGORIES = new Map([
10  [
11    'parser', new Set([
12      'AstStringConstants',
13      'parser-zone',
14      'pre-parser-zone',
15    ])
16  ],
17  [
18    'misc', new Set([
19      'Run',
20      'CanonicalHandleScope',
21      'Temporary scoped zone',
22      'UpdateFieldType',
23    ])
24  ],
25  [
26    'interpreter', new Set([
27      'InterpreterCompilationJob',
28    ])
29  ],
30  [
31    'regexp', new Set([
32      'CompileIrregexp',
33    ])
34  ],
35  [
36    'compiler-huge', new Set([
37      'graph-zone',
38      'instruction-zone',
39      'pipeline-compilation-job-zone',
40      'register-allocation-zone',
41      'register-allocator-verifier-zone',
42    ])
43  ],
44  [
45    'compiler-other', new Set([
46      'Compile',
47      'V8.TFAllocateFPRegisters',
48      'V8.TFAllocateGeneralRegisters',
49      'V8.TFAssembleCode',
50      'V8.TFAssignSpillSlots',
51      'V8.TFBuildLiveRangeBundles',
52      'V8.TFBuildLiveRanges',
53      'V8.TFBytecodeGraphBuilder',
54      'V8.TFCommitAssignment',
55      'V8.TFConnectRanges',
56      'V8.TFControlFlowOptimization',
57      'V8.TFDecideSpillingMode',
58      'V8.TFDecompressionOptimization',
59      'V8.TFEarlyOptimization',
60      'V8.TFEarlyTrimming',
61      'V8.TFEffectLinearization',
62      'V8.TFEscapeAnalysis',
63      'V8.TFFinalizeCode',
64      'V8.TFFrameElision',
65      'V8.TFGenericLowering',
66      'V8.TFHeapBrokerInitialization',
67      'V8.TFInlining',
68      'V8.TFJumpThreading',
69      'V8.TFLateGraphTrimming',
70      'V8.TFLateOptimization',
71      'V8.TFLoadElimination',
72      'V8.TFLocateSpillSlots',
73      'V8.TFLoopPeeling',
74      'V8.TFMachineOperatorOptimization',
75      'V8.TFMeetRegisterConstraints',
76      'V8.TFMemoryOptimization',
77      'V8.TFOptimizeMoves',
78      'V8.TFPopulatePointerMaps',
79      'V8.TFResolveControlFlow',
80      'V8.TFResolvePhis',
81      'V8.TFScheduling',
82      'V8.TFSelectInstructions',
83      'V8.TFSerializeMetadata',
84      'V8.TFSimplifiedLowering',
85      'V8.TFStoreStoreElimination',
86      'V8.TFTypedLowering',
87      'V8.TFTyper',
88      'V8.TFUntyper',
89      'V8.TFVerifyGraph',
90      'ValidatePendingAssessment',
91      'codegen-zone',
92    ])
93  ],
94  [UNCLASSIFIED_CATEGORY, new Set()],
95]);
96
97// Maps category to description text that is shown in html.
98export const CATEGORY_NAMES = new Map([
99  ['parser', 'Parser'],
100  ['misc', 'Misc'],
101  ['interpreter', 'Ignition'],
102  ['regexp', 'Regexp compiler'],
103  ['compiler-huge', 'TurboFan (huge zones)'],
104  ['compiler-other', 'TurboFan (other zones)'],
105  [UNCLASSIFIED_CATEGORY, UNCLASSIFIED_CATEGORY_NAME],
106]);
107
108function buildZoneToCategoryMap() {
109  const map = new Map();
110  for (let [category, zone_names] of CATEGORIES.entries()) {
111    for (let zone_name of zone_names) {
112      if (map.has(zone_name)) {
113        console.error("Zone belongs to multiple categories: " + zone_name);
114      } else {
115        map.set(zone_name, category);
116      }
117    }
118  }
119  return map;
120}
121
122const CATEGORY_BY_ZONE = buildZoneToCategoryMap();
123
124// Maps zone name to category.
125export function categoryByZoneName(zone_name) {
126  const category = CATEGORY_BY_ZONE.get(zone_name);
127  if (category !== undefined) return category;
128  return UNCLASSIFIED_CATEGORY;
129}
130