14.21.1 Using RTL SSA in a pass

A pass that wants to use the RTL SSA form should start with the following:

#define INCLUDE_ALGORITHM
#define INCLUDE_FUNCTIONAL
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "rtl.h"
#include "df.h"
#include "rtl-ssa.h"

All the RTL SSA code is contained in the rtl_ssa namespace, so most passes will then want to do:

using namespace rtl_ssa;

However, this is purely a matter of taste, and the examples in the rest of this section do not require it.

The RTL SSA represention is an optional on-the-side feature that applies on top of the normal RTL instructions. It is currently local to individual RTL passes and is not maintained across passes.

However, in order to allow the RTL SSA information to be preserved across passes in future, ‘crtl->ssa’ points to the current function’s SSA form (if any). Passes that want to use the RTL SSA form should first do:

crtl->ssa = new rtl_ssa::function_info (fn);

where fn is the function that the pass is processing. (Passes that are using namespace rtl_ssa do not need the ‘rtl_ssa::’.)

Once the pass has finished with the SSA form, it should do the following:

free_dominance_info (CDI_DOMINATORS);
if (crtl->ssa->perform_pending_updates ())
  cleanup_cfg (0);

delete crtl->ssa;
crtl->ssa = nullptr;

The free_dominance_info call is necessary because dominance information is not currently maintained between RTL passes. The next two lines commit any changes to the RTL instructions that were queued for later; see the comment above the declaration of perform_pending_updates for details. The final two lines discard the RTL SSA form and free the associated memory.