GCC Middle and Back End API Reference
gimple-match-exports.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "target.h"
#include "rtl.h"
#include "tree.h"
#include "gimple.h"
#include "ssa.h"
#include "cgraph.h"
#include "vec-perm-indices.h"
#include "fold-const.h"
#include "fold-const-call.h"
#include "stor-layout.h"
#include "gimple-iterator.h"
#include "gimple-fold.h"
#include "calls.h"
#include "tree-dfa.h"
#include "builtins.h"
#include "gimple-match.h"
#include "tree-pass.h"
#include "internal-fn.h"
#include "case-cfn-macros.h"
#include "gimplify.h"
#include "optabs-tree.h"
#include "tree-eh.h"
#include "dbgcnt.h"
#include "tm.h"
#include "gimple-range.h"
#include "langhooks.h"
Include dependency graph for gimple-match-exports.cc:

Functions

bool gimple_simplify (gimple_match_op *, gimple_seq *, tree(*)(tree), code_helper, tree, tree)
 
bool gimple_simplify (gimple_match_op *, gimple_seq *, tree(*)(tree), code_helper, tree, tree, tree)
 
bool gimple_simplify (gimple_match_op *, gimple_seq *, tree(*)(tree), code_helper, tree, tree, tree, tree)
 
bool gimple_simplify (gimple_match_op *, gimple_seq *, tree(*)(tree), code_helper, tree, tree, tree, tree, tree)
 
bool gimple_simplify (gimple_match_op *, gimple_seq *, tree(*)(tree), code_helper, tree, tree, tree, tree, tree, tree)
 
bool gimple_simplify (gimple_match_op *, gimple_seq *, tree(*)(tree), code_helper, tree, tree, tree, tree, tree, tree, tree)
 
bool gimple_simplify (gimple_match_op *, gimple_seq *, tree(*)(tree), code_helper, tree, tree, tree, tree, tree, tree, tree, tree)
 
tree gimple_simplify (enum tree_code, tree, tree, gimple_seq *, tree(*)(tree))
 
tree gimple_simplify (enum tree_code, tree, tree, tree, gimple_seq *, tree(*)(tree))
 
tree gimple_simplify (enum tree_code, tree, tree, tree, tree, gimple_seq *, tree(*)(tree))
 
tree gimple_simplify (combined_fn, tree, tree, gimple_seq *, tree(*)(tree))
 
tree gimple_simplify (combined_fn, tree, tree, tree, gimple_seq *, tree(*)(tree))
 
tree gimple_simplify (combined_fn, tree, tree, tree, tree, gimple_seq *, tree(*)(tree))
 
tree do_valueize (tree, tree(*)(tree), bool &)
 
tree do_valueize (tree(*)(tree), tree)
 
static bool gimple_resimplify1 (gimple_seq *, gimple_match_op *, tree(*)(tree))
 
static bool gimple_resimplify2 (gimple_seq *, gimple_match_op *, tree(*)(tree))
 
static bool gimple_resimplify3 (gimple_seq *, gimple_match_op *, tree(*)(tree))
 
static bool gimple_resimplify4 (gimple_seq *, gimple_match_op *, tree(*)(tree))
 
static bool gimple_resimplify5 (gimple_seq *, gimple_match_op *, tree(*)(tree))
 
static bool gimple_resimplify6 (gimple_seq *, gimple_match_op *, tree(*)(tree))
 
static bool gimple_resimplify7 (gimple_seq *, gimple_match_op *, tree(*)(tree))
 
static bool constant_for_folding (tree t)
 
static bool convert_conditional_op (gimple_match_op *orig_op, gimple_match_op *new_op)
 
void maybe_build_generic_op (gimple_match_op *res_op)
 
static gcallbuild_call_internal (internal_fn fn, gimple_match_op *res_op)
 
static bool maybe_resimplify_conditional_op (gimple_seq *seq, gimple_match_op *res_op, tree(*valueize)(tree))
 
static bool try_conditional_simplification (internal_fn ifn, gimple_match_op *res_op, gimple_seq *seq, tree(*valueize)(tree))
 
tree maybe_push_res_to_seq (gimple_match_op *res_op, gimple_seq *seq, tree res)
 
template<typename ValueizeOp , typename ValueizeCondition >
bool gimple_extract (gimple *stmt, gimple_match_op *res_op, ValueizeOp valueize_op, ValueizeCondition valueize_condition)
 
bool gimple_extract_op (gimple *stmt, gimple_match_op *res_op)
 
bool gimple_simplify (gimple *stmt, gimple_match_op *res_op, gimple_seq *seq, tree(*valueize)(tree), tree(*top_valueize)(tree))
 
code_helper canonicalize_code (code_helper code, tree type)
 
bool commutative_binary_op_p (code_helper code, tree type)
 
bool commutative_ternary_op_p (code_helper code, tree type)
 
int first_commutative_argument (code_helper code, tree type)
 
bool associative_binary_op_p (code_helper code, tree type)
 
bool directly_supported_p (code_helper code, tree type, optab_subtype query_type)
 
internal_fn get_conditional_internal_fn (code_helper code, tree type)
 

Variables

tree(* mprts_hook )(gimple_match_op *)
 

Function Documentation

◆ associative_binary_op_p()

bool associative_binary_op_p ( code_helper code,
tree type )
Return true if CODE is a binary operation that is associative when
operating on type TYPE.   

References associated_internal_fn(), associative_binary_fn_p(), associative_tree_code(), ggc_alloc(), and code_helper::is_tree_code().

Referenced by vectorizable_reduction().

◆ build_call_internal()

static gcall * build_call_internal ( internal_fn fn,
gimple_match_op * res_op )
static
Try to build RES_OP, which is known to be a call to FN.  Return null
if the target doesn't support the function.   

References cfun, direct_internal_fn_p(), direct_internal_fn_supported_p(), direct_internal_fn_types(), ggc_alloc(), gimple_build_call_internal(), MAX_FIXED_MODE_SIZE, NULL, OPTIMIZE_FOR_BOTH, PROP_gimple_lbitint, TREE_CODE, TREE_TYPE, and TYPE_PRECISION.

Referenced by maybe_push_res_to_seq().

◆ canonicalize_code()

code_helper canonicalize_code ( code_helper code,
tree type )
Return a canonical form for CODE when operating on TYPE.  The idea
is to remove redundant ways of representing the same operation so
that code_helpers can be hashed and compared for equality.

The only current canonicalization is to replace built-in functions
with internal functions, in cases where internal-fn.def defines
such an internal function.

Note that the new code_helper cannot necessarily be used in place of
the original code_helper.  For example, the new code_helper might be
an internal function that the target does not support.   

References associated_internal_fn(), and code_helper::is_fn_code().

Referenced by check_reduction_path(), and vect_transform_reduction().

◆ commutative_binary_op_p()

bool commutative_binary_op_p ( code_helper code,
tree type )
Return true if CODE is a binary operation and if CODE is commutative when
operating on type TYPE.   

References associated_internal_fn(), commutative_binary_fn_p(), commutative_tree_code(), ggc_alloc(), and code_helper::is_tree_code().

Referenced by gimple_resimplify2(), vect_transform_reduction(), and vectorizable_reduction().

◆ commutative_ternary_op_p()

bool commutative_ternary_op_p ( code_helper code,
tree type )
Return true if CODE represents a ternary operation and if the first two
operands are commutative when CODE is operating on TYPE.   

References associated_internal_fn(), commutative_ternary_fn_p(), commutative_ternary_tree_code(), ggc_alloc(), and code_helper::is_tree_code().

◆ constant_for_folding()

static bool constant_for_folding ( tree t)
inlinestatic
Return whether T is a constant that we'll dispatch to fold to
evaluate fully constant expressions.   

References CONSTANT_CLASS_P, ggc_alloc(), TREE_CODE, and TREE_OPERAND.

Referenced by gimple_resimplify1(), gimple_resimplify2(), gimple_resimplify3(), gimple_simplify(), gimple_simplify(), gimple_simplify(), gimple_simplify(), gimple_simplify(), and gimple_simplify().

◆ convert_conditional_op()

static bool convert_conditional_op ( gimple_match_op * orig_op,
gimple_match_op * new_op )
static
Try to convert conditional operation ORIG_OP into an IFN_COND_*
operation.  Return true on success, storing the new operation in NEW_OP.   

References as_combined_fn(), as_internal_fn(), get_conditional_internal_fn(), get_len_internal_fn(), ggc_alloc(), i, IFN_LAST, internal_fn_p(), and targetm.

Referenced by maybe_resimplify_conditional_op().

◆ directly_supported_p()

◆ do_valueize() [1/2]

tree do_valueize ( tree(*)(tree) valueize,
tree op )
Helper for the autogenerated code, valueize OP.   

References ggc_alloc(), and TREE_CODE.

◆ do_valueize() [2/2]

tree do_valueize ( tree op,
tree(*)(tree) valueize,
bool & valueized )
inline
Helper for gimple_simplify valueizing OP using VALUEIZE and setting
VALUEIZED to true if valueization changed OP.   

References ggc_alloc(), and TREE_CODE.

Referenced by gimple_bitwise_inverted_equal_p(), and gimple_simplify().

◆ first_commutative_argument()

◆ get_conditional_internal_fn()

internal_fn get_conditional_internal_fn ( code_helper code,
tree type )

◆ gimple_extract()

bool gimple_extract ( gimple * stmt,
gimple_match_op * res_op,
ValueizeOp valueize_op,
ValueizeCondition valueize_condition )
inline

◆ gimple_extract_op()

bool gimple_extract_op ( gimple * stmt,
gimple_match_op * res_op )
Try to describe STMT in RES_OP, returning true on success.
For GIMPLE_CONDs, describe the condition that is being tested.
For GIMPLE_ASSIGNs, describe the rhs of the assignment.
For GIMPLE_CALLs, describe the call.   

References ggc_alloc(), and gimple_extract().

Referenced by check_reduction_path(), vect_is_simple_reduction(), vect_mark_pattern_stmts(), vect_model_reduction_cost(), vect_transform_reduction(), and vectorizable_reduction().

◆ gimple_resimplify1()

static bool gimple_resimplify1 ( gimple_seq * seq,
gimple_match_op * res_op,
tree(*)(tree) valueize )
static
Forward declarations of the private auto-generated matchers.
They expect valueized operands in canonical order and do not
perform simplification of all-constant operands.   
Helper that matches and simplifies the toplevel result from
a gimple_simplify run (where we don't want to build
a stmt in case it's used in in-place folding).  Replaces
RES_OP with a simplified and/or canonicalized result and
returns whether any change was made.   

References const_unop(), CONSTANT_CLASS_P, constant_for_folding(), drop_tree_overflow(), dump_file, dump_flags, fold_const_call(), ggc_alloc(), gimple_simplify(), IS_EXPR_CODE_CLASS, maybe_resimplify_conditional_op(), NULL_TREE, TDF_FOLDING, TREE_CODE_CLASS, TREE_CODE_LENGTH, and TREE_OVERFLOW_P.

Referenced by gimple_match_op::resimplify(), and try_conditional_simplification().

◆ gimple_resimplify2()

static bool gimple_resimplify2 ( gimple_seq * seq,
gimple_match_op * res_op,
tree(*)(tree) valueize )
static
Helper that matches and simplifies the toplevel result from
a gimple_simplify run (where we don't want to build
a stmt in case it's used in in-place folding).  Replaces
RES_OP with a simplified and/or canonicalized result and
returns whether any change was made.   

References commutative_binary_op_p(), const_binop(), CONSTANT_CLASS_P, constant_for_folding(), drop_tree_overflow(), dump_file, dump_flags, fold_const_call(), ggc_alloc(), gimple_simplify(), IS_EXPR_CODE_CLASS, maybe_resimplify_conditional_op(), NULL_TREE, swap_tree_comparison(), tcc_comparison, TDF_FOLDING, TREE_CODE_CLASS, TREE_CODE_LENGTH, TREE_OVERFLOW_P, and tree_swap_operands_p().

Referenced by gimple_simplify(), gimple_match_op::resimplify(), and try_conditional_simplification().

◆ gimple_resimplify3()

static bool gimple_resimplify3 ( gimple_seq * seq,
gimple_match_op * res_op,
tree(*)(tree) valueize )
static
Helper that matches and simplifies the toplevel result from
a gimple_simplify run (where we don't want to build
a stmt in case it's used in in-place folding).  Replaces
RES_OP with a simplified and/or canonicalized result and
returns whether any change was made.   

References CONSTANT_CLASS_P, constant_for_folding(), drop_tree_overflow(), dump_file, dump_flags, first_commutative_argument(), fold_const_call(), fold_ternary, ggc_alloc(), gimple_simplify(), IS_EXPR_CODE_CLASS, maybe_resimplify_conditional_op(), NULL_TREE, TDF_FOLDING, TREE_CODE_CLASS, TREE_CODE_LENGTH, TREE_OVERFLOW_P, and tree_swap_operands_p().

Referenced by maybe_resimplify_conditional_op(), gimple_match_op::resimplify(), and try_conditional_simplification().

◆ gimple_resimplify4()

static bool gimple_resimplify4 ( gimple_seq * seq,
gimple_match_op * res_op,
tree(*)(tree) valueize )
static
Helper that matches and simplifies the toplevel result from
a gimple_simplify run (where we don't want to build
a stmt in case it's used in in-place folding).  Replaces
RES_OP with a simplified and/or canonicalized result and
returns whether any change was made.   

References dump_file, dump_flags, first_commutative_argument(), ggc_alloc(), gimple_simplify(), maybe_resimplify_conditional_op(), TDF_FOLDING, and tree_swap_operands_p().

Referenced by gimple_match_op::resimplify().

◆ gimple_resimplify5()

static bool gimple_resimplify5 ( gimple_seq * seq,
gimple_match_op * res_op,
tree(*)(tree) valueize )
static
Helper that matches and simplifies the toplevel result from
a gimple_simplify run (where we don't want to build
a stmt in case it's used in in-place folding).  Replaces
RES_OP with a simplified and/or canonicalized result and
returns whether any change was made.   

References first_commutative_argument(), ggc_alloc(), gimple_simplify(), maybe_resimplify_conditional_op(), and tree_swap_operands_p().

Referenced by gimple_match_op::resimplify().

◆ gimple_resimplify6()

static bool gimple_resimplify6 ( gimple_seq * seq,
gimple_match_op * res_op,
tree(*)(tree) valueize )
static
Helper that matches and simplifies the toplevel result from
a gimple_simplify run (where we don't want to build
a stmt in case it's used in in-place folding).  Replaces
RES_OP with a simplified and/or canonicalized result and
returns whether any change was made.   

References first_commutative_argument(), ggc_alloc(), gimple_simplify(), maybe_resimplify_conditional_op(), and tree_swap_operands_p().

Referenced by gimple_match_op::resimplify().

◆ gimple_resimplify7()

static bool gimple_resimplify7 ( gimple_seq * seq,
gimple_match_op * res_op,
tree(*)(tree) valueize )
static
Helper that matches and simplifies the toplevel result from
a gimple_simplify run (where we don't want to build
a stmt in case it's used in in-place folding).  Replaces
RES_OP with a simplified and/or canonicalized result and
returns whether any change was made.   

References first_commutative_argument(), ggc_alloc(), gimple_simplify(), maybe_resimplify_conditional_op(), and tree_swap_operands_p().

Referenced by gimple_match_op::resimplify().

◆ gimple_simplify() [1/14]

tree gimple_simplify ( combined_fn fn,
tree type,
tree arg0,
gimple_seq * seq,
tree(*)(tree) valueize )
Builtin or internal function with one argument.   

References CONSTANT_CLASS_P, constant_for_folding(), fold_const_call(), ggc_alloc(), gimple_simplify(), maybe_push_res_to_seq(), and NULL_TREE.

◆ gimple_simplify() [2/14]

tree gimple_simplify ( combined_fn fn,
tree type,
tree arg0,
tree arg1,
gimple_seq * seq,
tree(*)(tree) valueize )
Builtin or internal function with two arguments.   

References CONSTANT_CLASS_P, constant_for_folding(), fold_const_call(), ggc_alloc(), gimple_simplify(), maybe_push_res_to_seq(), and NULL_TREE.

◆ gimple_simplify() [3/14]

tree gimple_simplify ( combined_fn fn,
tree type,
tree arg0,
tree arg1,
tree arg2,
gimple_seq * seq,
tree(*)(tree) valueize )
Builtin or internal function with three arguments.   

References CONSTANT_CLASS_P, constant_for_folding(), fold_const_call(), ggc_alloc(), gimple_simplify(), maybe_push_res_to_seq(), and NULL_TREE.

◆ gimple_simplify() [4/14]

tree gimple_simplify ( enum tree_code code,
tree type,
tree op0,
gimple_seq * seq,
tree(*)(tree) valueize )
Functions that are needed by gimple-match but that are exported and used in
other places in the compiler.   
Public API overloads follow for operation being tree_code or
built_in_function and for one to three operands or arguments.
They return NULL_TREE if nothing could be simplified or
the resulting simplified value with parts pushed to SEQ.
If SEQ is NULL then if the simplification needs to create
new stmts it will fail.  If VALUEIZE is non-NULL then all
SSA names will be valueized using that hook prior to
applying simplifications.   
Unary ops.   

References const_unop(), CONSTANT_CLASS_P, constant_for_folding(), ggc_alloc(), gimple_simplify(), maybe_push_res_to_seq(), and NULL_TREE.

Referenced by cleanup_control_expr_graph(), fold_stmt_1(), gimple_build(), gimple_build(), gimple_build(), gimple_build(), gimple_build(), gimple_build(), gimple_fold_stmt_to_constant_1(), and process_bb().

◆ gimple_simplify() [5/14]

◆ gimple_simplify() [6/14]

◆ gimple_simplify() [7/14]

bool gimple_simplify ( gimple * stmt,
gimple_match_op * res_op,
gimple_seq * seq,
tree(*)(tree) valueize,
tree(*)(tree) top_valueize )
The main STMT based simplification entry.  It is used by the fold_stmt
and the fold_stmt_to_constant APIs.   

References build2(), do_valueize(), ggc_alloc(), gimple_extract(), gimple_resimplify2(), tcc_comparison, TREE_CODE, TREE_CODE_CLASS, TREE_OPERAND, TREE_TYPE, try_conditional_simplification(), and valueize_op().

◆ gimple_simplify() [8/14]

◆ gimple_simplify() [9/14]

bool gimple_simplify ( gimple_match_op * ,
gimple_seq * ,
tree(*)(tree) ,
code_helper ,
tree ,
tree ,
tree  )
extern

◆ gimple_simplify() [10/14]

bool gimple_simplify ( gimple_match_op * ,
gimple_seq * ,
tree(*)(tree) ,
code_helper ,
tree ,
tree ,
tree ,
tree  )
extern

◆ gimple_simplify() [11/14]

bool gimple_simplify ( gimple_match_op * ,
gimple_seq * ,
tree(*)(tree) ,
code_helper ,
tree ,
tree ,
tree ,
tree ,
tree  )
extern

◆ gimple_simplify() [12/14]

bool gimple_simplify ( gimple_match_op * ,
gimple_seq * ,
tree(*)(tree) ,
code_helper ,
tree ,
tree ,
tree ,
tree ,
tree ,
tree  )
extern

◆ gimple_simplify() [13/14]

bool gimple_simplify ( gimple_match_op * ,
gimple_seq * ,
tree(*)(tree) ,
code_helper ,
tree ,
tree ,
tree ,
tree ,
tree ,
tree ,
tree  )
extern

◆ gimple_simplify() [14/14]

bool gimple_simplify ( gimple_match_op * ,
gimple_seq * ,
tree(*)(tree) ,
code_helper ,
tree ,
tree ,
tree ,
tree ,
tree ,
tree ,
tree ,
tree  )
extern

◆ maybe_build_generic_op()

void maybe_build_generic_op ( gimple_match_op * res_op)
If in GIMPLE the operation described by RES_OP should be single-rhs,
build a GENERIC tree for that expression and update RES_OP accordingly.   

References build1(), build3(), ggc_alloc(), and REF_REVERSE_STORAGE_ORDER.

Referenced by maybe_push_res_to_seq(), and replace_stmt_with_simplification().

◆ maybe_push_res_to_seq()

◆ maybe_resimplify_conditional_op()

static bool maybe_resimplify_conditional_op ( gimple_seq * seq,
gimple_match_op * res_op,
tree(*)(tree) valueize )
static
RES_OP is the result of a simplification.  If it is conditional,
try to replace it with the equivalent UNCOND form, such as an
IFN_COND_* call or a VEC_COND_EXPR.  Also try to resimplify the
result of the replacement if appropriate, adding any new statements to
SEQ and using VALUEIZE as the valueization function.  Return true if
this resimplification occurred and resulted in at least one change.   

References convert_conditional_op(), FLOAT_TYPE_P, generic_expr_could_trap_p(), ggc_alloc(), gimple_resimplify3(), gimple_simplified_result_is_gimple_val(), INTEGRAL_TYPE_P, NULL_TREE, operation_could_trap_p(), TYPE_OVERFLOW_TRAPS, and VECTOR_TYPE_P.

Referenced by gimple_resimplify1(), gimple_resimplify2(), gimple_resimplify3(), gimple_resimplify4(), gimple_resimplify5(), gimple_resimplify6(), gimple_resimplify7(), and try_conditional_simplification().

◆ try_conditional_simplification()

static bool try_conditional_simplification ( internal_fn ifn,
gimple_match_op * res_op,
gimple_seq * seq,
tree(*)(tree) valueize )
static
If RES_OP is a call to a conditional internal function, try simplifying
the associated unconditional operation and using the result to build
a new conditional operation.  For example, if RES_OP is:

  IFN_COND_ADD (COND, A, B, ELSE)

try simplifying (plus A B) and using the result to build a replacement
for the whole IFN_COND_ADD.

Return true if this approach led to a simplification, otherwise leave
RES_OP unchanged (and so suitable for other simplifications).  When
returning true, add any new statements to SEQ and use VALUEIZE as the
valueization function.

RES_OP is known to be a call to IFN.   

References as_combined_fn(), conditional_internal_fn_code(), gcc_unreachable, get_unconditional_internal_fn(), ggc_alloc(), gimple_resimplify1(), gimple_resimplify2(), gimple_resimplify3(), IFN_LAST, internal_fn_len_index(), maybe_resimplify_conditional_op(), and NULL_TREE.

Referenced by gimple_simplify().

Variable Documentation

◆ mprts_hook

tree(* mprts_hook) (gimple_match_op *) ( gimple_match_op * )
Helpers for the autogenerated gimple-match.cc file.
   Copyright (C) 2023-2024 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   

Referenced by gimple_fold_stmt_to_constant_1(), maybe_push_res_to_seq(), try_to_simplify(), vn_lookup_simplify_result(), and vn_nary_build_or_lookup_1().