clang 24.0.0git
CIRGenBuiltin.cpp File Reference
#include "CIRGenCall.h"
#include "CIRGenFunction.h"
#include "CIRGenModule.h"
#include "CIRGenValue.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/Value.h"
#include "mlir/Support/LLVM.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/Expr.h"
#include "clang/AST/GlobalDecl.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/DiagnosticFrontend.h"
#include "clang/Basic/OperatorKinds.h"
#include "clang/CIR/Dialect/IR/CIRTypes.h"
#include "clang/CIR/MissingFeatures.h"
#include "clang/CodeGenUtils/CodeGenUtils.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/Support/ErrorHandling.h"

Go to the source code of this file.

Functions

static bool shouldEmitBuiltinAsIR (unsigned builtinID, const Builtin::Context &bi, const CIRGenFunction &cgf)
static RValue emitLibraryCall (CIRGenFunction &cgf, const FunctionDecl *fd, const CallExpr *e, mlir::Operation *calleeValue)
template<typename Op, typename... Args>
static mlir::Value createBuiltinBitOp (CIRGenFunction &cgf, const CallExpr *e, mlir::Value arg, Args... args)
template<typename Op, typename... Args>
static RValue emitBuiltinBitOp (CIRGenFunction &cgf, const CallExpr *e, Args... args)
template<typename Op>
static RValue emitBuiltinBitOpWithFallback (CIRGenFunction &cgf, const CallExpr *e)
 Emit a clz/ctz bit op with optional fallback for __builtin_c[lt]zg.
static bool isStdcBitOpWidthSupported (cir::IntType intTy)
static RValue errorStdcBitOpWidthNYI (CIRGenFunction &cgf, const CallExpr *e)
template<typename Op, typename... Args>
static RValue emitStdcFirstBit (CIRGenFunction &cgf, const CallExpr *e, bool invertArg, Args... args)
static RValue emitStdcBitCeil (CIRGenFunction &cgf, const CallExpr *e)
template<typename Op, typename... Args>
static RValue emitStdcCountOp (CIRGenFunction &cgf, const CallExpr *e, bool invertArg, Args... args)
template<typename Op, typename... Args>
static RValue emitStdcBitWidthMinus (CIRGenFunction &cgf, const CallExpr *e, Args... args)
static RValue emitStdcHasSingleBit (CIRGenFunction &cgf, const CallExpr *e)
static RValue emitStdcBitFloor (CIRGenFunction &cgf, const CallExpr *e)
static mlir::Value emitToInt (CIRGenFunction &cgf, mlir::Value v, QualType t, cir::IntType intType)
 Emit the conversions required to turn the given value into an integer of the given size.
static mlir::Value emitFromInt (CIRGenFunction &cgf, mlir::Value v, QualType t, mlir::Type resultType)
static mlir::Value emitSignBit (mlir::Location loc, CIRGenFunction &cgf, mlir::Value val)
static Address checkAtomicAlignment (CIRGenFunction &cgf, const CallExpr *e)
static RValue emitBinaryAtomic (CIRGenFunction &cgf, cir::AtomicFetchKind atomicOpkind, const CallExpr *e)
template<typename BinOp>
static RValue emitBinaryAtomicPost (CIRGenFunction &cgf, cir::AtomicFetchKind atomicOpkind, const CallExpr *e, bool invert=false)
static RValue emitAtomicXchg (CIRGenFunction &cgf, const CallExpr *e, cir::MemOrder ordering)
 Emit a cir.atomic.xchg for __sync_swap_N and __sync_lock_test_and_set_N.
static void emitAtomicLockRelease (CIRGenFunction &cgf, const CallExpr *e)
 Emit a release store of 0 for __sync_lock_release_N.
static void emitAtomicFenceOp (CIRGenFunction &cgf, const CallExpr *expr, cir::SyncScopeKind syncScope)
static RValue emitAtomicIsLockFree (CIRGenFunction &cgf, const CallExpr *e, unsigned builtinID)
static WidthAndSignedness getIntegerWidthAndSignedness (const clang::ASTContext &astContext, const clang::QualType type)
template<typename OpTy>
static std::pair< mlir::Value, mlir::ValueemitOverflowOp (CIRGenBuilderTy &builder, mlir::Location loc, mlir::Type resultTy, mlir::Value lhs, mlir::Value rhs)
 Create a checked overflow arithmetic op and return its result and overflow flag.
static struct WidthAndSignedness EncompassingIntegerType (ArrayRef< struct WidthAndSignedness > types)
template<class Operation>
static RValue emitUnaryMaybeConstrainedFPBuiltin (CIRGenFunction &cgf, const CallExpr &e)
template<class Operation>
static RValue emitUnaryFPBuiltin (CIRGenFunction &cgf, const CallExpr &e)
template<typename Op>
static RValue emitUnaryMaybeConstrainedFPToIntBuiltin (CIRGenFunction &cgf, const CallExpr &e)
template<typename Op>
static RValue emitBinaryFPBuiltin (CIRGenFunction &cgf, const CallExpr &e)
template<typename Op>
static RValue emitTernaryMaybeConstrainedFPBuiltin (CIRGenFunction &cgf, const CallExpr &e)
template<typename Op>
static mlir::Value emitBinaryMaybeConstrainedFPBuiltin (CIRGenFunction &cgf, const CallExpr &e)
static RValue errorBuiltinNYI (CIRGenFunction &cgf, const CallExpr *e, unsigned builtinID)
static RValue emitBuiltinAlloca (CIRGenFunction &cgf, const CallExpr *e, unsigned builtinID)
static bool shouldCIREmitFPMathIntrinsic (CIRGenFunction &cgf, const CallExpr *e, unsigned builtinID)
static RValue tryEmitFPMathIntrinsic (CIRGenFunction &cgf, const CallExpr *e, unsigned builtinID)
static mlir::Type decodeFixedType (CIRGenFunction &cgf, ArrayRef< llvm::Intrinsic::IITDescriptor > &infos, mlir::MLIRContext *context)
static mlir::Type correctIntegerSignedness (mlir::Type iitType, QualType astType, mlir::MLIRContext *context)
 Helper function to correct integer signedness for intrinsic arguments and return type.
static mlir::Type correctReturnType (mlir::Type iitType, const FunctionDecl *funcDecl, mlir::MLIRContext *context)
 Helper function to correct the return type for intrinsic calls.
static mlir::Value getCorrectedPtr (mlir::Value argValue, mlir::Type expectedTy, CIRGenBuilderTy &builder)
static cir::FuncType getIntrinsicType (CIRGenFunction &cgf, mlir::MLIRContext *context, llvm::Intrinsic::ID id)
static std::optional< mlir::ValueemitTargetArchBuiltinExpr (CIRGenFunction *cgf, unsigned builtinID, const CallExpr *e, ReturnValueSlot &returnValue, llvm::Triple::ArchType arch)

Function Documentation

◆ checkAtomicAlignment()

◆ correctIntegerSignedness()

mlir::Type correctIntegerSignedness ( mlir::Type iitType,
QualType astType,
mlir::MLIRContext * context )
static

Helper function to correct integer signedness for intrinsic arguments and return type.

IIT always returns signed integers, but the actual intrinsic may expect unsigned integers based on the AST FunctionDecl parameter types.

Definition at line 1168 of file CIRGenBuiltin.cpp.

References clang::Type::isUnsignedIntegerType().

Referenced by correctReturnType(), and clang::CIRGen::CIRGenFunction::emitBuiltinExpr().

◆ correctReturnType()

mlir::Type correctReturnType ( mlir::Type iitType,
const FunctionDecl * funcDecl,
mlir::MLIRContext * context )
static

Helper function to correct the return type for intrinsic calls.

This is needed because the AST FunctionDecl may have a different return type than the intrinsic's IIT descriptor. For example, builtins may need their signedness corrected, or a builtin may return a bool while the intrinsic returns an i1.

Definition at line 1185 of file CIRGenBuiltin.cpp.

References correctIntegerSignedness(), clang::FunctionDecl::getReturnType(), and clang::Type::isBooleanType().

Referenced by clang::CIRGen::CIRGenFunction::emitBuiltinExpr().

◆ createBuiltinBitOp()

◆ decodeFixedType()

mlir::Type decodeFixedType ( CIRGenFunction & cgf,
ArrayRef< llvm::Intrinsic::IITDescriptor > & infos,
mlir::MLIRContext * context )
static

◆ emitAtomicFenceOp()

◆ emitAtomicIsLockFree()

◆ emitAtomicLockRelease()

◆ emitAtomicXchg()

◆ emitBinaryAtomic()

RValue emitBinaryAtomic ( CIRGenFunction & cgf,
cir::AtomicFetchKind atomicOpkind,
const CallExpr * e )
static

◆ emitBinaryAtomicPost()

◆ emitBinaryFPBuiltin()

◆ emitBinaryMaybeConstrainedFPBuiltin()

◆ emitBuiltinAlloca()

◆ emitBuiltinBitOp()

template<typename Op, typename... Args>
RValue emitBuiltinBitOp ( CIRGenFunction & cgf,
const CallExpr * e,
Args... args )
static

◆ emitBuiltinBitOpWithFallback()

◆ emitFromInt()

◆ emitLibraryCall()

◆ emitOverflowOp()

template<typename OpTy>
std::pair< mlir::Value, mlir::Value > emitOverflowOp ( CIRGenBuilderTy & builder,
mlir::Location loc,
mlir::Type resultTy,
mlir::Value lhs,
mlir::Value rhs )
static

Create a checked overflow arithmetic op and return its result and overflow flag.

Definition at line 514 of file CIRGenBuiltin.cpp.

Referenced by clang::CIRGen::CIRGenFunction::emitBuiltinExpr().

◆ emitSignBit()

◆ emitStdcBitCeil()

◆ emitStdcBitFloor()

◆ emitStdcBitWidthMinus()

◆ emitStdcCountOp()

◆ emitStdcFirstBit()

◆ emitStdcHasSingleBit()

◆ emitTargetArchBuiltinExpr()

◆ emitTernaryMaybeConstrainedFPBuiltin()

◆ emitToInt()

mlir::Value emitToInt ( CIRGenFunction & cgf,
mlir::Value v,
QualType t,
cir::IntType intType )
static

Emit the conversions required to turn the given value into an integer of the given size.

Definition at line 267 of file CIRGenBuiltin.cpp.

References cir::CIRBaseBuilderTy::createPtrToInt(), clang::CIRGen::CIRGenFunction::emitToMemory(), and clang::CIRGen::CIRGenFunction::getBuilder().

Referenced by clang::CIRGen::CIRGenFunction::makeBinaryAtomicValue().

◆ emitUnaryFPBuiltin()

◆ emitUnaryMaybeConstrainedFPBuiltin()

◆ emitUnaryMaybeConstrainedFPToIntBuiltin()

◆ EncompassingIntegerType()

struct WidthAndSignedness EncompassingIntegerType ( ArrayRef< struct WidthAndSignedness > types)
static

◆ errorBuiltinNYI()

◆ errorStdcBitOpWidthNYI()

◆ getCorrectedPtr()

◆ getIntegerWidthAndSignedness()

◆ getIntrinsicType()

cir::FuncType getIntrinsicType ( CIRGenFunction & cgf,
mlir::MLIRContext * context,
llvm::Intrinsic::ID id )
static

Definition at line 1219 of file CIRGenBuiltin.cpp.

References decodeFixedType(), and clang::isa().

Referenced by clang::CIRGen::CIRGenFunction::emitBuiltinExpr().

◆ isStdcBitOpWidthSupported()

bool isStdcBitOpWidthSupported ( cir::IntType intTy)
static

◆ shouldCIREmitFPMathIntrinsic()

◆ shouldEmitBuiltinAsIR()

◆ tryEmitFPMathIntrinsic()