3 * Copyright © 2016 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 #ifndef BRW_IR_ANALYSIS_H
26 #define BRW_IR_ANALYSIS_H
30 * Bitset of state categories that can influence the result of IR analysis
33 enum analysis_dependency_class
{
35 * The analysis doesn't depend on the IR, its result is effectively a
36 * constant during the compilation.
38 DEPENDENCY_NOTHING
= 0,
40 * The analysis depends on the program being literally the same (good
41 * luck...), any change in the input invalidates previous analysis
44 DEPENDENCY_EVERYTHING
= ~0
47 inline analysis_dependency_class
48 operator|(analysis_dependency_class x
, analysis_dependency_class y
)
50 return static_cast<analysis_dependency_class
>(
51 static_cast<unsigned>(x
) | static_cast<unsigned>(y
));
56 * Instantiate a program analysis class \p L which can calculate an object of
57 * type \p T as result. \p C is a closure that encapsulates whatever
58 * information is required as argument to run the analysis pass. The purpose
59 * of this class is to make sure that:
61 * - The analysis pass is executed lazily whenever it's needed and multiple
62 * executions are optimized out as long as the cached result remains marked
65 * - There is no way to access the cached analysis result without first
66 * calling L::require(), which makes sure that the analysis pass is rerun
69 * - The cached result doesn't become inconsistent with the program for as
70 * long as it remains marked up-to-date. (This is only enforced in debug
71 * builds for performance reasons)
73 * The requirements on \p T are the following:
75 * - Constructible with a single argument, as in 'x = T(c)' for \p c of type
78 * - 'x.dependency_class()' on const \p x returns a bitset of
79 * brw::analysis_dependency_class specifying the set of IR objects that are
80 * required to remain invariant for the cached analysis result to be
83 * - 'x.validate(c)' on const \p x returns a boolean result specifying
84 * whether the analysis result \p x is consistent with the input IR. This
85 * is currently only used for validation in debug builds.
87 #define BRW_ANALYSIS(L, T, C) \
91 * Construct a program analysis. \p c is an arbitrary object \
92 * passed as argument to the constructor of the analysis result \
93 * object of type \p T. \
95 L(C const &c) : c(c), p(NULL) {} \
98 * Destroy a program analysis. \
106 * Obtain the result of a program analysis. This gives a \
107 * guaranteed up-to-date result, the analysis pass will be \
108 * rerun implicitly if it has become stale. \
114 assert(p->validate(c)); \
124 return const_cast<L *>(this)->require(); \
128 * Report that dependencies of the analysis pass may have changed \
129 * since the last calculation and the cached analysis result may \
130 * have to be discarded. \
133 invalidate(brw::analysis_dependency_class c) \
135 if (p && c & p->dependency_class()) { \