1/* Common hooks for NEC V850 series.
2   Copyright (C) 1996-2020 Free Software Foundation, Inc.
3
4   This file is part of GCC.
5
6   GCC is free software; you can redistribute it and/or modify it
7   under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 3, or (at your option)
9   any later version.
10
11   GCC is distributed in the hope that it will be useful, but WITHOUT
12   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14   for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with GCC; see the file COPYING3.  If not see
18   <http://www.gnu.org/licenses/>.  */
19
20#include "config.h"
21#include "system.h"
22#include "coretypes.h"
23#include "diagnostic-core.h"
24#include "tm.h"
25#include "common/common-target.h"
26#include "common/common-target-def.h"
27#include "opts.h"
28#include "flags.h"
29
30/* Information about the various small memory areas.  */
31static const int small_memory_physical_max[(int) SMALL_MEMORY_max] =
32{
33  256,
34  65536,
35  32768,
36};
37
38/* Set the maximum size of small memory area TYPE to the value given
39   by SIZE in structure OPTS (option text OPT passed at location LOC).  */
40
41static void
42v850_handle_memory_option (enum small_memory_type type,
43			   struct gcc_options *opts, const char *opt,
44			   int size, location_t loc)
45{
46  if (size > small_memory_physical_max[type])
47    error_at (loc, "value passed in %qs is too large", opt);
48  else
49    opts->x_small_memory_max[type] = size;
50}
51
52/* Implement TARGET_HANDLE_OPTION.  */
53
54static bool
55v850_handle_option (struct gcc_options *opts,
56		    struct gcc_options *opts_set ATTRIBUTE_UNUSED,
57		    const struct cl_decoded_option *decoded,
58		    location_t loc)
59{
60  size_t code = decoded->opt_index;
61  int value = decoded->value;
62
63  switch (code)
64    {
65    case OPT_mspace:
66      opts->x_target_flags |= MASK_EP | MASK_PROLOG_FUNCTION;
67      return true;
68
69    case OPT_mv850:
70      opts->x_target_flags &= ~(MASK_CPU ^ MASK_V850);
71      return true;
72
73    case OPT_mv850e:
74    case OPT_mv850e1:
75    case OPT_mv850es:
76      opts->x_target_flags &= ~(MASK_CPU ^ MASK_V850E);
77      return true;
78
79    case OPT_mv850e2:
80      opts->x_target_flags &= ~(MASK_CPU ^ MASK_V850E2);
81      return true;
82
83    case OPT_mv850e2v3:
84      opts->x_target_flags &= ~(MASK_CPU ^ MASK_V850E2V3);
85      return true;
86
87    case OPT_mtda_:
88      v850_handle_memory_option (SMALL_MEMORY_TDA, opts,
89				 decoded->orig_option_with_args_text,
90				 value, loc);
91      return true;
92
93    case OPT_msda_:
94      v850_handle_memory_option (SMALL_MEMORY_SDA, opts,
95				 decoded->orig_option_with_args_text,
96				 value, loc);
97      return true;
98
99    case OPT_mzda_:
100      v850_handle_memory_option (SMALL_MEMORY_ZDA, opts,
101				 decoded->orig_option_with_args_text,
102				 value, loc);
103      return true;
104
105    default:
106      return true;
107    }
108}
109
110/* Implement TARGET_OPTION_OPTIMIZATION_TABLE.  */
111
112static const struct default_options v850_option_optimization_table[] =
113  {
114    /* Note - we no longer enable MASK_EP when optimizing.  This is
115       because of a hardware bug which stops the SLD and SST instructions
116       from correctly detecting some hazards.  If the user is sure that
117       their hardware is fixed or that their program will not encounter
118       the conditions that trigger the bug then they can enable -mep by
119       hand.  */
120    { OPT_LEVELS_1_PLUS, OPT_mprolog_function, NULL, 1 },
121    { OPT_LEVELS_NONE, 0, NULL, 0 }
122  };
123
124#undef  TARGET_DEFAULT_TARGET_FLAGS
125#define TARGET_DEFAULT_TARGET_FLAGS \
126  (MASK_DEFAULT | MASK_APP_REGS | MASK_BIG_SWITCH)
127#undef  TARGET_HANDLE_OPTION
128#define TARGET_HANDLE_OPTION v850_handle_option
129#undef  TARGET_OPTION_OPTIMIZATION_TABLE
130#define TARGET_OPTION_OPTIMIZATION_TABLE v850_option_optimization_table
131
132struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER;
133