Commit 7b635880 authored by Mehdi Amini's avatar Mehdi Amini
Browse files

Fix MLIR build when the NVPTX target isn't configured

Differential Revision: https://reviews.llvm.org/D74472
parent 167c4284
Loading
Loading
Loading
Loading
+11 −16
Original line number Diff line number Diff line
if(MLIR_CUDA_CONVERSIONS_ENABLED)
add_llvm_library(MLIRGPUtoCUDATransforms
  ConvertKernelFuncToCubin.cpp
  ConvertLaunchFuncToCudaCalls.cpp
)
target_link_libraries(MLIRGPUtoCUDATransforms
    LLVMNVPTXCodeGen
    LLVMNVPTXDesc
    LLVMNVPTXInfo
  MLIRGPU
  MLIRLLVMIR
  MLIRNVVMIR
  MLIRPass
  MLIRTargetNVVMIR
)
endif()
+3 −4
Original line number Diff line number Diff line
@@ -57,10 +57,9 @@ public:
    gpu::GPUModuleOp module = getOperation();

    // Make sure the NVPTX target is initialized.
    LLVMInitializeNVPTXTarget();
    LLVMInitializeNVPTXTargetInfo();
    LLVMInitializeNVPTXTargetMC();
    LLVMInitializeNVPTXAsmPrinter();
    llvm::InitializeAllTargets();
    llvm::InitializeAllTargetMCs();
    llvm::InitializeAllAsmPrinters();

    auto llvmModule = translateModuleToNVVMIR(module);
    if (!llvmModule)
+13 −10
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ set(LIBS
  MLIREDSC
  MLIRFxpMathOps
  MLIRGPU
  MLIRGPUtoCUDATransforms
  MLIRGPUtoNVVMTransforms
  MLIRGPUtoROCDLTransforms
  MLIRGPUtoSPIRVTransforms
@@ -75,17 +76,19 @@ set(LIBS
  LLVMAsmParser
)

if(MLIR_CUDA_CONVERSIONS_ENABLED)
  list(APPEND LIBS
    LLVMNVPTXCodeGen
    LLVMNVPTXDesc
    LLVMNVPTXInfo
    MLIRGPUtoCUDATransforms
    MLIRTargetNVVMIR
  )
endif()
add_llvm_tool(mlir-opt
 mlir-opt.cpp
)
# Manually expand the target library, since our MLIR libraries
# aren't plugged into the LLVM dependency tracking. If we don't
# do this then we can't insert the CodeGen library after ourselves
llvm_expand_pseudo_components(TARGET_LIBS AllTargetsCodeGens)
# Prepend LLVM in front of every target, this is how the library
# are named with CMake
SET(targets_to_link)
FOREACH(t ${TARGET_LIBS})
  LIST(APPEND targets_to_link "LLVM${t}")
ENDFOREACH(t)

llvm_update_compile_flags(mlir-opt)
target_link_libraries(mlir-opt PRIVATE ${LIBS})
target_link_libraries(mlir-opt PRIVATE ${LIBS} ${targets_to_link})