From 47469bb461dcafdf0ce5fe5f020faed0e8d6d4d9 Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah <kugan.vivekanandarajah@linaro.org>
Date: Tue, 1 Sep 2015 08:40:40 +1000
Subject: [PATCH 5/7] debug stmt in widen mode
---
gcc/gimple-ssa-type-promote.c | 82 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 79 insertions(+), 3 deletions(-)
@@ -589,10 +589,86 @@ fixup_uses (tree use, tree promoted_type, tree old_type)
{
case GIMPLE_DEBUG:
{
- gsi = gsi_for_stmt (stmt);
- gsi_remove (&gsi, true);
- break;
+ /* Change the GIMPLE_DEBUG stmt such that the value bound is
+ computed in promoted_type and then converted to required
+ type. */
+ tree op, new_op = NULL_TREE;
+ gdebug *copy = NULL, *gs = as_a <gdebug *> (stmt);
+ enum tree_code code;
+
+ /* Get the value that is bound in debug stmt. */
+ switch (gs->subcode)
+ {
+ case GIMPLE_DEBUG_BIND:
+ op = gimple_debug_bind_get_value (gs);
+ break;
+ case GIMPLE_DEBUG_SOURCE_BIND:
+ op = gimple_debug_source_bind_get_value (gs);
+ break;
+ default:
+ gcc_unreachable ();
+ }
+
+ code = TREE_CODE (op);
+ /* Convert the value computed in promoted_type to
+ old_type. */
+ if (code == SSA_NAME && use == op)
+ new_op = build1 (NOP_EXPR, old_type, use);
+ else if (TREE_CODE_CLASS (TREE_CODE (op)) == tcc_unary
+ && code != NOP_EXPR)
+ {
+ tree op0 = TREE_OPERAND (op, 0);
+ if (op0 == use)
+ {
+ tree temp = build1 (code, promoted_type, op0);
+ new_op = build1 (NOP_EXPR, old_type, temp);
+ }
+ }
+ else if (TREE_CODE_CLASS (TREE_CODE (op)) == tcc_binary
+ /* Skip codes that are rejected in safe_to_promote_use_p. */
+ && code != LROTATE_EXPR
+ && code != RROTATE_EXPR
+ && code != COMPLEX_EXPR)
+ {
+ tree op0 = TREE_OPERAND (op, 0);
+ tree op1 = TREE_OPERAND (op, 1);
+ if (op0 == use || op1 == use)
+ {
+ if (TREE_CODE (op0) == INTEGER_CST)
+ op0 = convert_int_cst (promoted_type, op0, SIGNED);
+ if (TREE_CODE (op1) == INTEGER_CST)
+ op1 = convert_int_cst (promoted_type, op1, SIGNED);
+ tree temp = build2 (code, promoted_type, op0, op1);
+ new_op = build1 (NOP_EXPR, old_type, temp);
+ }
+ }
+
+ /* Create new GIMPLE_DEBUG stmt with the new value (new_op) to
+ be bound, if new value has been calculated */
+ if (new_op)
+ {
+ if (gimple_debug_bind_p (stmt))
+ {
+ copy = gimple_build_debug_bind
+ (gimple_debug_bind_get_var (stmt),
+ new_op,
+ stmt);
+ }
+ if (gimple_debug_source_bind_p (stmt))
+ {
+ copy = gimple_build_debug_source_bind
+ (gimple_debug_source_bind_get_var (stmt), new_op,
+ stmt);
+ }
+
+ if (copy)
+ {
+ gsi = gsi_for_stmt (stmt);
+ gsi_replace (&gsi, copy, false);
+ }
+ }
}
+ break;
case GIMPLE_ASM:
case GIMPLE_CALL:
--
1.9.1