//===------ CGGPUBuiltin.cpp - Codegen for GPU builtins -------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // Generates code for built-in GPU calls which are not runtime-specific. // (Runtime-specific codegen lives in programming model specific files.) // //===----------------------------------------------------------------------===// #include "CodeGenFunction.h" #include "clang/Basic/Builtins.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/Instruction.h" #include "llvm/Support/MathExtras.h" #include "llvm/Transforms/Utils/AMDGPUEmitPrintf.h" usingnamespaceclang; usingnamespaceCodeGen; namespace { llvm::Function *GetVprintfDeclaration(llvm::Module &M) { … } // Transforms a call to printf into a call to the NVPTX vprintf syscall (which // isn't particularly special; it's invoked just like a regular function). // vprintf takes two args: A format string, and a pointer to a buffer containing // the varargs. // // For example, the call // // printf("format string", arg1, arg2, arg3); // // is converted into something resembling // // struct Tmp { // Arg1 a1; // Arg2 a2; // Arg3 a3; // }; // char* buf = alloca(sizeof(Tmp)); // *(Tmp*)buf = {a1, a2, a3}; // vprintf("format string", buf); // // buf is aligned to the max of {alignof(Arg1), ...}. Furthermore, each of the // args is itself aligned to its preferred alignment. // // Note that by the time this function runs, E's args have already undergone the // standard C vararg promotion (short -> int, float -> double, etc.). std::pair<llvm::Value *, llvm::TypeSize> packArgsIntoNVPTXFormatBuffer(CodeGenFunction *CGF, const CallArgList &Args) { … } bool containsNonScalarVarargs(CodeGenFunction *CGF, const CallArgList &Args) { … } RValue EmitDevicePrintfCallExpr(const CallExpr *E, CodeGenFunction *CGF, llvm::Function *Decl, bool WithSizeArg) { … } } // namespace RValue CodeGenFunction::EmitNVPTXDevicePrintfCallExpr(const CallExpr *E) { … } RValue CodeGenFunction::EmitAMDGPUDevicePrintfCallExpr(const CallExpr *E) { … }