[PATCH] D155329: [TableGen][CodeEmitterGen] Add support for querying operand bit offsets

Ulrich Weigand via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 18 06:38:21 PDT 2023


uweigand added a comment.

In D155329#4509748 <https://reviews.llvm.org/D155329#4509748>, @iii wrote:

>   case SystemZ::LLILF: {
>     switch (OpNum) {
>     case 0:
>       // op: R1
>       return IsLittleEndian ? 36 : 8;
>     case 1:
>       // op: I2
>       return IsLittleEndian ? 0 : 16;
>     }
>     break;
>   }

I guess this numbers are still a bit confusing to me.  What exactly does `IsLittleEndian` specify here?   TableGen doesn't really inherently know about the in-memory representation, it defines the instruction as a single integer.  E.g.   looking at how this instruction format is defined:

  let Inst{47-40} = op{11-4};
  let Inst{39-36} = R1;
  let Inst{35-32} = op{3-0};
  let Inst{31-0}  = I2;

we see it's represented as a single 48-bit integer.  Its encoding into bytes in memory only happens in the platform-specific `encodeInstruction` routine here:

  void SystemZMCCodeEmitter::encodeInstruction(const MCInst &MI,
                                               SmallVectorImpl<char> &CB,
                                               SmallVectorImpl<MCFixup> &Fixups,
                                               const MCSubtargetInfo &STI) const {
    MemOpsEmitted = 0;
    uint64_t Bits = getBinaryCodeForInstr(MI, Fixups, STI);
    unsigned Size = MCII.get(MI.getOpcode()).getSize();
    // Big-endian insertion of Size bytes.
    unsigned ShiftValue = (Size * 8) - 8;
    for (unsigned I = 0; I != Size; ++I) {
      CB.push_back(uint8_t(Bits >> ShiftValue));
      ShiftValue -= 8;
    }
  }

So I would have expected the `getOperandBitOffset` call to return one of the values explicitly called out in the instruction format definition, i.e. 39 or 36 for `R1` in the above example.  (I guess it doesn't matter which one, as the user will know the field length, so they are able to compute the other one.)   Using that value, plus the total size of the current instruction (which can be gotten via `MCII.get(MI.getOpcode()).getSize()`), the caller should able to compute whatever they need.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155329/new/

https://reviews.llvm.org/D155329



More information about the llvm-commits mailing list