intel/compiler: use C++ template instead of preprocessor

Signed-off-by: Marcin Ślusarz <marcin.slusarz@intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
Acked-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7382>
This commit is contained in:
Marcin Ślusarz
2020-10-29 20:13:50 +01:00
committed by Marge Bot
parent 788f6dc857
commit 06764e0e5d
4 changed files with 63 additions and 69 deletions

View File

@@ -343,12 +343,9 @@ public:
const struct brw_vue_map *input_vue_map;
BRW_ANALYSIS(live_analysis, brw::fs_live_variables,
backend_shader *) live_analysis;
BRW_ANALYSIS(regpressure_analysis, brw::register_pressure,
fs_visitor *) regpressure_analysis;
BRW_ANALYSIS(performance_analysis, brw::performance,
fs_visitor *) performance_analysis;
brw_analysis<brw::fs_live_variables, backend_shader> live_analysis;
brw_analysis<brw::register_pressure, fs_visitor> regpressure_analysis;
brw_analysis<brw::performance, fs_visitor> performance_analysis;
/** Number of uniform variable components visited. */
unsigned uniforms;

View File

@@ -130,63 +130,63 @@ namespace brw {
* whether the analysis result \p x is consistent with the input IR. This
* is currently only used for validation in debug builds.
*/
#define BRW_ANALYSIS(L, T, C) \
class L { \
public: \
/** \
* Construct a program analysis. \p c is an arbitrary object \
* passed as argument to the constructor of the analysis result \
* object of type \p T. \
*/ \
L(C const &c) : c(c), p(NULL) {} \
\
/** \
* Destroy a program analysis. \
*/ \
~L() \
{ \
delete p; \
} \
\
/** \
* Obtain the result of a program analysis. This gives a \
* guaranteed up-to-date result, the analysis pass will be \
* rerun implicitly if it has become stale. \
*/ \
T & \
require() \
{ \
if (p) \
assert(p->validate(c)); \
else \
p = new T(c); \
\
return *p; \
} \
\
const T & \
require() const \
{ \
return const_cast<L *>(this)->require(); \
} \
\
/** \
* Report that dependencies of the analysis pass may have changed \
* since the last calculation and the cached analysis result may \
* have to be discarded. \
*/ \
void \
invalidate(brw::analysis_dependency_class c) \
{ \
if (p && c & p->dependency_class()) { \
delete p; \
p = NULL; \
} \
} \
\
private: \
C c; \
T *p; \
template<class T, class C>
class brw_analysis {
public:
/**
* Construct a program analysis. \p c is an arbitrary object
* passed as argument to the constructor of the analysis result
* object of type \p T.
*/
brw_analysis(const C *c) : c(c), p(NULL) {}
/**
* Destroy a program analysis.
*/
~brw_analysis()
{
delete p;
}
/**
* Obtain the result of a program analysis. This gives a
* guaranteed up-to-date result, the analysis pass will be
* rerun implicitly if it has become stale.
*/
T &
require()
{
if (p)
assert(p->validate(c));
else
p = new T(c);
return *p;
}
const T &
require() const
{
return const_cast<brw_analysis<T, C> *>(this)->require();
}
/**
* Report that dependencies of the analysis pass may have changed
* since the last calculation and the cached analysis result may
* have to be discarded.
*/
void
invalidate(brw::analysis_dependency_class c)
{
if (p && (c & p->dependency_class())) {
delete p;
p = NULL;
}
}
private:
const C *c;
T *p;
};
#endif

View File

@@ -69,8 +69,7 @@ public:
exec_list instructions;
cfg_t *cfg;
BRW_ANALYSIS(idom_analysis, brw::idom_tree,
const backend_shader *) idom_analysis;
brw_analysis<brw::idom_tree, backend_shader> idom_analysis;
gl_shader_stage stage;
bool debug_enabled;

View File

@@ -107,10 +107,8 @@ public:
int first_non_payload_grf;
unsigned int max_grf;
BRW_ANALYSIS(live_analysis, brw::vec4_live_variables,
backend_shader *) live_analysis;
BRW_ANALYSIS(performance_analysis, brw::performance,
vec4_visitor *) performance_analysis;
brw_analysis<brw::vec4_live_variables, backend_shader> live_analysis;
brw_analysis<brw::performance, vec4_visitor> performance_analysis;
bool need_all_constants_in_pull_buffer;