clang 20.0.0git
Classes | Namespaces | Macros | Enumerations | Functions
CGExprScalar.cpp File Reference
#include "CGCXXABI.h"
#include "CGCleanup.h"
#include "CGDebugInfo.h"
#include "CGObjCRuntime.h"
#include "CGOpenMPRuntime.h"
#include "CGRecordLayout.h"
#include "CodeGenFunction.h"
#include "CodeGenModule.h"
#include "ConstantEmitter.h"
#include "TargetInfo.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Attr.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ParentMapContext.h"
#include "clang/AST/RecordLayout.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/Basic/TargetInfo.h"
#include "llvm/ADT/APFixedPoint.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/FixedPointBuilder.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/IntrinsicsPowerPC.h"
#include "llvm/IR/MatrixBuilder.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/TypeSize.h"
#include <cstdarg>
#include <optional>

Go to the source code of this file.

Classes

struct  GEPOffsetAndOverflow
 

Namespaces

namespace  llvm
 Diagnostic wrappers for TextAPI types for error reporting.
 

Macros

#define HANDLEBINOP(OP)
 
#define VISITCOMP(CODE, UI, SI, FP, SIG)
 
#define HANDLE_BINOP(OP)
 
#define COMPOUND_OP(Op)
 

Enumerations

enum  IntrinsicType { VCMPEQ , VCMPGT }
 

Functions

static std::pair< ScalarExprEmitter::ImplicitConversionCheckKind, std::pair< llvm::Value *, SanitizerMask > > EmitIntegerTruncationCheckHelper (Value *Src, QualType SrcType, Value *Dst, QualType DstType, CGBuilderTy &Builder)
 
static bool PromotionIsPotentiallyEligibleForImplicitIntegerConversionCheck (QualType SrcType, QualType DstType)
 
static llvm::ValueEmitIsNegativeTestHelper (Value *V, QualType VType, const char *Name, CGBuilderTy &Builder)
 
static std::pair< ScalarExprEmitter::ImplicitConversionCheckKind, std::pair< llvm::Value *, SanitizerMask > > EmitIntegerSignChangeCheckHelper (Value *Src, QualType SrcType, Value *Dst, QualType DstType, CGBuilderTy &Builder)
 
static std::pair< ScalarExprEmitter::ImplicitConversionCheckKind, std::pair< llvm::Value *, SanitizerMask > > EmitBitfieldTruncationCheckHelper (Value *Src, QualType SrcType, Value *Dst, QualType DstType, CGBuilderTy &Builder)
 
static std::pair< ScalarExprEmitter::ImplicitConversionCheckKind, std::pair< llvm::Value *, SanitizerMask > > EmitBitfieldSignChangeCheckHelper (Value *Src, QualType SrcType, Value *Dst, QualType DstType, CGBuilderTy &Builder)
 
static int getMaskElt (llvm::ShuffleVectorInst *SVI, unsigned Idx, unsigned Off)
 
static int getAsInt32 (llvm::ConstantInt *C, llvm::Type *I32Ty)
 
static BinOpInfo createBinOpInfoFromIncDec (const UnaryOperator *E, llvm::Value *InVal, bool IsInc, FPOptions FPFeatures)
 
static bool matchesPostDecrInWhile (const UnaryOperator *UO, bool isInc, bool isPre, ASTContext &Ctx)
 For the purposes of overflow pattern exclusion, does this match the "while(i--)" pattern?
 
static ValueemitPointerArithmetic (CodeGenFunction &CGF, const BinOpInfo &op, bool isSubtraction)
 Emit pointer + index arithmetic.
 
static ValuebuildFMulAdd (llvm::Instruction *MulOp, Value *Addend, const CodeGenFunction &CGF, CGBuilderTy &Builder, bool negMul, bool negAdd)
 
static ValuetryEmitFMulAdd (const BinOpInfo &op, const CodeGenFunction &CGF, CGBuilderTy &Builder, bool isSub=false)
 
static llvm::Intrinsic::ID GetIntrinsic (IntrinsicType IT, BuiltinType::Kind ElemKind)
 
static bool isCheapEnoughToEvaluateUnconditionally (const Expr *E, CodeGenFunction &CGF)
 isCheapEnoughToEvaluateUnconditionally - Return true if the specified expression is cheap enough and side-effect-free enough to evaluate unconditionally instead of conditionally.
 
static ValueConvertVec3AndVec4 (CGBuilderTy &Builder, CodeGenFunction &CGF, Value *Src, unsigned NumElementsDst)
 
static ValuecreateCastsForTypeOfSameSize (CGBuilderTy &Builder, const llvm::DataLayout &DL, Value *Src, llvm::Type *DstTy, StringRef Name="")
 
static GEPOffsetAndOverflow EmitGEPOffsetInBytes (Value *BasePtr, Value *GEPVal, llvm::LLVMContext &VMContext, CodeGenModule &CGM, CGBuilderTy &Builder)
 Evaluate given GEPVal, which is either an inbounds GEP, or a constant, and compute the total offset it applies from it's base pointer BasePtr.
 

Macro Definition Documentation

◆ COMPOUND_OP

#define COMPOUND_OP (   Op)
Value:
case BO_##Op##Assign: \
return Scalar.EmitCompoundAssignLValue(E, &ScalarExprEmitter::Emit##Op, \
Result)
Expr * E

◆ HANDLE_BINOP

#define HANDLE_BINOP (   OP)
Value:
case BO_##OP: \
return Emit##OP(EmitBinOps(BO, PromotionType));

◆ HANDLEBINOP

#define HANDLEBINOP (   OP)
Value:
Value *VisitBin##OP(const BinaryOperator *E) { \
QualType promotionTy = getPromotionType(E->getType()); \
auto result = Emit##OP(EmitBinOps(E, promotionTy)); \
if (result && !promotionTy.isNull()) \
result = EmitUnPromotedValue(result, E->getType()); \
return result; \
} \
Value *VisitBin##OP##Assign(const CompoundAssignOperator *E) { \
return EmitCompoundAssign(E, &ScalarExprEmitter::Emit##OP); \
}
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3860
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4122
QualType getType() const
Definition: Expr.h:142
A (possibly-)qualified type.
Definition: Type.h:941
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:1008

Definition at line 867 of file CGExprScalar.cpp.

◆ VISITCOMP

#define VISITCOMP (   CODE,
  UI,
  SI,
  FP,
  SIG 
)
Value:
Value *VisitBin##CODE(const BinaryOperator *E) { \
return EmitCompare(E, llvm::ICmpInst::UI, llvm::ICmpInst::SI, \
llvm::FCmpInst::FP, SIG); }
static llvm::Value * EmitCompare(CGBuilderTy &Builder, CodeGenFunction &CGF, const BinaryOperator *E, llvm::Value *LHS, llvm::Value *RHS, CompareKind Kind, const char *NameSuffix="")
Definition: CGExprAgg.cpp:992

Definition at line 894 of file CGExprScalar.cpp.

Enumeration Type Documentation

◆ IntrinsicType

Enumerator
VCMPEQ 
VCMPGT 

Definition at line 4582 of file CGExprScalar.cpp.

Function Documentation

◆ buildFMulAdd()

static Value * buildFMulAdd ( llvm::Instruction *  MulOp,
Value Addend,
const CodeGenFunction CGF,
CGBuilderTy Builder,
bool  negMul,
bool  negAdd 
)
static

◆ ConvertVec3AndVec4()

static Value * ConvertVec3AndVec4 ( CGBuilderTy Builder,
CodeGenFunction CGF,
Value Src,
unsigned  NumElementsDst 
)
static

Definition at line 5421 of file CGExprScalar.cpp.

◆ createBinOpInfoFromIncDec()

static BinOpInfo createBinOpInfoFromIncDec ( const UnaryOperator E,
llvm::Value InVal,
bool  IsInc,
FPOptions  FPFeatures 
)
static

Definition at line 2745 of file CGExprScalar.cpp.

References E, and clang::Expr::getType().

◆ createCastsForTypeOfSameSize()

static Value * createCastsForTypeOfSameSize ( CGBuilderTy Builder,
const llvm::DataLayout &  DL,
Value Src,
llvm::Type DstTy,
StringRef  Name = "" 
)
static

Definition at line 5443 of file CGExprScalar.cpp.

References clang::Value::getType().

◆ EmitBitfieldSignChangeCheckHelper()

static std::pair< ScalarExprEmitter::ImplicitConversionCheckKind, std::pair< llvm::Value *, SanitizerMask > > EmitBitfieldSignChangeCheckHelper ( Value Src,
QualType  SrcType,
Value Dst,
QualType  DstType,
CGBuilderTy Builder 
)
static

Definition at line 1303 of file CGExprScalar.cpp.

References EmitIsNegativeTestHelper().

◆ EmitBitfieldTruncationCheckHelper()

static std::pair< ScalarExprEmitter::ImplicitConversionCheckKind, std::pair< llvm::Value *, SanitizerMask > > EmitBitfieldTruncationCheckHelper ( Value Src,
QualType  SrcType,
Value Dst,
QualType  DstType,
CGBuilderTy Builder 
)
static

◆ EmitGEPOffsetInBytes()

static GEPOffsetAndOverflow EmitGEPOffsetInBytes ( Value BasePtr,
Value GEPVal,
llvm::LLVMContext &  VMContext,
CodeGenModule CGM,
CGBuilderTy Builder 
)
static

Evaluate given GEPVal, which is either an inbounds GEP, or a constant, and compute the total offset it applies from it's base pointer BasePtr.

Returns offset in bytes and a boolean flag whether an overflow happened during evaluation.

Return the result of the given binary operation.

Definition at line 5658 of file CGExprScalar.cpp.

References clang::CodeGen::CodeGenModule::getDataLayout(), clang::CodeGen::CodeGenModule::getIntrinsic(), and clang::Value::getType().

◆ EmitIntegerSignChangeCheckHelper()

static std::pair< ScalarExprEmitter::ImplicitConversionCheckKind, std::pair< llvm::Value *, SanitizerMask > > EmitIntegerSignChangeCheckHelper ( Value Src,
QualType  SrcType,
Value Dst,
QualType  DstType,
CGBuilderTy Builder 
)
static

◆ EmitIntegerTruncationCheckHelper()

static std::pair< ScalarExprEmitter::ImplicitConversionCheckKind, std::pair< llvm::Value *, SanitizerMask > > EmitIntegerTruncationCheckHelper ( Value Src,
QualType  SrcType,
Value Dst,
QualType  DstType,
CGBuilderTy Builder 
)
static

◆ EmitIsNegativeTestHelper()

static llvm::Value * EmitIsNegativeTestHelper ( Value V,
QualType  VType,
const char *  Name,
CGBuilderTy Builder 
)
static

◆ emitPointerArithmetic()

static Value * emitPointerArithmetic ( CodeGenFunction CGF,
const BinOpInfo &  op,
bool  isSubtraction 
)
static

◆ getAsInt32()

static int getAsInt32 ( llvm::ConstantInt *  C,
llvm::Type I32Ty 
)
static

Definition at line 2034 of file CGExprScalar.cpp.

References clang::C.

◆ GetIntrinsic()

static llvm::Intrinsic::ID GetIntrinsic ( IntrinsicType  IT,
BuiltinType::Kind  ElemKind 
)
static

Definition at line 4584 of file CGExprScalar.cpp.

References VCMPEQ.

◆ getMaskElt()

static int getMaskElt ( llvm::ShuffleVectorInst *  SVI,
unsigned  Idx,
unsigned  Off 
)
static

Definition at line 2026 of file CGExprScalar.cpp.

◆ isCheapEnoughToEvaluateUnconditionally()

static bool isCheapEnoughToEvaluateUnconditionally ( const Expr E,
CodeGenFunction CGF 
)
static

isCheapEnoughToEvaluateUnconditionally - Return true if the specified expression is cheap enough and side-effect-free enough to evaluate unconditionally instead of conditionally.

This is used to convert control flow into selects in some cases.

Definition at line 5195 of file CGExprScalar.cpp.

References E, clang::CodeGen::CodeGenFunction::getContext(), clang::Expr::IgnoreParens(), and clang::Expr::isEvaluatable().

◆ matchesPostDecrInWhile()

static bool matchesPostDecrInWhile ( const UnaryOperator UO,
bool  isInc,
bool  isPre,
ASTContext Ctx 
)
static

For the purposes of overflow pattern exclusion, does this match the "while(i--)" pattern?

Definition at line 2783 of file CGExprScalar.cpp.

References clang::ASTContext::getLangOpts(), clang::ASTContext::getParentMapContext(), clang::ParentMapContext::getParents(), clang::LangOptions::isOverflowPatternExcluded(), Parent, and clang::LangOptionsBase::PostDecrInWhile.

◆ PromotionIsPotentiallyEligibleForImplicitIntegerConversionCheck()

static bool PromotionIsPotentiallyEligibleForImplicitIntegerConversionCheck ( QualType  SrcType,
QualType  DstType 
)
static

Definition at line 1077 of file CGExprScalar.cpp.

References clang::Type::isIntegerType().

◆ tryEmitFMulAdd()

static Value * tryEmitFMulAdd ( const BinOpInfo &  op,
const CodeGenFunction CGF,
CGBuilderTy Builder,
bool  isSub = false 
)
static

Definition at line 4093 of file CGExprScalar.cpp.

References buildFMulAdd().