diff --git a/llvm/lib/Support/FileCheck.cpp b/llvm/lib/Support/FileCheck.cpp --- a/llvm/lib/Support/FileCheck.cpp +++ b/llvm/lib/Support/FileCheck.cpp @@ -312,6 +312,14 @@ return LeftOp - RightOp; } +static uint64_t umax(uint64_t LeftOp, uint64_t RightOp) { + return std::max(LeftOp, RightOp); +} + +static uint64_t umin(uint64_t LeftOp, uint64_t RightOp) { + return std::min(LeftOp, RightOp); +} + Expected> Pattern::parseBinop(StringRef Expr, StringRef &RemainingExpr, std::unique_ptr LeftOp, @@ -336,6 +344,25 @@ case '*': EvalBinop = mul; break; + case '.': { + // Parse a named operation of the form "..". + size_t NameEnd = RemainingExpr.find('.'); + if (NameEnd == StringRef::npos) + return ErrorDiagnostic::get(SM, OpLoc, "unterminated named operation"); + + StringRef Name = RemainingExpr.take_front(NameEnd); + auto OptBinOp = StringSwitch>(Name) + .Case("usat_low", umax) + .Case("usat_high", umin) + .Default(None); + if (!OptBinOp) + return ErrorDiagnostic::get( + SM, OpLoc, Twine("unsupported named operation '") + Name + "'"); + + EvalBinop = *OptBinOp; + RemainingExpr = RemainingExpr.drop_front(NameEnd + 1); + break; + } default: return ErrorDiagnostic::get( SM, OpLoc, Twine("unsupported operation '") + Twine(Operator) + "'"); diff --git a/llvm/test/FileCheck/numeric-expression.txt b/llvm/test/FileCheck/numeric-expression.txt --- a/llvm/test/FileCheck/numeric-expression.txt +++ b/llvm/test/FileCheck/numeric-expression.txt @@ -68,6 +68,10 @@ 12 10 33 +11 +10 +20 +11 c d b @@ -91,6 +95,10 @@ CHECK-NEXT: [[#%u,VAR1+1]] CHECK-NEXT: [[#%u,VAR1-1]] CHECK-NEXT: [[#%u,VAR1*3]] +CHECK-NEXT: [[#%u,VAR1.usat_high.20]] +CHECK-NEXT: [[#%u,VAR1.usat_high.10]] +CHECK-NEXT: [[#%u,VAR1.usat_low.20]] +CHECK-NEXT: [[#%u,VAR1.usat_low.10]] CHECK-NEXT: [[#%x,VAR2]] CHECK-NEXT: [[#%x,VAR2+1]] CHECK-NEXT: [[#%x,VAR2-1]] @@ -130,6 +138,12 @@ 22 22 22 +10 +10 +10 +10 +10 +10 CHECK-LABEL: USE EXPL FMT IMPL MATCH SPC CHECK-NEXT: [[#%u, VAR1]] CHECK-NEXT: [[# %u, VAR1]] @@ -152,6 +166,12 @@ CHECK-NEXT: [[# %u , VAR1 *2]] CHECK-NEXT: [[# %u , VAR1 * 2]] CHECK-NEXT: [[# %u , VAR1 * 2 ]] +CHECK-NEXT: [[#%u, VAR1.usat_high.10]] +CHECK-NEXT: [[# %u, VAR1.usat_high.10]] +CHECK-NEXT: [[# %u , VAR1.usat_high.10]] +CHECK-NEXT: [[# %u , VAR1 .usat_high.10]] +CHECK-NEXT: [[# %u , VAR1 .usat_high. 10]] +CHECK-NEXT: [[# %u , VAR1 .usat_high. 10 ]] ; Numeric expressions in implicit matching format and default matching rule using ; variables defined on other lines. @@ -170,6 +190,10 @@ C 1B D0 +11 +10 +20 +11 CHECK-LABEL: USE IMPL FMT IMPL MATCH CHECK-NEXT: [[#VAR1]] CHECK-NEXT: [[#VAR1+1]] @@ -185,6 +209,10 @@ CHECK-NEXT: [[#VAR3-1]] CHECK-NEXT: [[#VAR3+14]] CHECK-NEXT: [[#VAR3*16]] +CHECK-NEXT: [[#VAR1.usat_high.20]] +CHECK-NEXT: [[#VAR1.usat_high.10]] +CHECK-NEXT: [[#VAR1.usat_low.20]] +CHECK-NEXT: [[#VAR1.usat_low.10]] ; Numeric expressions using variables defined on other lines and an immediate ; interpreted as an unsigned value. @@ -292,6 +320,34 @@ INVAL-OP-MSG-NEXT: {{I}}NVAL-OP-NEXT: NUMVAR%2: {{\[\[#NUMVAR\%2\]\]}} INVAL-OP-MSG-NEXT: {{^}} ^{{$}} +; Numeric expression with unsupported named operator. +RUN: %ProtectFileCheckOutput \ +RUN: not FileCheck -D#NUMVAR=10 --check-prefix INVAL-NAMED-OP \ +RUN: --input-file %s %s 2>&1 \ +RUN: | FileCheck --strict-whitespace --check-prefix INVAL-NAMED-OP-MSG %s + +INVALID NAMED OPERATOR +NUMVAR.made_up_name.2: 22 +INVAL-NAMED-OP-LABEL: INVALID NAMED OPERATOR +INVAL-NAMED-OP-NEXT: NUMVAR.made_up_name.2: [[#NUMVAR.made_up_name.2]] +INVAL-NAMED-OP-MSG: numeric-expression.txt:[[#@LINE-1]]:54: error: unsupported named operation 'made_up_name' +INVAL-NAMED-OP-MSG-NEXT: {{I}}NVAL-NAMED-OP-NEXT: NUMVAR.made_up_name.2: {{\[\[#NUMVAR\.made_up_name\.2\]\]}} +INVAL-NAMED-OP-MSG-NEXT: {{^}} ^{{$}} + +; Numeric expression with unsupported named operator. +RUN: %ProtectFileCheckOutput \ +RUN: not FileCheck -D#NUMVAR=10 --check-prefix INVAL-NAMED-OP-2 \ +RUN: --input-file %s %s 2>&1 \ +RUN: | FileCheck --strict-whitespace --check-prefix INVAL-NAMED-OP-2-MSG %s + +UNTERMINATED NAMED OPERATOR +NUMVAR.made_up_name 4: 22 +INVAL-NAMED-OP-2-LABEL: UNTERMINATED NAMED OPERATOR +INVAL-NAMED-OP-2-NEXT: NUMVAR.made_up_name 4: [[#NUMVAR.made_up_name 4]] +INVAL-NAMED-OP-2-MSG: numeric-expression.txt:[[#@LINE-1]]:56: error: unterminated named operation +INVAL-NAMED-OP-2-MSG-NEXT: {{I}}NVAL-NAMED-OP-2-NEXT: NUMVAR.made_up_name 4: {{\[\[#NUMVAR\.made_up_name 4\]\]}} +INVAL-NAMED-OP-2-MSG-NEXT: {{^}} ^{{$}} + ; Name conflict between Numeric variable definition and string variable ; definition whether from the command-line or input text. RUN: %ProtectFileCheckOutput \