About TableGen RangeList

Hi All,

One thing I believe also bothers someone else. Say we have the following code snippet:

bits<32> insnEncoding;
let insnEncoding{15-12} = 0b0100;

Can we write the let expression with range list like this, with the same meaning?

let insnEncoding{12-15} = 0b0100;

I take a look on TGParser::ParseRangePiece (lib/TableGen/TGParser.cpp), seems the
answer is YES. Can anyone confirm this?

Thanks.

Regards,
chenwj

Okay, a little experiment shows the order matters.

  $ cat bits_4_0.td
  def basic_bits {
    bits<10> zz;
    let zz{4-0} = 0b11001;
  }

  $ llvm-tblgen bits_4_0.td
  def basic_bits {
    bits<10> zz = { ?, ?, ?, ?, ?, 1, 1, 0, 0, 1 };
    string NAME = ?;
  }

  $ cat bits_0_4.td
  def basic_bits {
    bits<10> zz;
    let zz{0-4} = 0b11001;
  }

  $ llvm-tblgen bits_4_0.td
  def basic_bits {
    bits<10> zz = { ?, ?, ?, ?, ?, 1, 0, 0, 1, 1 };
    string NAME = ?;
  }

Interesting, thanks for reporting back. Personally I find it pretty
scary that we support the second form at all. It's mixing two
different endiannesses with no real indication of which one will win.

Tim.

Well, I won't give it a judgement here, just want to document this
explicit, https://reviews.llvm.org/D32117 .

:wink:

I recall seeing an option to control this in InstrInfo:

  // Target can specify its instructions in either big or little-endian formats.
  // For instance, while both Sparc and PowerPC are big-endian platforms, the
  // Sparc manual specifies its instructions in the format [31..0] (big), while
  // PowerPC specifies them using the format [0..31] (little).
  bit isLittleEndianEncoding = 0;

Hi Matt,

I believe bit isLittleEndianEncoding is irrelevant here. Tim and I are talking about if the (a) and (b)
below getting the same (expected) result.

bits<32> insnEncoding;
let insnEncoding{15-12} = 0b0100; // (a)
let insnEncoding{15-12} = 0b0100; // (b)

Looking at TGParser::ParseRangePiece [1], no one use isLittleEndianEncoding. I think Tim’s concern
is it’s quite easy to misuse those {15-12} and {12-15}, and users won’t be notified if thing doesn’t go as
they expected.

[1] http://llvm.org/doxygen/TGParser_8cpp_source.html

Regards,
chenwj