FPGA開発日記

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

Vitis-HLSのLLVMフロントエンドを試す (3. FPGAディレクトリを確認)

FPGA向けのバックエンド実装は以下に含まれていた(HLS的な名前なのかと思っていたので、FPGAというディレクトリにしばらく気が付かなかった)。

github.com

ディレクトリ構成を確認すると以下のようだった。

tree lib/Target/FPGA
lib/Target/FPGA
|-- CMakeLists.txt
|-- FPGA.h
|-- FPGA.td
|-- FPGASchedUltraScale.td
|-- FPGASchedule.td
|-- FPGASubtarget.cpp
|-- FPGASubtarget.h
|-- FPGATargetMachine.cpp
|-- FPGATargetMachine.h
|-- FPGATargetTransformInfo.cpp
|-- FPGATargetTransformInfo.h
|-- LLVMBuild.txt
|-- MCTargetDesc
|   |-- CMakeLists.txt
|   |-- FPGAMCTargetDesc.cpp
|   |-- FPGAMCTargetDesc.h
|   `-- LLVMBuild.txt
`-- TargetInfo
    |-- CMakeLists.txt
    |-- FPGATargetInfo.cpp
    `-- LLVMBuild.txt

2 directories, 19 files

FPGA.tdはTarget Descriptionの中心となるファイルだが、FPGATargetMachine.{h,cpp}C++の中心となる実装で、FPGASubtarget.{h,cpp}がサブターゲットの実装となっている。MCTargetDescの実装が多いということは、やはりMCレイヤでの処理が中心ということかな?

ファイルの行数を確認する。

     12 CMakeLists.txt
     42 FPGA.h
    123 FPGA.td
     40 FPGASchedUltraScale.td
     36 FPGASchedule.td
     74 FPGASubtarget.cpp
     86 FPGASubtarget.h
    145 FPGATargetMachine.cpp
     59 FPGATargetMachine.h
    365 FPGATargetTransformInfo.cpp
    170 FPGATargetTransformInfo.h
     43 LLVMBuild.txt

   3 MCTargetDesc/CMakeLists.txt
  73 MCTargetDesc/FPGAMCTargetDesc.cpp
  58 MCTargetDesc/FPGAMCTargetDesc.h
  35 MCTargetDesc/LLVMBuild.txt

   3 TargetInfo/CMakeLists.txt
  34 TargetInfo/FPGATargetInfo.cpp
  35 TargetInfo/LLVMBuild.txt
  72 total

うーんどれも大したことないなあ?気になるのはFPGATargetTransformInfoというやつだ。これは今まで見たことない。

 //===----------------------------------------------------------------------===//
 // FPGA TTI query.
 //===----------------------------------------------------------------------===//

 TargetTransformInfo FPGATargetMachine::getTargetTransformInfo(const Function &F) {
   return TargetTransformInfo(FPGATTIImpl(this, F));
 }
  • HLS/llvm/llvm/include/llvm/Analysis/TargetTransformInfo.h
 /// \brief This pass provides access to the codegen interfaces that are needed
 /// for IR-level transformations.
 class TargetTransformInfo {
 public:
   /// \brief Construct a TTI object using a type implementing the \c Concept
   /// API below.
   ///
   /// This is used by targets to construct a TTI wrapping their target-specific
   /// implementaion that encodes appropriate costs for their target.
   template <typename T> TargetTransformInfo(T Impl);

   /// \brief Construct a baseline TTI object using a minimal implementation of
   /// the \c Concept API below.
   ///
   /// The TTI implementation will reflect the information in the DataLayout
   /// provided if non-null.
   explicit TargetTransformInfo(const DataLayout &DL);
...

ふーむ、IRレベルでの変換ということ?