gccint: MODE_CC Condition Codes
1
1 18.15.2 Representation of condition codes using registers
1 ---------------------------------------------------------
1
1 -- Macro: SELECT_CC_MODE (OP, X, Y)
1 On many machines, the condition code may be produced by other
1 instructions than compares, for example the branch can use directly
1 the condition code set by a subtract instruction. However, on some
1 machines when the condition code is set this way some bits (such as
1 the overflow bit) are not set in the same way as a test
1 instruction, so that a different branch instruction must be used
1 for some conditional branches. When this happens, use the machine
1 mode of the condition code register to record different formats of
1 the condition code register. Modes can also be used to record
1 which compare instruction (e.g. a signed or an unsigned
1 comparison) produced the condition codes.
1
1 If other modes than 'CCmode' are required, add them to
1 'MACHINE-modes.def' and define 'SELECT_CC_MODE' to choose a mode
1 given an operand of a compare. This is needed because the modes
1 have to be chosen not only during RTL generation but also, for
1 example, by instruction combination. The result of
1 'SELECT_CC_MODE' should be consistent with the mode used in the
1 patterns; for example to support the case of the add on the SPARC
1 discussed above, we have the pattern
1
1 (define_insn ""
1 [(set (reg:CCNZ 0)
1 (compare:CCNZ
1 (plus:SI (match_operand:SI 0 "register_operand" "%r")
1 (match_operand:SI 1 "arith_operand" "rI"))
1 (const_int 0)))]
1 ""
1 "...")
1
1 together with a 'SELECT_CC_MODE' that returns 'CCNZmode' for
1 comparisons whose argument is a 'plus':
1
1 #define SELECT_CC_MODE(OP,X,Y) \
1 (GET_MODE_CLASS (GET_MODE (X)) == MODE_FLOAT \
1 ? ((OP == LT || OP == LE || OP == GT || OP == GE) \
1 ? CCFPEmode : CCFPmode) \
1 : ((GET_CODE (X) == PLUS || GET_CODE (X) == MINUS \
1 || GET_CODE (X) == NEG || GET_CODE (x) == ASHIFT) \
1 ? CCNZmode : CCmode))
1
1 Another reason to use modes is to retain information on which
1 operands were used by the comparison; see 'REVERSIBLE_CC_MODE'
1 later in this section.
1
1 You should define this macro if and only if you define extra CC
1 modes in 'MACHINE-modes.def'.
1
1 -- Target Hook: void TARGET_CANONICALIZE_COMPARISON (int *CODE, rtx
1 *OP0, rtx *OP1, bool OP0_PRESERVE_VALUE)
1 On some machines not all possible comparisons are defined, but you
1 can convert an invalid comparison into a valid one. For example,
1 the Alpha does not have a 'GT' comparison, but you can use an 'LT'
1 comparison instead and swap the order of the operands.
1
1 On such machines, implement this hook to do any required
1 conversions. CODE is the initial comparison code and OP0 and OP1
1 are the left and right operands of the comparison, respectively.
1 If OP0_PRESERVE_VALUE is 'true' the implementation is not allowed
1 to change the value of OP0 since the value might be used in RTXs
1 which aren't comparisons. E.g. the implementation is not allowed
1 to swap operands in that case.
1
1 GCC will not assume that the comparison resulting from this macro
1 is valid but will see if the resulting insn matches a pattern in
1 the 'md' file.
1
1 You need not to implement this hook if it would never change the
1 comparison code or operands.
1
1 -- Macro: REVERSIBLE_CC_MODE (MODE)
1 A C expression whose value is one if it is always safe to reverse a
1 comparison whose mode is MODE. If 'SELECT_CC_MODE' can ever return
1 MODE for a floating-point inequality comparison, then
1 'REVERSIBLE_CC_MODE (MODE)' must be zero.
1
1 You need not define this macro if it would always returns zero or
1 if the floating-point format is anything other than
1 'IEEE_FLOAT_FORMAT'. For example, here is the definition used on
1 the SPARC, where floating-point inequality comparisons are given
1 either 'CCFPEmode' or 'CCFPmode':
1
1 #define REVERSIBLE_CC_MODE(MODE) \
1 ((MODE) != CCFPEmode && (MODE) != CCFPmode)
1
1 -- Macro: REVERSE_CONDITION (CODE, MODE)
1 A C expression whose value is reversed condition code of the CODE
1 for comparison done in CC_MODE MODE. The macro is used only in
1 case 'REVERSIBLE_CC_MODE (MODE)' is nonzero. Define this macro in
1 case machine has some non-standard way how to reverse certain
1 conditionals. For instance in case all floating point conditions
1 are non-trapping, compiler may freely convert unordered compares to
1 ordered ones. Then definition may look like:
1
1 #define REVERSE_CONDITION(CODE, MODE) \
1 ((MODE) != CCFPmode ? reverse_condition (CODE) \
1 : reverse_condition_maybe_unordered (CODE))
1
1 -- Target Hook: bool TARGET_FIXED_CONDITION_CODE_REGS (unsigned int
1 *P1, unsigned int *P2)
1 On targets which do not use '(cc0)', and which use a hard register
1 rather than a pseudo-register to hold condition codes, the regular
1 CSE passes are often not able to identify cases in which the hard
1 register is set to a common value. Use this hook to enable a small
1 pass which optimizes such cases. This hook should return true to
1 enable this pass, and it should set the integers to which its
1 arguments point to the hard register numbers used for condition
1 codes. When there is only one such register, as is true on most
1 systems, the integer pointed to by P2 should be set to
1 'INVALID_REGNUM'.
1
1 The default version of this hook returns false.
1
1 -- Target Hook: machine_mode TARGET_CC_MODES_COMPATIBLE (machine_mode
1 M1, machine_mode M2)
1 On targets which use multiple condition code modes in class
1 'MODE_CC', it is sometimes the case that a comparison can be
1 validly done in more than one mode. On such a system, define this
1 target hook to take two mode arguments and to return a mode in
1 which both comparisons may be validly done. If there is no such
1 mode, return 'VOIDmode'.
1
1 The default version of this hook checks whether the modes are the
1 same. If they are, it returns that mode. If they are different,
1 it returns 'VOIDmode'.
1
1 -- Target Hook: unsigned int TARGET_FLAGS_REGNUM
1 If the target has a dedicated flags register, and it needs to use
1 the post-reload comparison elimination pass, then this value should
1 be set appropriately.
1