Commit c98c2430 by Martin Liska Committed by Martin Liska

Come up with TARGET_GET_VALID_OPTION_VALUES option hook (PR driver/83193).

2018-09-03  Martin Liska  <mliska@suse.cz>

        PR driver/83193
	* common/common-target.def: Add TARGET_GET_VALID_OPTION_VALUES.
	* common/common-targhooks.c (default_get_valid_option_values):
        New function.
	* common/common-targhooks.h (default_get_valid_option_values):
        Likewise.
	* common/config/i386/i386-common.c: Move processor_target_table
        from i386.c.
	(ix86_get_valid_option_values): New function.
	(TARGET_GET_VALID_OPTION_VALUES): New macro.
	* config/i386/i386.c (struct ptt): Move to i386-common.c.
	(PTA_*): Move all defined masks into i386-common.c.
	(ix86_function_specific_restore): Use new processor_cost_table.
	* config/i386/i386.h (struct ptt): Moved from i386.c.
	(struct pta): Likewise.
	* doc/tm.texi: Document new TARGET_GET_VALID_OPTION_VALUES.
	* doc/tm.texi.in: Likewise.
	* opt-suggestions.c (option_proposer::suggest_option):
        Pass prefix to build_option_suggestions.
	(option_proposer::get_completions): Likewise.
	(option_proposer::build_option_suggestions): Use the new target
        hook.
	* opts.c (struct option_help_tuple): New struct.
	(print_filtered_help): Use the new target hook.
2018-09-03  Martin Liska  <mliska@suse.cz>

        PR driver/83193
	* gcc.dg/completion-4.c: New test.

From-SVN: r264052
parent d1dfeff0
2018-09-03 Martin Liska <mliska@suse.cz>
PR driver/83193
* common/common-target.def: Add TARGET_GET_VALID_OPTION_VALUES.
* common/common-targhooks.c (default_get_valid_option_values):
New function.
* common/common-targhooks.h (default_get_valid_option_values):
Likewise.
* common/config/i386/i386-common.c: Move processor_target_table
from i386.c.
(ix86_get_valid_option_values): New function.
(TARGET_GET_VALID_OPTION_VALUES): New macro.
* config/i386/i386.c (struct ptt): Move to i386-common.c.
(PTA_*): Move all defined masks into i386-common.c.
(ix86_function_specific_restore): Use new processor_cost_table.
* config/i386/i386.h (struct ptt): Moved from i386.c.
(struct pta): Likewise.
* doc/tm.texi: Document new TARGET_GET_VALID_OPTION_VALUES.
* doc/tm.texi.in: Likewise.
* opt-suggestions.c (option_proposer::suggest_option):
Pass prefix to build_option_suggestions.
(option_proposer::get_completions): Likewise.
(option_proposer::build_option_suggestions): Use the new target
hook.
* opts.c (struct option_help_tuple): New struct.
(print_filtered_help): Use the new target hook.
2018-09-03 Martin Liska <mliska@suse.cz>
PR middle-end/59521
* predict.c (set_even_probabilities): Add likely_edges
argument and handle cases where we have precisely one
......
......@@ -80,6 +80,17 @@ DEFHOOK
bool, (bool report, struct gcc_options *opts),
hook_bool_bool_gcc_optionsp_false)
DEFHOOK
(get_valid_option_values,
"The hook is used for options that have a non-trivial list of\
possible option values. OPTION_CODE is option code of opt_code\
enum type. PREFIX is used for bash completion and allows an implementation\
to return more specific completion based on the prefix. All string values\
should be allocated from heap memory and consumers should release them. \
The result will be pruned to cases with PREFIX if not NULL.",
vec<const char *>, (int option_code, const char *prefix),
default_get_valid_option_values)
/* Leave the boolean fields at the end. */
/* True if unwinding tables should be generated by default. */
......
......@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see
#include "tm.h"
#include "common/common-target.h"
#include "common/common-targhooks.h"
#include "opts.h"
/* Determine the exception handling mechanism for the target. */
......@@ -77,6 +78,14 @@ default_target_handle_option (struct gcc_options *opts ATTRIBUTE_UNUSED,
return true;
}
/* Default version of TARGET_GET_VALID_OPTION_VALUES. */
vec<const char *>
default_get_valid_option_values (int, const char *)
{
return vec<const char *> ();
}
const struct default_options empty_optimization_table[] =
{
{ OPT_LEVELS_NONE, 0, NULL, 0 }
......
......@@ -28,6 +28,7 @@ extern bool default_target_handle_option (struct gcc_options *,
struct gcc_options *,
const struct cl_decoded_option *,
location_t);
extern vec<const char *> default_get_valid_option_values (int, const char *);
extern const struct default_options empty_optimization_table[];
......
......@@ -2277,6 +2277,156 @@ enum processor_type
PROCESSOR_max
};
#if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) && !defined(IN_RTS)
/* Processor target table, indexed by processor number */
struct ptt
{
const char *const name; /* processor name */
/* Default alignments. */
const char *const align_loop;
const char *const align_jump;
const char *const align_label;
const char *const align_func;
};
extern const struct ptt processor_target_table[PROCESSOR_max];
#include "wide-int-bitmask.h"
const wide_int_bitmask PTA_3DNOW (HOST_WIDE_INT_1U << 0);
const wide_int_bitmask PTA_3DNOW_A (HOST_WIDE_INT_1U << 1);
const wide_int_bitmask PTA_64BIT (HOST_WIDE_INT_1U << 2);
const wide_int_bitmask PTA_ABM (HOST_WIDE_INT_1U << 3);
const wide_int_bitmask PTA_AES (HOST_WIDE_INT_1U << 4);
const wide_int_bitmask PTA_AVX (HOST_WIDE_INT_1U << 5);
const wide_int_bitmask PTA_BMI (HOST_WIDE_INT_1U << 6);
const wide_int_bitmask PTA_CX16 (HOST_WIDE_INT_1U << 7);
const wide_int_bitmask PTA_F16C (HOST_WIDE_INT_1U << 8);
const wide_int_bitmask PTA_FMA (HOST_WIDE_INT_1U << 9);
const wide_int_bitmask PTA_FMA4 (HOST_WIDE_INT_1U << 10);
const wide_int_bitmask PTA_FSGSBASE (HOST_WIDE_INT_1U << 11);
const wide_int_bitmask PTA_LWP (HOST_WIDE_INT_1U << 12);
const wide_int_bitmask PTA_LZCNT (HOST_WIDE_INT_1U << 13);
const wide_int_bitmask PTA_MMX (HOST_WIDE_INT_1U << 14);
const wide_int_bitmask PTA_MOVBE (HOST_WIDE_INT_1U << 15);
const wide_int_bitmask PTA_NO_SAHF (HOST_WIDE_INT_1U << 16);
const wide_int_bitmask PTA_PCLMUL (HOST_WIDE_INT_1U << 17);
const wide_int_bitmask PTA_POPCNT (HOST_WIDE_INT_1U << 18);
const wide_int_bitmask PTA_PREFETCH_SSE (HOST_WIDE_INT_1U << 19);
const wide_int_bitmask PTA_RDRND (HOST_WIDE_INT_1U << 20);
const wide_int_bitmask PTA_SSE (HOST_WIDE_INT_1U << 21);
const wide_int_bitmask PTA_SSE2 (HOST_WIDE_INT_1U << 22);
const wide_int_bitmask PTA_SSE3 (HOST_WIDE_INT_1U << 23);
const wide_int_bitmask PTA_SSE4_1 (HOST_WIDE_INT_1U << 24);
const wide_int_bitmask PTA_SSE4_2 (HOST_WIDE_INT_1U << 25);
const wide_int_bitmask PTA_SSE4A (HOST_WIDE_INT_1U << 26);
const wide_int_bitmask PTA_SSSE3 (HOST_WIDE_INT_1U << 27);
const wide_int_bitmask PTA_TBM (HOST_WIDE_INT_1U << 28);
const wide_int_bitmask PTA_XOP (HOST_WIDE_INT_1U << 29);
const wide_int_bitmask PTA_AVX2 (HOST_WIDE_INT_1U << 30);
const wide_int_bitmask PTA_BMI2 (HOST_WIDE_INT_1U << 31);
const wide_int_bitmask PTA_RTM (HOST_WIDE_INT_1U << 32);
const wide_int_bitmask PTA_HLE (HOST_WIDE_INT_1U << 33);
const wide_int_bitmask PTA_PRFCHW (HOST_WIDE_INT_1U << 34);
const wide_int_bitmask PTA_RDSEED (HOST_WIDE_INT_1U << 35);
const wide_int_bitmask PTA_ADX (HOST_WIDE_INT_1U << 36);
const wide_int_bitmask PTA_FXSR (HOST_WIDE_INT_1U << 37);
const wide_int_bitmask PTA_XSAVE (HOST_WIDE_INT_1U << 38);
const wide_int_bitmask PTA_XSAVEOPT (HOST_WIDE_INT_1U << 39);
const wide_int_bitmask PTA_AVX512F (HOST_WIDE_INT_1U << 40);
const wide_int_bitmask PTA_AVX512ER (HOST_WIDE_INT_1U << 41);
const wide_int_bitmask PTA_AVX512PF (HOST_WIDE_INT_1U << 42);
const wide_int_bitmask PTA_AVX512CD (HOST_WIDE_INT_1U << 43);
/* Hole after PTA_MPX was removed. */
const wide_int_bitmask PTA_SHA (HOST_WIDE_INT_1U << 45);
const wide_int_bitmask PTA_PREFETCHWT1 (HOST_WIDE_INT_1U << 46);
const wide_int_bitmask PTA_CLFLUSHOPT (HOST_WIDE_INT_1U << 47);
const wide_int_bitmask PTA_XSAVEC (HOST_WIDE_INT_1U << 48);
const wide_int_bitmask PTA_XSAVES (HOST_WIDE_INT_1U << 49);
const wide_int_bitmask PTA_AVX512DQ (HOST_WIDE_INT_1U << 50);
const wide_int_bitmask PTA_AVX512BW (HOST_WIDE_INT_1U << 51);
const wide_int_bitmask PTA_AVX512VL (HOST_WIDE_INT_1U << 52);
const wide_int_bitmask PTA_AVX512IFMA (HOST_WIDE_INT_1U << 53);
const wide_int_bitmask PTA_AVX512VBMI (HOST_WIDE_INT_1U << 54);
const wide_int_bitmask PTA_CLWB (HOST_WIDE_INT_1U << 55);
const wide_int_bitmask PTA_MWAITX (HOST_WIDE_INT_1U << 56);
const wide_int_bitmask PTA_CLZERO (HOST_WIDE_INT_1U << 57);
const wide_int_bitmask PTA_NO_80387 (HOST_WIDE_INT_1U << 58);
const wide_int_bitmask PTA_PKU (HOST_WIDE_INT_1U << 59);
const wide_int_bitmask PTA_AVX5124VNNIW (HOST_WIDE_INT_1U << 60);
const wide_int_bitmask PTA_AVX5124FMAPS (HOST_WIDE_INT_1U << 61);
const wide_int_bitmask PTA_AVX512VPOPCNTDQ (HOST_WIDE_INT_1U << 62);
const wide_int_bitmask PTA_SGX (HOST_WIDE_INT_1U << 63);
const wide_int_bitmask PTA_AVX512VNNI (0, HOST_WIDE_INT_1U);
const wide_int_bitmask PTA_GFNI (0, HOST_WIDE_INT_1U << 1);
const wide_int_bitmask PTA_VAES (0, HOST_WIDE_INT_1U << 2);
const wide_int_bitmask PTA_AVX512VBMI2 (0, HOST_WIDE_INT_1U << 3);
const wide_int_bitmask PTA_VPCLMULQDQ (0, HOST_WIDE_INT_1U << 4);
const wide_int_bitmask PTA_AVX512BITALG (0, HOST_WIDE_INT_1U << 5);
const wide_int_bitmask PTA_RDPID (0, HOST_WIDE_INT_1U << 6);
const wide_int_bitmask PTA_PCONFIG (0, HOST_WIDE_INT_1U << 7);
const wide_int_bitmask PTA_WBNOINVD (0, HOST_WIDE_INT_1U << 8);
const wide_int_bitmask PTA_WAITPKG (0, HOST_WIDE_INT_1U << 9);
const wide_int_bitmask PTA_CORE2 = PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2
| PTA_SSE3 | PTA_SSSE3 | PTA_CX16 | PTA_FXSR;
const wide_int_bitmask PTA_NEHALEM = PTA_CORE2 | PTA_SSE4_1 | PTA_SSE4_2
| PTA_POPCNT;
const wide_int_bitmask PTA_WESTMERE = PTA_NEHALEM | PTA_AES | PTA_PCLMUL;
const wide_int_bitmask PTA_SANDYBRIDGE = PTA_WESTMERE | PTA_AVX | PTA_XSAVE
| PTA_XSAVEOPT;
const wide_int_bitmask PTA_IVYBRIDGE = PTA_SANDYBRIDGE | PTA_FSGSBASE
| PTA_RDRND | PTA_F16C;
const wide_int_bitmask PTA_HASWELL = PTA_IVYBRIDGE | PTA_AVX2 | PTA_BMI
| PTA_BMI2 | PTA_LZCNT | PTA_FMA | PTA_MOVBE | PTA_HLE;
const wide_int_bitmask PTA_BROADWELL = PTA_HASWELL | PTA_ADX | PTA_PRFCHW
| PTA_RDSEED;
const wide_int_bitmask PTA_SKYLAKE = PTA_BROADWELL | PTA_CLFLUSHOPT
| PTA_XSAVEC | PTA_XSAVES | PTA_SGX;
const wide_int_bitmask PTA_SKYLAKE_AVX512 = PTA_SKYLAKE | PTA_AVX512F
| PTA_AVX512CD | PTA_AVX512VL | PTA_AVX512BW | PTA_AVX512DQ | PTA_PKU
| PTA_CLWB;
const wide_int_bitmask PTA_CANNONLAKE = PTA_SKYLAKE | PTA_AVX512F
| PTA_AVX512CD | PTA_AVX512VL | PTA_AVX512BW | PTA_AVX512DQ | PTA_PKU
| PTA_AVX512VBMI | PTA_AVX512IFMA | PTA_SHA;
const wide_int_bitmask PTA_ICELAKE_CLIENT = PTA_CANNONLAKE | PTA_AVX512VNNI
| PTA_GFNI | PTA_VAES | PTA_AVX512VBMI2 | PTA_VPCLMULQDQ | PTA_AVX512BITALG
| PTA_RDPID | PTA_CLWB;
const wide_int_bitmask PTA_ICELAKE_SERVER = PTA_ICELAKE_CLIENT | PTA_PCONFIG
| PTA_WBNOINVD;
const wide_int_bitmask PTA_KNL = PTA_BROADWELL | PTA_AVX512PF | PTA_AVX512ER
| PTA_AVX512F | PTA_AVX512CD;
const wide_int_bitmask PTA_BONNELL = PTA_CORE2 | PTA_MOVBE;
const wide_int_bitmask PTA_SILVERMONT = PTA_WESTMERE | PTA_MOVBE | PTA_RDRND;
const wide_int_bitmask PTA_GOLDMONT = PTA_SILVERMONT | PTA_SHA | PTA_XSAVE
| PTA_RDSEED | PTA_XSAVEC | PTA_XSAVES | PTA_CLFLUSHOPT | PTA_XSAVEOPT
| PTA_FSGSBASE;
const wide_int_bitmask PTA_GOLDMONT_PLUS = PTA_GOLDMONT | PTA_RDPID
| PTA_SGX;
const wide_int_bitmask PTA_TREMONT = PTA_GOLDMONT_PLUS | PTA_CLWB
| PTA_GFNI;
const wide_int_bitmask PTA_KNM = PTA_KNL | PTA_AVX5124VNNIW
| PTA_AVX5124FMAPS | PTA_AVX512VPOPCNTDQ;
#ifndef GENERATOR_FILE
#include "insn-attr-common.h"
struct pta
{
const char *const name; /* processor name or nickname. */
const enum processor_type processor;
const enum attr_cpu schedule;
const wide_int_bitmask flags;
};
extern const pta processor_alias_table[];
extern int const pta_size;
#endif
#endif
extern enum processor_type ix86_tune;
extern enum processor_type ix86_arch;
......
......@@ -5057,6 +5057,10 @@ Returns true if the target wants GCC's default stack protect runtime support, ot
Whether this target supports splitting the stack when the options described in @var{opts} have been passed. This is called after options have been parsed, so the target may reject splitting the stack in some configurations. The default version of this hook returns false. If @var{report} is true, this function may issue a warning or error; if @var{report} is false, it must simply return a value
@end deftypefn
@deftypefn {Common Target Hook} {vec<const char *>} TARGET_GET_VALID_OPTION_VALUES (int @var{option_code}, const char *@var{prefix})
The hook is used for options that have a non-trivial list of possible option values. OPTION_CODE is option code of opt_code enum type. PREFIX is used for bash completion and allows an implementation to return more specific completion based on the prefix. All string values should be allocated from heap memory and consumers should release them. The result will be pruned to cases with PREFIX if not NULL.
@end deftypefn
@node Miscellaneous Register Hooks
@subsection Miscellaneous register hooks
@cindex miscellaneous register hooks
......
......@@ -3669,6 +3669,8 @@ generic code.
@hook TARGET_SUPPORTS_SPLIT_STACK
@hook TARGET_GET_VALID_OPTION_VALUES
@node Miscellaneous Register Hooks
@subsection Miscellaneous register hooks
@cindex miscellaneous register hooks
......
......@@ -26,6 +26,7 @@ along with GCC; see the file COPYING3. If not see
#include "params.h"
#include "spellcheck.h"
#include "opt-suggestions.h"
#include "common/common-target.h"
#include "selftest.h"
option_proposer::~option_proposer ()
......@@ -38,7 +39,7 @@ option_proposer::suggest_option (const char *bad_opt)
{
/* Lazily populate m_option_suggestions. */
if (!m_option_suggestions)
build_option_suggestions ();
build_option_suggestions (NULL);
gcc_assert (m_option_suggestions);
/* "m_option_suggestions" is now populated. Use it. */
......@@ -80,7 +81,7 @@ option_proposer::get_completions (const char *option_prefix,
{
/* Lazily populate m_option_suggestions. */
if (!m_option_suggestions)
build_option_suggestions ();
build_option_suggestions (option_prefix);
gcc_assert (m_option_suggestions);
for (unsigned i = 0; i < m_option_suggestions->length (); i++)
......@@ -108,7 +109,7 @@ option_proposer::suggest_completion (const char *option_prefix)
}
void
option_proposer::build_option_suggestions (void)
option_proposer::build_option_suggestions (const char *prefix)
{
gcc_assert (m_option_suggestions == NULL);
m_option_suggestions = new auto_string_vec ();
......@@ -135,8 +136,27 @@ option_proposer::build_option_suggestions (void)
}
}
else
{
if (option->flags & CL_TARGET)
{
vec<const char *> option_values
= targetm_common.get_valid_option_values (i, prefix);
if (!option_values.is_empty ())
{
for (unsigned j = 0; j < option_values.length (); j++)
{
char *with_arg = concat (opt_text, option_values[j],
NULL);
add_misspelling_candidates (m_option_suggestions, option,
with_arg);
free (with_arg);
}
}
}
else
add_misspelling_candidates (m_option_suggestions, option,
opt_text);
}
break;
case OPT_fsanitize_:
......
......@@ -58,8 +58,10 @@ public:
private:
/* Helper function for option_proposer::suggest_option. Populate
m_option_suggestions with candidate strings for misspelled options.
The strings will be freed by the option_proposer's dtor. */
void build_option_suggestions ();
The strings will be freed by the option_proposer's dtor.
PREFIX is used for bash completion suggestions, otherwise
it's set to NULL. */
void build_option_suggestions (const char *prefix);
/* Find parameter completions for --param format with SEPARATOR.
Again, save the completions into results. */
......
......@@ -1090,6 +1090,21 @@ wrap_help (const char *help,
while (remaining);
}
/* Data structure used to print list of valid option values. */
struct option_help_tuple
{
option_help_tuple (int code, vec<const char *> values):
m_code (code), m_values (values)
{}
/* Code of an option. */
int m_code;
/* List of possible values. */
vec<const char *> m_values;
};
/* Print help for a specific front-end, etc. */
static void
print_filtered_help (unsigned int include_flags,
......@@ -1143,6 +1158,8 @@ print_filtered_help (unsigned int include_flags,
if (!opts->x_help_enum_printed)
opts->x_help_enum_printed = XCNEWVAR (char, cl_enums_count);
auto_vec<option_help_tuple> help_tuples;
for (i = 0; i < cl_options_count; i++)
{
const struct cl_option *option = cl_options + i;
......@@ -1303,6 +1320,13 @@ print_filtered_help (unsigned int include_flags,
if (option->var_type == CLVC_ENUM
&& opts->x_help_enum_printed[option->var_enum] != 2)
opts->x_help_enum_printed[option->var_enum] = 1;
else
{
vec<const char *> option_values
= targetm_common.get_valid_option_values (i, NULL);
if (!option_values.is_empty ())
help_tuples.safe_push (option_help_tuple (i, option_values));
}
}
if (! found)
......@@ -1366,6 +1390,15 @@ print_filtered_help (unsigned int include_flags,
printf ("\n\n");
opts->x_help_enum_printed[i] = 2;
}
for (unsigned i = 0; i < help_tuples.length (); i++)
{
const struct cl_option *option = cl_options + help_tuples[i].m_code;
printf (" Known valid arguments for %s option:\n ", option->opt_text);
for (unsigned j = 0; j < help_tuples[i].m_values.length (); j++)
printf (" %s", help_tuples[i].m_values[j]);
printf ("\n\n");
}
}
/* Display help for a specified type of option.
......
2018-09-03 Martin Liska <mliska@suse.cz>
PR driver/83193
* gcc.dg/completion-4.c: New test.
2018-09-03 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/84980
......
/* { dg-do compile { target { i?86-*-* x86_64-*-* } } } */
/* { dg-options "--completion=-march=geo" } */
/* { dg-begin-multiline-output "" }
-march=geode
{ dg-end-multiline-output "" } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment