Compiler projects using llvm
import("//llvm/utils/TableGen/tablegen.gni")

# RISCV is the only target that has a "compress instr emitter", and it's
# a bit strange in that it defines static functions depending on which
# defines are set. Instead of housing these functions in one library,
# various libraries include the generated .inc file with different defines set.
tablegen("RISCVGenCompressInstEmitter") {
  visibility = [
    ":LLVMRISCVCodeGen",
    "AsmParser",
    "MCTargetDesc",
  ]
  args = [ "-gen-compress-inst-emitter" ]
  td_file = "RISCV.td"
}

tablegen("RISCVGenDAGISel") {
  visibility = [ ":LLVMRISCVCodeGen" ]
  args = [ "-gen-dag-isel" ]
  td_file = "RISCV.td"
}

tablegen("RISCVGenGlobalISel") {
  visibility = [ ":LLVMRISCVCodeGen" ]
  args = [ "-gen-global-isel" ]
  td_file = "RISCV.td"
}

tablegen("RISCVGenMCPseudoLowering") {
  visibility = [ ":LLVMRISCVCodeGen" ]
  args = [ "-gen-pseudo-lowering" ]
  td_file = "RISCV.td"
}

tablegen("RISCVGenRegisterBank") {
  visibility = [ ":LLVMRISCVCodeGen" ]
  args = [ "-gen-register-bank" ]
  td_file = "RISCV.td"
}

static_library("LLVMRISCVCodeGen") {
  deps = [
    ":RISCVGenCompressInstEmitter",
    ":RISCVGenDAGISel",
    ":RISCVGenGlobalISel",
    ":RISCVGenMCPseudoLowering",
    ":RISCVGenRegisterBank",

    # See https://reviews.llvm.org/D69130
    "AsmParser:RISCVGenAsmMatcher",
    "MCTargetDesc",
    "TargetInfo",
    "//llvm/include/llvm/Config:llvm-config",
    "//llvm/lib/CodeGen",
    "//llvm/lib/CodeGen/AsmPrinter",
    "//llvm/lib/CodeGen/SelectionDAG",
    "//llvm/lib/IR",
    "//llvm/lib/MC",
    "//llvm/lib/Support",
    "//llvm/lib/Target",
    "//llvm/lib/Transforms/IPO",
  ]
  include_dirs = [ "." ]
  sources = [
    "RISCVAsmPrinter.cpp",
    "RISCVCallLowering.cpp",
    "RISCVCodeGenPrepare.cpp",
    "RISCVExpandAtomicPseudoInsts.cpp",
    "RISCVExpandPseudoInsts.cpp",
    "RISCVFrameLowering.cpp",
    "RISCVGatherScatterLowering.cpp",
    "RISCVISelDAGToDAG.cpp",
    "RISCVISelLowering.cpp",
    "RISCVInsertVSETVLI.cpp",
    "RISCVInstrInfo.cpp",
    "RISCVInstructionSelector.cpp",
    "RISCVLegalizerInfo.cpp",
    "RISCVMCInstLower.cpp",
    "RISCVMachineFunctionInfo.cpp",
    "RISCVMacroFusion.cpp",
    "RISCVMakeCompressible.cpp",
    "RISCVMergeBaseOffset.cpp",
    "RISCVRedundantCopyElimination.cpp",
    "RISCVRegisterBankInfo.cpp",
    "RISCVRegisterInfo.cpp",
    "RISCVSExtWRemoval.cpp",
    "RISCVSubtarget.cpp",
    "RISCVTargetMachine.cpp",
    "RISCVTargetObjectFile.cpp",
    "RISCVTargetTransformInfo.cpp",
  ]
}

# This is a bit different from most build files: Due to this group
# having the directory's name, "//llvm/lib/Target/RISCV" will refer to this
# target, which pulls in the code in this directory *and all subdirectories*.
# For most other directories, "//llvm/lib/Foo" only pulls in the code directly
# in "llvm/lib/Foo". The forwarding targets in //llvm/lib/Target expect this
# different behavior.
group("RISCV") {
  deps = [
    ":LLVMRISCVCodeGen",
    "AsmParser",
    "Disassembler",
    "MCTargetDesc",
    "TargetInfo",
  ]
}