Gimple statements¶
-
class
gcc.
Gimple
¶ A statement, in GCC’s Gimple representation.
The __str__ method is implemented using GCC’s own pretty-printer for gimple, so e.g.:
str(stmt)
might return:
'D.3259 = (long unsigned int) i;'
-
loc
¶ Source code location of this statement, as a
gcc.Location
(or None)
-
exprtype
¶ The type of the main expression computed by this statement, as a
gcc.Tree
(which might begcc.VoidType
)
-
str_no_uid
¶ A string representation of this statement, like str(), but without including any internal UIDs.
This is intended for use in selftests that compare output against some expected value, to avoid embedding values that change into the expected output.
For example, given an assignment to a temporary, the str(stmt) for the gcc.GimpleAssign might be:
'D.3259 = (long unsigned int) i;'
where the UID “3259” is liable to change from compile to compile, whereas the stmt.str_no_uid has value:
'D.xxxx = (long unsigned int) i;'
which won’t arbitrarily change each time.
-
walk_tree
(callback, *args, **kwargs)¶ Visit all
gcc.Tree
nodes associated with this statement, potentially more than once each. This will visit both the left-hand-side and right-hand-side operands of the statement (if any), and recursively visit any of their child nodes.For each node, the callback is invoked, supplying the node, and any extra positional and keyword arguments passed to walk_tree:
callback(node, *args, **kwargs)
If the callback returns a true value, the traversal stops, and that
gcc.Tree
is the result of the call to walk_tree. Otherwise, the traversal continues, and walk_tree eventually returns None.
-
gcc.Gimple
has various subclasses, each corresponding to the
one of the kinds of statement within GCC’s internal representation.
The following subclasses have been wrapped for use from Python scripts:
Subclass | Meaning |
---|---|
gcc.GimpleAsm |
One or more inline assembly statements |
gcc.GimpleAssign |
An assignment of an expression to an l-value: LHS = RHS1 EXPRCODE RHS2;
|
gcc.GimpleCall |
A function call: [ LHS = ] FN(ARG1, ..., ARGN);
|
gcc.GimpleCond |
A conditional jump, of the form: if (LHS EXPRCODE RHS) goto TRUE_LABEL else goto FALSE_LABEL;
|
gcc.GimpleLabel |
A label statement (jump target): LABEL:
|
gcc.GimpleNop |
The “do nothing” statement |
gcc.GimplePhi |
Used in the SSA passes: LHS = PHI <ARG1, ..., ARGN>;
|
gcc.GimpleReturn |
A “return” statement: RETURN [RETVAL];
|
gcc.GimpleSwitch |
A switch statement: switch (INDEXVAR)
{
case LAB1: ...; break;
...
case LABN: ...; break;
default: ...
}
|
There are some additional subclasses that have not yet been fully wrapped by the Python plugin (email the gcc-python-plugin’s mailing list if you’re interested in working with these):
Subclass | Meaning |
---|---|
gcc.GimpleBind |
A lexical scope |
gcc.GimpleCatch |
An exception handler |
gcc.GimpleDebug |
A debug statement |
gcc.GimpleEhDispatch |
Used in exception-handling |
gcc.GimpleEhFilter |
Used in exception-handling |
gcc.GimpleEhMustNotThrow |
Used in exception-handling |
gcc.GimpleErrorMark |
A dummy statement used for handling internal errors |
gcc.GimpleGoto |
An unconditional jump |
gcc.GimpleOmpAtomicLoad |
Used for implementing OpenMP |
gcc.GimpleOmpAtomicStore |
(ditto) |
gcc.GimpleOmpContinue |
(ditto) |
gcc.GimpleOmpCritical |
(ditto) |
gcc.GimpleOmpFor |
(ditto) |
gcc.GimpleOmpMaster |
(ditto) |
gcc.GimpleOmpOrdered |
(ditto) |
gcc.GimpleOmpParallel |
(ditto) |
gcc.GimpleOmpReturn |
(ditto) |
gcc.GimpleOmpSection |
(ditto) |
gcc.GimpleOmpSections |
(ditto) |
gcc.GimpleOmpSectionsSwitch |
(ditto) |
gcc.GimpleOmpSingle |
(ditto) |
gcc.GimpleOmpTask |
(ditto) |
gcc.GimplePredict |
A hint for branch prediction |
gcc.GimpleResx |
Resumes execution after an exception |
gcc.GimpleTry |
A try/catch or try/finally statement |
gcc.GimpleWithCleanupExpr |
Internally used when generating GIMPLE |
-
class
gcc.
GimpleAsm
¶ Subclass of
gcc.Gimple
: a fragment of inline assembler code.-
string
¶ The inline assembler code, as a str.
-
-
class
gcc.
GimpleAssign
¶ Subclass of
gcc.Gimple
: an assignment of an expression to an l-value:LHS = RHS1 EXPRCODE RHS2;
-
class
gcc.
GimpleCall
¶ Subclass of
gcc.Gimple
: an invocation of a function, potentially assigning the result to an l-value:[ LHS = ] FN(ARG1, ..., ARGN);
-
noreturn
¶ (boolean) Has this call been marked as not returning? (e.g. a call to exit)
-
-
class
gcc.
GimpleReturn
¶ Subclass of
gcc.Gimple
: a “return” statement, signifying the end of agcc.BasicBlock
:RETURN [RETVAL];
-
retval
¶
The return value, as a
gcc.Tree
, or None.-
-
class
gcc.
GimpleCond
¶ Subclass of
gcc.Gimple
: a conditional jump, of the form:if (LHS EXPRCODE RHS) goto TRUE_LABEL else goto FALSE_LABEL
-
exprcode
¶ The comparison predicate, as a
gcc.Comparison
subclass (the type itself, not an instance). For example, the gcc.GimpleCond statement for this fragment of C code:if (a == b)
would have stmt.exprcode == gcc.EqExpr
-
true_label
¶ The
gcc.LabelDecl
node used as the jump target for when the comparison is true
-
false_label
¶ The
gcc.LabelDecl
node used as the jump target for when the comparison is false
Note that a C conditional of the form:
if (some_int) {suiteA} else {suiteB}
is implicitly expanded to:
if (some_int != 0) {suiteA} else {suiteB}
and this becomes a gcc.GimpleCond with lhs as the integer, exprcode as <type ‘gcc.NeExpr’>, and rhs as gcc.IntegerCst(0).
-
-
class
gcc.
GimplePhi
¶ Subclass of
gcc.Gimple
used in the SSA passes: a “PHI” or “phoney” function, for merging the various possible values a variable can have based on the edge that we entered thisgcc.BasicBlock
on:LHS = PHI <ARG1, ..., ARGN>;
-
lhs
¶ Left-hand-side of the assignment, as a
gcc.SsaName
-
args
¶ A list of (
gcc.Tree
,gcc.Edge
) pairs representing the possible (expr, edge) inputs. Each expr is either agcc.SsaName
or agcc.Constant
-
-
class
gcc.
GimpleSwitch
¶ Subclass of
gcc.Gimple
: a switch statement, signifying the end of agcc.BasicBlock
:switch (INDEXVAR) { case LAB1: ...; break; ... case LABN: ...; break; default: ... }
-
labels
¶ The labels of the switch statement, as a list of
gcc.CaseLabelExpr
.The initial label in the list is always the default.
-
-
class
gcc.
GimpleLabel
¶ Subclass of
gcc.Gimple
, representing a “label” statement:.. py:attribute:: labels
The underlyinggcc.LabelDecl
node representing this jump target
-
class
gcc.
GimpleAssign
Subclass of
gcc.Gimple
: an assignment of an expression to an l-value:LHS = RHS1 EXPRCODE RHS2;
-
lhs
Left-hand-side of the assignment, as a
gcc.Tree
-
rhs
The operands on the right-hand-side of the expression, as a list of
gcc.Tree
instances (either of length 1 or length 2, depending on the expression).
-
exprcode
The kind of the expression, as an
gcc.Tree
subclass (the type itself, not an instance)
-
-
class
gcc.
GimpleNop
¶ - Subclass of
gcc.Gimple
, representing a “do-nothing” statement (a.k.a. “no operation”).