CFGraph.xcc

Benoit Dupont de Dinechin (Benoit.Dupont-de-Dinechin@st.com).

Copyright 2002 - 2007 STMicroelectronics. Copyright 1995 - 1998 Commissariat a l'Energie Atomique.

This program is free software; you can redistribute it and/or modify it under the terms of either (at your option): the GNU General Public License (GPL) version 2; the GNU Lesser General Public License (LGPL) version 2.1; any later version of these licences as published by the Free Software Foundation.

CFGArc— Arc of the control-flow graph.
struct CFGArc_;
  //@access TAIL        (CFGNode)DGraphArc_TAILNODE(this)
  //@access HEAD        (CFGNode)DGraphArc_HEADNODE(this)
CFGNode— Node of the control-flow graph.
struct CFGNode_;
  //@access INDEX       DGraphNode_INDEX(this)
  //@access NUMBER      DGraphNode_NUMBER(this)
CFGArcFlag— Enumerates the CFGArc flags.
typedef enum {
  CFGArcFlag_Fall = 0x1,                // CFGArc is fall-through.
} enum_CFGArcFlag;
typedef uint8_t CFGArcFlags;
CFGArc_probability— This CFGArc probability.
static inline float
CFGArc_probability(CFGArc this)
{
  return CFGArc_PROBABILITY(this);
}
CFGArc_setProbability— Set this CFGArc probability.
static inline void
CFGArc_setProbability(CFGArc this, float probability)
{
  *CFGArc__PROBABILITY(this) = probability;
}
CFGArc_attachTailNode— Attach this CFGArc to a tail CFGNode.
void
CFGArc_attachTailNode(CFGArc this, CFGNode node);
#define CFGArc_attachTailNode(this, node) \
  DGraphArc_attachTailNode((DGraphArc)(this), (DGraphNode)(node))
CFGArc_attachHeadNode— Attach this CFGArc to a head CFGNode.
void
CFGArc_attachHeadNode(CFGArc this, CFGNode node);
#define CFGArc_attachHeadNode(this, node) \
  DGraphArc_attachHeadNode((DGraphArc)(this), (DGraphNode)(node))
CFGArc_detachTailNode— Detach this CFGArc from its tail CFGNode.
void
CFGArc_detachTailNode(CFGArc this);
#define CFGArc_detachTailNode(this) \
  DGraphArc_detachTailNode((DGraphArc)(this))
CFGArc_detachHeadNode— Detach this CFGArc from its head CFGNode.
void
CFGArc_detachHeadNode(CFGArc this);
#define CFGArc_detachHeadNode(this) \
  DGraphArc_detachHeadNode((DGraphArc)(this))
CFGArc_setFlags— Set the flags of the arc.
static inline void
CFGArc_setFlags(CFGArc this, CFGArcFlags flags)
{
    *CFGArc__FLAGS(this) = flags;
}
CFGArc_addFlags— Add the following flags to the arc. (union)
static inline void
CFGArc_addFlags(CFGArc this, CFGArcFlags flags)
{
    *CFGArc__FLAGS(this) |= flags;
}
CFGArc_clearFlags— Clear the following flags from the arc. (difference)
static inline void
CFGArc_clearFlags(CFGArc this, CFGArcFlags flags)
{
  *CFGArc__FLAGS(this) &= ~flags;
}
CFGNodeFlag— Enumerates the CFGNode flags.
typedef enum {
  CFGNodeFlag_Stop = 0x1,               // CFGNode is a superblock stop node.
  CFGNodeFlag_Grow = 0x2,               // CFGNode is a superblock grow node.
  CFGNodeFlag_Start = 0x4,              // CFGNode must start a superblock.
  CFGNodeFlag_Widen = 0x8,              // CFGNode is a widening point.
  CFGNodeFlag_Inner = 0x10              // CFGNode is a inner loop header.
} enum_CFGNodeFlag;
typedef uint8_t CFGNodeFlags;
CFGNode_index— This CFGNode index in the CFGraph.
static inline uint32_t
CFGNode_index(CFGNode this)
{
  return CFGNode_INDEX(this);
}
CFGNode_number— This CFGNode number in the CFGraph.
static inline uint32_t
CFGNode_number(CFGNode this)
{
  return CFGNode_NUMBER(this);
}
CFGNode_basicBlock— This CFGNode BasicBlock.
static inline BasicBlock
CFGNode_basicBlock(CFGNode this)
{
  return CFGNode_BASICBLOCK(this);
}
CFGNode_liveInSet— The live-in for this CFGNode.
static inline TemporarySet
CFGNode_liveInSet(CFGNode this)
{
  return CFGNode_LIVEINSET(this);
}
#define CFGNode_isLiveInSet(this, temporary) \
  TemporarySet_contains(CFGNode_liveInSet(this), temporary)
CFGNode_liveOutSet— The live-out for this CFGNode.
static inline TemporarySet
CFGNode_liveOutSet(CFGNode this)
{
  return CFGNode_LIVEOUTSET(this);
}
#define CFGNode_isLiveOutSet(this, temporary) \
  TemporarySet_contains(CFGNode_liveOutSet(this), temporary)
CFGNode_nextNode— The next CFGNode in the BlockTrace.
static inline CFGNode
CFGNode_nextNode(CFGNode this)
{
  return CFGNode_NEXTNODE(this);
}
CFGNode_prevNode— The previous CFGNode in the BlockTrace.
static inline CFGNode
CFGNode_prevNode(CFGNode this)
{
  return CFGNode_PREVNODE(this);
}
CFGNode_numbering— This CFGNode numbering in the BlockTrace.
static inline int
CFGNode_numbering(CFGNode this)
{
  return CFGNode_NUMBERING(this);
}
CFGNode_FORENTER_CFGArc— Iterate over the entering CFGArcs.
#define CFGNode_FORENTER_CFGArc(this, arc) \
  DGraphNode_FORENTER(this, CFGArc_, arc)
#define CFGNode_ENDENTER_CFGArc \
  DGraphNode_ENDENTER;
CFGNode_FORLEAVE_CFGArc— Iterate over the leaving CFGArcs.
#define CFGNode_FORLEAVE_CFGArc(this, arc) \
  DGraphNode_FORLEAVE(this, CFGArc_, arc)
#define CFGNode_ENDLEAVE_CFGArc \
  DGraphNode_ENDLEAVE;
CFGNode_liveInSet_FORSORT_Temporary— Iterate over the liveInSet Temporaries.
#define CFGNode_liveInSet_FORSORT_Temporary(this, temporary) \
  TemporarySet_FORSORT_Temporary(CFGNode_liveInSet(this), Temporary_compare, temporary)
#define CFGNode_liveInSet_ENDSORT_Temporary \
  TemporarySet_ENDSORT_Temporary;
CFGNode_liveOutSet_FORSORT_Temporary— Iterate over the liveOutSet Temporaries.
#define CFGNode_liveOutSet_FORSORT_Temporary(this, temporary) \
  TemporarySet_FORSORT_Temporary(CFGNode_liveOutSet(this), Temporary_compare, temporary)
#define CFGNode_liveOutSet_ENDSORT_Temporary \
  TemporarySet_ENDSORT_Temporary;
CFGNode_check— Check this CFGNode.
bool
CFGNode_check(const_CFGNode this);
CFGNode_pretty— Pretty-print this CFGNode.
bool
CFGNode_pretty(CFGNode this, FILE *file);
CFGNode_isPredecessor— Tests if that CFGNode is a predecessor of this CFGNode.
bool
CFGNode_isPredecessor(CFGNode this, CFGNode that);
CFGNode_isSuccessor— Tests if that CFGNode is a successor of this CFGNode.
bool
CFGNode_isSuccessor(CFGNode this, CFGNode that);
CFGNode_hasSuccessor— Tests if that CFGNode is a successor of this CFGNode.
bool
CFGNode_hasSuccessor(CFGNode this, CFGNode that);
CFGNode_getOnlyPredecessor— Get the only predecessor of this CFGNode.
CFGNode
CFGNode_getOnlyPredecessor(CFGNode this);
CFGNode_isOnlyPredecessor— Test if that CFGNode is the only predecessor of this CFGNode.
#define CFGNode_isOnlyPredecessor(this, that) \
  (CFGNode_getOnlyPredecessor(this) == that)
CFGNode_getOnlySuccessor— Get the only successor of this CFGNode.
CFGNode
CFGNode_getOnlySuccessor(CFGNode this);
CFGNode_isOnlySuccessor— Test if that CFGNode is the only successor of this CFGNode.
#define CFGNode_isOnlySuccessor(this, that) \
  (CFGNode_getOnlySuccessor(this) == that)
CFGNode_getCFGArc— Get the CFGArc between two CFGNodes.
position
The position of the CFGArc (0 means first arc).
CFGArc
CFGNode_getCFGArc(CFGNode this, CFGNode that, int position);

CFGNode_getGoToOperation - Get the GOTO operation of this CFGNode.

Operation
CFGNode_getGoToOperation(CFGNode this);
CFGNode_hasGoToOperation— Test if this CFGNode has a GOTO operation.
#define CFGNode_hasGoToOperation(this) \
  (CFGNode_getGoToOperation(this) != NULL)
CFGNode_invertGoToOperation— Invert this CFGNode conditional GOTO operation.
bool
CFGNode_invertGoToOperation(CFGNode this);
CFGNode_discardGoToOperation— Discard this CFGNode unconditional GOTO operation.
bool
CFGNode_discardGoToOperation(CFGNode this);
!CFGNode_compare— Compare function for CFGNode(s).
//
int
CFGNode_compare(CFGNode this, CFGNode that);
CFGNode_getTargetArc— Get the target arc of this CFGNode.
CFGArc
CFGNode_getTargetArc(CFGNode this);
CFGNode_getFallArc— Get the fall-thru arc of this CFGNode.

Relies on CFGArc_isFall that must be properly set.

CFGArc
CFGNode_getFallArc(const_CFGNode this);
CFGNodeSet— Set of CFGNode(s).
struct CFGNodeSet_ {
  //@args       Memory memory, int32_t estimate
  PtrSet_ PTRSET_;              // The PtrSet_ that implements the set.
  //@access PTRSET      CFGNodeSet__PTRSET_(this)
  //@access MEMORY      PtrSet_memory(CFGNodeSet_PTRSET(this))
};
CFGNodeSet_ptrset— For use in CFGNodeSet_FORSORT_CFGNode.
static inline PtrSet
CFGNodeSet_ptrset(CFGNodeSet this)
{
  return CFGNodeSet_PTRSET(this);
}
CFGNodeSet_FOREACH_CFGNode— Iterate over this CFGNodeSet CFGNode(s).
#define CFGNodeSet_FOREACH_CFGNode(this, cfgNode) { \
  PtrSet CFGNodeSet_PTRSET = CFGNodeSet_ptrset(this); \
  PtrSet_FOREACH(CFGNodeSet_PTRSET, CFGNode, cfgNode) {
#define CFGNodeSet_ENDEACH_CFGNode \
  } PtrSet_ENDEACH \
}
CFGNodeSet_FORSORT_CFGNode— Iterate over this CFGNodeSet sorted CFGNode(s).
#define CFGNodeSet_FORSORT_CFGNode(this, cfgNode) { \
  PtrSet CFGNodeSet_PTRSET = CFGNodeSet_ptrset(this); \
  PtrSet_FORSORT(CFGNodeSet_PTRSET, CFGNode_compare, CFGNode, cfgNode) {
#define CFGNodeSet_ENDSORT_CFGNode \
  } PtrSet_ENDSORT \
}
CFGraph— Control-flow graph.

The CFGraph always contains a ROOT CFGNode, whose associated basic block is NULL. This ROOT CFGNode is connected to the Control-flow graph entries. Likewise, the CFGraph always contains a SINK CFGNode, whose associated basic block is NULL. The Control-flow exits are connected to this SINK CFGNode.

struct CFGraph_ {
  //@args       Memory memory, int32_t maxNodes
  //@access MEMORY      DGraph_memory(CFGraph_DGRAPH(this))
  //@access NODECOUNT   DGraph_count(CFGraph_DGRAPH(this))
  DGraph_ DGRAPH_;              // The base DGraph.
  //@access DGRAPH      CFGraph__DGRAPH_(this)
  //@access NODES       (CFGNode *)DGraph_nodes(CFGraph_DGRAPH(this))
  //@access NODEOF      (CFGraph_NODES(this) - 1)
  //@access ROOTNODE    (CFGNode)DGraph_rootNode(CFGraph_DGRAPH(this))
  CFGNode SINKNODE;
};
CFGraph_dgraph— This CFGraph DGraph.
static inline DGraph
CFGraph_dgraph(CFGraph this)
{
  return CFGraph_DGRAPH(this);
}
CFGraph_memory— This CFGraph Memory.
static inline Memory
CFGraph_memory(CFGraph this)
{
  return CFGraph_MEMORY(this);
}
CFGraph_rootNode— The start CFGNode of this CFGraph.
static inline CFGNode
CFGraph_rootNode(CFGraph this)
{
  return CFGraph_ROOTNODE(this);
}
CFGraph_sinkNode— Return the stop CFGNode of this CFGraph.
static inline CFGNode
CFGraph_sinkNode(CFGraph this)
{
  return CFGraph_SINKNODE(this);
}
CFGraph_FOREACH_CFGNode— Iterate over this CFGraph CFGNodes.
#define CFGraph_FOREACH_CFGNode(this, node) { \
  DGraph CFGraph_DGRAPH = CFGraph_dgraph(this); \
  DGraph_FOREACH(CFGraph_DGRAPH, CFGNode_, node)
#define CFGraph_ENDEACH_CFGNode \
  DGraph_ENDEACH \
}
CFGraph_makeArc— Make a CFGArc in this CFGraph.
CFGArc
CFGraph_makeArc(CFGraph this, CFGNode tail_node, CFGNode head_node,
                float probability, CFGArcFlags flags);
CFGraph_makeNode— Make a CFGNode in this CFGraph.
CFGNode
CFGraph_makeNode(CFGraph this, BasicBlock basicBlock);
CFGraph_complete— Complete the CFGraph with the SINKNODE.
CFGNode
CFGraph_complete(CFGraph this);
CFGraph_sortLeaveArcs— Sort this CFGraph leaving arcs.

The leaving CFGArcs are sorted using CFGArc_compare, thus ensuring that the highest frequency arc appears first in the leaving arc list. It there are more than two leaving arcs the order is unchanged.

CFGraph
CFGraph_sortLeaveArcs(CFGraph this);
CFGraph_prettyVCG— Pretty-print this CFGraph in VCG format.
bool
CFGraph_prettyVCG(CFGraph this, FILE *file, const char *name);