2017-03-21 04:17:05 +08:00
|
|
|
/* Simple expression parser */
|
|
|
|
%{
|
2020-02-28 17:36:13 +08:00
|
|
|
#define YYDEBUG 1
|
2021-09-23 15:46:13 +08:00
|
|
|
#include <assert.h>
|
2021-09-23 15:46:05 +08:00
|
|
|
#include <math.h>
|
2021-11-11 08:21:08 +08:00
|
|
|
#include <stdlib.h>
|
2017-03-21 04:17:05 +08:00
|
|
|
#include "util/debug.h"
|
|
|
|
#define IN_EXPR_Y 1
|
|
|
|
#include "expr.h"
|
|
|
|
%}
|
|
|
|
|
2020-01-13 03:22:59 +08:00
|
|
|
%define api.pure full
|
|
|
|
|
2017-03-21 04:17:05 +08:00
|
|
|
%parse-param { double *final_val }
|
2020-04-02 04:33:34 +08:00
|
|
|
%parse-param { struct expr_parse_ctx *ctx }
|
2021-09-23 15:46:13 +08:00
|
|
|
%parse-param { bool compute_ids }
|
2020-02-28 17:36:13 +08:00
|
|
|
%parse-param {void *scanner}
|
|
|
|
%lex-param {void* scanner}
|
2017-03-21 04:17:05 +08:00
|
|
|
|
|
|
|
%union {
|
2020-02-28 17:36:13 +08:00
|
|
|
double num;
|
|
|
|
char *str;
|
2021-09-23 15:46:13 +08:00
|
|
|
struct ids {
|
|
|
|
/*
|
|
|
|
* When creating ids, holds the working set of event ids. NULL
|
|
|
|
* implies the set is empty.
|
|
|
|
*/
|
|
|
|
struct hashmap *ids;
|
|
|
|
/*
|
|
|
|
* The metric value. When not creating ids this is the value
|
|
|
|
* read from a counter, a constant or some computed value. When
|
|
|
|
* creating ids the value is either a constant or BOTTOM. NAN is
|
|
|
|
* used as the special BOTTOM value, representing a "set of all
|
|
|
|
* values" case.
|
|
|
|
*/
|
|
|
|
double val;
|
|
|
|
} ids;
|
2017-03-21 04:17:05 +08:00
|
|
|
}
|
|
|
|
|
2021-11-11 08:21:09 +08:00
|
|
|
%token ID NUMBER MIN MAX IF ELSE LITERAL D_RATIO SOURCE_COUNT EXPR_ERROR
|
2017-08-12 07:26:23 +08:00
|
|
|
%left MIN MAX IF
|
2017-03-21 04:17:05 +08:00
|
|
|
%left '|'
|
|
|
|
%left '^'
|
|
|
|
%left '&'
|
2020-06-11 07:58:23 +08:00
|
|
|
%left '<' '>'
|
2017-03-21 04:17:05 +08:00
|
|
|
%left '-' '+'
|
|
|
|
%left '*' '/' '%'
|
|
|
|
%left NEG NOT
|
2021-11-11 08:21:06 +08:00
|
|
|
%type <num> NUMBER LITERAL
|
2021-09-23 15:46:07 +08:00
|
|
|
%type <str> ID
|
|
|
|
%destructor { free ($$); } <str>
|
2021-09-23 15:46:13 +08:00
|
|
|
%type <ids> expr if_expr
|
|
|
|
%destructor { ids__free($$.ids); } <ids>
|
2017-03-21 04:17:05 +08:00
|
|
|
|
|
|
|
%{
|
2020-02-28 17:36:13 +08:00
|
|
|
static void expr_error(double *final_val __maybe_unused,
|
2020-04-02 04:33:34 +08:00
|
|
|
struct expr_parse_ctx *ctx __maybe_unused,
|
2021-09-23 15:46:13 +08:00
|
|
|
bool compute_ids __maybe_unused,
|
2020-02-28 17:36:13 +08:00
|
|
|
void *scanner,
|
2017-03-21 04:17:05 +08:00
|
|
|
const char *s)
|
|
|
|
{
|
|
|
|
pr_debug("%s\n", s);
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:46:13 +08:00
|
|
|
/*
|
|
|
|
* During compute ids, the special "bottom" value uses NAN to represent the set
|
|
|
|
* of all values. NAN is selected as it isn't a useful constant value.
|
|
|
|
*/
|
|
|
|
#define BOTTOM NAN
|
|
|
|
|
2021-09-23 15:46:14 +08:00
|
|
|
/* During computing ids, does val represent a constant (non-BOTTOM) value? */
|
|
|
|
static bool is_const(double val)
|
|
|
|
{
|
|
|
|
return isfinite(val);
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:46:13 +08:00
|
|
|
static struct ids union_expr(struct ids ids1, struct ids ids2)
|
|
|
|
{
|
|
|
|
struct ids result = {
|
|
|
|
.val = BOTTOM,
|
|
|
|
.ids = ids__union(ids1.ids, ids2.ids),
|
|
|
|
};
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-11-11 08:21:08 +08:00
|
|
|
static struct ids handle_id(struct expr_parse_ctx *ctx, char *id,
|
2021-11-11 08:21:09 +08:00
|
|
|
bool compute_ids, bool source_count)
|
2021-11-11 08:21:08 +08:00
|
|
|
{
|
|
|
|
struct ids result;
|
|
|
|
|
|
|
|
if (!compute_ids) {
|
|
|
|
/*
|
|
|
|
* Compute the event's value from ID. If the ID isn't known then
|
|
|
|
* it isn't used to compute the formula so set to NAN.
|
|
|
|
*/
|
|
|
|
struct expr_id_data *data;
|
|
|
|
|
|
|
|
result.val = NAN;
|
2021-11-11 08:21:09 +08:00
|
|
|
if (expr__resolve_id(ctx, id, &data) == 0) {
|
|
|
|
result.val = source_count
|
|
|
|
? expr_id_data__source_count(data)
|
|
|
|
: expr_id_data__value(data);
|
|
|
|
}
|
2021-11-11 08:21:08 +08:00
|
|
|
result.ids = NULL;
|
|
|
|
free(id);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Set the value to BOTTOM to show that any value is possible
|
|
|
|
* when the event is computed. Create a set of just the ID.
|
|
|
|
*/
|
|
|
|
result.val = BOTTOM;
|
|
|
|
result.ids = ids__new();
|
|
|
|
if (!result.ids || ids__insert(result.ids, id)) {
|
|
|
|
pr_err("Error creating IDs for '%s'", id);
|
|
|
|
free(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:46:14 +08:00
|
|
|
/*
|
|
|
|
* If we're not computing ids or $1 and $3 are constants, compute the new
|
|
|
|
* constant value using OP. Its invariant that there are no ids. If computing
|
|
|
|
* ids for non-constants union the set of IDs that must be computed.
|
|
|
|
*/
|
2021-09-23 15:46:08 +08:00
|
|
|
#define BINARY_OP(RESULT, OP, LHS, RHS) \
|
2021-09-23 15:46:14 +08:00
|
|
|
if (!compute_ids || (is_const(LHS.val) && is_const(RHS.val))) { \
|
|
|
|
assert(LHS.ids == NULL); \
|
|
|
|
assert(RHS.ids == NULL); \
|
2023-02-19 17:28:34 +08:00
|
|
|
if (isnan(LHS.val) || isnan(RHS.val)) { \
|
|
|
|
RESULT.val = NAN; \
|
|
|
|
} else { \
|
|
|
|
RESULT.val = LHS.val OP RHS.val; \
|
|
|
|
} \
|
2021-09-23 15:46:13 +08:00
|
|
|
RESULT.ids = NULL; \
|
|
|
|
} else { \
|
|
|
|
RESULT = union_expr(LHS, RHS); \
|
|
|
|
}
|
2021-09-23 15:46:08 +08:00
|
|
|
|
2017-03-21 04:17:05 +08:00
|
|
|
%}
|
|
|
|
%%
|
|
|
|
|
2021-09-23 15:46:13 +08:00
|
|
|
start: if_expr
|
2020-02-28 17:36:13 +08:00
|
|
|
{
|
2021-09-23 15:46:13 +08:00
|
|
|
if (compute_ids)
|
|
|
|
ctx->ids = ids__union($1.ids, ctx->ids);
|
2020-02-28 17:36:13 +08:00
|
|
|
|
2021-09-23 15:46:13 +08:00
|
|
|
if (final_val)
|
|
|
|
*final_val = $1.val;
|
|
|
|
}
|
|
|
|
;
|
2021-09-23 15:46:09 +08:00
|
|
|
|
2022-10-04 10:15:50 +08:00
|
|
|
if_expr: expr IF expr ELSE if_expr
|
2021-09-23 15:46:09 +08:00
|
|
|
{
|
2021-09-23 15:46:15 +08:00
|
|
|
if (fpclassify($3.val) == FP_ZERO) {
|
|
|
|
/*
|
|
|
|
* The IF expression evaluated to 0 so treat as false, take the
|
|
|
|
* ELSE and discard everything else.
|
|
|
|
*/
|
|
|
|
$$.val = $5.val;
|
|
|
|
$$.ids = $5.ids;
|
|
|
|
ids__free($1.ids);
|
|
|
|
ids__free($3.ids);
|
|
|
|
} else if (!compute_ids || is_const($3.val)) {
|
|
|
|
/*
|
|
|
|
* If ids aren't computed then treat the expression as true. If
|
|
|
|
* ids are being computed and the IF expr is a non-zero
|
|
|
|
* constant, then also evaluate the true case.
|
|
|
|
*/
|
|
|
|
$$.val = $1.val;
|
|
|
|
$$.ids = $1.ids;
|
|
|
|
ids__free($3.ids);
|
|
|
|
ids__free($5.ids);
|
2021-09-23 15:46:16 +08:00
|
|
|
} else if ($1.val == $5.val) {
|
|
|
|
/*
|
|
|
|
* LHS == RHS, so both are an identical constant. No need to
|
|
|
|
* evaluate any events.
|
|
|
|
*/
|
|
|
|
$$.val = $1.val;
|
|
|
|
$$.ids = NULL;
|
|
|
|
ids__free($1.ids);
|
|
|
|
ids__free($3.ids);
|
|
|
|
ids__free($5.ids);
|
2021-09-23 15:46:13 +08:00
|
|
|
} else {
|
2021-09-23 15:46:15 +08:00
|
|
|
/*
|
|
|
|
* Value is either the LHS or RHS and we need the IF expression
|
|
|
|
* to compute it.
|
|
|
|
*/
|
2021-09-23 15:46:13 +08:00
|
|
|
$$ = union_expr($1, union_expr($3, $5));
|
|
|
|
}
|
2021-09-23 15:46:09 +08:00
|
|
|
}
|
|
|
|
| expr
|
|
|
|
;
|
|
|
|
|
|
|
|
expr: NUMBER
|
|
|
|
{
|
2021-09-23 15:46:13 +08:00
|
|
|
$$.val = $1;
|
|
|
|
$$.ids = NULL;
|
2021-09-23 15:46:09 +08:00
|
|
|
}
|
2021-11-11 08:21:09 +08:00
|
|
|
| ID { $$ = handle_id(ctx, $1, compute_ids, /*source_count=*/false); }
|
|
|
|
| SOURCE_COUNT '(' ID ')' { $$ = handle_id(ctx, $3, compute_ids, /*source_count=*/true); }
|
2023-05-19 14:37:18 +08:00
|
|
|
| expr '|' expr
|
|
|
|
{
|
|
|
|
if (is_const($1.val) && is_const($3.val)) {
|
|
|
|
assert($1.ids == NULL);
|
|
|
|
assert($3.ids == NULL);
|
|
|
|
$$.ids = NULL;
|
|
|
|
$$.val = (fpclassify($1.val) == FP_ZERO && fpclassify($3.val) == FP_ZERO) ? 0 : 1;
|
|
|
|
} else if (is_const($1.val)) {
|
|
|
|
assert($1.ids == NULL);
|
|
|
|
if (fpclassify($1.val) == FP_ZERO) {
|
|
|
|
$$ = $3;
|
|
|
|
} else {
|
|
|
|
$$.val = 1;
|
|
|
|
$$.ids = NULL;
|
|
|
|
ids__free($3.ids);
|
|
|
|
}
|
|
|
|
} else if (is_const($3.val)) {
|
|
|
|
assert($3.ids == NULL);
|
|
|
|
if (fpclassify($3.val) == FP_ZERO) {
|
|
|
|
$$ = $1;
|
|
|
|
} else {
|
|
|
|
$$.val = 1;
|
|
|
|
$$.ids = NULL;
|
|
|
|
ids__free($1.ids);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$$ = union_expr($1, $3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
| expr '&' expr
|
|
|
|
{
|
|
|
|
if (is_const($1.val) && is_const($3.val)) {
|
|
|
|
assert($1.ids == NULL);
|
|
|
|
assert($3.ids == NULL);
|
|
|
|
$$.val = (fpclassify($1.val) != FP_ZERO && fpclassify($3.val) != FP_ZERO) ? 1 : 0;
|
|
|
|
$$.ids = NULL;
|
|
|
|
} else if (is_const($1.val)) {
|
|
|
|
assert($1.ids == NULL);
|
|
|
|
if (fpclassify($1.val) != FP_ZERO) {
|
|
|
|
$$ = $3;
|
|
|
|
} else {
|
|
|
|
$$.val = 0;
|
|
|
|
$$.ids = NULL;
|
|
|
|
ids__free($3.ids);
|
|
|
|
}
|
|
|
|
} else if (is_const($3.val)) {
|
|
|
|
assert($3.ids == NULL);
|
|
|
|
if (fpclassify($3.val) != FP_ZERO) {
|
|
|
|
$$ = $1;
|
|
|
|
} else {
|
|
|
|
$$.val = 0;
|
|
|
|
$$.ids = NULL;
|
|
|
|
ids__free($1.ids);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$$ = union_expr($1, $3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
| expr '^' expr
|
|
|
|
{
|
|
|
|
if (is_const($1.val) && is_const($3.val)) {
|
|
|
|
assert($1.ids == NULL);
|
|
|
|
assert($3.ids == NULL);
|
|
|
|
$$.val = (fpclassify($1.val) == FP_ZERO) != (fpclassify($3.val) == FP_ZERO) ? 1 : 0;
|
|
|
|
$$.ids = NULL;
|
|
|
|
} else {
|
|
|
|
$$ = union_expr($1, $3);
|
|
|
|
}
|
|
|
|
}
|
2021-09-23 15:46:09 +08:00
|
|
|
| expr '<' expr { BINARY_OP($$, <, $1, $3); }
|
|
|
|
| expr '>' expr { BINARY_OP($$, >, $1, $3); }
|
|
|
|
| expr '+' expr { BINARY_OP($$, +, $1, $3); }
|
|
|
|
| expr '-' expr { BINARY_OP($$, -, $1, $3); }
|
|
|
|
| expr '*' expr { BINARY_OP($$, *, $1, $3); }
|
|
|
|
| expr '/' expr
|
|
|
|
{
|
2021-09-23 15:46:14 +08:00
|
|
|
if (fpclassify($3.val) == FP_ZERO) {
|
|
|
|
pr_debug("division by zero\n");
|
perf metric: Change divide by zero and !support events behavior
Division by zero causes expression parsing to fail and no metric to be
generated. This can mean for short running benchmarks metrics are not
shown. Change the behavior to make the value nan, which gets shown like:
'''
$ perf stat -M TopdownL2 true
Performance counter stats for 'true':
1,031,492 INST_RETIRED.ANY # nan % tma_fetch_bandwidth
# nan % tma_heavy_operations
# nan % tma_light_operations
29,304 CPU_CLK_UNHALTED.REF_XCLK # nan % tma_fetch_latency
# nan % tma_branch_mispredicts
# nan % tma_machine_clears
# nan % tma_core_bound
# nan % tma_memory_bound
2,658,319 IDQ_UOPS_NOT_DELIVERED.CORE
11,167 EXE_ACTIVITY.BOUND_ON_STORES
262,058 EXE_ACTIVITY.1_PORTS_UTIL
<not counted> BR_MISP_RETIRED.ALL_BRANCHES (0.00%)
<not counted> INT_MISC.RECOVERY_CYCLES_ANY (0.00%)
<not counted> CPU_CLK_UNHALTED.ONE_THREAD_ACTIVE (0.00%)
<not counted> CPU_CLK_UNHALTED.THREAD (0.00%)
<not counted> UOPS_RETIRED.RETIRE_SLOTS (0.00%)
<not counted> CYCLE_ACTIVITY.STALLS_MEM_ANY (0.00%)
<not counted> UOPS_RETIRED.MACRO_FUSED (0.00%)
<not counted> IDQ_UOPS_NOT_DELIVERED.CYCLES_0_UOPS_DELIV.CORE (0.00%)
<not counted> EXE_ACTIVITY.2_PORTS_UTIL (0.00%)
<not counted> CYCLE_ACTIVITY.STALLS_TOTAL (0.00%)
<not counted> MACHINE_CLEARS.COUNT (0.00%)
<not counted> UOPS_ISSUED.ANY (0.00%)
0.002864879 seconds time elapsed
0.003012000 seconds user
0.000000000 seconds sys
'''
When events aren't supported a count of 0 can be confusing and make
metrics look meaningful. Change these to be nan also which, with the
next change, gets shown like:
'''
$ perf stat true
Performance counter stats for 'true':
1.25 msec task-clock:u # 0.387 CPUs utilized
0 context-switches:u # 0.000 /sec
0 cpu-migrations:u # 0.000 /sec
46 page-faults:u # 36.702 K/sec
255,942 cycles:u # 0.204 GHz (88.66%)
123,046 instructions:u # 0.48 insn per cycle
28,301 branches:u # 22.580 M/sec
2,489 branch-misses:u # 8.79% of all branches
4,719 CPU_CLK_UNHALTED.REF_XCLK:u # 3.765 M/sec
# nan % tma_frontend_bound
# nan % tma_retiring
# nan % tma_backend_bound
# nan % tma_bad_speculation
344,855 IDQ_UOPS_NOT_DELIVERED.CORE:u # 275.147 M/sec
<not supported> INT_MISC.RECOVERY_CYCLES_ANY:u
<not counted> CPU_CLK_UNHALTED.ONE_THREAD_ACTIVE:u (0.00%)
<not counted> CPU_CLK_UNHALTED.THREAD:u (0.00%)
<not counted> UOPS_RETIRED.RETIRE_SLOTS:u (0.00%)
<not counted> UOPS_ISSUED.ANY:u (0.00%)
0.003238142 seconds time elapsed
0.000000000 seconds user
0.003434000 seconds sys
'''
Ensure that nan metric values are quoted as nan isn't a valid number
in JSON.
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Kan Liang <kan.liang@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ahmad Yasin <ahmad.yasin@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Edward Baker <edward.baker@intel.com>
Cc: Florian Fischer <florian.fischer@muhq.space>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kang Minchul <tegongkang@gmail.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Samantha Alt <samantha.alt@intel.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Link: https://lore.kernel.org/r/20230502223851.2234828-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-05-03 06:38:08 +08:00
|
|
|
assert($3.ids == NULL);
|
|
|
|
if (compute_ids)
|
|
|
|
ids__free($1.ids);
|
|
|
|
$$.val = NAN;
|
|
|
|
$$.ids = NULL;
|
2021-09-23 15:46:14 +08:00
|
|
|
} else if (!compute_ids || (is_const($1.val) && is_const($3.val))) {
|
|
|
|
assert($1.ids == NULL);
|
|
|
|
assert($3.ids == NULL);
|
2021-09-23 15:46:13 +08:00
|
|
|
$$.val = $1.val / $3.val;
|
|
|
|
$$.ids = NULL;
|
|
|
|
} else {
|
2021-09-23 15:46:14 +08:00
|
|
|
/* LHS and/or RHS need computing from event IDs so union. */
|
2021-09-23 15:46:13 +08:00
|
|
|
$$ = union_expr($1, $3);
|
2021-09-23 15:46:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
| expr '%' expr
|
|
|
|
{
|
2021-09-23 15:46:14 +08:00
|
|
|
if (fpclassify($3.val) == FP_ZERO) {
|
|
|
|
pr_debug("division by zero\n");
|
|
|
|
YYABORT;
|
|
|
|
} else if (!compute_ids || (is_const($1.val) && is_const($3.val))) {
|
|
|
|
assert($1.ids == NULL);
|
|
|
|
assert($3.ids == NULL);
|
2021-09-23 15:46:13 +08:00
|
|
|
$$.val = (long)$1.val % (long)$3.val;
|
|
|
|
$$.ids = NULL;
|
|
|
|
} else {
|
2021-09-23 15:46:14 +08:00
|
|
|
/* LHS and/or RHS need computing from event IDs so union. */
|
2021-09-23 15:46:13 +08:00
|
|
|
$$ = union_expr($1, $3);
|
2021-09-23 15:46:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
| D_RATIO '(' expr ',' expr ')'
|
|
|
|
{
|
2021-09-23 15:46:14 +08:00
|
|
|
if (fpclassify($5.val) == FP_ZERO) {
|
|
|
|
/*
|
|
|
|
* Division by constant zero always yields zero and no events
|
|
|
|
* are necessary.
|
|
|
|
*/
|
|
|
|
assert($5.ids == NULL);
|
|
|
|
$$.val = 0.0;
|
|
|
|
$$.ids = NULL;
|
|
|
|
ids__free($3.ids);
|
|
|
|
} else if (!compute_ids || (is_const($3.val) && is_const($5.val))) {
|
|
|
|
assert($3.ids == NULL);
|
|
|
|
assert($5.ids == NULL);
|
|
|
|
$$.val = $3.val / $5.val;
|
2021-09-23 15:46:13 +08:00
|
|
|
$$.ids = NULL;
|
2021-09-23 15:46:09 +08:00
|
|
|
} else {
|
2021-09-23 15:46:14 +08:00
|
|
|
/* LHS and/or RHS need computing from event IDs so union. */
|
2021-09-23 15:46:13 +08:00
|
|
|
$$ = union_expr($3, $5);
|
2021-09-23 15:46:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
| '-' expr %prec NEG
|
|
|
|
{
|
2021-09-23 15:46:13 +08:00
|
|
|
$$.val = -$2.val;
|
|
|
|
$$.ids = $2.ids;
|
2021-09-23 15:46:09 +08:00
|
|
|
}
|
|
|
|
| '(' if_expr ')'
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
| MIN '(' expr ',' expr ')'
|
|
|
|
{
|
2021-09-23 15:46:13 +08:00
|
|
|
if (!compute_ids) {
|
|
|
|
$$.val = $3.val < $5.val ? $3.val : $5.val;
|
|
|
|
$$.ids = NULL;
|
|
|
|
} else {
|
|
|
|
$$ = union_expr($3, $5);
|
|
|
|
}
|
2021-09-23 15:46:09 +08:00
|
|
|
}
|
|
|
|
| MAX '(' expr ',' expr ')'
|
|
|
|
{
|
2021-09-23 15:46:13 +08:00
|
|
|
if (!compute_ids) {
|
|
|
|
$$.val = $3.val > $5.val ? $3.val : $5.val;
|
|
|
|
$$.ids = NULL;
|
|
|
|
} else {
|
|
|
|
$$ = union_expr($3, $5);
|
|
|
|
}
|
2021-09-23 15:46:09 +08:00
|
|
|
}
|
2021-11-11 08:21:06 +08:00
|
|
|
| LITERAL
|
2021-09-23 15:46:09 +08:00
|
|
|
{
|
2021-11-11 08:21:06 +08:00
|
|
|
$$.val = $1;
|
2021-09-23 15:46:13 +08:00
|
|
|
$$.ids = NULL;
|
2021-09-23 15:46:09 +08:00
|
|
|
}
|
|
|
|
;
|
2017-03-21 04:17:05 +08:00
|
|
|
|
|
|
|
%%
|