From ae1d962dffd3cd212fbff1dac26617668381d89a Mon Sep 17 00:00:00 2001 From: York Jasper Niebuhr Date: Mon, 13 Oct 2025 22:39:45 +0200 Subject: [PATCH] Plan for pattern graph --- plugin/pattern.cpp | 65 ++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/plugin/pattern.cpp b/plugin/pattern.cpp index a091d85..ab0dc31 100644 --- a/plugin/pattern.cpp +++ b/plugin/pattern.cpp @@ -2,8 +2,29 @@ #include -class LocationPattern { +class PatternNode { +public: + enum OP { NOP /* just move */, ADD, SUB, NEG, CALL, MEMREF }; +private: + OP m_op; +public: + // ... +}; +class PatternEdge { +public: + enum DATATYPE { VAR, CONST, FIELDOFF /* field offset is specialization of CONST */ }; +private: + DATATYPE m_datatype; + // std::size_t m_datasize; +public: + // ... +}; + +// TODO -> build pattern tree from output root to input leafs + +class LocationPattern { + // ... public: LocationPattern() {} ~LocationPattern() {} @@ -28,35 +49,29 @@ int register_gimple_statement_pattern(gimple_stmt_iterator* gsi) { LocationPattern& pattern = lp_it->second; /* - scan_stmt_for_offsetof(funcname, &gsi); - for (unsigned i = 0; i < gimple_num_ops(stmt); ++i) { - tree op = gimple_op(stmt, i); - scan_tree_for_components(op, funcname, &gsi); - } + for (unsigned i = 0; i < gimple_num_ops(stmt); ++i) { + tree op = gimple_op(stmt, i); + scan_tree_for_components(op, funcname, &gsi); + } + */ - Build GimpleStatementPattern tree from individual gimple statement - Add GimpleStatementPattern to LocationPattern (attached at matching variable names (potentially unnamed ssa)) - Patterns include markers for member offsets (type, member, value) - Later load a set of RTLInstructionPattern to match the patterns - */ + switch (stmt_code) { + case GIMPLE_CALL: + // check for offsetof, then fall through to operand scanning + case GIMPLE_ASSIGN: + case GIMPLE_COND: + case GIMPLE_LABEL: + case GIMPLE_RETURN: + return 0; + default: + return 1; + } - switch (stmt_code) { - case GIMPLE_CALL: - // check for offsetof, then fall through to operand scanning - case GIMPLE_ASSIGN: - case GIMPLE_COND: - case GIMPLE_LABEL: - case GIMPLE_RETURN: - return 0; - default: - return 1; - } - - return 0; + return 0; } void clean_unnecessary_patterns() { - // TODO + // TODO -> erase all that do not contain a single member offset } int register_rtl_instruction_pattern(rtx_insn* i) {