17 #include "llvm/IR/DataLayout.h"
18 #include "llvm/IR/Instruction.h"
19 #include "llvm/Support/MathExtras.h"
21 using namespace clang;
22 using namespace CodeGen;
25 llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
26 llvm::Type::getInt8PtrTy(M.getContext())};
27 llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
28 llvm::Type::getInt32Ty(M.getContext()), ArgTypes,
false);
30 if (
auto* F = M.getFunction(
"vprintf")) {
34 assert(F->getFunctionType() == VprintfFuncType);
87 if (std::any_of(Args.begin() + 1, Args.end(),
88 [](
const CallArg &A) {
return !A.RV.isScalar(); })) {
95 if (Args.size() <= 1) {
97 BufferPtr = llvm::ConstantPointerNull::get(llvm::Type::getInt8PtrTy(Ctx));
101 ArgTypes.push_back(Args[
I].RV.getScalarVal()->getType());
105 for (
unsigned I = 1, NumArgs = Args.size();
I <
NumArgs; ++
I) {
110 BufferPtr =
Builder.CreatePointerCast(Alloca, llvm::Type::getInt8PtrTy(Ctx));
116 Builder.CreateCall(VprintfFunc, {Args[0].RV.getScalarVal(), BufferPtr}));
ReturnValueSlot - Contains the address where the return value of a function can be stored...
llvm::IntegerType * IntTy
int
void EmitCallArgs(CallArgList &Args, const T *CallArgTypeInfo, llvm::iterator_range< CallExpr::const_arg_iterator > ArgRange, const FunctionDecl *CalleeDecl=nullptr, unsigned ParamsToSkip=0)
EmitCallArgs - Emit call arguments for a function.
External linkage, which indicates that the entity can be referred to from other translation units...
llvm::Module & getModule() const
llvm::LLVMContext & getLLVMContext()
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
CreateTempAlloca - This creates a alloca and inserts it into the entry block.
const llvm::DataLayout & getDataLayout() const
const LangOptions & getLangOpts() const
unsigned getBuiltinCallee() const
getBuiltinCallee - If this is a call to a builtin, return the builtin ID of the callee.
detail::InMemoryDirectory::const_iterator I
Represents a prototype with parameter type info, e.g.
RValue - This trivial value class is used to represent the result of an expression that is evaluated...
class LLVM_ALIGNAS(8) TemplateSpecializationType unsigned NumArgs
Represents a type template specialization; the template must be a class template, a type alias templa...
The l-value was considered opaque, so the alignment was determined from a type.
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr * > VL, ArrayRef< Expr * > PL, ArrayRef< Expr * > IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
Address CreateStructGEP(Address Addr, unsigned Index, CharUnits Offset, const llvm::Twine &Name="")
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
detail::InMemoryDirectory::const_iterator E
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
const T * getAs() const
Member-template getAs<specific type>'.
static llvm::Function * GetVprintfDeclaration(llvm::Module &M)
RValue EmitCUDADevicePrintfCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue)
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
static RValue get(llvm::Value *V)
llvm::StoreInst * CreateAlignedStore(llvm::Value *Val, llvm::Value *Addr, CharUnits Align, bool IsVolatile=false)
CallArgList - Type for representing both the value and type of arguments in a call.
Defines enum values for all the target-independent builtin functions.