Issue with adding 72 bit registers

I’ve added 72-bit registers to the backend of the Xtensa experimental build. However, while building the compiler, I’m facing issues with the MCCodeEmitter. It seems the error is related to how the MCCodeEmitter only returns uint_64 datatypes in the .inc file and is unable to handle 72 bit instruction words.

/auto/worka/irohit/test_bld/lib/Target/Xtensa/XtensaGenMCCodeEmitter.inc:9:6: error: no declaration matches ‘void {anonymous}::XtensaMCCodeEmitter::getBinaryCodeForInstr(const llvm::MCInst&, llvm::SmallVectorImpl<llvm::MCFixup>&, llvm::APInt&, llvm::APInt&, const llvm::MCSubtargetInfo&) const’
    9 | void XtensaMCCodeEmitter::getBinaryCodeForInstr(const MCInst &MI,
      |      ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:52:9: note: candidate is: ‘llvm::APInt {anonymous}::XtensaMCCodeEmitter::getBinaryCodeForInstr(const llvm::MCInst&, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’
   52 |   APInt getBinaryCodeForInstr(const MCInst &MI,
      |         ^~~~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:34:7: note: ‘class {anonymous}::XtensaMCCodeEmitter’ defined here
   34 | class XtensaMCCodeEmitter : public MCCodeEmitter {
      |       ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:52:9: warning: ‘llvm::APInt {anonymous}::XtensaMCCodeEmitter::getBinaryCodeForInstr(const llvm::MCInst&, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ used but never defined
   52 |   APInt getBinaryCodeForInstr(const MCInst &MI,
      |         ^~~~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:781:1: warning: ‘int16_t {anonymous}::XtensaMCCodeEmitter::getOffset_64_16OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  781 | XtensaMCCodeEmitter::getOffset_64_16OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:769:1: warning: ‘uint8_t {anonymous}::XtensaMCCodeEmitter::getOffset_128_1OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  769 | XtensaMCCodeEmitter::getOffset_128_1OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:756:1: warning: ‘uint8_t {anonymous}::XtensaMCCodeEmitter::getOffset_128_2OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  756 | XtensaMCCodeEmitter::getOffset_128_2OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:743:1: warning: ‘int16_t {anonymous}::XtensaMCCodeEmitter::getOffset_256_4OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  743 | XtensaMCCodeEmitter::getOffset_256_4OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:730:1: warning: ‘int16_t {anonymous}::XtensaMCCodeEmitter::getOffset_256_16OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  730 | XtensaMCCodeEmitter::getOffset_256_16OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:717:1: warning: ‘int16_t {anonymous}::XtensaMCCodeEmitter::getOffset_256_8OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  717 | XtensaMCCodeEmitter::getOffset_256_8OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:704:1: warning: ‘int8_t {anonymous}::XtensaMCCodeEmitter::getOffset_16_16OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  704 | XtensaMCCodeEmitter::getOffset_16_16OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:692:1: warning: ‘uint8_t {anonymous}::XtensaMCCodeEmitter::getSelect_256OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  692 | XtensaMCCodeEmitter::getSelect_256OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:680:1: warning: ‘uint8_t {anonymous}::XtensaMCCodeEmitter::getSelect_16OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  680 | XtensaMCCodeEmitter::getSelect_16OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:668:1: warning: ‘uint8_t {anonymous}::XtensaMCCodeEmitter::getSelect_8OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  668 | XtensaMCCodeEmitter::getSelect_8OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:656:1: warning: ‘uint8_t {anonymous}::XtensaMCCodeEmitter::getSelect_4OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  656 | XtensaMCCodeEmitter::getSelect_4OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:644:1: warning: ‘uint8_t {anonymous}::XtensaMCCodeEmitter::getSelect_2OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  644 | XtensaMCCodeEmitter::getSelect_2OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:631:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getSeimm7_22OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  631 | XtensaMCCodeEmitter::getSeimm7_22OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:581:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getB4constuOpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  581 | XtensaMCCodeEmitter::getB4constuOpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:533:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getB4constOpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  533 | XtensaMCCodeEmitter::getB4constOpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:521:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getEntry_Imm12OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  521 | XtensaMCCodeEmitter::getEntry_Imm12OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:508:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getImm64n_4nOpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  508 | XtensaMCCodeEmitter::getImm64n_4nOpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:493:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getImm8n_7OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  493 | XtensaMCCodeEmitter::getImm8n_7OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:481:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getImm32n_95OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  481 | XtensaMCCodeEmitter::getImm32n_95OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:465:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getImm1n_15OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  465 | XtensaMCCodeEmitter::getImm1n_15OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:453:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getImm1_16OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  453 | XtensaMCCodeEmitter::getImm1_16OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:441:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getShimm1_31OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  441 | XtensaMCCodeEmitter::getShimm1_31OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:429:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getUimm5OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  429 | XtensaMCCodeEmitter::getUimm5OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:417:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getUimm4OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  417 | XtensaMCCodeEmitter::getUimm4OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:405:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getImm12OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  405 | XtensaMCCodeEmitter::getImm12OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:392:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getImm8_sh8OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  392 | XtensaMCCodeEmitter::getImm8_sh8OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:380:10: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getImm8OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  380 | uint32_t XtensaMCCodeEmitter::getImm8OpValue(const MCInst &MI, unsigned OpNo,
      |          ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:332:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getMemRegEncoding(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  332 | XtensaMCCodeEmitter::getMemRegEncoding(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:312:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getL32RTargetEncoding(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  312 | XtensaMCCodeEmitter::getL32RTargetEncoding(const MCInst &MI, unsigned OpNum,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:291:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getCallEncoding(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  291 | XtensaMCCodeEmitter::getCallEncoding(const MCInst &MI, unsigned int OpNum,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:274:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getLoopTargetEncoding(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  274 | XtensaMCCodeEmitter::getLoopTargetEncoding(const MCInst &MI, unsigned int OpNum,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:250:10: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getBranchTargetEncoding(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  250 | uint32_t XtensaMCCodeEmitter::getBranchTargetEncoding(
      |          ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:236:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getJumpTargetEncoding(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  236 | XtensaMCCodeEmitter::getJumpTargetEncoding(const MCInst &MI, unsigned int OpNum,
      | ^~~~~~~~~~~~~~~~~~~

This patch from a few years back was supposed to support instructions widths larger than 64. ⚙ D67487 [CodeEmitter] Support instruction widths > 64 bits

I’m on vacation this week so can’t easily do more investigation.

1 Like

These are not the same thing. Which is it?

But it looks like you’ve made your functions return an APInt rather than take an APInt by reference. You should read the error messages carefully and compare the types; all the information you need looks to be there.

72 bit registers with 72 bit instruction encoding.

Yes, I was just testing out if we could return an APInt but, as you have pointed out, can only take APInt by reference. This was the original error I got while building.

As I understand it, it uses the patch that @topperc mentioned. It uses APInts to support instruction widths over 64 bits and automatically adds AP& Inst, AP& Scratch parameters in the class declaration. However, while building, I face this error which says that there is no declaration in the first place, which I’m unable to understand why.

In file included from /auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:793:
/auto/worka/irohit/test_bld/lib/Target/Xtensa/XtensaGenMCCodeEmitter.inc:9:6: error: no declaration matches ‘void {anonymous}::XtensaMCCodeEmitter::getBinaryCodeForInstr(const llvm::MCInst&, llvm::SmallVectorImpl<llvm::MCFixup>&, llvm::APInt&, llvm::APInt&, const llvm::MCSubtargetInfo&) const’
    9 | void XtensaMCCodeEmitter::getBinaryCodeForInstr(const MCInst &MI,
      |      ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:52:12: note: candidate is: ‘uint64_t {anonymous}::XtensaMCCodeEmitter::getBinaryCodeForInstr(const llvm::MCInst&, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’
   52 |   uint64_t getBinaryCodeForInstr(const MCInst &MI,
      |            ^~~~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:34:7: note: ‘class {anonymous}::XtensaMCCodeEmitter’ defined here
   34 | class XtensaMCCodeEmitter : public MCCodeEmitter {
      |       ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:52:12: warning: ‘uint64_t {anonymous}::XtensaMCCodeEmitter::getBinaryCodeForInstr(const llvm::MCInst&, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ used but never defined
   52 |   uint64_t getBinaryCodeForInstr(const MCInst &MI,
      |            ^~~~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:781:1: warning: ‘int16_t {anonymous}::XtensaMCCodeEmitter::getOffset_64_16OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  781 | XtensaMCCodeEmitter::getOffset_64_16OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:769:1: warning: ‘uint8_t {anonymous}::XtensaMCCodeEmitter::getOffset_128_1OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  769 | XtensaMCCodeEmitter::getOffset_128_1OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:756:1: warning: ‘uint8_t {anonymous}::XtensaMCCodeEmitter::getOffset_128_2OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  756 | XtensaMCCodeEmitter::getOffset_128_2OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:743:1: warning: ‘int16_t {anonymous}::XtensaMCCodeEmitter::getOffset_256_4OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  743 | XtensaMCCodeEmitter::getOffset_256_4OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:730:1: warning: ‘int16_t {anonymous}::XtensaMCCodeEmitter::getOffset_256_16OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  730 | XtensaMCCodeEmitter::getOffset_256_16OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:717:1: warning: ‘int16_t {anonymous}::XtensaMCCodeEmitter::getOffset_256_8OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  717 | XtensaMCCodeEmitter::getOffset_256_8OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:704:1: warning: ‘int8_t {anonymous}::XtensaMCCodeEmitter::getOffset_16_16OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  704 | XtensaMCCodeEmitter::getOffset_16_16OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:692:1: warning: ‘uint8_t {anonymous}::XtensaMCCodeEmitter::getSelect_256OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  692 | XtensaMCCodeEmitter::getSelect_256OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:680:1: warning: ‘uint8_t {anonymous}::XtensaMCCodeEmitter::getSelect_16OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  680 | XtensaMCCodeEmitter::getSelect_16OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:668:1: warning: ‘uint8_t {anonymous}::XtensaMCCodeEmitter::getSelect_8OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  668 | XtensaMCCodeEmitter::getSelect_8OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:656:1: warning: ‘uint8_t {anonymous}::XtensaMCCodeEmitter::getSelect_4OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  656 | XtensaMCCodeEmitter::getSelect_4OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:644:1: warning: ‘uint8_t {anonymous}::XtensaMCCodeEmitter::getSelect_2OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  644 | XtensaMCCodeEmitter::getSelect_2OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:631:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getSeimm7_22OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  631 | XtensaMCCodeEmitter::getSeimm7_22OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:581:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getB4constuOpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  581 | XtensaMCCodeEmitter::getB4constuOpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:533:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getB4constOpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  533 | XtensaMCCodeEmitter::getB4constOpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:521:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getEntry_Imm12OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  521 | XtensaMCCodeEmitter::getEntry_Imm12OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:508:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getImm64n_4nOpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  508 | XtensaMCCodeEmitter::getImm64n_4nOpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:493:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getImm8n_7OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  493 | XtensaMCCodeEmitter::getImm8n_7OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:481:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getImm32n_95OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  481 | XtensaMCCodeEmitter::getImm32n_95OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:465:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getImm1n_15OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  465 | XtensaMCCodeEmitter::getImm1n_15OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:453:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getImm1_16OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  453 | XtensaMCCodeEmitter::getImm1_16OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:441:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getShimm1_31OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  441 | XtensaMCCodeEmitter::getShimm1_31OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:429:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getUimm5OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  429 | XtensaMCCodeEmitter::getUimm5OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:417:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getUimm4OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  417 | XtensaMCCodeEmitter::getUimm4OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:405:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getImm12OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  405 | XtensaMCCodeEmitter::getImm12OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:392:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getImm8_sh8OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  392 | XtensaMCCodeEmitter::getImm8_sh8OpValue(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:380:10: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getImm8OpValue(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  380 | uint32_t XtensaMCCodeEmitter::getImm8OpValue(const MCInst &MI, unsigned OpNo,
      |          ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:332:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getMemRegEncoding(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  332 | XtensaMCCodeEmitter::getMemRegEncoding(const MCInst &MI, unsigned OpNo,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:312:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getL32RTargetEncoding(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  312 | XtensaMCCodeEmitter::getL32RTargetEncoding(const MCInst &MI, unsigned OpNum,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:291:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getCallEncoding(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  291 | XtensaMCCodeEmitter::getCallEncoding(const MCInst &MI, unsigned int OpNum,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:274:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getLoopTargetEncoding(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  274 | XtensaMCCodeEmitter::getLoopTargetEncoding(const MCInst &MI, unsigned int OpNum,
      | ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:250:10: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getBranchTargetEncoding(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  250 | uint32_t XtensaMCCodeEmitter::getBranchTargetEncoding(
      |          ^~~~~~~~~~~~~~~~~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:236:1: warning: ‘uint32_t {anonymous}::XtensaMCCodeEmitter::getJumpTargetEncoding(const llvm::MCInst&, unsigned int, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
  236 | XtensaMCCodeEmitter::getJumpTargetEncoding(const MCInst &MI, unsigned int OpNum,
      | ^~~~~~~~~~~~~~~~~~~
gmake[2]: *** [lib/Target/Xtensa/MCTargetDesc/CMakeFiles/LLVMXtensaDesc.dir/build.make:132: lib/Target/Xtensa/MCTargetDesc/CMakeFiles/LLVMXtensaDesc.dir/XtensaMCCodeEmitter.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:15121: lib/Target/Xtensa/MCTargetDesc/CMakeFiles/LLVMXtensaDesc.dir/all] Error 2
gmake: *** [Makefile:156: all] Error 2```

Please read the error messages. This:

is not the same as:

Your class is declaring the methods as if they’re dealing with <= 64 bits.

I’m sorry, I seem confused about the dependencies between CodeEmitterGen.cpp and TargetMCCodeEmitter.cpp. As I seem to understand it, CodeEmitterGen.cpp generates the Target-specific MCCodeEmitter.cpp, which generates the Target-specific GenMCCodeEmitter.inc file right? If so, I am under the assumption that CodeEmitterGen.cpp will make the necessary changes in class declarations of TargetMCCodeEmitter.cpp when it sees that the instruction width > 64 bits. Please do correct me where I’m wrong.

No, the latter is a hand-written file that lives in llvm/lib/Target/Foo/MCTargetDesc, as you can see from the path being in the source directory not the build directory.

Thanks for the clarification! So what role do the MCCodeEmitter.cpp and CodeEmitterGen.cpp play in generating the target specific .inc file?

And should changing all class declarations in MCCodeEmitter.cpp to the > 64 bits format fix the issue?

None, it’s a bunch of hand-written functions that work with the generated GenMCCodeEmitter.inc.

It generates GenMCCodeEmitter.inc.

It’ll improve things. Whether or not there are other things you also need to fix I don’t know.

After debugging, I have only two errors left to resolve. As Scratch and Inst are APInt types, I’m confused about where to declare them. I tried declaring them in the encodeInstruction method as APInt &Inst, APInt &Scratch but still facing the same issue.

void XtensaMCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS,
                                            SmallVectorImpl<MCFixup> &Fixups,
                                            const MCSubtargetInfo &STI) const {
  uint64_t Bits = getBinaryCodeForInstr(MI, Fixups, Inst, Scratch, STI);
  unsigned Size = MCII.get(MI.getOpcode()).getSize();

  if (IsLittleEndian) {
    // Little-endian insertion of Size bytes.
    unsigned ShiftValue = 0;
    for (unsigned I = 0; I != Size; ++I) {
      OS << uint8_t(Bits >> ShiftValue);
      ShiftValue += 8;
    }
  } else {
    // TODO Big-endian insertion of Size bytes.
    report_fatal_error("Big-endian mode currently is not supported!");
  }
}```
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp: In member function ‘virtual void {anonymous}::XtensaMCCodeEmitter::encodeInstruction(const llvm::MCInst&, llvm::raw_ostream&, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const’:
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:241:53: error: ‘Inst’ was not declared in this scope
  241 |   uint64_t Bits = getBinaryCodeForInstr(MI, Fixups, Inst, Scratch, STI);
      |                                                     ^~~~
/auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:241:59: error: ‘Scratch’ was not declared in this scope
  241 |   uint64_t Bits = getBinaryCodeForInstr(MI, Fixups, Inst, Scratch, STI);
      |                                                           ^~~~~~~
In file included from /auto/worka/irohit/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp:863:
/auto/worka/irohit/test_bld/lib/Target/Xtensa/XtensaGenMCCodeEmitter.inc: At global scope:
/auto/worka/irohit/test_bld/lib/Target/Xtensa/XtensaGenMCCodeEmitter.inc:9:6: warning: ‘void {anonymous}::XtensaMCCodeEmitter::getBinaryCodeForInstr(const llvm::MCInst&, llvm::SmallVectorImpl<llvm::MCFixup>&, llvm::APInt&, llvm::APInt&, const llvm::MCSubtargetInfo&) const’ defined but not used [-Wunused-function]
    9 | void XtensaMCCodeEmitter::getBinaryCodeForInstr(const MCInst &MI,
      |      ^~~~~~~~~~~~~~~~~~~
gmake[2]: *** [lib/Target/Xtensa/MCTargetDesc/CMakeFiles/LLVMXtensaDesc.dir/build.make:132: lib/Target/Xtensa/MCTargetDesc/CMakeFiles/LLVMXtensaDesc.dir/XtensaMCCodeEmitter.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:15121: lib/Target/Xtensa/MCTargetDesc/CMakeFiles/LLVMXtensaDesc.dir/all] Error 2
gmake: *** [Makefile:156: all] Error 2```

Sounds like you want:

APInt Bits, Scratch;
getBinaryCodeForInstr(MI, Fixups, Bits, Scratch, STI);

no?

Yup, that worked. However, the encode instruction function does not work as getBinaryCodeForInstr is a void function and hence returns nothing but I don’t think I can change its type as it is specified in GenMCCodeEmitter.inc so I’m not sure what to do exactly.

Another issue I think we might face is the fact that the bits returned by getBinaryCodeForInstr will be greater than 64 bits so do we have to change its datatype to APInt as well?

void XtensaMCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS,
                                            SmallVectorImpl<MCFixup> &Fixups,
                                            const MCSubtargetInfo &STI) const {
  APInt Inst;
  APInt Scratch;
  uint64_t Bits = getBinaryCodeForInstr(MI, Fixups, Inst, Scratch, STI);
  unsigned Size = MCII.get(MI.getOpcode()).getSize();

  if (IsLittleEndian) {
    // Little-endian insertion of Size bytes.
    unsigned ShiftValue = 0;
    for (unsigned I = 0; I != Size; ++I) {
      OS << uint8_t(Bits >> ShiftValue);
      ShiftValue += 8;
    }
  } else {
    // TODO Big-endian insertion of Size bytes.
    report_fatal_error("Big-endian mode currently is not supported!");
  }
}```

So, according to the patch mentioned by @topperc, the Inst parameter of getBinaryCodeForInstr returns the encoded instruction; hence, I have written the encodeInstruction function like so. The build was also successfully completed. Will test if the implementation works and get back to you. Thanks a lot for the help @jrtc27!

void XtensaMCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS,
                                            SmallVectorImpl<MCFixup> &Fixups,
                                            const MCSubtargetInfo &STI) const {
  APInt Inst;
  APInt Scratch;
  getBinaryCodeForInstr(MI, Fixups, Inst, Scratch, STI);
}