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);
72 assert(
getTarget().getTriple().isNVPTX());
86 if (std::any_of(Args.begin() + 1, Args.end(), [&](
const CallArg &A) {
87 return !A.getRValue(*this).isScalar();
95 if (Args.size() <= 1) {
97 BufferPtr = llvm::ConstantPointerNull::get(llvm::Type::getInt8PtrTy(Ctx));
100 for (
unsigned I = 1, NumArgs = Args.size(); I < NumArgs; ++I)
101 ArgTypes.push_back(Args[I].getRValue(*this).getScalarVal()->getType());
111 for (
unsigned I = 1, NumArgs = Args.size(); I < NumArgs; ++I) {
113 llvm::Value *Arg = Args[I].getRValue(*this).getScalarVal();
116 BufferPtr =
Builder.CreatePointerCast(Alloca, llvm::Type::getInt8PtrTy(Ctx));
122 VprintfFunc, {Args[0].getRValue(*this).getScalarVal(), BufferPtr}));
const llvm::DataLayout & getDataLayout() const
ReturnValueSlot - Contains the address where the return value of a function can be stored...
llvm::IntegerType * IntTy
int
External linkage, which indicates that the entity can be referred to from other translation units...
llvm::LLVMContext & getLLVMContext()
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
const T * getAs() const
Member-template getAs<specific type>'.
const TargetInfo & getTarget() const
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates an alloca and inserts it into the entry block if ArraySize is nullptr...
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...
void EmitCallArgs(CallArgList &Args, const T *CallArgTypeInfo, llvm::iterator_range< CallExpr::const_arg_iterator > ArgRange, AbstractCallee AC=AbstractCallee(), unsigned ParamsToSkip=0, EvaluationOrder Order=EvaluationOrder::Default)
EmitCallArgs - Emit call arguments for a function.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
static llvm::Function * GetVprintfDeclaration(llvm::Module &M)
unsigned getBuiltinCallee() const
getBuiltinCallee - If this is a call to a builtin, return the builtin ID of the callee.
The l-value was considered opaque, so the alignment was determined from a type.
RValue EmitNVPTXDevicePrintfCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue)
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
Dataflow Directional Tag Classes.
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.
llvm::Module & getModule() const
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.
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.