clang 24.0.0git
CIRDialect.cpp File Reference
#include "clang/CIR/Dialect/IR/CIRDialect.h"
#include "clang/CIR/Dialect/IR/CIRAttrs.h"
#include "clang/CIR/Dialect/IR/CIRDataLayout.h"
#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
#include "clang/CIR/Dialect/IR/CIRTypes.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/DialectImplementation.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/Value.h"
#include "mlir/Interfaces/ControlFlowInterfaces.h"
#include "mlir/Interfaces/FunctionImplementation.h"
#include "mlir/Support/LLVM.h"
#include "clang/Basic/TargetCXXABI.h"
#include "clang/CIR/Dialect/IR/CIROpsDialect.cpp.inc"
#include "clang/CIR/Dialect/IR/CIROpsEnums.cpp.inc"
#include "clang/CIR/MissingFeatures.h"
#include "llvm/ADT/SetOperations.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/LogicalResult.h"
#include "CIRDialectBytecode.h"
#include "CIROpDefinitions.h"

Go to the source code of this file.

Macros

#define REGISTER_ENUM_TYPE(Ty)

Functions

static bool isOpenCLVersionAttrName (StringRef attrName)
static LogicalResult verifyOpenCLVersionAttrPlacement (Operation *op, NamedAttribute attr)
static bool areOpenCLVersionsCompatible (cir::OpenCLVersionAttr openCLVersion, cir::OpenCLVersionAttr cxxVersion)
static LogicalResult verifyOpenCLCXXVersion (ModuleOp module, cir::OpenCLVersionAttr cxxVersion)
static LogicalResult verifyOpenCLVersionAttr (Operation *op, NamedAttribute attr)
static LogicalResult verifyOffloadKind (mlir::ModuleOp module, cir::OffloadKind expected)
static LogicalResult verifyOffloadContainer (mlir::Operation *op)
static int parseOptionalKeywordAlternative (AsmParser &parser, ArrayRef< llvm::StringRef > keywords)
template<typename EnumTy, typename RetTy = EnumTy>
static RetTy parseOptionalCIRKeyword (AsmParser &parser, EnumTy defaultValue)
 Parse an enum from the keyword, or default to the provided default value.
template<typename EnumTy, typename RetTy = EnumTy>
static ParseResult parseCIRKeyword (AsmParser &parser, RetTy &result)
 Parse an enum from the keyword, return failure if the keyword is not found.
static LogicalResult ensureRegionTerm (OpAsmParser &parser, Region &region, SMLoc errLoc)
static bool omitRegionTerm (mlir::Region &r)
template<typename ExpectedProducerOp>
static LogicalResult verifyProducedBy (Operation *op, Value operand, StringRef operandName)
ParseResult parseInlineKindAttr (OpAsmParser &parser, cir::InlineKindAttr &inlineKindAttr)
void printInlineKindAttr (OpAsmPrinter &p, cir::InlineKindAttr inlineKindAttr)
template<typename Op>
static LogicalResult verifyArrayCtorDtor (Op op)
static bool isInVarCtorRegion (mlir::Operation *op)
 Returns true if op is nested in the ctor region of a cir.global or cir.local_init without crossing a cir.func or a cir.register_exit_dtor.
static bool mayBreakOutOf (cir::LoopOpInterface loop)
 Return true if a cir.break may leave loop.
template<typename LoopOpTy>
static LogicalResult verifyLoopCleanup (LoopOpTy op)
static LogicalResult checkConstantTypes (mlir::Operation *op, mlir::Type opType, mlir::Attribute attrType)
static bool isFloatingPointCastKind (cir::CastKind kind)
static bool isIntOrBoolCast (cir::CastOp op)
static bool isCirFunctionPointerType (mlir::Type ty)
static Value tryFoldCastChain (cir::CastOp op)
static mlir::ParseResult parseTryCallDestinations (mlir::OpAsmParser &parser, mlir::OperationState &result)
static ParseResult checkEffectAttrKinds (mlir::OpAsmParser &parser, llvm::SMLoc loc, const mlir::NamedAttrList &attrs)
 Reject an attribute in an explicit attribute dictionary whose value is not the attribute class expected for its name.
static mlir::ParseResult parseCallCommon (mlir::OpAsmParser &parser, mlir::OperationState &result, bool hasDestinationBlocks=false)
static void printCallCommon (mlir::Operation *op, mlir::FlatSymbolRefAttr calleeSym, mlir::Value indirectCallee, mlir::OpAsmPrinter &printer, bool isNothrow, ArrayAttr argAttrs, ArrayAttr resAttrs, mlir::Block *normalDest=nullptr, mlir::Block *unwindDest=nullptr)
static LogicalResult verifyCallCommInSymbolUses (mlir::Operation *op, SymbolTableCollection &symbolTable)
static mlir::LogicalResult checkReturnAndFunction (cir::ReturnOp op, cir::FuncOp function)
static bool isRedundantBeforeReturn (mlir::Region &cleanupRegion)
static ParseResult parseConstantValue (OpAsmParser &parser, mlir::Attribute &valueAttr)
static void printConstant (OpAsmPrinter &p, Attribute value)
static void printComdatName (OpAsmPrinter &p, StringAttr comdat)
static llvm::StringRef getLinkageAttrNameString ()
 Returns the name used for the linkage attribute.
static bool isFuncAttrInDict (llvm::StringRef name)
 Declared cir.func attributes with no dedicated syntax, which print in and parse from the attribute dictionary instead.
static LogicalResult verifyMemberPtrCast (Operation *op, mlir::Value src, mlir::Type resultTy)
static mlir::Type memberPointeeType (cir::RecordType recordTy, unsigned idx)
static void getLoadEffects (OpOperand &addr, bool isVolatileOrAtomic, SmallVectorImpl< MemoryEffects::EffectInstance > &effects)
 Adds the effects of a load from addr.
static OpFoldResult foldUnaryBitOp (mlir::Attribute inputAttr, llvm::function_ref< llvm::APInt(const llvm::APInt &)> func, bool poisonZero=false)
template<typename ThrowOpTy>
static mlir::LogicalResult verifyThrowOpImpl (ThrowOpTy op)
static LogicalResult verifyCatchParamPairing (mlir::Region &handlerRegion, cir::ConstructCatchParamOp constructOp)
 Verify that each cir.init_catch_param in handlerRegion, outside any nested cir.try, agrees with the handler's leading cir.construct_catch_param constructOp, which may be null.
static std::optional< unsigned > getRecordedIntegerWidth (mlir::Attribute attr)
 Reads a fundamental integer width from a signless i32 attribute.
static LogicalResult verifyCatchParamAddr (mlir::Operation *op, cir::InitCatchKind kind, cir::PointerType paramAddrType)
 For the reference_to_pointer and reference_to_record_pointer kinds, emit an error on op unless paramAddrType is the type of the address of a reference to a pointer.

Macro Definition Documentation

◆ REGISTER_ENUM_TYPE

#define REGISTER_ENUM_TYPE ( Ty)
Value:
template <> struct EnumTraits<cir::Ty> { \
static llvm::StringRef stringify(cir::Ty value) { \
return stringify##Ty(value); \
} \
static unsigned getMaxEnumVal() { return cir::getMaxEnumValFor##Ty(); } \
}

Definition at line 389 of file CIRDialect.cpp.

Function Documentation

◆ areOpenCLVersionsCompatible()

bool areOpenCLVersionsCompatible ( cir::OpenCLVersionAttr openCLVersion,
cir::OpenCLVersionAttr cxxVersion )
static

Definition at line 134 of file CIRDialect.cpp.

Referenced by verifyOpenCLCXXVersion().

◆ checkConstantTypes()

LogicalResult checkConstantTypes ( mlir::Operation * op,
mlir::Type opType,
mlir::Attribute attrType )
static

Definition at line 950 of file CIRDialect.cpp.

◆ checkEffectAttrKinds()

ParseResult checkEffectAttrKinds ( mlir::OpAsmParser & parser,
llvm::SMLoc loc,
const mlir::NamedAttrList & attrs )
static

Reject an attribute in an explicit attribute dictionary whose value is not the attribute class expected for its name.

Where an op declares the attribute it is stored as a property, so a value of the wrong class would be dropped without a diagnostic.

Definition at line 1540 of file CIRDialect.cpp.

Referenced by parseCallCommon().

◆ checkReturnAndFunction()

mlir::LogicalResult checkReturnAndFunction ( cir::ReturnOp op,
cir::FuncOp function )
static

Definition at line 1934 of file CIRDialect.cpp.

◆ ensureRegionTerm()

LogicalResult ensureRegionTerm ( OpAsmParser & parser,
Region & region,
SMLoc errLoc )
static

Definition at line 433 of file CIRDialect.cpp.

Referenced by cir::parseOmittedTerminatorRegion().

◆ foldUnaryBitOp()

OpFoldResult foldUnaryBitOp ( mlir::Attribute inputAttr,
llvm::function_ref< llvm::APInt(const llvm::APInt &)> func,
bool poisonZero = false )
static

Definition at line 5012 of file CIRDialect.cpp.

◆ getLinkageAttrNameString()

llvm::StringRef getLinkageAttrNameString ( )
static

Returns the name used for the linkage attribute.

This must correspond to the name of the attribute in ODS.

Definition at line 3016 of file CIRDialect.cpp.

◆ getLoadEffects()

void getLoadEffects ( OpOperand & addr,
bool isVolatileOrAtomic,
SmallVectorImpl< MemoryEffects::EffectInstance > & effects )
static

Adds the effects of a load from addr.

A volatile or atomic load also has unknown read and write effects, as in the LLVM dialect, so that it is never erased when its result is unused.

Definition at line 4842 of file CIRDialect.cpp.

◆ getRecordedIntegerWidth()

std::optional< unsigned > getRecordedIntegerWidth ( mlir::Attribute attr)
static

Reads a fundamental integer width from a signless i32 attribute.

Definition at line 5832 of file CIRDialect.cpp.

References int64_t, and cir::isValidFundamentalIntWidth().

◆ isCirFunctionPointerType()

bool isCirFunctionPointerType ( mlir::Type ty)
static

Definition at line 1315 of file CIRDialect.cpp.

Referenced by tryFoldCastChain().

◆ isFloatingPointCastKind()

bool isFloatingPointCastKind ( cir::CastKind kind)
static

Definition at line 1024 of file CIRDialect.cpp.

References kind.

◆ isFuncAttrInDict()

bool isFuncAttrInDict ( llvm::StringRef name)
static

Declared cir.func attributes with no dedicated syntax, which print in and parse from the attribute dictionary instead.

Definition at line 3020 of file CIRDialect.cpp.

◆ isIntOrBoolCast()

bool isIntOrBoolCast ( cir::CastOp op)
static

Definition at line 1309 of file CIRDialect.cpp.

References kind.

Referenced by tryFoldCastChain().

◆ isInVarCtorRegion()

bool isInVarCtorRegion ( mlir::Operation * op)
static

Returns true if op is nested in the ctor region of a cir.global or cir.local_init without crossing a cir.func or a cir.register_exit_dtor.

Definition at line 797 of file CIRDialect.cpp.

◆ isOpenCLVersionAttrName()

bool isOpenCLVersionAttrName ( StringRef attrName)
static

Definition at line 118 of file CIRDialect.cpp.

◆ isRedundantBeforeReturn()

bool isRedundantBeforeReturn ( mlir::Region & cleanupRegion)
static

Definition at line 2168 of file CIRDialect.cpp.

◆ mayBreakOutOf()

bool mayBreakOutOf ( cir::LoopOpInterface loop)
static

Return true if a cir.break may leave loop.

A break nested in an inner loop or switch leaves that operation instead.

Definition at line 847 of file CIRDialect.cpp.

◆ memberPointeeType()

mlir::Type memberPointeeType ( cir::RecordType recordTy,
unsigned idx )
static

Definition at line 4319 of file CIRDialect.cpp.

References cir::RecordType::getMembers(), and cir::memberStorageType().

◆ omitRegionTerm()

bool omitRegionTerm ( mlir::Region & r)
static

Definition at line 460 of file CIRDialect.cpp.

Referenced by cir::printOmittedTerminatorRegion().

◆ parseCallCommon()

mlir::ParseResult parseCallCommon ( mlir::OpAsmParser & parser,
mlir::OperationState & result,
bool hasDestinationBlocks = false )
static

◆ parseCIRKeyword()

template<typename EnumTy, typename RetTy = EnumTy>
ParseResult parseCIRKeyword ( AsmParser & parser,
RetTy & result )
static

Parse an enum from the keyword, return failure if the keyword is not found.

Definition at line 419 of file CIRDialect.cpp.

References parseOptionalKeywordAlternative().

Referenced by parseCallCommon().

◆ parseConstantValue()

ParseResult parseConstantValue ( OpAsmParser & parser,
mlir::Attribute & valueAttr )
static

Definition at line 2606 of file CIRDialect.cpp.

◆ parseInlineKindAttr()

ParseResult parseInlineKindAttr ( OpAsmParser & parser,
cir::InlineKindAttr & inlineKindAttr )

Definition at line 498 of file CIRDialect.cpp.

◆ parseOptionalCIRKeyword()

template<typename EnumTy, typename RetTy = EnumTy>
RetTy parseOptionalCIRKeyword ( AsmParser & parser,
EnumTy defaultValue )
static

Parse an enum from the keyword, or default to the provided default value.

The return type is the enum type by default, unless overriden with the second template argument.

Definition at line 406 of file CIRDialect.cpp.

References parseOptionalKeywordAlternative().

◆ parseOptionalKeywordAlternative()

int parseOptionalKeywordAlternative ( AsmParser & parser,
ArrayRef< llvm::StringRef > keywords )
static

Definition at line 377 of file CIRDialect.cpp.

Referenced by parseCIRKeyword(), and parseOptionalCIRKeyword().

◆ parseTryCallDestinations()

mlir::ParseResult parseTryCallDestinations ( mlir::OpAsmParser & parser,
mlir::OperationState & result )
static

Definition at line 1518 of file CIRDialect.cpp.

Referenced by parseCallCommon().

◆ printCallCommon()

void printCallCommon ( mlir::Operation * op,
mlir::FlatSymbolRefAttr calleeSym,
mlir::Value indirectCallee,
mlir::OpAsmPrinter & printer,
bool isNothrow,
ArrayAttr argAttrs,
ArrayAttr resAttrs,
mlir::Block * normalDest = nullptr,
mlir::Block * unwindDest = nullptr )
static

Definition at line 1696 of file CIRDialect.cpp.

◆ printComdatName()

void printComdatName ( OpAsmPrinter & p,
StringAttr comdat )
static

Definition at line 2744 of file CIRDialect.cpp.

◆ printConstant()

void printConstant ( OpAsmPrinter & p,
Attribute value )
static

Definition at line 2612 of file CIRDialect.cpp.

◆ printInlineKindAttr()

void printInlineKindAttr ( OpAsmPrinter & p,
cir::InlineKindAttr inlineKindAttr )

Definition at line 524 of file CIRDialect.cpp.

◆ tryFoldCastChain()

Value tryFoldCastChain ( cir::CastOp op)
static

Definition at line 1320 of file CIRDialect.cpp.

References isCirFunctionPointerType(), and isIntOrBoolCast().

◆ verifyArrayCtorDtor()

template<typename Op>
LogicalResult verifyArrayCtorDtor ( Op op)
static

Definition at line 595 of file CIRDialect.cpp.

◆ verifyCallCommInSymbolUses()

LogicalResult verifyCallCommInSymbolUses ( mlir::Operation * op,
SymbolTableCollection & symbolTable )
static

Definition at line 1803 of file CIRDialect.cpp.

References cir::MissingFeatures::opCallCallConv().

◆ verifyCatchParamAddr()

LogicalResult verifyCatchParamAddr ( mlir::Operation * op,
cir::InitCatchKind kind,
cir::PointerType paramAddrType )
static

For the reference_to_pointer and reference_to_record_pointer kinds, emit an error on op unless paramAddrType is the type of the address of a reference to a pointer.

Any other kind is accepted.

Definition at line 5882 of file CIRDialect.cpp.

References kind.

◆ verifyCatchParamPairing()

LogicalResult verifyCatchParamPairing ( mlir::Region & handlerRegion,
cir::ConstructCatchParamOp constructOp )
static

Verify that each cir.init_catch_param in handlerRegion, outside any nested cir.try, agrees with the handler's leading cir.construct_catch_param constructOp, which may be null.

A cir.init_catch_param of kind reference_to_pointer or non_trivial_copy needs constructOp on its parameter, and a cir.init_catch_param on the parameter of constructOp must have the kind of constructOp.

Definition at line 5486 of file CIRDialect.cpp.

References kind.

◆ verifyLoopCleanup()

template<typename LoopOpTy>
LogicalResult verifyLoopCleanup ( LoopOpTy op)
static

Definition at line 923 of file CIRDialect.cpp.

◆ verifyMemberPtrCast()

LogicalResult verifyMemberPtrCast ( Operation * op,
mlir::Value src,
mlir::Type resultTy )
static

Definition at line 3843 of file CIRDialect.cpp.

References cir::MissingFeatures::memberFuncPtrCast().

◆ verifyOffloadContainer()

LogicalResult verifyOffloadContainer ( mlir::Operation * op)
static

Definition at line 225 of file CIRDialect.cpp.

References verifyOffloadKind().

◆ verifyOffloadKind()

LogicalResult verifyOffloadKind ( mlir::ModuleOp module,
cir::OffloadKind expected )
static

Definition at line 206 of file CIRDialect.cpp.

Referenced by verifyOffloadContainer().

◆ verifyOpenCLCXXVersion()

LogicalResult verifyOpenCLCXXVersion ( ModuleOp module,
cir::OpenCLVersionAttr cxxVersion )
static

Definition at line 146 of file CIRDialect.cpp.

References areOpenCLVersionsCompatible().

Referenced by verifyOpenCLVersionAttr().

◆ verifyOpenCLVersionAttr()

LogicalResult verifyOpenCLVersionAttr ( Operation * op,
NamedAttribute attr )
static

Definition at line 166 of file CIRDialect.cpp.

References verifyOpenCLCXXVersion(), and verifyOpenCLVersionAttrPlacement().

◆ verifyOpenCLVersionAttrPlacement()

LogicalResult verifyOpenCLVersionAttrPlacement ( Operation * op,
NamedAttribute attr )
static

Definition at line 124 of file CIRDialect.cpp.

Referenced by verifyOpenCLVersionAttr().

◆ verifyProducedBy()

template<typename ExpectedProducerOp>
LogicalResult verifyProducedBy ( Operation * op,
Value operand,
StringRef operandName )
static

Definition at line 472 of file CIRDialect.cpp.

◆ verifyThrowOpImpl()

template<typename ThrowOpTy>
mlir::LogicalResult verifyThrowOpImpl ( ThrowOpTy op)
static

Definition at line 5384 of file CIRDialect.cpp.