clang 19.0.0git
Namespaces | Macros | Enumerations | Functions
CGStmt.cpp File Reference
#include "CGDebugInfo.h"
#include "CGOpenMPRuntime.h"
#include "CodeGenFunction.h"
#include "CodeGenModule.h"
#include "TargetInfo.h"
#include "clang/AST/Attr.h"
#include "clang/AST/Expr.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/DiagnosticSema.h"
#include "clang/Basic/PrettyStackTrace.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/IR/Assumptions.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/Support/SaveAndRestore.h"
#include <optional>
#include "clang/AST/StmtNodes.inc"

Go to the source code of this file.

Namespaces

namespace  llvm
 Diagnostic wrappers for TextAPI types for error reporting.
 

Macros

#define STMT(Type, Base)
 
#define ABSTRACT_STMT(Op)
 
#define EXPR(Type, Base)    case Stmt::Type##Class:
 

Enumerations

enum  CSFC_Result { CSFC_Failure , CSFC_FallThrough , CSFC_Success }
 CollectStatementsForCase - Given the body of a 'switch' statement and a constant value that is being switched on, see if we can dead code eliminate the body of the switch to a simple series of statements to emit. More...
 

Functions

static bool isSwiftAsyncCallee (const CallExpr *CE)
 Determine if the given call uses the swiftasync calling convention.
 
static CSFC_Result CollectStatementsForCase (const Stmt *S, const SwitchCase *Case, bool &FoundCase, SmallVectorImpl< const Stmt * > &ResultStmts)
 
static bool FindCaseStatementsForValue (const SwitchStmt &S, const llvm::APSInt &ConstantCondValue, SmallVectorImpl< const Stmt * > &ResultStmts, ASTContext &C, const SwitchCase *&ResultCase)
 FindCaseStatementsForValue - Find the case statement being jumped to and then invoke CollectStatementsForCase to find the list of statements to emit for a switch on constant.
 
static std::optional< SmallVector< uint64_t, 16 > > getLikelihoodWeights (ArrayRef< Stmt::Likelihood > Likelihoods)
 
static std::string SimplifyConstraint (const char *Constraint, const TargetInfo &Target, SmallVectorImpl< TargetInfo::ConstraintInfo > *OutCons=nullptr)
 
static std::string AddVariableConstraints (const std::string &Constraint, const Expr &AsmExpr, const TargetInfo &Target, CodeGenModule &CGM, const AsmStmt &Stmt, const bool EarlyClobber, std::string *GCCReg=nullptr)
 AddVariableConstraints - Look at AsmExpr and if it is a variable declared as using a particular register add that as a constraint that will be used in this asm stmt.
 
static llvm::MDNode * getAsmSrcLocInfo (const StringLiteral *Str, CodeGenFunction &CGF)
 getAsmSrcLocInfo - Return the !srcloc metadata node to attach to an inline asm call instruction.
 
static void UpdateAsmCallInst (llvm::CallBase &Result, bool HasSideEffect, bool HasUnwindClobber, bool ReadOnly, bool ReadNone, bool NoMerge, const AsmStmt &S, const std::vector< llvm::Type * > &ResultRegTypes, const std::vector< llvm::Type * > &ArgElemTypes, CodeGenFunction &CGF, std::vector< llvm::Value * > &RegResults)
 
static void EmitAsmStores (CodeGenFunction &CGF, const AsmStmt &S, const llvm::ArrayRef< llvm::Value * > RegResults, const llvm::ArrayRef< llvm::Type * > ResultRegTypes, const llvm::ArrayRef< llvm::Type * > ResultTruncRegTypes, const llvm::ArrayRef< LValue > ResultRegDests, const llvm::ArrayRef< QualType > ResultRegQualTys, const llvm::BitVector &ResultTypeRequiresCast, const llvm::BitVector &ResultRegIsFlagReg)
 
static void EmitHipStdParUnsupportedAsm (CodeGenFunction *CGF, const AsmStmt &S)
 

Macro Definition Documentation

◆ ABSTRACT_STMT

#define ABSTRACT_STMT (   Op)

◆ EXPR

#define EXPR (   Type,
  Base 
)     case Stmt::Type##Class:

◆ STMT

#define STMT (   Type,
  Base 
)

Enumeration Type Documentation

◆ CSFC_Result

CollectStatementsForCase - Given the body of a 'switch' statement and a constant value that is being switched on, see if we can dead code eliminate the body of the switch to a simple series of statements to emit.

Basically, on a switch (5) we want to find these statements: case 5: printf(...); <– ++i; <– break;

and add them to the ResultStmts vector. If it is unsafe to do this transformation (for example, one of the elided statements contains a label that might be jumped to), return CSFC_Failure. If we handled it and 'S' should include statements after it (e.g. the printf() line is a substmt of the case) then return CSFC_FallThrough. If we handled it and found a break statement, then return CSFC_Success.

If Case is non-null, then we are looking for the specified case, checking that nothing we jump over contains labels. If Case is null, then we found the case and are looking for the break.

If the recursive walk actually finds our Case, then we set FoundCase to true.

Enumerator
CSFC_Failure 
CSFC_FallThrough 
CSFC_Success 

Definition at line 1758 of file CGStmt.cpp.

Function Documentation

◆ AddVariableConstraints()

static std::string AddVariableConstraints ( const std::string &  Constraint,
const Expr AsmExpr,
const TargetInfo Target,
CodeGenModule CGM,
const AsmStmt Stmt,
const bool  EarlyClobber,
std::string *  GCCReg = nullptr 
)
static

AddVariableConstraints - Look at AsmExpr and if it is a variable declared as using a particular register add that as a constraint that will be used in this asm stmt.

Definition at line 2243 of file CGStmt.cpp.

References clang::TargetInfo::ConstraintInfo::allowsRegister(), clang::CodeGen::CodeGenFunction::CGM, clang::CodeGen::CodeGenModule::ErrorUnsupported(), clang::DeclRefExpr::getDecl(), and clang::SC_Register.

◆ CollectStatementsForCase()

static CSFC_Result CollectStatementsForCase ( const Stmt S,
const SwitchCase Case,
bool FoundCase,
SmallVectorImpl< const Stmt * > &  ResultStmts 
)
static

◆ EmitAsmStores()

static void EmitAsmStores ( CodeGenFunction CGF,
const AsmStmt S,
const llvm::ArrayRef< llvm::Value * >  RegResults,
const llvm::ArrayRef< llvm::Type * >  ResultRegTypes,
const llvm::ArrayRef< llvm::Type * >  ResultTruncRegTypes,
const llvm::ArrayRef< LValue >  ResultRegDests,
const llvm::ArrayRef< QualType ResultRegQualTys,
const llvm::BitVector &  ResultTypeRequiresCast,
const llvm::BitVector &  ResultRegIsFlagReg 
)
static

◆ EmitHipStdParUnsupportedAsm()

static void EmitHipStdParUnsupportedAsm ( CodeGenFunction CGF,
const AsmStmt S 
)
static

◆ FindCaseStatementsForValue()

static bool FindCaseStatementsForValue ( const SwitchStmt S,
const llvm::APSInt ConstantCondValue,
SmallVectorImpl< const Stmt * > &  ResultStmts,
ASTContext C,
const SwitchCase *&  ResultCase 
)
static

FindCaseStatementsForValue - Find the case statement being jumped to and then invoke CollectStatementsForCase to find the list of statements to emit for a switch on constant.

See the comment above CollectStatementsForCase for more details.

Definition at line 1914 of file CGStmt.cpp.

References clang::C, CollectStatementsForCase(), clang::CodeGen::CodeGenFunction::ContainsLabel(), CSFC_Failure, clang::Expr::EvaluateKnownConstInt(), clang::CaseStmt::getLHS(), clang::SwitchCase::getNextSwitchCase(), and clang::CaseStmt::getRHS().

◆ getAsmSrcLocInfo()

static llvm::MDNode * getAsmSrcLocInfo ( const StringLiteral Str,
CodeGenFunction CGF 
)
static

◆ getLikelihoodWeights()

static std::optional< SmallVector< uint64_t, 16 > > getLikelihoodWeights ( ArrayRef< Stmt::Likelihood Likelihoods)
static

◆ isSwiftAsyncCallee()

static bool isSwiftAsyncCallee ( const CallExpr CE)
static

Determine if the given call uses the swiftasync calling convention.

Definition at line 1345 of file CGStmt.cpp.

References clang::Type::castAs(), clang::CC_SwiftAsync, clang::FunctionType::getCallConv(), clang::CallExpr::getCallee(), clang::Type::getPointeeType(), and clang::Expr::getType().

◆ SimplifyConstraint()

static std::string SimplifyConstraint ( const char *  Constraint,
const TargetInfo Target,
SmallVectorImpl< TargetInfo::ConstraintInfo > *  OutCons = nullptr 
)
static

Definition at line 2190 of file CGStmt.cpp.

References clang::Result.

◆ UpdateAsmCallInst()

static void UpdateAsmCallInst ( llvm::CallBase &  Result,
bool  HasSideEffect,
bool  HasUnwindClobber,
bool  ReadOnly,
bool  ReadNone,
bool  NoMerge,
const AsmStmt S,
const std::vector< llvm::Type * > &  ResultRegTypes,
const std::vector< llvm::Type * > &  ArgElemTypes,
CodeGenFunction CGF,
std::vector< llvm::Value * > &  RegResults 
)
static