[PATCH] D11623: TableGen: Support folding casts from bits to int

James Molloy james at jamesmolloy.co.uk
Thu Jul 30 06:47:45 PDT 2015


Hi Matt,

This looks sensible to me.

James

On Thu, 30 Jul 2015 at 07:29 Matt Arsenault <Matthew.Arsenault at amd.com>
wrote:

> arsenm created this revision.
> arsenm added a subscriber: llvm-commits.
>
> This is to fix an incorrect error when trying to initialize
> DwarfNumbers with a !cast<int> of a bits initializer.
> getValuesAsListOfInts("DwarfNumbers") would not see an IntInit
> and instead the cast, so would give up.
>
> It seems likely that this could be generalized to attempt
> the convertInitializerTo for any type. I'm not really sure
> why the existing code seems to special case the string cast cases
> when convertInitializerTo seems like it should generally handle this
> sort of thing.
>
>
> http://reviews.llvm.org/D11623
>
> Files:
>   lib/TableGen/Record.cpp
>   test/TableGen/cast-list-initializer.td
>
> Index: test/TableGen/cast-list-initializer.td
> ===================================================================
> --- /dev/null
> +++ test/TableGen/cast-list-initializer.td
> @@ -0,0 +1,10 @@
> +// RUN: llvm-tblgen %s | FileCheck %s
> +
> +class Foo<bits<8> b> {
> +// CHECK: list<int> ListOfInts = [170];
> +// CHECK: list<int> AnotherList = [170, 7];
> +  list<int> ListOfInts = [!cast<int>(b)];
> +  list<int> AnotherList = [!cast<int>(b), !cast<int>({1, 1, 1})];
> +}
> +
> +def : Foo<{1, 0, 1, 0, 1, 0, 1, 0}>;
> Index: lib/TableGen/Record.cpp
> ===================================================================
> --- lib/TableGen/Record.cpp
> +++ lib/TableGen/Record.cpp
> @@ -673,6 +673,14 @@
>          PrintFatalError(CurRec->getLoc(),
>                          "Undefined reference:'" + Name + "'\n");
>        }
> +
> +      if (isa<IntRecTy>(getType())) {
> +        if (BitsInit *BI = dyn_cast<BitsInit>(LHS)) {
> +          if (Init *NewInit = BI->convertInitializerTo(IntRecTy::get()))
> +            return NewInit;
> +          break;
> +        }
> +      }
>      }
>      break;
>    }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150730/8d91e6df/attachment.html>


More information about the llvm-commits mailing list