/* Check whether G is a potential conditional compare candidate. */
static bool
ccmp_candidate_p (gimple *g)
{
tree rhs = gimple_assign_rhs_to_tree (g);
tree lhs, op0, op1;
gimple *gs0, *gs1;
enum tree_code tcode, tcode0, tcode1;
tcode = TREE_CODE (rhs);
if (tcode != BIT_AND_EXPR && tcode != BIT_IOR_EXPR)
return false;
lhs = gimple_assign_lhs (g);
op0 = TREE_OPERAND (rhs, 0);
op1 = TREE_OPERAND (rhs, 1);
if ((TREE_CODE (op0) != SSA_NAME) || (TREE_CODE (op1) != SSA_NAME)
|| !has_single_use (lhs))
return false;
gs0 = get_gimple_for_ssa_name (op0);
gs1 = get_gimple_for_ssa_name (op1);
if (!gs0 || !gs1 || !is_gimple_assign (gs0) || !is_gimple_assign (gs1)
/* g, gs0 and gs1 must be in the same basic block, since current stage
is out-of-ssa. We can not guarantee the correctness when forwording
the gs0 and gs1 into g whithout DATAFLOW analysis. */
|| gimple_bb (gs0) != gimple_bb (gs1)
|| gimple_bb (gs0) != gimple_bb (g))
return false;
if (!(INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (gs0)))
|| POINTER_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (gs0))))
|| !(INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (gs1)))
|| POINTER_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (gs1)))))
return false;
tcode0 = gimple_assign_rhs_code (gs0);
tcode1 = gimple_assign_rhs_code (gs1);
if (TREE_CODE_CLASS (tcode0) == tcc_comparison
&& TREE_CODE_CLASS (tcode1) == tcc_comparison)
return true;
if (TREE_CODE_CLASS (tcode0) == tcc_comparison
&& ccmp_candidate_p (gs1))
return true;
else if (TREE_CODE_CLASS (tcode1) == tcc_comparison
&& ccmp_candidate_p (gs0))
return true;
/* We skip ccmp_candidate_p (gs1) && ccmp_candidate_p (gs0) since
there is no way to set the CC flag. */
return false;
}
开发者ID:woailuoli993,项目名称:gcc,代码行数:52,代码来源:ccmp.c
示例2: cilkplus_an_triplet_types_ok_p
bool
cilkplus_an_triplet_types_ok_p (location_t loc, tree start_index, tree length,
tree stride, tree type)
{
size_t stride_rank = 0, length_rank = 0, start_rank = 0;
if (!TREE_TYPE (start_index) || !INTEGRAL_TYPE_P (TREE_TYPE (start_index)))
{
error_at (loc, "start-index of array notation triplet is not an integer");
return false;
}
if (!TREE_TYPE (length) || !INTEGRAL_TYPE_P (TREE_TYPE (length)))
{
error_at (loc, "length of array notation triplet is not an integer");
return false;
}
if (!TREE_TYPE (stride) || !INTEGRAL_TYPE_P (TREE_TYPE (stride)))
{
error_at (loc, "stride of array notation triplet is not an integer");
return false;
}
if (TREE_CODE (type) == FUNCTION_TYPE)
{
error_at (loc, "array notation cannot be used with function type");
return false;
}
if (!find_rank (loc, start_index, start_index, false, &start_rank)
|| !find_rank (loc, length, length, false, &length_rank)
|| !find_rank (loc, stride, stride, false, &stride_rank))
return false;
if (start_rank != 0)
{
error_at (loc, "rank of an array notation triplet%'s start-index is not "
"zero");
return false;
}
if (length_rank != 0)
{
error_at (loc, "rank of an array notation triplet%'s length is not zero");
return false;
}
if (stride_rank != 0)
{
error_at (loc, "rank of array notation triplet%'s stride is not zero");
return false;
}
return true;
}
tree
c_finish_omp_atomic (location_t loc, enum tree_code code, tree lhs, tree rhs)
{
tree x, type, addr;
if (lhs == error_mark_node || rhs == error_mark_node)
return error_mark_node;
/* ??? According to one reading of the OpenMP spec, complex type are
supported, but there are no atomic stores for any architecture.
But at least icc 9.0 doesn't support complex types here either.
And lets not even talk about vector types... */
type = TREE_TYPE (lhs);
if (!INTEGRAL_TYPE_P (type)
&& !POINTER_TYPE_P (type)
&& !SCALAR_FLOAT_TYPE_P (type))
{
error_at (loc, "invalid expression type for %<#pragma omp atomic%>");
return error_mark_node;
}
/* ??? Validate that rhs does not overlap lhs. */
/* Take and save the address of the lhs. From then on we'll reference it
via indirection. */
addr = build_unary_op (loc, ADDR_EXPR, lhs, 0);
if (addr == error_mark_node)
return error_mark_node;
addr = save_expr (addr);
if (TREE_CODE (addr) != SAVE_EXPR
&& (TREE_CODE (addr) != ADDR_EXPR
|| TREE_CODE (TREE_OPERAND (addr, 0)) != VAR_DECL))
{
/* Make sure LHS is simple enough so that goa_lhs_expr_p can recognize
it even after unsharing function body. */
tree var = create_tmp_var_raw (TREE_TYPE (addr), NULL);
DECL_CONTEXT (var) = current_function_decl;
addr = build4 (TARGET_EXPR, TREE_TYPE (addr), var, addr, NULL, NULL);
}
lhs = build_indirect_ref (loc, addr, RO_NULL);
/* There are lots of warnings, errors, and conversions that need to happen
in the course of interpreting a statement. Use the normal mechanisms
to do this, and then take it apart again. */
x = build_modify_expr (input_location, lhs, NULL_TREE, code,
input_location, rhs, NULL_TREE);
if (x == error_mark_node)
return error_mark_node;
gcc_assert (TREE_CODE (x) == MODIFY_EXPR);
rhs = TREE_OPERAND (x, 1);
/* Punt the actual generation of atomic operations to common code. */
x = build2 (OMP_ATOMIC, void_type_node, addr, rhs);
SET_EXPR_LOCATION (x, loc);
return x;
}
开发者ID:FilipinOTech,项目名称:gcc,代码行数:56,代码来源:c-omp.c
示例5: insert_trap_and_remove_trailing_statements
static void
insert_trap_and_remove_trailing_statements (gimple_stmt_iterator *si_p, tree op)
{
/* We want the NULL pointer dereference to actually occur so that
code that wishes to catch the signal can do so.
If the dereference is a load, then there's nothing to do as the
LHS will be a throw-away SSA_NAME and the RHS is the NULL dereference.
If the dereference is a store and we can easily transform the RHS,
then simplify the RHS to enable more DCE. Note that we require the
statement to be a GIMPLE_ASSIGN which filters out calls on the RHS. */
gimple stmt = gsi_stmt (*si_p);
if (walk_stmt_load_store_ops (stmt, (void *)op, NULL, check_loadstore)
&& is_gimple_assign (stmt)
&& INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_lhs (stmt))))
{
/* We just need to turn the RHS into zero converted to the proper
type. */
tree type = TREE_TYPE (gimple_assign_lhs (stmt));
gimple_assign_set_rhs_code (stmt, INTEGER_CST);
gimple_assign_set_rhs1 (stmt, fold_convert (type, integer_zero_node));
update_stmt (stmt);
}
gimple new_stmt
= gimple_build_call (builtin_decl_explicit (BUILT_IN_TRAP), 0);
gimple_seq seq = NULL;
gimple_seq_add_stmt (&seq, new_stmt);
/* If we had a NULL pointer dereference, then we want to insert the
__builtin_trap after the statement, for the other cases we want
to insert before the statement. */
if (walk_stmt_load_store_ops (stmt, (void *)op,
check_loadstore,
check_loadstore))
gsi_insert_after (si_p, seq, GSI_NEW_STMT);
else
gsi_insert_before (si_p, seq, GSI_NEW_STMT);
/* We must remove statements from the end of the block so that we
never reference a released SSA_NAME. */
basic_block bb = gimple_bb (gsi_stmt (*si_p));
for (gimple_stmt_iterator si = gsi_last_bb (bb);
gsi_stmt (si) != gsi_stmt (*si_p);
si = gsi_last_bb (bb))
{
stmt = gsi_stmt (si);
unlink_stmt_vdef (stmt);
gsi_remove (&si, true);
release_defs (stmt);
}
}
static void
instrument_si_overflow (gimple_stmt_iterator gsi)
{
gimple stmt = gsi_stmt (gsi);
tree_code code = gimple_assign_rhs_code (stmt);
tree lhs = gimple_assign_lhs (stmt);
tree lhstype = TREE_TYPE (lhs);
tree a, b;
gimple g;
/* If this is not a signed operation, don't instrument anything here.
Also punt on bit-fields. */
if (!INTEGRAL_TYPE_P (lhstype)
|| TYPE_OVERFLOW_WRAPS (lhstype)
|| GET_MODE_BITSIZE (TYPE_MODE (lhstype)) != TYPE_PRECISION (lhstype))
return;
switch (code)
{
case MINUS_EXPR:
case PLUS_EXPR:
case MULT_EXPR:
/* Transform
i = u {+,-,*} 5;
into
i = UBSAN_CHECK_{ADD,SUB,MUL} (u, 5); */
a = gimple_assign_rhs1 (stmt);
b = gimple_assign_rhs2 (stmt);
g = gimple_build_call_internal (code == PLUS_EXPR
? IFN_UBSAN_CHECK_ADD
: code == MINUS_EXPR
? IFN_UBSAN_CHECK_SUB
: IFN_UBSAN_CHECK_MUL, 2, a, b);
gimple_call_set_lhs (g, lhs);
gsi_replace (&gsi, g, false);
break;
case NEGATE_EXPR:
/* Represent i = -u;
as
i = UBSAN_CHECK_SUB (0, u); */
a = build_int_cst (lhstype, 0);
b = gimple_assign_rhs1 (stmt);
g = gimple_build_call_internal (IFN_UBSAN_CHECK_SUB, 2, a, b);
gimple_call_set_lhs (g, lhs);
gsi_replace (&gsi, g, false);
break;
default:
break;
}
}
static bool
process_assignment (gimple stmt, gimple_stmt_iterator call, tree *m,
tree *a, tree *ass_var)
{
tree op0, op1 = NULL_TREE, non_ass_var = NULL_TREE;
tree dest = gimple_assign_lhs (stmt);
enum tree_code code = gimple_assign_rhs_code (stmt);
enum gimple_rhs_class rhs_class = get_gimple_rhs_class (code);
tree src_var = gimple_assign_rhs1 (stmt);
/* See if this is a simple copy operation of an SSA name to the function
result. In that case we may have a simple tail call. Ignore type
conversions that can never produce extra code between the function
call and the function return. */
if ((rhs_class == GIMPLE_SINGLE_RHS || gimple_assign_cast_p (stmt))
&& (TREE_CODE (src_var) == SSA_NAME))
{
/* Reject a tailcall if the type conversion might need
additional code. */
if (gimple_assign_cast_p (stmt))
{
if (TYPE_MODE (TREE_TYPE (dest)) != TYPE_MODE (TREE_TYPE (src_var)))
return false;
/* Even if the type modes are the same, if the precision of the
type is smaller than mode's precision,
reduce_to_bit_field_precision would generate additional code. */
if (INTEGRAL_TYPE_P (TREE_TYPE (dest))
&& (GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (dest)))
> TYPE_PRECISION (TREE_TYPE (dest))))
return false;
}
if (src_var != *ass_var)
return false;
*ass_var = dest;
return true;
}
switch (rhs_class)
{
case GIMPLE_BINARY_RHS:
op1 = gimple_assign_rhs2 (stmt);
/* Fall through. */
case GIMPLE_UNARY_RHS:
op0 = gimple_assign_rhs1 (stmt);
break;
default:
return false;
}
/* Accumulator optimizations will reverse the order of operations.
We can only do that for floating-point types if we're assuming
that addition and multiplication are associative. */
if (!flag_associative_math)
if (FLOAT_TYPE_P (TREE_TYPE (DECL_RESULT (current_function_decl))))
return false;
if (rhs_class == GIMPLE_UNARY_RHS)
;
else if (op0 == *ass_var
&& (non_ass_var = independent_of_stmt_p (op1, stmt, call)))
;
else if (op1 == *ass_var
&& (non_ass_var = independent_of_stmt_p (op0, stmt, call)))
;
else
return false;
switch (code)
{
case PLUS_EXPR:
*a = non_ass_var;
*ass_var = dest;
return true;
case POINTER_PLUS_EXPR:
if (op0 != *ass_var)
return false;
*a = non_ass_var;
*ass_var = dest;
return true;
case MULT_EXPR:
*m = non_ass_var;
*ass_var = dest;
return true;
case NEGATE_EXPR:
*m = build_minus_one_cst (TREE_TYPE (op0));
*ass_var = dest;
return true;
case MINUS_EXPR:
if (*ass_var == op0)
*a = fold_build1 (NEGATE_EXPR, TREE_TYPE (non_ass_var), non_ass_var);
//.........这里部分代码省略.........
tree
c_finish_omp_for (location_t locus, tree decl, tree init, tree cond,
tree incr, tree body, tree pre_body)
{
location_t elocus = locus;
bool fail = false;
if (EXPR_HAS_LOCATION (init))
elocus = EXPR_LOCATION (init);
/* Validate the iteration variable. */
if (!INTEGRAL_TYPE_P (TREE_TYPE (decl)))
{
error ("%Hinvalid type for iteration variable %qE", &elocus, decl);
fail = true;
}
if (TYPE_UNSIGNED (TREE_TYPE (decl)))
warning (0, "%Hiteration variable %qE is unsigned", &elocus, decl);
/* In the case of "for (int i = 0...)", init will be a decl. It should
have a DECL_INITIAL that we can turn into an assignment. */
if (init == decl)
{
elocus = DECL_SOURCE_LOCATION (decl);
init = DECL_INITIAL (decl);
if (init == NULL)
{
error ("%H%qE is not initialized", &elocus, decl);
init = integer_zero_node;
fail = true;
}
init = build_modify_expr (decl, NOP_EXPR, init);
SET_EXPR_LOCATION (init, elocus);
}
gcc_assert (TREE_CODE (init) == MODIFY_EXPR);
gcc_assert (TREE_OPERAND (init, 0) == decl);
if (cond == NULL_TREE)
{
error ("%Hmissing controlling predicate", &elocus);
fail = true;
}
else
{
bool cond_ok = false;
if (EXPR_HAS_LOCATION (cond))
elocus = EXPR_LOCATION (cond);
if (TREE_CODE (cond) == LT_EXPR
|| TREE_CODE (cond) == LE_EXPR
|| TREE_CODE (cond) == GT_EXPR
|| TREE_CODE (cond) == GE_EXPR)
{
tree op0 = TREE_OPERAND (cond, 0);
tree op1 = TREE_OPERAND (cond, 1);
/* 2.5.1. The comparison in the condition is computed in the type
of DECL, otherwise the behavior is undefined.
For example:
long n; int i;
i < n;
according to ISO will be evaluated as:
(long)i < n;
We want to force:
i < (int)n; */
if (TREE_CODE (op0) == NOP_EXPR
&& decl == TREE_OPERAND (op0, 0))
{
TREE_OPERAND (cond, 0) = TREE_OPERAND (op0, 0);
TREE_OPERAND (cond, 1) = fold_build1 (NOP_EXPR, TREE_TYPE (decl),
TREE_OPERAND (cond, 1));
}
else if (TREE_CODE (op1) == NOP_EXPR
&& decl == TREE_OPERAND (op1, 0))
{
TREE_OPERAND (cond, 1) = TREE_OPERAND (op1, 0);
TREE_OPERAND (cond, 0) = fold_build1 (NOP_EXPR, TREE_TYPE (decl),
TREE_OPERAND (cond, 0));
}
if (decl == TREE_OPERAND (cond, 0))
cond_ok = true;
else if (decl == TREE_OPERAND (cond, 1))
{
TREE_SET_CODE (cond, swap_tree_comparison (TREE_CODE (cond)));
TREE_OPERAND (cond, 1) = TREE_OPERAND (cond, 0);
TREE_OPERAND (cond, 0) = decl;
cond_ok = true;
}
}
if (!cond_ok)
{
error ("%Hinvalid controlling predicate", &elocus);
//.........这里部分代码省略.........
开发者ID:austinsc,项目名称:GCCXML,代码行数:101,代码来源:c-omp.c
示例12: forward_propagate_addr_expr_1
static bool
forward_propagate_addr_expr_1 (tree name, tree def_rhs,
gimple_stmt_iterator *use_stmt_gsi,
bool single_use_p)
{
tree lhs, rhs, rhs2, array_ref;
tree *rhsp, *lhsp;
gimple use_stmt = gsi_stmt (*use_stmt_gsi);
enum tree_code rhs_code;
bool res = true;
gcc_assert (TREE_CODE (def_rhs) == ADDR_EXPR);
lhs = gimple_assign_lhs (use_stmt);
rhs_code = gimple_assign_rhs_code (use_stmt);
rhs = gimple_assign_rhs1 (use_stmt);
/* Trivial cases. The use statement could be a trivial copy or a
useless conversion. Recurse to the uses of the lhs as copyprop does
not copy through different variant pointers and FRE does not catch
all useless conversions. Treat the case of a single-use name and
a conversion to def_rhs type separate, though. */
if (TREE_CODE (lhs) == SSA_NAME
&& ((rhs_code == SSA_NAME && rhs == name)
|| CONVERT_EXPR_CODE_P (rhs_code)))
{
/* Only recurse if we don't deal with a single use or we cannot
do the propagation to the current statement. In particular
we can end up with a conversion needed for a non-invariant
address which we cannot do in a single statement. */
if (!single_use_p
|| (!useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (def_rhs))
&& (!is_gimple_min_invariant (def_rhs)
|| (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
&& POINTER_TYPE_P (TREE_TYPE (def_rhs))
&& (TYPE_PRECISION (TREE_TYPE (lhs))
> TYPE_PRECISION (TREE_TYPE (def_rhs)))))))
return forward_propagate_addr_expr (lhs, def_rhs);
gimple_assign_set_rhs1 (use_stmt, unshare_expr (def_rhs));
if (useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (def_rhs)))
gimple_assign_set_rhs_code (use_stmt, TREE_CODE (def_rhs));
else
gimple_assign_set_rhs_code (use_stmt, NOP_EXPR);
return true;
}
/* Now strip away any outer COMPONENT_REF/ARRAY_REF nodes from the LHS.
ADDR_EXPR will not appear on the LHS. */
lhsp = gimple_assign_lhs_ptr (use_stmt);
while (handled_component_p (*lhsp))
lhsp = &TREE_OPERAND (*lhsp, 0);
lhs = *lhsp;
/* Now see if the LHS node is an INDIRECT_REF using NAME. If so,
propagate the ADDR_EXPR into the use of NAME and fold the result. */
if (TREE_CODE (lhs) == INDIRECT_REF
&& TREE_OPERAND (lhs, 0) == name)
{
if (may_propagate_address_into_dereference (def_rhs, lhs)
&& (lhsp != gimple_assign_lhs_ptr (use_stmt)
|| useless_type_conversion_p
(TREE_TYPE (TREE_OPERAND (def_rhs, 0)), TREE_TYPE (rhs))))
{
*lhsp = unshare_expr (TREE_OPERAND (def_rhs, 0));
fold_stmt_inplace (use_stmt);
tidy_after_forward_propagate_addr (use_stmt);
/* Continue propagating into the RHS if this was not the only use. */
if (single_use_p)
return true;
}
else
/* We can have a struct assignment dereferencing our name twice.
Note that we didn't propagate into the lhs to not falsely
claim we did when propagating into the rhs. */
res = false;
}
/* Strip away any outer COMPONENT_REF, ARRAY_REF or ADDR_EXPR
nodes from the RHS. */
rhsp = gimple_assign_rhs1_ptr (use_stmt);
while (handled_component_p (*rhsp)
|| TREE_CODE (*rhsp) == ADDR_EXPR)
rhsp = &TREE_OPERAND (*rhsp, 0);
rhs = *rhsp;
/* Now see if the RHS node is an INDIRECT_REF using NAME. If so,
propagate the ADDR_EXPR into the use of NAME and fold the result. */
if (TREE_CODE (rhs) == INDIRECT_REF
&& TREE_OPERAND (rhs, 0) == name
&& may_propagate_address_into_dereference (def_rhs, rhs))
{
*rhsp = unshare_expr (TREE_OPERAND (def_rhs, 0));
fold_stmt_inplace (use_stmt);
tidy_after_forward_propagate_addr (use_stmt);
return res;
}
/* Now see if the RHS node is an INDIRECT_REF using NAME. If so,
//.........这里部分代码省略.........
static tree
avr_resolve_overloaded_builtin (unsigned int iloc, tree fndecl, void *vargs)
{
tree type0, type1, fold = NULL_TREE;
enum avr_builtin_id id = AVR_BUILTIN_COUNT;
location_t loc = (location_t) iloc;
vec<tree, va_gc> &args = * (vec<tree, va_gc>*) vargs;
switch (DECL_FUNCTION_CODE (fndecl))
{
default:
break;
case AVR_BUILTIN_ABSFX:
if (args.length() != 1)
{
error_at (loc, "%qs expects 1 argument but %d given",
"absfx", (int) args.length());
fold = error_mark_node;
break;
}
type0 = TREE_TYPE (args[0]);
if (!FIXED_POINT_TYPE_P (type0))
{
error_at (loc, "%qs expects a fixed-point value as argument",
"absfx");
fold = error_mark_node;
}
switch (TYPE_MODE (type0))
{
case QQmode: id = AVR_BUILTIN_ABSHR; break;
case HQmode: id = AVR_BUILTIN_ABSR; break;
case SQmode: id = AVR_BUILTIN_ABSLR; break;
case DQmode: id = AVR_BUILTIN_ABSLLR; break;
case HAmode: id = AVR_BUILTIN_ABSHK; break;
case SAmode: id = AVR_BUILTIN_ABSK; break;
case DAmode: id = AVR_BUILTIN_ABSLK; break;
case TAmode: id = AVR_BUILTIN_ABSLLK; break;
case UQQmode:
case UHQmode:
case USQmode:
case UDQmode:
case UHAmode:
case USAmode:
case UDAmode:
case UTAmode:
warning_at (loc, 0, "using %qs with unsigned type has no effect",
"absfx");
return args[0];
default:
error_at (loc, "no matching fixed-point overload found for %qs",
"absfx");
fold = error_mark_node;
break;
}
fold = targetm.builtin_decl (id, true);
if (fold != error_mark_node)
fold = build_function_call_vec (loc, vNULL, fold, &args, NULL);
break; // absfx
case AVR_BUILTIN_ROUNDFX:
if (args.length() != 2)
{
error_at (loc, "%qs expects 2 arguments but %d given",
"roundfx", (int) args.length());
fold = error_mark_node;
break;
}
type0 = TREE_TYPE (args[0]);
type1 = TREE_TYPE (args[1]);
if (!FIXED_POINT_TYPE_P (type0))
{
error_at (loc, "%qs expects a fixed-point value as first argument",
"roundfx");
fold = error_mark_node;
}
if (!INTEGRAL_TYPE_P (type1))
{
error_at (loc, "%qs expects an integer value as second argument",
"roundfx");
fold = error_mark_node;
}
//.........这里部分代码省略.........
请发表评论