1//===- LowerToLLVMOffloadPrintf.h - Lower cir.offload.printf ----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Lowerings of cir.offload.printf to the printf runtime interface of each
10// device target.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef CLANG_CIR_LOWERING_DIRECTTOLLVM_LOWERTOLLVMOFFLOADPRINTF_H
15#define CLANG_CIR_LOWERING_DIRECTTOLLVM_LOWERTOLLVMOFFLOADPRINTF_H
16
17#include "mlir/IR/SymbolTable.h"
18#include "mlir/Interfaces/DataLayoutInterfaces.h"
19#include "mlir/Transforms/DialectConversion.h"
20#include "clang/CIR/Dialect/IR/CIRDialect.h"
21
22namespace cir {
23namespace direct {
24
25/// Lowers \p op, whose lowered format and arguments are \p format and
26/// \p args, to a call to vprintf.
27mlir::LogicalResult lowerNVPTXPrintf(cir::OffloadPrintfOp op,
28 mlir::Value format, mlir::ValueRange args,
29 mlir::ConversionPatternRewriter &rewriter,
30 const mlir::DataLayout &dataLayout,
31 mlir::SymbolTableCollection &symbolTables);
32
33/// Lowers \p op, whose lowered operands are \p operands, to the buffered
34/// printf runtime interface if \p isBuffered and to hostcall printf otherwise.
35/// Strings are passed to the runtime in \p genericAddrSpace.
36mlir::LogicalResult lowerAMDGPUPrintf(cir::OffloadPrintfOp op,
37 mlir::ValueRange operands,
38 mlir::ConversionPatternRewriter &rewriter,
39 const mlir::DataLayout &dataLayout,
40 mlir::SymbolTableCollection &symbolTables,
41 unsigned genericAddrSpace,
42 bool isBuffered);
43
44/// Whether \p module lowers device printf with the AMDGPU runtime
45/// interface: an AMDGCN triple, or SPIR-V with the AMD vendor.
46bool isAMDGPUPrintfModule(mlir::ModuleOp module);
47
48/// Resolve constant format strings for AMDGPU printf ops while their
49/// producers are still CIR, recording one string per operand on each
50/// op for the lowering to read. Must run before ConvertCIRToLLVM.
51void annotateAMDGPUPrintfStrings(mlir::ModuleOp module,
52 mlir::SymbolTableCollection &symbolTables);
53
54} // namespace direct
55} // namespace cir
56
57#endif // CLANG_CIR_LOWERING_DIRECTTOLLVM_LOWERTOLLVMOFFLOADPRINTF_H
58