clang 24.0.0git
LowerToLLVMOffloadPrintf.cpp
Go to the documentation of this file.
1//===- LowerToLLVMOffloadPrintf.cpp - Lower cir.offload.printf ------------===//
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// This file lowers cir.offload.printf to the printf runtime interface of each
10// device target.
11//
12//===----------------------------------------------------------------------===//
13
15#include "LowerToLLVM.h"
16#include "TargetLoweringInfo.h"
17
19#include "llvm/TargetParser/Triple.h"
20
21namespace cir {
22namespace direct {
23
24mlir::LogicalResult CIRToLLVMOffloadPrintfOpLowering::matchAndRewrite(
25 cir::OffloadPrintfOp op, OpAdaptor adaptor,
26 mlir::ConversionPatternRewriter &rewriter) const {
27 auto mod = op->getParentOfType<mlir::ModuleOp>();
28 llvm::StringRef tripleStr;
29 if (auto tripleAttr = mod->getAttrOfType<mlir::StringAttr>(
30 cir::CIRDialect::getTripleAttrName()))
31 tripleStr = tripleAttr.getValue();
32 llvm::Triple triple(tripleStr);
33
34 if (triple.isNVPTX())
35 return lowerNVPTXPrintf(op, adaptor.getFormat(), adaptor.getArgs(),
36 rewriter, dataLayout, symbolTables);
37
38 if (triple.isAMDGCN() ||
39 (triple.isSPIRV() && triple.getVendor() == llvm::Triple::AMD)) {
40 bool isBuffered = false;
41 if (auto kind = mod->getAttrOfType<mlir::StringAttr>(
42 cir::CIRDialect::getAMDGPUPrintfKindAttrName()))
43 isBuffered = kind.getValue() == "buffered";
44 std::unique_ptr<cir::TargetLoweringInfo> targetInfo =
45 triple.isSPIRV() ? cir::createSPIRVTargetLoweringInfo()
47 unsigned genericAddrSpace = targetInfo->getTargetAddrSpaceFromCIRAddrSpace(
48 cir::LangAddressSpace::OffloadGeneric);
49 return lowerAMDGPUPrintf(op, adaptor.getOperands(), rewriter, dataLayout,
50 symbolTables, genericAddrSpace, isBuffered);
51 }
52
53 return op.emitError() << "offload printf lowering is NYI for target '"
54 << tripleStr << "'";
55}
56
57} // namespace direct
58} // namespace cir
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
mlir::LogicalResult lowerAMDGPUPrintf(cir::OffloadPrintfOp op, mlir::ValueRange operands, mlir::ConversionPatternRewriter &rewriter, const mlir::DataLayout &dataLayout, mlir::SymbolTableCollection &symbolTables, unsigned genericAddrSpace, bool isBuffered)
Lowers op, whose lowered operands are operands, to the buffered printf runtime interface if isBuffere...
mlir::LogicalResult lowerNVPTXPrintf(cir::OffloadPrintfOp op, mlir::Value format, mlir::ValueRange args, mlir::ConversionPatternRewriter &rewriter, const mlir::DataLayout &dataLayout, mlir::SymbolTableCollection &symbolTables)
Lowers op, whose lowered format and arguments are format and args, to a call to vprintf.
std::unique_ptr< TargetLoweringInfo > createSPIRVTargetLoweringInfo()
Definition SPIRV.cpp:57
std::unique_ptr< TargetLoweringInfo > createAMDGPUTargetLoweringInfo()
Definition AMDGPU.cpp:50