[llvm-commits] [PATCH] Rework bit/bits value resolving in tblgen

Michael Liao michael.liao at intel.com
Tue Aug 28 14:35:54 PDT 2012


Hi,

I found several failure cases on bit/bits value resolving in tblgen. One
example is to convert enumerable values into encoding bits to improve
readability, e.g. with this class

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

we could use S<n>.Val to access the encoding bits for value n. But, this
td fails with "error: could not get type for !if". Later, I found a
similar but not exactly the same issue in PR8330 on bit/bits value
reference. This leads the patch attached to re-work bit/bits value
references in tblgen.

This patch resolves bit/bits value by resolving initializer value first
and get its bit value from the specified position by adding (or
promoting) getBits() to all Init(s) and removing resolveBitReference().
We unify bit/bits with other types and remove redundant logic.

For '!if' operator, the type inference logic is revised to handle
non-TypedInit better as we could convert some of them into bit/bits now.
But, this will results in some cases a invalid integer value is assigned
into bit and cannot check them during class definition time, e.g.

class X<int a, bit b> {
  bit Val = !if(!eq(a, 7), 2, b);
}

We could only find such illegal assignment during instantiation. For
such case, verbose diagnostic message is generated to help locate the
error.

The attached patch also fix PR8330. Thanks your time to review it.

Regards
- Michael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Re-work-bit-bits-value-resolving-in-tblgen.patch
Type: text/x-patch
Size: 26255 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120828/ea2f4aa3/attachment.bin>


More information about the llvm-commits mailing list