1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00
Commit Graph

57 Commits

Author SHA1 Message Date
Hal Finkel
91f4861f4f [TableGen] Correctly generate implicit anonymous prototype defs in multiclasses
Even within a multiclass, we had been generating concrete implicit anonymous
defs when parsing values (generally in value lists). This behavior was
incorrect, and led to errors when multiclass parameters were used in the
parameter list of the implicit anonymous def.

If we had some multiclass:

multiclass mc<string n> {

 ... : SomeClass<SomeOtherClass<n> >

The capture of the multiclass parameter 'n' would not work correctly, and
depending on how the implicit SomeOtherClass was used, either TableGen would
ignore something it shouldn't, or would crash.

To fix this problem, when inside a multiclass, we generate prototype anonymous
defs for implicit anonymous defs (just as we do for explicit anonymous defs).
Within the multiclass, the current record prototype is populated with a node
that is essentially: !cast<SomeOtherClass>(!strconcat(NAME, anon_value_name)).
This is then resolved to the correct concrete anonymous def, in the usual way,
when NAME is resolved during multiclass instantiation.

llvm-svn: 198348
2014-01-02 20:47:09 +00:00
Hal Finkel
fe40c76eea [TableGen] Use the same anonymous name as the prefix on all multiclass defs
TableGen had been generating a different name for an anonymous multiclass's
NAME for every def in the multiclass. This had an unfortunate side effect: it
was impossible to reference one def within the multiclass from another (in the
parameter list, for example). By making sure we only generate an anonymous name
once per multiclass (which, as it turns out, requires only changing the name
parameter to reference type), we can now concatenate NAME within the multiclass
with a def name in order to generate a reference to that def.

This does not matter so much, in and of itself, but is necessary for a
follow-up commit that will fix variable capturing in implicit anonymous
multiclass defs (and that is important).

llvm-svn: 198340
2014-01-02 19:35:33 +00:00
Alp Toker
cc76786c50 TableGen: Generate valid identifiers for anonymous records
Backends like OptParserEmitter assume that record names can be used as valid
identifiers.

The period '.' in generated anonymous names broke that assumption, causing a
build-time error and in practice forcing all records to be named.

llvm-svn: 197869
2013-12-21 18:51:00 +00:00
Craig Topper
77fb9fd06a Add an error check for a typo I accidentally made in a td file that caused an assert to fire.
llvm-svn: 188742
2013-08-20 04:22:09 +00:00
Reid Kleckner
59f77601ec Remove some std stream usage from Support and TableGen
LLVM's coding standards recommend raw_ostream and MemoryBuffer for
reading and writing text.

This has the side effect of allowing clang to compile more of Support
and TableGen in the Microsoft C++ ABI.

llvm-svn: 187826
2013-08-06 22:51:21 +00:00
Jakob Stoklund Olesen
83c1b42b62 Allow TableGen DAG arguments to be just a name.
DAG arguments can optionally be named:

  (dag node, node:$name)

With this change, the node is also optional:

  (dag node, node:$name, $name)

The missing node is treated as an UnsetInit, so the above is equivalent
to:

  (dag node, node:$name, ?:$name)

This syntax is useful in output patterns where we currently require the
types of variables to be repeated:

  def : Pat<(subc i32:$b, i32:$c), (SUBCCrr i32:$b, i32:$c)>;

This is preferable:

  def : Pat<(subc i32:$b, i32:$c), (SUBCCrr $b, $c)>;

llvm-svn: 177843
2013-03-24 19:36:51 +00:00
Michael J. Spencer
1f361eb77c [TableGen] Fix ICE on MSVC 2012 Release builds.
llvm-svn: 176125
2013-02-26 21:29:47 +00:00
Hal Finkel
4279c8573b Add an addition operator to TableGen
This adds an !add(a, b) operator to tablegen; this will be used
to cleanup the PPC register definitions.

llvm-svn: 173445
2013-01-25 14:49:08 +00:00
Jordan Rose
6b1722a271 TableGen: Keep track of superclass reference ranges.
def foo : bar;
          ~~~

This allows us to produce more precise diagnostics about a certain
superclass, and even provide fixits.

llvm-svn: 172085
2013-01-10 18:50:11 +00:00
Jordan Rose
24610f9d5e TableGen: record anonymous instantiations of classes.
llvm-svn: 172084
2013-01-10 18:50:05 +00:00
Sean Silva
54bb0c16da tblgen: use an early return to reduce indentation.
llvm-svn: 171954
2013-01-09 05:28:12 +00:00
Sean Silva
40aeddd482 tblgen: Factor out common code.
llvm-svn: 171951
2013-01-09 04:49:14 +00:00
Sean Silva
24c4e27e37 Inline this into its only caller.
It's clearer and additionally this gets rid of the usage of `DefmID`,
which doesn't really correspond to anything in the language (it was just
used in the name of this parsing function which parsed a `MultiClassID`
and returned that multiclass's record).

This area of the code still needs a lot of work.

llvm-svn: 171938
2013-01-09 02:17:14 +00:00
Sean Silva
29f0a1b1d7 tblgen: Reuse function that is 2 lines above.
llvm-svn: 171937
2013-01-09 02:17:13 +00:00
Sean Silva
020d07bb39 fix copy-paste-o
llvm-svn: 171936
2013-01-09 02:11:57 +00:00
Sean Silva
83bc854f4c docs: Bring TableGen syntax a bit closer to reality.
It's not just def's but actually a limited subset of Object's that are
allowed inside a multiclass.

Spotted by Joel Jones.

llvm-svn: 171935
2013-01-09 02:11:55 +00:00
Craig Topper
112a6dc350 Revert r171140. We don't actually need to support #NAME. Because NAME by itself is interpreted just fine.
llvm-svn: 171695
2013-01-07 05:09:33 +00:00
Craig Topper
56ee68554d Update tablegen parser to allow defm names to start with #NAME.
llvm-svn: 171140
2012-12-27 06:32:52 +00:00
Chandler Carruth
a490793037 Use the new script to sort the includes of every file under lib.
Sooooo many of these had incorrect or strange main module includes.
I have manually inspected all of these, and fixed the main module
include to be the nearest plausible thing I could find. If you own or
care about any of these source files, I encourage you to take some time
and check that these edits were sensible. I can't have broken anything
(I strictly added headers, and reordered them, never removed), but they
may not be the headers you'd really like to identify as containing the
API being implemented.

Many forward declarations and missing includes were added to a header
files to allow them to parse cleanly when included first. The main
module rule does in fact have its merits. =]

llvm-svn: 169131
2012-12-03 16:50:05 +00:00
Sean Silva
cbe79850e7 tblgen: Use semantically correct RTTI functions.
Also, some minor cleanup.

llvm-svn: 165647
2012-10-10 20:24:47 +00:00
Sean Silva
a6a1c05042 tblgen: Mechanically move dynamic_cast<> to dyn_cast<>.
Some of these dyn_cast<>'s would be better phrased as isa<> or cast<>.
That will happen in a future patch.

There are also two dyn_cast_or_null<>'s slipped in instead of
dyn_cast<>'s, since they were causing crashes with just dyn_cast<>.

llvm-svn: 165646
2012-10-10 20:24:43 +00:00
Sean Silva
a400d20965 tblgen: Remove pointless method call.
llvm-svn: 165511
2012-10-09 17:03:11 +00:00
Sean Silva
f8b271827e tblgen: Replace uses of dynamic_cast<XXXRecTy> with dyn_cast<>.
This is a mechanical change of dynamic_cast<> to dyn_cast<>. A number of
these uses are actually more like isa<> or cast<>, and will be changed
to the semanticaly appropriate one in a future patch.

llvm-svn: 165291
2012-10-05 03:31:58 +00:00
Michael Liao
086020d2e5 Re-work bit/bits value resolving in tblgen
- This patch is inspired by the failure of the following code snippet
  which is used to convert enumerable values into encoding bits to
  improve the readability of td files.

  class S<int s> {
    bits<2> V = !if(!eq(s, 8),  {0, 0},
                !if(!eq(s, 16), {0, 1},
                !if(!eq(s, 32), {1, 0},
                !if(!eq(s, 64), {1, 1}, {?, ?}))));
  }

  Later, PR8330 is found to report not exactly the same bug relevant
  issue to bit/bits values.

- Instead of resolving bit/bits values separately through
  resolveBitReference(), this patch adds getBit() for all Inits and
  resolves bit value by resolving plus getting the specified bit. This
  unifies the resolving of bit with other values and removes redundant
  logic for resolving bit only. In addition,
  BitsInit::resolveReferences() is optimized to take advantage of this
  origanization by resolving VarBitInit's variable reference first and
  then getting bits from it.

- The type interference in '!if' operator is revised to support possible
  combinations of int and bits/bit in MHS and RHS.

- As there may be illegal assignments from integer value to bit, says
  assign 2 to a bit, but we only check this during instantiation in some
  cases, e.g.

  bit V = !if(!eq(x, 17), 0, 2);

  Verbose diagnostic message is generated when invalid value is
  resolveed to help locating the error.

- PR8330 is fixed as well.

llvm-svn: 163360
2012-09-06 23:32:48 +00:00
Jakob Stoklund Olesen
4c8373f54e Print out the location of expanded multiclass defs in TableGen errors.
When reporting an error for a defm, we would previously only report the
location of the outer defm, which is not always where the error is.

Now we also print the location of the expanded multiclass defs:

lib/Target/X86/X86InstrSSE.td:2902:12: error: foo
  defm ADD : basic_sse12_fp_binop_s<0x58, "add", fadd, SSE_ALU_ITINS_S>,
             ^
lib/Target/X86/X86InstrSSE.td:2801:11: note: instantiated from multiclass
  defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode, VR128,
            ^
lib/Target/X86/X86InstrSSE.td:194:5: note: instantiated from multiclass
    def rm : PI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
        ^

llvm-svn: 162409
2012-08-22 23:33:58 +00:00
Jim Grosbach
5cde605008 TableGen: Allow use of #NAME# outside of 'def' names.
Previously, def NAME values were only populated, and references to NAME
resolved, when NAME was referenced in the 'def' entry of the multiclass
sub-entry. e.g.,
multiclass foo<...> {
  def prefix_#NAME : ...
}

It's useful, however, to be able to reference NAME even when the default
def name is used. For example, when a multiclass has 'def : Pat<...>'
or 'def : InstAlias<...>' entries which refer to earlier instruction
definitions in the same multiclass. e.g.,
multiclass myMulti<RegisterClass rc> {
  def _r : myI<(outs rc:$d), (ins rc:$r), "r $d, $r", []>;

  def : InstAlias<\"wilma $r\", (!cast<Instruction>(NAME#\"_r\") rc:$r, rc:$r)>;
}

llvm-svn: 161198
2012-08-02 18:46:42 +00:00
Jakob Stoklund Olesen
e263c35c03 Add support for range expressions in TableGen foreach loops.
Like this:

  foreach i = 0-127 in ...

Use braces for composite ranges:

  foreach i = {0-3,9-7} in ...

llvm-svn: 157432
2012-05-24 22:17:39 +00:00
Jakob Stoklund Olesen
4d1e62df51 Don't put TGParser scratch results in the output.
Only fully expanded Records should go into RecordKeeper.

llvm-svn: 157431
2012-05-24 22:17:36 +00:00
Jakob Stoklund Olesen
34ca22c4f0 Simplify TGParser::ProcessForEachDefs.
Use static type checking.

llvm-svn: 157430
2012-05-24 22:17:33 +00:00
David Greene
7cabd2e787 Add Foreach Loop
Add some data structures to represent for loops.  These will be
referenced during object processing to do any needed iteration and
instantiation.

Add foreach keyword support to the lexer.

Add a mode to indicate that we're parsing a foreach loop.  This allows
the value parser to early-out when processing the foreach value list.

Add a routine to parse foreach iteration declarations.  This is
separate from ParseDeclaration because the type of the named value
(the iterator) doesn't match the type of the initializer value (the
value list).  It also needs to add two values to the foreach record:
the iterator and the value list.

Add parsing support for foreach.

Add the code to process foreach loops and create defs based
on iterator values.

Allow foreach loops to be matched at the top level.

When parsing an IDValue check if it is a foreach loop iterator for one
of the active loops.  If so, return a VarInit for it.

Add Emacs keyword support for foreach.

Add VIM keyword support for foreach.

Add tests to check foreach operation.

Add TableGen documentation for foreach.

Support foreach with multiple objects.

Support non-braced foreach body with one object.

Do not require types for the foreach declaration.  Assume the iterator
type from the iteration list element type.

llvm-svn: 151164
2012-02-22 16:09:41 +00:00
Craig Topper
639b152ca5 Convert assert(0) to llvm_unreachable
llvm-svn: 149967
2012-02-07 05:05:23 +00:00
David Greene
7748b4cf3b Fix Record Name Reference
Get the record name though the init to avoid an assert.

llvm-svn: 149153
2012-01-28 00:03:24 +00:00
David Blaikie
06ecc99a56 More dead code removal (using -Wunreachable-code)
llvm-svn: 148578
2012-01-20 21:51:11 +00:00
Jim Grosbach
2b1f17ec6e TblGen diagnostic for mismatched template instantiation.
Providing a template argment to a non-templatized class was crashing
tblgen. Add a diagnostic.

For example,
$ cat bug.td
class A;

def B : A<0> {
}
$ llvm-tblgen bug.td
bug.td:3:11: error: template argument provided to non-template class
def B : A<0> {
          ^

llvm-svn: 148565
2012-01-20 20:02:39 +00:00
Jakob Stoklund Olesen
9ba097a208 Delete CodeInit and CodeRecTy from TableGen.
The code type was always identical to a string anyway. Now it is simply
a synonym. The code literal syntax [{...}] is still valid.

llvm-svn: 148092
2012-01-13 03:38:34 +00:00
Jakob Stoklund Olesen
3776477761 Use uniqued StringInit pointers for lookups.
This avoids a gazillion StringMap and dynamic_cast calls, making
TableGen run 3x faster.

llvm-svn: 148091
2012-01-13 03:16:35 +00:00
Jim Grosbach
129c6dbc32 Check for error after InstantiateMultclassDef.
llvm-svn: 145689
2011-12-02 18:33:03 +00:00
David Greene
d5d61b6c0c Implement Paste
Add a paste operator '#' to take two identifier-like strings and joint
them.  Internally paste gets represented as a !strconcat() with any
necessary casts to string added.

This will be used to implement basic for loop functionality as in:

for i = [0, 1, 2, 3, 4, 5, 6, 7] {
  def R#i : Register<...>
}

llvm-svn: 142525
2011-10-19 13:04:43 +00:00
David Greene
82113dc5a1 Process NAME
During multiclass def instantiation, replace NAME in any expressions
with the value of the def or defm ID.

llvm-svn: 142524
2011-10-19 13:04:35 +00:00
David Greene
fadf000eb9 Process Defm Prefix as Init
Parse and process a defm prefix as an Init expression.  This allows
paste operations to create defm prefixes.

llvm-svn: 142523
2011-10-19 13:04:31 +00:00
David Greene
1ce450a01d Parse Def ID as Value
Allow def and defm IDs to be general values.  We need this for paste
functionality.

llvm-svn: 142522
2011-10-19 13:04:29 +00:00
David Greene
8bafcdaa89 Don't Parse Object Body as a Name
Stop parsing a value if we are in name parsing mode and we see a left
brace.  A left brace indicates the start of an object body when we are
parsing a name.

llvm-svn: 142521
2011-10-19 13:04:26 +00:00
David Greene
b703001e0b Use Parse Mode
Augment the value parser to respect the parse mode and not error if an
ID doesn't map to an object and we are in name parsing mode.

llvm-svn: 142520
2011-10-19 13:04:21 +00:00
David Greene
3aebc33998 Make ID Parsing More Flexible
Add a mode control to value and ID parsers.  The two modes are:

- Parse a value.  Expect the parsed ID to map to an existing object.

- Parse a name.  Expect the parsed ID to not map to any existing object.

The first is used when parsing an identifier to be looked up, for
example a record field or template argument.  The second is used for
parsing declarations.  Paste functionality implies that declarations
can contain arbitrary expressions so we need to be able to call into
the general value parser to parse declarations with paste operators.
So we need a way to parse a value-like thing without expecting that
the result will map to some existing object.  This parse mode provides
that.

llvm-svn: 142519
2011-10-19 13:04:20 +00:00
David Greene
09fc0034ab Add NAME Member
Add a Value named "NAME" to each Record.  This will be set to the def or defm
name when instantiating multiclasses.  This will replace the #NAME# processing
hack once paste functionality is in place.

llvm-svn: 142518
2011-10-19 13:04:13 +00:00
David Greene
947cd6bbaf Fix Name Access
Get the Record name as a string explicitly to avoid asserts.

llvm-svn: 142517
2011-10-19 13:04:02 +00:00
David Greene
3cf03cfd6a Fix Name Access
Get the Record name as a string explicitly to avoid asserts.

llvm-svn: 142516
2011-10-19 13:03:58 +00:00
David Greene
b883bee7d6 Fix Name Access
Get the Record name as a string explicitly to avoid asserts.

llvm-svn: 142515
2011-10-19 13:03:51 +00:00
David Greene
9647006543 Fix Name Access
Get the Record name by string explicitly to avoid potential asserts.

llvm-svn: 142514
2011-10-19 13:03:45 +00:00
David Greene
19302d2140 Make Template Arg Names Inits
Allow template arg names to be Inits.  This is further work to
implement paste as it allows template names to participate in paste
operations.

llvm-svn: 142500
2011-10-19 13:02:42 +00:00