aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/TableGen/TGParser.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-04-26ReformatNAKAMURA Takumi1-1/+2
2023-04-25TableGen: Introduce `!range` operator for half-opened intervalNAKAMURA Takumi1-0/+61
`!range(a, b)` generates a list `[a,b)`. `a` is optional and `0` by default. - `!range(-1, 4)` generates `[-1, 0, 1, 2, 3]` - `!range(4)` generates `[0, 1, 2, 3]` - `!range(2, 2)` generates `[]<list<int>>` `!range(list)` is equivalent to `!range(0, !size(list))`. Differential Revision: https://reviews.llvm.org/D145871
2023-04-14[TableGen] Allow references to class template arguments in defvarwangpc1-3/+3
We can't refer to template arguments for defvar statements in class definitions, or it will report some errors like: ``` error: Variable not defined: 'xxx'. ``` The key point here is we used to pass nullptr to `ParseValue` in `ParseDefvar`. As a result, we can't refer to template arguments since `CurRec` is nullptr in `ParseIDValue`. So we add an argument `CurRec` to `ParseDefvar` and provide it when parsing defvar statements in class definitions. Reviewed By: tra, simon_tatham Differential Revision: https://reviews.llvm.org/D148197
2023-03-07[TableGen] add !toupper and !tolower operators to change the casing of strings.Zain Jaffal1-0/+14
Reviewed By: fpetrogalli Differential Revision: https://reviews.llvm.org/D145300
2023-03-03[RISCV][llvm-tblgen] Support conditional definitions using !exists clausesPhilip Reames1-0/+25
The core part of this change is an extension to the tablegen language to allow conditional definition of records using if-statements based on !exists conditions. The RISCV td file change is mostly to illustrate the potential use of conditional definitions. I am deliberately not maximally simplifying in this change to make merging with downstream code (or simply rebasing while this on review) easier. Some background to make the change understandable. TableGen does not have an if statement internally. It has if expressions - in the form of TernInitOp with IF opcode - and foreach statements. It implements an if-statement as a foreach which iterates either 0 or 1 times. Foreach nodes are then evaluated via unrolling inside the parser. Specifically, they are evaluated, at latest, when the outermost multiclass or loop containing them reaches end of scope. The unrolled statements remain (potentially) unresolved after unrolling, but the number of iterations must be known at this point. An !exists clause can only evaluate at final evaluation. (Specifically, forward references to definitions are allowed - up to the end of the containing scope at least.) The existing code did not set the final flag on the resolver, and thus would leave the !exists clause in an unresolved state. This would then cause an error since we don't know how many iterations on which to unroll the (synthetic) foreach loop. I chose to only finally-evaluate the condition of the if-expression. This allows us to pick an arm at scope exit without inhibiting definitions in the arm from having self references. Differential Revision: https://reviews.llvm.org/D145108
2022-12-09[TableGen] Add a !listremove() bang operatorSimon Pilgrim1-1/+19
This patch proposes to add a !listremove() bang operator to allow us to prune list entries by removing any entries from the first list arg that are also contained in the second list arg. The particular use case I have in mind is for improved analysis of x86 scheduler models for which I'm hoping to start using the CodeGenProcModel 'Unsupported' features lists, which lists the ISA features a particular model DOESN'T support - with such a diverse and growing list of x86 ISAs, I don't want to have to update all these lists with every ISA change to every model - so I'm intending to keep a single central list of all x86 features, and then have the each model "remove" the features that it supports via a !listremove() - leaving just the unsupported ones. Differential Revision: https://reviews.llvm.org/D139642
2022-12-06[ADT] Don't including None.h (NFC)Kazu Hirata1-1/+0
These source files no longer use None, so they do not need to include None.h. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-02[llvm] Use std::nullopt instead of None (NFC)Kazu Hirata1-1/+1
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-10-26[TableGen] Add log bang operatorMichael Maitland1-0/+7
This patch adds base 2 logarithm that returns integer result. I initially wanted to name it `!log2`, but numbers are not permitted in the name. The documentation makes sure to clarify that it is base 2 since it is not explicit in the operator name. Differential Revision: https://reviews.llvm.org/D134068
2022-09-30[TableGen] Add div bang operatorMichael Maitland1-1/+6
This patch adds the div bang operator which performs division. Differential Revision: https://reviews.llvm.org/D134001
2022-09-28[TableGen] Only track reference locations if askedRiver Riddle1-13/+20
Normal compilation doesn't care about tracking references, and shouldn't pay the compilation time cost.
2022-09-27[TableGen] Track reference locations of Records/RecordValsRiver Riddle1-20/+53
This is extremely useful for language tooling as it allows for providing go-to-def/find-references/etc. for many more situations than what is currently possible. Differential Revision: https://reviews.llvm.org/D134087
2022-08-28[llvm] Qualify auto in range-based for loops (NFC)Kazu Hirata1-1/+1
2022-07-20[TableGen] Add a location for a class definition that was forward-declaredRoman Rusyaev1-0/+2
This change improves ctags generation for tablegen files. For the following example ``` class A; class A { int a; } ``` Previously, tags were generated only for a forward declaration of class 'A'. This patch allows generating tags for the forward declarations and further definition of class 'A'. Reviewed By: barannikov88 Original patch by: rusyaev-roman (Roman Rusyaev) Some adjustments by: nhaehnle (Nicolai Hähnle) Differential Revision: https://reviews.llvm.org/D129935
2022-06-23[TableGen] Add new operator !existswangpc1-0/+47
We can cast a string to a record via !cast, but we have no mechanism to check if it is valid and TableGen will raise an error if failed to cast. Besides, we have no semantic null in TableGen (we have `?` but different backends handle uninitialized value differently), so operator like `dyn_cast<>` is hard to implement. In this patch, we add a new operator `!exists<T>(s)` to check whether a record with type `T` and name `s` exists. Self-references are allowed just like `!cast`. By doing these, we can write code like: ``` class dyn_cast_to_record<string name> { R value = !if(!exists<R>(name), !cast<R>(name), default_value); } defvar v = dyn_cast_to_record<"R0">.value; // R0 or default_value. ``` Reviewed By: tra, nhaehnle Differential Revision: https://reviews.llvm.org/D127948
2022-05-11[TableGen] Remove the use of global Record stateRiver Riddle1-94/+106
This commits removes TableGens reliance on managed static global record state by moving the RecordContext into the RecordKeeper. The RecordKeeper is now treated similarly to a (LLVM|MLIR|etc)Context object and is passed to static construction functions. This is an important step forward in removing TableGens reliance on global state, and in a followup will allow for users that parse tablegen to parse multiple tablegen files without worrying about Record lifetime. Differential Revision: https://reviews.llvm.org/D125276
2022-01-28Cleanup include dependencies for LLVMTableGenserge-sans-paille1-2/+1
Based on the output of include-what-you-use. No other library seems affected by the new forward declaration. $ clang++ -E -Iinclude -I../llvm/include ../llvm/lib/TableGen/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l before: 795231 after: 750654 Related Discourse thread: https://llvm.discourse.group/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D118374
2022-01-07[llvm] Use true/false instead of 1/0 (NFC)Kazu Hirata1-1/+2
Identified with modernize-use-bool-literals.
2021-11-03[TableGen] Emit a warning for unused template argsCullen Rhodes1-2/+11
Add a warning to TableGen for unused template arguments in classes and multiclasses, for example: multiclass Foo<int x> { def bar; } $ llvm-tblgen foo.td foo.td:1:20: warning: unused template argument: Foo::x multiclass Foo<int x> { ^ A flag '--no-warn-on-unused-template-args' is added to disable the warning. The warning is disabled for LLVM and sub-projects if 'LLVM_ENABLE_WARNINGS=OFF'. Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D109359
2021-06-10[TableGen] Eliminate dead code in ParseForeachDeclaration [NFC]Paul C. Anagnostopoulos1-4/+1
Differential Revision: https://reviews.llvm.org/D103904
2021-04-30[TableGen] Fix two bugs in 'defm' when complex 'assert' is involved.Paul C. Anagnostopoulos1-0/+3
This patch fixes two bugs that arise when a 'defm' inherits from a multiclass and also from a class with assertions. Differential Revision: https://reviews.llvm.org/D101626
2021-04-28[TableGen] Add the !find bang operatorPaul C. Anagnostopoulos1-1/+93
!find searches a source string for a target string and returns the position. Differential Revision: https://reviews.llvm.org/D101318
2021-04-26[TableGen] Remove a TODO comment that is no longer relevant [NFC]Paul C. Anagnostopoulos1-2/+0
2021-04-26[TableGen] Change assertion information from a tuple to a struct [NFC]Paul C. Anagnostopoulos1-21/+13
Differential Revision: https://reviews.llvm.org/D100854
2021-04-23[TableGen] Correct some comments in the TableGen parser [NFC]Paul C. Anagnostopoulos1-4/+4
Differential Revision: https://reviews.llvm.org/D101088
2021-04-19[TableGen] Add support for the 'assert' statement in multiclassesPaul C. Anagnostopoulos1-14/+51
This is step 3 of adding the 'assert' statement. Differential Revision: https://reviews.llvm.org/D99751
2021-04-09[TableGen] Report an error message on a missing commaAlex Richardson1-3/+3
I recently forgot a comma in a defm argument list and tablegen just failed with exit code 1 without printing an error message. I believe this issue was introduced in a9fc44c5573208859c2550382755098d750fc47d. This change prints the following instead: .../clang/include/clang/Driver/Options.td:569:3: error: Expected comma before next argument Reviewed By: Paul-C-Anagnostopoulos Differential Revision: https://reviews.llvm.org/D100178
2021-04-08Revert "[TableGen] Add support for the 'assert' statement in multiclasses"Paul C. Anagnostopoulos1-51/+15
This reverts commit 3b9a15d910a8c748b1444333a4a3905a996528bc.
2021-04-08[TableGen] Add support for the 'assert' statement in multiclassesPaul C. Anagnostopoulos1-15/+51
2021-03-29[TableGen] Add support for the 'assert' statement in class definitions.Paul C. Anagnostopoulos1-33/+6
Differential Revision: https://reviews.llvm.org/D99275
2021-03-19[TableGen] Improve handling of template argumentsPaul C. Anagnostopoulos1-174/+172
This requires changes to TableGen files and some C++ files due to incompatible multiclass template arguments that slipped through before the improved handling.
2021-02-18Revert "[TableGen] Improve algorithms for processing template arguments"Paul C. Anagnostopoulos1-172/+174
This reverts commit e589207d5aaee6cbf1d7c7de8867a17727d14aca.
2021-02-18[TableGen] Improve algorithms for processing template argumentsPaul C. Anagnostopoulos1-174/+172
Rework template argument checking so that all arguments are type-checked and cast if necessary. Add a test. Differential Revision: https://reviews.llvm.org/D96416
2021-02-01[TableGen] Fix anonymous record self-reference in foreach and multiclassJ-Y You1-2/+3
If we instantiate self-referenced anonymous records in foreach and multiclass, the NAME value will point to incorrect record. It's because anonymous name is resolved too early. This patch adds AnonymousNameInit to represent an anonymous record name. When instantiating an anonymous record, it will update the referred name. Differential Revision: https://reviews.llvm.org/D95309
2021-01-29[TableGen] Fix instantiating multiclass in foreachJ-Y You1-2/+2
If multiclass argument comes from loop varaible and argument is record type, it will not recognize the type. This patch ensures that loop variables are resolved correctly. Differential Revision: https://reviews.llvm.org/D95308
2021-01-20Revert "[TableGen] Improve algorithm for inheriting class template args and ↵Paul C. Anagnostopoulos1-47/+45
fields" This reverts commit c056f824340ff0189f3ef7870b83e3730de401d1. That commit causes build failures.
2021-01-20[TableGen] Improve algorithm for inheriting class template args and fieldsPaul C. Anagnostopoulos1-45/+47
Differential Revision: https://reviews.llvm.org/D94822
2021-01-12[TableGen] Improve error message for semicolon after braced body.Paul C. Anagnostopoulos1-2/+17
Add a test for this message. Differential Revision: https://reviews.llvm.org/D94412
2021-01-08[TableGen] Fix use of *CurRec when CurRec is null.Paul C. Anagnostopoulos1-4/+1
I cannot build with the undefined sanitizer on Visual Studio.
2021-01-08[TableGen] Remove unused declaration that caused build failures.Paul C. Anagnostopoulos1-1/+0
2021-01-08[TableGen] Add the assert statement, step 1Paul C. Anagnostopoulos1-20/+100
Differential Revision: https://reviews.llvm.org/D93911 This first step adds the assert statement and supports it at top level and in record definitions. Later steps will support it in class definitions and multiclasses.
2021-01-07[TableGen] Add field kind to the RecordVal class.Paul C. Anagnostopoulos1-6/+9
Differential Revision: https://reviews.llvm.org/D93969
2020-12-23[TableGen] Add the !substr() bang operatorPaul C. Anagnostopoulos1-1/+94
Update the documentation and add a test. Build failed: Change SIZE_MAX to std::numeric_limits<int64_t>::max(). Differential Revision: https://reviews.llvm.org/D93419
2020-12-21Revert "[TableGen] Add the !substr() bang operator"Paul C. Anagnostopoulos1-94/+1
This reverts commit 3a675c777dd5788e2313cb06fb27b01f8a2e7573.
2020-12-21[TableGen] Add the !substr() bang operatorPaul C. Anagnostopoulos1-1/+94
Update the documentation and add a test. Differential Revision: https://reviews.llvm.org/D93419
2020-12-03[TableGen] Eliminate the 'code' typePaul C. Anagnostopoulos1-3/+6
Update the documentation. Rework various backends that relied on the code type. Differential Revision: https://reviews.llvm.org/D92269
2020-11-23[TableGen] Eliminte source location from CodeInitPaul C. Anagnostopoulos1-1/+1
Step 1 in eliminating the 'code' type. Differential Revision: https://reviews.llvm.org/D91932
2020-11-13[TableGen] Enhance the six comparison bang operators.Paul C. Anagnostopoulos1-6/+17
Update the Programmer's Reference. Differential Revision: https://reviews.llvm.org/D91036
2020-11-09[TableGen] Add the !filter bang operator.Paul C. Anagnostopoulos1-108/+131
Add a test. Update the Programmer's Reference. Use it in some TableGen files. Differential Revision: https://reviews.llvm.org/D91008
2020-11-05[TableGen] Add true and false literals to represent booleansPaul C. Anagnostopoulos1-2/+15
Update the Programmer's Reference document. Add a test. Update a couple of tests with an improved error message. Differential Revision: https://reviews.llvm.org/D90635