FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

LLVM16が公開されたので、LLVM本のベースリポジトリをLLVM16に移す作業をしてみる

LLVM16が公開された。毎度毎度LLVMはバージョンが変わるたびにAPIの仕様が変わるので、自分の作ったLLVM本の実装が変わってしまう。 この修正が毎回大変なのだ。

releases.llvm.org

今回、とりあえずLLVM16のベースブランチに切り替えて作業をしてみる。 release/16.xブランチへの切り替えは意外と簡単にうまくいったが、コンパイルが通らない。

$ cmake -G Ninja     -DCMAKE_BUILD_TYPE="Debug"      -DLLVM_TARGETS_TO_BUILD="X86;AArch64;RISCV;MYRISCVX"    -DLLVM_ENABLE_PROJECTS="clang"   ../llvm
$ ninja
  1. どうもTarget Descriptionの仕様が変わっている。以前の記述をそのまま使うならば、useDeprecatedPositionallyEncodedOperandsというのを追加する必要があるようだ。
llvm-myriscvx160/llvm/lib/Target/MYRISCVX/MYRISCVXInstrInfo.td:858:5: error: No operand named rs1 in record CSRRCI (would've used positional operand #0 ('rd') sub-op #0 with useDeprecatedPositionallyEncodedOperands=true)
def CSRRCI : CSRI <0b1110011, 0b111, "csrrci">;
    ^
diff --git a/llvm/lib/Target/MYRISCVX/MYRISCVX.td b/llvm/lib/Target/MYRISCVX/MYRISCVX.td
index dd19b5c0d926..d7b66313b805 100644
--- a/llvm/lib/Target/MYRISCVX/MYRISCVX.td
+++ b/llvm/lib/Target/MYRISCVX/MYRISCVX.td
@@ -50,7 +50,9 @@ include "MYRISCVXSchedule.td"
 include "MYRISCVXInstrInfo.td"      // 命令定義を含んだtdファイル
 include "MYRISCVXCallingConv.td"

-def MYRISCVXInstrInfo : InstrInfo;
+def MYRISCVXInstrInfo : InstrInfo {
+   let useDeprecatedPositionallyEncodedOperands = 1
+}

 // @{ Add_MYRISCVX_td_MYRISCVXAsmParser
 // AsmParserで使用するMatcherを生成する
  1. いくつかの関数の仕様が変わっている。
/home/msyksphinz/work/llvm/llvm-myriscvx160/llvm/lib/Target/MYRISCVX/MYRISCVXRegisterInfo.h:47:10: error: conflicting return type specified for ‘virtual void llvm::MYRISCVXRegisterInfo::eliminateFrameIndex(llvm::MachineBasicBlock::iterator, int, \
unsigned int, llvm::RegScavenger*) const’
   47 |     void eliminateFrameIndex(MachineBasicBlock::iterator II,
      |          ^~~~~~~~~~~~~~~~~~~
In file included from /home/msyksphinz/work/llvm/llvm-myriscvx160/llvm/lib/Target/MYRISCVX/MYRISCVXRegisterInfo.h:18,
                 from /home/msyksphinz/work/llvm/llvm-myriscvx160/llvm/lib/Target/MYRISCVX/MYRISCVXInstrInfo.h:18,
                 from /home/msyksphinz/work/llvm/llvm-myriscvx160/llvm/lib/Target/MYRISCVX/MYRISCVXSubtarget.h:19,
                 from /home/msyksphinz/work/llvm/llvm-myriscvx160/llvm/lib/Target/MYRISCVX/MYRISCVXSubtarget.cpp:14:
/home/msyksphinz/work/llvm/llvm-myriscvx160/llvm/include/llvm/CodeGen/TargetRegisterInfo.h:1053:16: note: overridden function is ‘virtual bool llvm::TargetRegisterInfo::eliminateFrameIndex(llvm::MachineBasicBlock::iterator, int, unsigned int, llv\
m::RegScavenger*) const’
 1053 |   virtual bool eliminateFrameIndex(MachineBasicBlock::iterator MI,
      |                ^~~~~~~~~~~~~~~~~~~
diff --git a/llvm/lib/Target/MYRISCVX/MYRISCVXInstrInfo.h b/llvm/lib/Target/MYRISCVX/MYRISCVXInstrInfo.h
index 9be4027c90e5..4756a57669c9 100644
--- a/llvm/lib/Target/MYRISCVX/MYRISCVXInstrInfo.h
+++ b/llvm/lib/Target/MYRISCVX/MYRISCVXInstrInfo.h
@@ -60,7 +60,8 @@ class MYRISCVXInstrInfo : public MYRISCVXGenInstrInfo {
                            MachineBasicBlock::iterator MBBI,
                            Register SrcReg, bool isKill, int FrameIndex,
                            const TargetRegisterClass *RC,
-                           const TargetRegisterInfo *TRI) const override {
+                           const TargetRegisterInfo *TRI,
+                           Register VReg) const override {
     storeRegToStack(MBB, MBBI, SrcReg, isKill, FrameIndex, RC, TRI, 0);
   }

@@ -68,7 +69,8 @@ class MYRISCVXInstrInfo : public MYRISCVXGenInstrInfo {
                             MachineBasicBlock::iterator MBBI,
                             Register DestReg, int FrameIndex,
                             const TargetRegisterClass *RC,
-                            const TargetRegisterInfo *TRI) const override {
+                            const TargetRegisterInfo *TRI,
+                            Register VReg) const override {
     loadRegFromStack(MBB, MBBI, DestReg, FrameIndex, RC, TRI, 0);
   }

diff --git a/llvm/lib/Target/MYRISCVX/MYRISCVXRegisterInfo.cpp b/llvm/lib/Target/MYRISCVX/MYRISCVXRegisterInfo.cpp
index 8062ae85f099..16dd4af1cf8c 100644
--- a/llvm/lib/Target/MYRISCVX/MYRISCVXRegisterInfo.cpp
+++ b/llvm/lib/Target/MYRISCVX/MYRISCVXRegisterInfo.cpp
@@ -81,7 +81,7 @@ getReservedRegs(const MachineFunction &MF) const {
 // @{ MYRISCVXRegisterInfo_eliminateFrameIndex_Implemented
 // eliminateFrameIndexでは関数内での変数参照に使用される仮想的なオフセットを
 // 具体的なオフセット計算に置き換える
-void MYRISCVXRegisterInfo::
+bool MYRISCVXRegisterInfo::
 eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj,
                     unsigned FIOperandNum, RegScavenger *RS) const {
   MachineInstr &MI = *II;
@@ -139,6 +139,8 @@ eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj,
   MI.getOperand(i+0).ChangeToRegister(FrameReg, false);
   MI.getOperand(i+1).ChangeToImmediate(Offset);
   // @} eliminateFrameIndex_changeMI
+
+  return true;
 }
 // @} MYRISCVXRegisterInfo_eliminateFrameIndex_Implemented
 // @} MYRISCVXRegisterInfo_eliminateFrameIndex
diff --git a/llvm/lib/Target/MYRISCVX/MYRISCVXRegisterInfo.h b/llvm/lib/Target/MYRISCVX/MYRISCVXRegisterInfo.h
index c514d2f84a98..4f25ea7e6ed8 100644
--- a/llvm/lib/Target/MYRISCVX/MYRISCVXRegisterInfo.h
+++ b/llvm/lib/Target/MYRISCVX/MYRISCVXRegisterInfo.h
@@ -44,7 +44,7 @@ namespace llvm {
     bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const override;

     /// Stack Frame Processing Methods
-    void eliminateFrameIndex(MachineBasicBlock::iterator II,
+    bool eliminateFrameIndex(MachineBasicBlock::iterator II,
                              int SPAdj, unsigned FIOperandNum,
                              RegScavenger *RS = nullptr) const override;
diff --git a/llvm/lib/Target/MYRISCVX/MCTargetDesc/MYRISCVXInstPrinter.cpp b/llvm/lib/Target/MYRISCVX/MCTargetDesc/MYRISCVXInstPrinter.cpp
index ca472f1cca47..0e716cf71acf 100644
--- a/llvm/lib/Target/MYRISCVX/MCTargetDesc/MYRISCVXInstPrinter.cpp
+++ b/llvm/lib/Target/MYRISCVX/MCTargetDesc/MYRISCVXInstPrinter.cpp
@@ -29,7 +29,7 @@ using namespace llvm;
 #define PRINT_ALIAS_INSTR
 #include "MYRISCVXGenAsmWriter.inc"

-void MYRISCVXInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
+void MYRISCVXInstPrinter::printRegName(raw_ostream &OS, MCRegister RegNo) const {
   //- getRegisterName(RegNo) defined in MYRISCVXGenAsmWriter.inc which indicate in
   //   MYRISCVX.td.
   OS << StringRef(getRegisterName(RegNo)).lower();
diff --git a/llvm/lib/Target/MYRISCVX/MCTargetDesc/MYRISCVXInstPrinter.h b/llvm/lib/Target/MYRISCVX/MCTargetDesc/MYRISCVXInstPrinter.h
index a3ad6a60c9e6..9d4ff018db46 100644
--- a/llvm/lib/Target/MYRISCVX/MCTargetDesc/MYRISCVXInstPrinter.h
+++ b/llvm/lib/Target/MYRISCVX/MCTargetDesc/MYRISCVXInstPrinter.h
@@ -31,10 +31,10 @@ class MYRISCVXInstPrinter : public MCInstPrinter {

   // Autogenerated by tblgen.
   void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O);
-  static const char *getRegisterName(unsigned RegNo);
+  static const char *getRegisterName(MCRegister RegNo);
   std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;

-  void printRegName(raw_ostream &OS, unsigned RegNo) const override;
+  void printRegName(raw_ostream &OS, MCRegister RegNo) const override;
   void printInst(const MCInst *MI, uint64_t Address,
                  StringRef Annot, const MCSubtargetInfo &STI,
                  raw_ostream &O) override;

まだまだ続く...