Mesa (master): intel/compiler: use C++ template instead of preprocessor
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Nov 3 10:48:19 UTC 2020
Module: Mesa
Branch: master
Commit: 06764e0e5d5e37f9a3e00db7676b76d5472e305b
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=06764e0e5d5e37f9a3e00db7676b76d5472e305b
Author: Marcin Ślusarz <marcin.slusarz at intel.com>
Date: Thu Oct 29 20:13:50 2020 +0100
intel/compiler: use C++ template instead of preprocessor
Signed-off-by: Marcin Ślusarz <marcin.slusarz at intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Francisco Jerez <currojerez at riseup.net>
Acked-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7382>
---
src/intel/compiler/brw_fs.h | 9 +--
src/intel/compiler/brw_ir_analysis.h | 114 +++++++++++++++++------------------
src/intel/compiler/brw_shader.h | 3 +-
src/intel/compiler/brw_vec4.h | 6 +-
4 files changed, 63 insertions(+), 69 deletions(-)
diff --git a/src/intel/compiler/brw_fs.h b/src/intel/compiler/brw_fs.h
index 8b71f8c5b9a..8f543e1ec88 100644
--- a/src/intel/compiler/brw_fs.h
+++ b/src/intel/compiler/brw_fs.h
@@ -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;
diff --git a/src/intel/compiler/brw_ir_analysis.h b/src/intel/compiler/brw_ir_analysis.h
index 360b2f70735..33b8f5178a6 100644
--- a/src/intel/compiler/brw_ir_analysis.h
+++ b/src/intel/compiler/brw_ir_analysis.h
@@ -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
diff --git a/src/intel/compiler/brw_shader.h b/src/intel/compiler/brw_shader.h
index 03b09cce8e1..5085d1fb99c 100644
--- a/src/intel/compiler/brw_shader.h
+++ b/src/intel/compiler/brw_shader.h
@@ -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;
diff --git a/src/intel/compiler/brw_vec4.h b/src/intel/compiler/brw_vec4.h
index a6015b83f34..be2cd412967 100644
--- a/src/intel/compiler/brw_vec4.h
+++ b/src/intel/compiler/brw_vec4.h
@@ -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;
More information about the mesa-commit
mailing list