GCC Middle and Back End API Reference
genpreds.c File Reference
#include "bconfig.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "rtl.h"
#include "errors.h"
#include "obstack.h"
#include "read-md.h"
#include "gensupport.h"
Include dependency graph for genpreds.c:

Data Structures

struct  constraint_data

Macros

#define NO_MODE_TEST(EXP)   RTX_FLAG (EXP, volatil)
#define FOR_ALL_CONSTRAINTS(iter_)   for (iter_ = first_constraint; iter_; iter_ = iter_->next_textual)

Functions

static bool validate_exp ()
static void process_define_predicate ()
static void write_predicate_subfunction ()
static bool needs_variable ()
static void mark_mode_tests ()
static bool generate_switch_p ()
static void add_mode_tests ()
static void write_extract_subexp ()
static void write_match_code ()
static void write_predicate_expr ()
static void write_match_code_switch ()
static void write_predicate_stmts ()
static void write_one_predicate_function ()
static const char * mangle ()
static void add_constraint (const char *name, const char *regclass, rtx exp, bool is_memory, bool is_address, int lineno)
static void process_define_constraint ()
static void process_define_register_constraint ()
static void write_enum_constraint_num ()
static void write_lookup_constraint ()
static void write_insn_constraint_len ()
static void write_regclass_for_constraint ()
static void write_tm_constrs_h ()
static void write_constraint_satisfied_p ()
static void write_insn_const_int_ok_for_constraint ()
static void write_insn_extra_memory_constraint ()
static void write_insn_extra_address_constraint ()
static void write_tm_preds_h ()
static void write_insn_preds_c ()
static bool parse_option ()
int main ()

Variables

static struct constraint_dataconstraints_by_letter_table [1<< CHAR_BIT]
static struct constraint_datafirst_constraint
static struct constraint_data ** last_constraint_ptr = &first_constraint
static const char generic_constraint_letters [] = "EFVXginoprs"
static const char const_int_constraints [] = "IJKLMNOP"
static const char const_dbl_constraints [] = "GH"
static unsigned int constraint_max_namelen
static bool have_register_constraints
static bool have_memory_constraints
static bool have_address_constraints
static bool have_extra_constraints
static bool have_const_int_constraints
static bool have_const_dbl_constraints
static bool gen_header
static bool gen_constrs

Macro Definition Documentation

#define FOR_ALL_CONSTRAINTS (   iter_)    for (iter_ = first_constraint; iter_; iter_ = iter_->next_textual)
#define NO_MODE_TEST (   EXP)    RTX_FLAG (EXP, volatil)

Given an RTL expression EXP, find all subexpressions which we may assume to perform mode tests. Normal MATCH_OPERAND does; MATCH_CODE does if it applies to the whole expression and accepts CONST_INT or CONST_DOUBLE; and we have to assume that MATCH_TEST does not. These combine in almost-boolean fashion - the only exception is that (not X) must be assumed not to perform a mode test, whether or not X does.

The mark is the RTL /v flag, which is true for subexpressions which do not perform mode tests.

Referenced by add_mode_tests().


Function Documentation

static void add_constraint ( const char *  name,
const char *  regclass,
rtx  exp,
bool  is_memory,
bool  is_address,
int  lineno 
)
static

Add one constraint, of any sort, to the tables. NAME is its name; REGCLASS is the register class, if any; EXP is the expression to test, if any; IS_MEMORY and IS_ADDRESS indicate memory and address constraints, respectively; LINENO is the line number from the MD reader. Not all combinations of arguments are valid; most importantly, REGCLASS is mutually exclusive with EXP, and IS_MEMORY/IS_ADDRESS are only meaningful for constraints with EXP.

This function enforces all syntactic and semantic rules about what constraints can be defined.

     This causes slot to end up pointing to the
     next_this_letter field of the last constraint with a name
     of equal or greater length than the new constraint; hence
     the new constraint will be inserted after all previous
     constraints with names of the same length.   
     Consider relaxing this requirement in the future.   
 Insert this constraint in the list of all constraints in textual
 order.   
static void add_mode_tests ( )
static

Given a predicate, work out where in its RTL expression to add tests for proper modes. Special predicates do not get any such tests. We try to avoid adding tests when we don't have to; in particular, other normal predicates can be counted on to do it for us.

 Don't touch special predicates.   
 If the whole expression already tests the mode, we're done.   
 It is always correct to rewrite p->exp as

    (and (...) (match_test "mode == VOIDmode || GET_MODE (op) == mode"))

 but there are a couple forms where we can do better.  If the
 top-level pattern is an IOR, and one of the two branches does test
 the mode, we can wrap just the branch that doesn't.  Likewise, if
 we have an IF_THEN_ELSE, and one side of it tests the mode, we can
 wrap just the side that doesn't.  And, of course, we can repeat this
 descent as many times as it works.   
         The switch code generation in write_predicate_stmts prefers
         rtx code tests to be at the top of the expression tree.  So
         push this AND down into the second operand of an existing
         AND expression.   
             Must put it on the dependent clause, not the
             controlling expression, or we change the meaning of
             the test.   

References gcc_assert, generate_switch_p(), GET_CODE, NO_MODE_TEST, and XEXP.

static bool generate_switch_p ( )
static

Determine whether the expression EXP is a MATCH_CODE that should be written as a switch statement.

Referenced by add_mode_tests().

int main ( )

Master control.

static const char* mangle ( )
static

Convert NAME, which contains angle brackets and/or underscores, to a string that can be used as part of a C identifier. The string comes from the rtl_obstack.

static void mark_mode_tests ( )
static

A ? B : C does a mode test if (one of A and B) does a mode test, and C does too.

static bool needs_variable ( )
static

Given a predicate expression EXP, from form NAME, determine whether it refers to the variable given as VAR.

     Ternary, binary, unary expressions need a variable if
     any of their subexpressions do.   
     else fall through  
     else fall through  
     MATCH_CODE uses "op", but nothing else.   
     MATCH_OPERAND uses "op" and may use "mode".   
     MATCH_TEST uses var if XSTR (exp, 0) =~ /\b${var}\b/o;  

Referenced by write_insn_constraint_len().

static bool parse_option ( )
static
static void process_define_constraint ( )
static

Process a DEFINE_CONSTRAINT, DEFINE_MEMORY_CONSTRAINT, or DEFINE_ADDRESS_CONSTRAINT expression, C.

static void process_define_predicate ( )
static

Predicates are defined with (define_predicate) or (define_special_predicate) expressions in the machine description.

References pred_data::c_block, pred_data::name, and rtl_obstack.

static void process_define_register_constraint ( )
static

Process a DEFINE_REGISTER_CONSTRAINT expression, C.

static bool validate_exp ( )
static

Generate from machine description:

  • prototype declarations for operand predicates (tm-preds.h)
  • function definitions of operand predicates, if defined new-style (insn-preds.c) Copyright (C) 2001-2013 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 version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 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 http://www.gnu.org/licenses/. Given a predicate expression EXP, from form NAME at line LINENO, verify that it does not contain any RTL constructs which are not valid in predicate definitions. Returns true if EXP is INvalid; issues error messages, caller need not.

     Ternary, binary, unary expressions: recurse into subexpressions.   
     else fall through  
     else fall through  
     MATCH_CODE might have a syntax error in its path expression.   
     fall through  
     These need no special checking.   

References message_with_line().

static void write_constraint_satisfied_p ( )
static

Write out the wrapper function, constraint_satisfied_p, that maps a CONSTRAINT_xxx constant to one of the predicate functions generated above.

References constraint_data::c_name, FOR_ALL_CONSTRAINTS, and constraint_data::is_memory.

static void write_enum_constraint_num ( )
static

Write out an enumeration with one entry per machine-specific constraint.

Referenced by write_insn_extra_memory_constraint().

static void write_extract_subexp ( )
static

PATH is a string describing a path from the root of an RTL expression to an inner subexpression to be tested. Output code which computes the subexpression from the variable holding the root of the expression.

We first write out the operations (XEXP or XVECEXP) in reverse order, then write "op", then the indices in forward order.

References scan_comma_elt().

static void write_insn_const_int_ok_for_constraint ( )
static

Write out the function which computes whether a given value matches a given CONST_INT constraint. This doesn't just forward to constraint_satisfied_p because caller passes the INTVAL, not the RTX.

c->exp is guaranteed to be (and (match_code "const_int") (...)); we know at this point that we have a const_int, so we need not bother with that part of the test.

static void write_insn_constraint_len ( )
static

Write out a function which looks at a string and determines what the constraint name length is.

Constraints with multiple characters should have the same length.

References constraint_data::c_name, constraint_data::exp, FOR_ALL_CONSTRAINTS, in_fname, constraint_data::is_register, needs_variable(), and progname.

Referenced by write_insn_extra_memory_constraint().

static void write_insn_extra_address_constraint ( )
static

Write out the function which computes whether a given constraint is an address constraint.

static void write_insn_extra_memory_constraint ( )
static

Write out the function which computes whether a given constraint is a memory constraint.

References write_enum_constraint_num(), and write_insn_constraint_len().

static void write_insn_preds_c ( )
static

Write insn-preds.c. N.B. the list of headers to include was copied from genrecog; it may not be ideal.

FUTURE: Write #line markers referring back to the machine description. (Can't practically do this now since we don't know the line number of the C block - just the line number of the enclosing expression.)

static void write_lookup_constraint ( )
static

Write out a function which looks at a string and determines what constraint name, if any, it begins with.

References error(), constraint_data::namelen, and constraint_data::next_this_letter.

static void write_match_code ( )
static

CODES is a list of RTX codes. Write out an expression which determines whether the operand has one of those codes.

static void write_match_code_switch ( )
static

Write the MATCH_CODE expression EXP as a switch statement.

static void write_one_predicate_function ( )
static

Given a predicate, write out a complete C function to compute it.

A normal predicate can legitimately not look at enum machine_mode if it accepts only CONST_INTs and/or CONST_DOUBLEs.

static void write_predicate_expr ( )
static

EXP is an RTL (sub)expression for a predicate. Recursively descend the expression and write out an equivalent C expression.

static void write_predicate_stmts ( )
static

Given a predicate expression EXP, write out a sequence of stmts to evaluate it. This is similar to write_predicate_expr but can generate efficient switch statements.

static void write_predicate_subfunction ( )
static

Given a predicate, if it has an embedded C block, write the block out as a static inline subroutine, and augment the RTL test with a match_test that calls that subroutine. For instance,

(define_predicate "basereg_operand"
  (match_operand 0 "register_operand")
{
  if (GET_CODE (op) == SUBREG)
    op = SUBREG_REG (op);
  return REG_POINTER (op);
})

becomes

static inline int basereg_operand_1(rtx op, enum machine_mode mode)
{
  if (GET_CODE (op) == SUBREG)
    op = SUBREG_REG (op);
  return REG_POINTER (op);
}

(define_predicate "basereg_operand"
  (and (match_operand 0 "register_operand")
       (match_test "basereg_operand_1 (op, mode)")))

The only wart is that there's no way to insist on a { } string in an RTL template, so we have to handle "" strings.

Construct the function-call expression.

 Add the function-call expression to the complete expression to be
 evaluated.   
static void write_regclass_for_constraint ( )
static

Write out the function which computes the register class corresponding to a register constraint.

static void write_tm_constrs_h ( )
static

Write out the functions which compute whether a given value matches a given non-register constraint.

References constraint_data::c_name, FOR_ALL_CONSTRAINTS, and constraint_data::is_register.

static void write_tm_preds_h ( )
static

Write tm-preds.h. Unfortunately, it is impossible to forward-declare an enumeration in portable C, so we have to condition all these prototypes on HAVE_MACHINE_MODES.


Variable Documentation

const char const_dbl_constraints[] = "GH"
static

Machine-independent code expects that constraints with these (initial) letters will allow only (a subset of all) CONST_DOUBLEs.

const char const_int_constraints[] = "IJKLMNOP"
static

Machine-independent code expects that constraints with these (initial) letters will allow only (a subset of all) CONST_INTs.

unsigned int constraint_max_namelen
static

Summary data used to decide whether to output various functions and macro definitions.

struct constraint_data* constraints_by_letter_table[1<< CHAR_BIT]
static

Overview of all constraints beginning with a given letter.

struct constraint_data* first_constraint
static

For looking up all the constraints in the order that they appeared in the machine description.

bool gen_constrs
static
bool gen_header
static

Argument parsing.

const char generic_constraint_letters[] = "EFVXginoprs"
static

These letters, and all names beginning with them, are reserved for generic constraints. The 'm' constraint is not mentioned here since that constraint letter can be overridden by the back end by defining the TARGET_MEM_CONSTRAINT macro.

bool have_address_constraints
static
bool have_const_dbl_constraints
static
bool have_const_int_constraints
static
bool have_extra_constraints
static
bool have_memory_constraints
static
bool have_register_constraints
static
struct constraint_data** last_constraint_ptr = &first_constraint
static