Path: blob/main/contrib/llvm-project/clang/lib/CodeGen/CGBuiltin.h
213766 views
//===------ CGBuiltin.h - Emit LLVM Code for builtins ---------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_CLANG_LIB_CODEGEN_CGBUILTIN_H9#define LLVM_CLANG_LIB_CODEGEN_CGBUILTIN_H1011#include "CodeGenFunction.h"1213// Many of MSVC builtins are on x64, ARM and AArch64; to avoid repeating code,14// we handle them here.15enum class clang::CodeGen::CodeGenFunction::MSVCIntrin {16_BitScanForward,17_BitScanReverse,18_InterlockedAnd,19_InterlockedCompareExchange,20_InterlockedDecrement,21_InterlockedExchange,22_InterlockedExchangeAdd,23_InterlockedExchangeSub,24_InterlockedIncrement,25_InterlockedOr,26_InterlockedXor,27_InterlockedExchangeAdd_acq,28_InterlockedExchangeAdd_rel,29_InterlockedExchangeAdd_nf,30_InterlockedExchange_acq,31_InterlockedExchange_rel,32_InterlockedExchange_nf,33_InterlockedCompareExchange_acq,34_InterlockedCompareExchange_rel,35_InterlockedCompareExchange_nf,36_InterlockedCompareExchange128,37_InterlockedCompareExchange128_acq,38_InterlockedCompareExchange128_rel,39_InterlockedCompareExchange128_nf,40_InterlockedOr_acq,41_InterlockedOr_rel,42_InterlockedOr_nf,43_InterlockedXor_acq,44_InterlockedXor_rel,45_InterlockedXor_nf,46_InterlockedAnd_acq,47_InterlockedAnd_rel,48_InterlockedAnd_nf,49_InterlockedIncrement_acq,50_InterlockedIncrement_rel,51_InterlockedIncrement_nf,52_InterlockedDecrement_acq,53_InterlockedDecrement_rel,54_InterlockedDecrement_nf,55__fastfail,56};5758// Emit a simple intrinsic that has N scalar arguments and a return type59// matching the argument type. It is assumed that only the first argument is60// overloaded.61template <unsigned N>62llvm::Value *emitBuiltinWithOneOverloadedType(clang::CodeGen::CodeGenFunction &CGF,63const clang::CallExpr *E,64unsigned IntrinsicID,65llvm::StringRef Name = "") {66static_assert(N, "expect non-empty argument");67clang::SmallVector<llvm::Value *, N> Args;68for (unsigned I = 0; I < N; ++I)69Args.push_back(CGF.EmitScalarExpr(E->getArg(I)));70llvm::Function *F = CGF.CGM.getIntrinsic(IntrinsicID, Args[0]->getType());71return CGF.Builder.CreateCall(F, Args, Name);72}7374llvm::Value *emitUnaryMaybeConstrainedFPBuiltin(clang::CodeGen::CodeGenFunction &CGF,75const clang::CallExpr *E,76unsigned IntrinsicID,77unsigned ConstrainedIntrinsicID);7879llvm::Value *EmitToInt(clang::CodeGen::CodeGenFunction &CGF, llvm::Value *V,80clang::QualType T, llvm::IntegerType *IntType);8182llvm::Value *EmitFromInt(clang::CodeGen::CodeGenFunction &CGF, llvm::Value *V,83clang::QualType T, llvm::Type *ResultType);8485clang::CodeGen::Address CheckAtomicAlignment(clang::CodeGen::CodeGenFunction &CGF,86const clang::CallExpr *E);8788llvm::Value *MakeBinaryAtomicValue(clang::CodeGen::CodeGenFunction &CGF,89llvm::AtomicRMWInst::BinOp Kind,90const clang::CallExpr *E,91llvm::AtomicOrdering Ordering =92llvm::AtomicOrdering::SequentiallyConsistent);9394llvm::Value *EmitOverflowIntrinsic(clang::CodeGen::CodeGenFunction &CGF,95const llvm::Intrinsic::ID IntrinsicID,96llvm::Value *X,97llvm::Value *Y,98llvm::Value *&Carry);99100llvm::Value *MakeAtomicCmpXchgValue(clang::CodeGen::CodeGenFunction &CGF,101const clang::CallExpr *E,102bool ReturnBool);103104#endif105106107