GCC Middle and Back End API Reference
hw-doloop.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "rtl.h"
#include "df.h"
#include "insn-config.h"
#include "regs.h"
#include "memmodel.h"
#include "emit-rtl.h"
#include "recog.h"
#include "cfgrtl.h"
#include "hw-doloop.h"
#include "dumpfile.h"
Include dependency graph for hw-doloop.cc:


#define BB_AUX_INDEX(BB)   ((intptr_t) (BB)->aux)


static void dump_hwloops (hwloop_info loops)
static bool bb_in_loop_p (hwloop_info loop, basic_block bb)
static void scan_loop (hwloop_info loop)
static bool process_incoming_edges (hwloop_info loop)
static bool add_forwarder_blocks (hwloop_info loop)
static void discover_loop (hwloop_info loop, basic_block tail_bb, rtx_insn *tail_insn, rtx reg)
static hwloop_info discover_loops (bitmap_obstack *loop_stack, struct hw_doloop_hooks *hooks)
static void free_loops (hwloop_info loops)
static void set_bb_indices (void)
static void reorder_loops (hwloop_info loops)
static void optimize_loop (hwloop_info loop, struct hw_doloop_hooks *hooks)
void reorg_loops (bool do_reorder, struct hw_doloop_hooks *hooks)

Macro Definition Documentation


#define BB_AUX_INDEX ( BB)    ((intptr_t) (BB)->aux)

Referenced by reorder_loops().

Function Documentation

◆ add_forwarder_blocks()

static bool add_forwarder_blocks ( hwloop_info loop)
Try to identify a forwarder block that jump into LOOP, and add it to
the set of blocks in the loop, updating the vector of incoming blocks as
well.  This transformation gives a second chance to loops we couldn't
otherwise handle by increasing the chance that we'll end up with one
incoming_src block.
Return true if we made a change, false otherwise.   

References bitmap_set_bit, dump_file, FOR_EACH_EDGE, forwarder_block_p(), edge_iterator::index, and vec_safe_push().

Referenced by discover_loop().

◆ bb_in_loop_p()

static bool bb_in_loop_p ( hwloop_info loop,
basic_block bb )
Return true if BB is part of LOOP.   

References bitmap_bit_p, and basic_block_def::index.

Referenced by _loop_vec_info::_loop_vec_info(), discover_loop(), and scan_loop().

◆ discover_loop()

static void discover_loop ( hwloop_info loop,
basic_block tail_bb,
rtx_insn * tail_insn,
rtx reg )
Called from reorg_loops when a potential loop end is found.  LOOP is
a newly set up structure describing the loop, it is this function's
responsibility to fill most of it.  TAIL_BB and TAIL_INSN point to the
loop_end insn and its enclosing basic block.  REG is the loop counter
For our purposes, a loop is defined by the set of blocks reachable from
the loop head in which the loop counter register is live.  This matches
the expected use; targets that call into this code usually replace the
loop counter with a different special register.   

References add_forwarder_blocks(), as_a(), bb_in_loop_p(), bitmap_bit_p, bitmap_set_bit, BRANCH_EDGE, cfun, df_get_live_in(), dump_file, EDGE_COUNT, EDGE_SUCC, EXIT_BLOCK_PTR_FOR_FN, FALLTHRU_EDGE, FOR_EACH_EDGE, FOR_EACH_VEC_ELT, basic_block_def::index, edge_iterator::index, JUMP_LABEL, basic_block_def::preds, process_incoming_edges(), REGNO, REGNO_REG_SET_P, basic_block_def::succs, vec_alloc(), and vec_safe_push().

Referenced by discover_loops().

◆ discover_loops()

static hwloop_info discover_loops ( bitmap_obstack * loop_stack,
struct hw_doloop_hooks * hooks )
Analyze the structure of the loops in the current function.  Use
LOOP_STACK for bitmap allocations.  Returns all the valid candidates for
hardware loops found in this function.  HOOKS is the argument
passed to reorg_loops, used here to find the iteration registers
from a loop_end pattern.   

References hwloop_info_d::bad, BB_END, BB_HEAD, BITMAP_ALLOC, bitmap_intersect_compl_p(), bitmap_intersect_p(), hwloop_info_d::block_bitmap, cfun, delete_insn_and_edges(), df_get_live_in(), discover_loop(), dump_file, dump_hwloops(), hw_doloop_hooks::end_pattern_reg, FALLTHRU_EDGE, FOR_EACH_BB_FN, JUMP_LABEL_AS_INSN(), JUMP_P, hwloop_info_d::loop_no, hwloop_info_d::loops, hwloop_info_d::next, loop::next, NEXT_INSN(), NONDEBUG_INSN_P, NOTE_P, NULL, NULL_RTX, PREV_INSN(), print_rtl_single(), REGNO, and REGNO_REG_SET_P.

Referenced by reorg_loops().

◆ dump_hwloops()

static void dump_hwloops ( hwloop_info loops)
Code to analyze doloop loops in order for targets to perform late
   optimizations converting doloops to other forms of hardware loops.
   Copyright (C) 2011-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

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
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
Dump information collected in LOOPS.   

References b, dump_file, i, loop::next, NULL, and REGNO.

Referenced by discover_loops(), and reorg_loops().

◆ free_loops()

static void free_loops ( hwloop_info loops)
Free up the loop structures in LOOPS.   

References BITMAP_FREE, and loop::next.

Referenced by reorg_loops().

◆ optimize_loop()

static void optimize_loop ( hwloop_info loop,
struct hw_doloop_hooks * hooks )
Call the OPT function for LOOP and all of its sub-loops.  This is
done in a depth-first search; innermost loops are visited first.
OPTIMIZE and FAIL are the functions passed to reorg_loops by the
target's reorg pass.   

References hwloop_info_d::bad, hwloop_info_d::depth, dump_file, hw_doloop_hooks::fail, hw_doloop_hooks::opt, optimize_loop(), and hwloop_info_d::regs_set_in_loop.

Referenced by optimize_loop(), and reorg_loops().

◆ process_incoming_edges()

static bool process_incoming_edges ( hwloop_info loop)
Compute the incoming_dest and incoming_src members of LOOP by
identifying the edges that jump into the loop.  If there is more
than one block that jumps into the loop, incoming_src will be set
to NULL; likewise, if there is more than one block in the loop that
is the destination of an incoming edge, incoming_dest will be NULL.

Return true if either of these two fields is nonnull, false

References FOR_EACH_EDGE, and NULL.

Referenced by discover_loop().

◆ reorder_loops()

static void reorder_loops ( hwloop_info loops)
The taken-branch edge from the loop end can actually go forward.
If the target's hardware loop support requires that the loop end be
after the loop start, try to reorder a loop's basic blocks when we
find such a case.
This is not very aggressive; it only moves at most one block.  It
does not introduce new branches into loops; it may remove them, or
it may switch fallthru/jump edges.   

References basic_block_def::aux, BB_AUX_INDEX, bitmap_bit_p, cfg_layout_finalize(), cfg_layout_initialize(), cfun, clear_aux_for_blocks(), df_analyze(), dump_file, EXIT_BLOCK_PTR_FOR_FN, FOR_EACH_BB_FN, FOR_EACH_EDGE, basic_block_def::index, loop::next, basic_block_def::next_bb, NULL, basic_block_def::prev_bb, and set_bb_indices().

Referenced by reorg_loops().

◆ reorg_loops()

void reorg_loops ( bool do_reorder,
struct hw_doloop_hooks * hooks )
This function can be used from a port's machine_dependent_reorg to
find and analyze loops that end in loop_end instructions.  It uses
a set of function pointers in HOOKS to call back into the
target-specific functions to perform the actual machine-specific

Such transformations typically involve additional set-up
instructions before the loop, to define loop bounds or set up a
special loop counter register.

DO_REORDER should be set to true if we should try to use the
reorder_loops function to ensure the loop end occurs after the loop
start.  This is for use by targets where the loop hardware requires
this condition.

HOOKS is used to pass in target specific hooks; see

References bitmap_obstack_initialize(), bitmap_obstack_release(), crtl, df_analyze(), df_live_add_problem(), df_live_set_all_dirty(), discover_loops(), dump_file, dump_hwloops(), free_loops(), get_insns(), loop::next, NULL, optimize_loop(), print_rtl(), reorder_loops(), and scan_loop().

◆ scan_loop()

static void scan_loop ( hwloop_info loop)

◆ set_bb_indices()

static void set_bb_indices ( void )
Initialize the aux fields to give ascending indices to basic blocks.   

References basic_block_def::aux, cfun, and FOR_EACH_BB_FN.

Referenced by reorder_loops().