This patch contains code to resolve metadirectives, either during parsing or Gimplification. The dynamic candidate selection algorithm from the OpenMP 5.1 spec is implemented in omp_get_dynamic_candidates in omp-general.c, which returns a vector containing information on the top-scoring candidate variants. The vector always consists of entries with dynamic selectors first, followed by a single entry with an all-static selector (which can be the default clause if all the other clauses are dynamic). If all selectors are static (i.e. OpenMP 5.0), then omp_get_dynamic_candidates will return a vector of at most length 1. If any part of the selectors in the candidate list cannot be resolved at the current stage of compilation, an empty list is returned. Note that it is possible to resolve metadirectives even with some selectors unresolvable as long as those selectors are not part of the candidate list. omp_context_selector_matches should always return 1 for dynamic selectors (since we can generate code to evaluate the condition at any time). omp_dynamic_cond, when given a selector, should return just the part of it that must be evaluated at run-time. Metadirectives are resolved in both tree and Gimple form by generating a sequence of if..then..else statements that evaluate the dynamic selector of each candidate returned from omp_get_dynamic_candidates in order, jumping to the directive body if true, to the next evaluation if not. Kwok