clang 23.0.0git
cir::direct Namespace Reference

Classes

class  CIRAttrToValue
class  CIRDialectLLVMIRTranslationInterface
 Implementation of the dialect interface that converts CIR attributes to LLVM IR metadata. More...
struct  ConvertCIRToLLVMPass
class  GlobalInitAttrRewriter
struct  LLVMBlockAddressInfo

Functions

std::unique_ptr< llvm::Module > lowerDirectlyFromCIRToLLVMIR (mlir::ModuleOp mlirModule, llvm::LLVMContext &llvmCtx, llvm::StringRef mlirSaveTempsOutFile={}, llvm::vfs::FileSystem *fs=nullptr)
std::unique_ptr< mlir::Pass > createConvertCIRToLLVMPass ()
 Create a pass that fully lowers CIR to the LLVMIR dialect.
void populateCIRToLLVMPasses (mlir::OpPassManager &pm)
 Adds passes that fully lower CIR to the LLVMIR dialect.
static mlir::Type convertTypeForMemory (const mlir::TypeConverter &converter, mlir::DataLayout const &dataLayout, mlir::Type type)
 Given a type convertor and a data layout, convert the given type to a type that is suitable for memory operations.
static mlir::Value createIntCast (mlir::OpBuilder &bld, mlir::Value src, mlir::IntegerType dstTy, bool isSigned=false)
static mlir::LLVM::Visibility lowerCIRVisibilityToLLVMVisibility (cir::VisibilityKind visibilityKind)
static mlir::Value emitFromMemory (mlir::ConversionPatternRewriter &rewriter, mlir::DataLayout const &dataLayout, cir::LoadOp op, mlir::Value value)
 Emits the value from memory as expected by its users.
static mlir::Value emitToMemory (mlir::ConversionPatternRewriter &rewriter, mlir::DataLayout const &dataLayout, mlir::Type origType, mlir::Value value)
 Emits a value to memory with the expected scalar type.
mlir::LLVM::Linkage convertLinkage (cir::GlobalLinkageKind linkage)
static mlir::LLVM::CConv convertCallingConv (cir::CallingConv callingConv)
static mlir::Value getLLVMIntCast (mlir::ConversionPatternRewriter &rewriter, mlir::Value llvmSrc, mlir::Type llvmDstIntTy, bool isUnsigned, uint64_t cirSrcWidth, uint64_t cirDstIntWidth)
mlir::Value lowerCirAttrAsValue (mlir::Operation *parentOp, const mlir::Attribute attr, mlir::ConversionPatternRewriter &rewriter, const mlir::TypeConverter *converter)
 Switches on the type of attribute and calls the appropriate conversion.
void convertSideEffectForCall (mlir::Operation *callOp, bool isNothrow, cir::SideEffect sideEffect, mlir::LLVM::MemoryEffectsAttr &memoryEffect, bool &noUnwind, bool &willReturn, bool &noReturn)
static mlir::LLVM::CallIntrinsicOp createCallLLVMIntrinsicOp (mlir::ConversionPatternRewriter &rewriter, mlir::Location loc, const llvm::Twine &intrinsicName, mlir::Type resultTy, mlir::ValueRange operands)
static mlir::LLVM::CallIntrinsicOp replaceOpWithCallLLVMIntrinsicOp (mlir::ConversionPatternRewriter &rewriter, mlir::Operation *op, const llvm::Twine &intrinsicName, mlir::Type resultTy, mlir::ValueRange operands)
static mlir::LLVM::AtomicOrdering getLLVMMemOrder (std::optional< cir::MemOrder > memorder)
static llvm::StringRef getLLVMSyncScope (cir::SyncScopeKind syncScope)
static std::optional< llvm::StringRef > getLLVMSyncScope (std::optional< cir::SyncScopeKind > syncScope)
static mlir::LLVM::AtomicBinOp getLLVMAtomicBinOp (cir::AtomicFetchKind k, bool isInt, bool isSignedInt)
static llvm::StringLiteral getLLVMBinopForPostAtomic (cir::AtomicFetchKind k, bool isInt)
static mlir::Value convertToIndexTy (mlir::ConversionPatternRewriter &rewriter, mlir::ModuleOp mod, mlir::Value index, mlir::Type baseTy, cir::IntType strideTy)
static void lowerCallAttributes (cir::CIRCallOpInterface op, SmallVectorImpl< mlir::NamedAttribute > &result)
static mlir::LogicalResult rewriteCallOrInvoke (mlir::Operation *op, mlir::ValueRange callOperands, mlir::ConversionPatternRewriter &rewriter, const mlir::TypeConverter *converter, mlir::FlatSymbolRefAttr calleeAttr, mlir::Block *continueBlock=nullptr, mlir::Block *landingPadBlock=nullptr)
bool hasTrailingZeros (cir::ConstArrayAttr attr)
static uint64_t getTypeSize (mlir::Type type, mlir::Operation &op)
static mlir::LLVM::IntegerOverflowFlags nswFlag (bool nsw)
template<typename CIROp, typename LLVMIntOp>
static mlir::LogicalResult lowerIncDecOp (CIROp op, typename CIROp::Adaptor adaptor, mlir::ConversionPatternRewriter &rewriter, double fpConstant)
static bool isIntTypeUnsigned (mlir::Type type)
template<typename BinOp>
static mlir::LLVM::IntegerOverflowFlags intOverflowFlag (BinOp op)
template<typename UIntSatOp, typename SIntSatOp, typename IntOp, typename FPOp, typename CIROp>
static mlir::LogicalResult lowerSaturatableArithOp (CIROp op, mlir::Value lhs, mlir::Value rhs, mlir::ConversionPatternRewriter &rewriter)
 Lower an arithmetic op that supports saturation, overflow flags, and an FP variant.
template<typename UIntOp, typename SIntOp, typename FPOp, typename CIROp>
static mlir::LogicalResult lowerIntFPBinaryOp (CIROp op, mlir::Value lhs, mlir::Value rhs, mlir::ConversionPatternRewriter &rewriter)
 Lower a binary op that maps to unsigned/signed/FP LLVM ops depending on operand type.
template<typename CIROp, typename UIntOp, typename SIntOp>
static mlir::LogicalResult lowerMinMaxOp (CIROp op, typename CIROp::Adaptor adaptor, mlir::ConversionPatternRewriter &rewriter)
static mlir::LLVM::ICmpPredicate convertCmpKindToICmpPredicate (cir::CmpOpKind kind, bool isSigned)
 Convert from a CIR comparison kind to an LLVM IR integral comparison kind.
static mlir::LLVM::FCmpPredicate convertCmpKindToFCmpPredicate (cir::CmpOpKind kind)
 Convert from a CIR comparison kind to an LLVM IR floating-point comparison kind.
template<typename OpTy>
static mlir::LogicalResult lowerBinOpOverflow (OpTy op, typename OpTy::Adaptor adaptor, mlir::ConversionPatternRewriter &rewriter, const mlir::TypeConverter *typeConverter, llvm::StringRef opStr)
 Shared lowering logic for checked binary arithmetic overflow operations.
static void prepareTypeConverter (mlir::LLVMTypeConverter &converter, mlir::DataLayout &dataLayout)
static void buildCtorDtorList (mlir::ModuleOp module, StringRef globalXtorName, StringRef llvmXtorName, llvm::function_ref< std::pair< StringRef, int >(mlir::Attribute)> createXtor)
static void collectUnreachable (mlir::Operation *parent, llvm::SmallVector< mlir::Operation * > &ops)
void createLLVMFuncOpIfNotExist (mlir::ConversionPatternRewriter &rewriter, mlir::Operation *srcOp, llvm::StringRef fnName, mlir::Type fnTy, mlir::ArrayAttr argAttrs=nullptr, mlir::ArrayAttr resAttrs=nullptr)
static mlir::LLVM::LLVMStructType getLLVMLandingPadStructTy (mlir::ConversionPatternRewriter &rewriter)
static mlir::Value getValueForVTableSymbol (mlir::Operation *op, mlir::ConversionPatternRewriter &rewriter, const mlir::TypeConverter *converter, mlir::FlatSymbolRefAttr nameAttr, mlir::Type &eltType)
mlir::IntegerType computeBitfieldIntType (mlir::Type storageType, mlir::MLIRContext *context, unsigned &storageSize)
std::unique_ptr< llvm::Module > lowerDirectlyFromCIRToLLVMIR (mlir::ModuleOp mlirModule, LLVMContext &llvmCtx, StringRef mlirSaveTempsOutFile, llvm::vfs::FileSystem *fs)
void registerCIRDialectTranslation (mlir::DialectRegistry &registry)

Function Documentation

◆ buildCtorDtorList()

void cir::direct::buildCtorDtorList ( mlir::ModuleOp module,
StringRef globalXtorName,
StringRef llvmXtorName,
llvm::function_ref< std::pair< StringRef, int >(mlir::Attribute)> createXtor )
static

Definition at line 3346 of file LowerToLLVM.cpp.

Referenced by cir::direct::ConvertCIRToLLVMPass::runOnOperation().

◆ collectUnreachable()

void cir::direct::collectUnreachable ( mlir::Operation * parent,
llvm::SmallVector< mlir::Operation * > & ops )
static

Definition at line 3444 of file LowerToLLVM.cpp.

◆ computeBitfieldIntType()

mlir::IntegerType cir::direct::computeBitfieldIntType ( mlir::Type storageType,
mlir::MLIRContext * context,
unsigned & storageSize )

Definition at line 4622 of file LowerToLLVM.cpp.

References computeBitfieldIntType().

Referenced by computeBitfieldIntType().

◆ convertCallingConv()

mlir::LLVM::CConv cir::direct::convertCallingConv ( cir::CallingConv callingConv)
static

Definition at line 191 of file LowerToLLVM.cpp.

◆ convertCmpKindToFCmpPredicate()

mlir::LLVM::FCmpPredicate cir::direct::convertCmpKindToFCmpPredicate ( cir::CmpOpKind kind)
static

Convert from a CIR comparison kind to an LLVM IR floating-point comparison kind.

Definition at line 2877 of file LowerToLLVM.cpp.

References kind.

◆ convertCmpKindToICmpPredicate()

mlir::LLVM::ICmpPredicate cir::direct::convertCmpKindToICmpPredicate ( cir::CmpOpKind kind,
bool isSigned )
static

Convert from a CIR comparison kind to an LLVM IR integral comparison kind.

Definition at line 2851 of file LowerToLLVM.cpp.

References kind.

◆ convertLinkage()

mlir::LLVM::Linkage cir::direct::convertLinkage ( cir::GlobalLinkageKind linkage)

Definition at line 160 of file LowerToLLVM.cpp.

◆ convertSideEffectForCall()

void cir::direct::convertSideEffectForCall ( mlir::Operation * callOp,
bool isNothrow,
cir::SideEffect sideEffect,
mlir::LLVM::MemoryEffectsAttr & memoryEffect,
bool & noUnwind,
bool & willReturn,
bool & noReturn )

Definition at line 312 of file LowerToLLVM.cpp.

Referenced by rewriteCallOrInvoke().

◆ convertToIndexTy()

mlir::Value cir::direct::convertToIndexTy ( mlir::ConversionPatternRewriter & rewriter,
mlir::ModuleOp mod,
mlir::Value index,
mlir::Type baseTy,
cir::IntType strideTy )
static

Definition at line 1458 of file LowerToLLVM.cpp.

References getLLVMIntCast(), and isUnsigned().

◆ convertTypeForMemory()

mlir::Type cir::direct::convertTypeForMemory ( const mlir::TypeConverter & converter,
mlir::DataLayout const & dataLayout,
mlir::Type type )
static

Given a type convertor and a data layout, convert the given type to a type that is suitable for memory operations.

For example, this can be used to lower cir.bool accesses to i8.

Definition at line 81 of file LowerToLLVM.cpp.

Referenced by prepareTypeConverter().

◆ createCallLLVMIntrinsicOp()

mlir::LLVM::CallIntrinsicOp cir::direct::createCallLLVMIntrinsicOp ( mlir::ConversionPatternRewriter & rewriter,
mlir::Location loc,
const llvm::Twine & intrinsicName,
mlir::Type resultTy,
mlir::ValueRange operands )
static

Definition at line 355 of file LowerToLLVM.cpp.

Referenced by replaceOpWithCallLLVMIntrinsicOp().

◆ createConvertCIRToLLVMPass()

std::unique_ptr< mlir::Pass > cir::direct::createConvertCIRToLLVMPass ( )

Create a pass that fully lowers CIR to the LLVMIR dialect.

Definition at line 5079 of file LowerToLLVM.cpp.

References createConvertCIRToLLVMPass().

Referenced by createConvertCIRToLLVMPass(), and populateCIRToLLVMPasses().

◆ createIntCast()

mlir::Value cir::direct::createIntCast ( mlir::OpBuilder & bld,
mlir::Value src,
mlir::IntegerType dstTy,
bool isSigned = false )
static

Definition at line 94 of file LowerToLLVM.cpp.

Referenced by emitFromMemory(), and emitToMemory().

◆ createLLVMFuncOpIfNotExist()

void cir::direct::createLLVMFuncOpIfNotExist ( mlir::ConversionPatternRewriter & rewriter,
mlir::Operation * srcOp,
llvm::StringRef fnName,
mlir::Type fnTy,
mlir::ArrayAttr argAttrs = nullptr,
mlir::ArrayAttr resAttrs = nullptr )

Definition at line 3921 of file LowerToLLVM.cpp.

References createLLVMFuncOpIfNotExist().

Referenced by createLLVMFuncOpIfNotExist().

◆ emitFromMemory()

mlir::Value cir::direct::emitFromMemory ( mlir::ConversionPatternRewriter & rewriter,
mlir::DataLayout const & dataLayout,
cir::LoadOp op,
mlir::Value value )
static

Emits the value from memory as expected by its users.

Should be called when the memory represetnation of a CIR type is not equal to its scalar representation.

Definition at line 128 of file LowerToLLVM.cpp.

References createIntCast().

◆ emitToMemory()

mlir::Value cir::direct::emitToMemory ( mlir::ConversionPatternRewriter & rewriter,
mlir::DataLayout const & dataLayout,
mlir::Type origType,
mlir::Value value )
static

Emits a value to memory with the expected scalar type.

Should be called when the memory represetnation of a CIR type is not equal to its scalar representation.

Definition at line 145 of file LowerToLLVM.cpp.

References createIntCast().

◆ getLLVMAtomicBinOp()

mlir::LLVM::AtomicBinOp cir::direct::getLLVMAtomicBinOp ( cir::AtomicFetchKind k,
bool isInt,
bool isSignedInt )
static

Definition at line 985 of file LowerToLLVM.cpp.

◆ getLLVMBinopForPostAtomic()

llvm::StringLiteral cir::direct::getLLVMBinopForPostAtomic ( cir::AtomicFetchKind k,
bool isInt )
static

Definition at line 1019 of file LowerToLLVM.cpp.

◆ getLLVMIntCast()

mlir::Value cir::direct::getLLVMIntCast ( mlir::ConversionPatternRewriter & rewriter,
mlir::Value llvmSrc,
mlir::Type llvmDstIntTy,
bool isUnsigned,
uint64_t cirSrcWidth,
uint64_t cirDstIntWidth )
static

Definition at line 265 of file LowerToLLVM.cpp.

References isUnsigned().

Referenced by convertToIndexTy().

◆ getLLVMLandingPadStructTy()

mlir::LLVM::LLVMStructType cir::direct::getLLVMLandingPadStructTy ( mlir::ConversionPatternRewriter & rewriter)
static

Definition at line 4012 of file LowerToLLVM.cpp.

References getLLVMLandingPadStructTy().

Referenced by getLLVMLandingPadStructTy().

◆ getLLVMMemOrder()

mlir::LLVM::AtomicOrdering cir::direct::getLLVMMemOrder ( std::optional< cir::MemOrder > memorder)
static

Definition at line 863 of file LowerToLLVM.cpp.

◆ getLLVMSyncScope() [1/2]

llvm::StringRef cir::direct::getLLVMSyncScope ( cir::SyncScopeKind syncScope)
static

Definition at line 882 of file LowerToLLVM.cpp.

Referenced by getLLVMSyncScope().

◆ getLLVMSyncScope() [2/2]

std::optional< llvm::StringRef > cir::direct::getLLVMSyncScope ( std::optional< cir::SyncScopeKind > syncScope)
static

Definition at line 887 of file LowerToLLVM.cpp.

References getLLVMSyncScope().

◆ getTypeSize()

uint64_t cir::direct::getTypeSize ( mlir::Type type,
mlir::Operation & op )
static

Definition at line 2105 of file LowerToLLVM.cpp.

◆ getValueForVTableSymbol()

mlir::Value cir::direct::getValueForVTableSymbol ( mlir::Operation * op,
mlir::ConversionPatternRewriter & rewriter,
const mlir::TypeConverter * converter,
mlir::FlatSymbolRefAttr nameAttr,
mlir::Type & eltType )
static

Definition at line 4154 of file LowerToLLVM.cpp.

References getValueForVTableSymbol().

Referenced by getValueForVTableSymbol().

◆ hasTrailingZeros()

bool cir::direct::hasTrailingZeros ( cir::ConstArrayAttr attr)

Definition at line 1960 of file LowerToLLVM.cpp.

◆ intOverflowFlag()

template<typename BinOp>
mlir::LLVM::IntegerOverflowFlags cir::direct::intOverflowFlag ( BinOp op)
static

Definition at line 2703 of file LowerToLLVM.cpp.

Referenced by lowerSaturatableArithOp().

◆ isIntTypeUnsigned()

bool cir::direct::isIntTypeUnsigned ( mlir::Type type)
static

Definition at line 2691 of file LowerToLLVM.cpp.

Referenced by lowerIntFPBinaryOp(), lowerMinMaxOp(), and lowerSaturatableArithOp().

◆ lowerBinOpOverflow()

template<typename OpTy>
mlir::LogicalResult cir::direct::lowerBinOpOverflow ( OpTy op,
typename OpTy::Adaptor adaptor,
mlir::ConversionPatternRewriter & rewriter,
const mlir::TypeConverter * typeConverter,
llvm::StringRef opStr )
static

Shared lowering logic for checked binary arithmetic overflow operations.

The opStr parameter specifies the arithmetic operation name used in the LLVM intrinsic (e.g., "add", "sub", "mul").

Definition at line 3006 of file LowerToLLVM.cpp.

References sign().

◆ lowerCallAttributes()

void cir::direct::lowerCallAttributes ( cir::CIRCallOpInterface op,
SmallVectorImpl< mlir::NamedAttribute > & result )
static

Definition at line 1703 of file LowerToLLVM.cpp.

References cir::MissingFeatures::opFuncExtraAttrs().

Referenced by rewriteCallOrInvoke().

◆ lowerCirAttrAsValue()

mlir::Value cir::direct::lowerCirAttrAsValue ( mlir::Operation * parentOp,
mlir::Attribute attr,
mlir::ConversionPatternRewriter & rewriter,
const mlir::TypeConverter * converter )

Switches on the type of attribute and calls the appropriate conversion.

Convert a CIR attribute to an LLVM attribute.

May use the datalayout for lowering attributes to-be-stored in memory.

Definition at line 301 of file LowerToLLVM.cpp.

◆ lowerCIRVisibilityToLLVMVisibility()

mlir::LLVM::Visibility cir::direct::lowerCIRVisibilityToLLVMVisibility ( cir::VisibilityKind visibilityKind)
static

Definition at line 114 of file LowerToLLVM.cpp.

◆ lowerDirectlyFromCIRToLLVMIR() [1/2]

std::unique_ptr< llvm::Module > cir::direct::lowerDirectlyFromCIRToLLVMIR ( mlir::ModuleOp mlirModule,
llvm::LLVMContext & llvmCtx,
llvm::StringRef mlirSaveTempsOutFile = {},
llvm::vfs::FileSystem * fs = nullptr )

◆ lowerDirectlyFromCIRToLLVMIR() [2/2]

std::unique_ptr< llvm::Module > cir::direct::lowerDirectlyFromCIRToLLVMIR ( mlir::ModuleOp mlirModule,
LLVMContext & llvmCtx,
StringRef mlirSaveTempsOutFile,
llvm::vfs::FileSystem * fs )

◆ lowerIncDecOp()

template<typename CIROp, typename LLVMIntOp>
mlir::LogicalResult cir::direct::lowerIncDecOp ( CIROp op,
typename CIROp::Adaptor adaptor,
mlir::ConversionPatternRewriter & rewriter,
double fpConstant )
static

Definition at line 2596 of file LowerToLLVM.cpp.

References nswFlag().

◆ lowerIntFPBinaryOp()

template<typename UIntOp, typename SIntOp, typename FPOp, typename CIROp>
mlir::LogicalResult cir::direct::lowerIntFPBinaryOp ( CIROp op,
mlir::Value lhs,
mlir::Value rhs,
mlir::ConversionPatternRewriter & rewriter )
static

Lower a binary op that maps to unsigned/signed/FP LLVM ops depending on operand type.

Used for Div and Rem which share identical dispatch logic.

Definition at line 2768 of file LowerToLLVM.cpp.

References isIntTypeUnsigned().

◆ lowerMinMaxOp()

template<typename CIROp, typename UIntOp, typename SIntOp>
mlir::LogicalResult cir::direct::lowerMinMaxOp ( CIROp op,
typename CIROp::Adaptor adaptor,
mlir::ConversionPatternRewriter & rewriter )
static

Definition at line 2824 of file LowerToLLVM.cpp.

References isIntTypeUnsigned().

◆ lowerSaturatableArithOp()

template<typename UIntSatOp, typename SIntSatOp, typename IntOp, typename FPOp, typename CIROp>
mlir::LogicalResult cir::direct::lowerSaturatableArithOp ( CIROp op,
mlir::Value lhs,
mlir::Value rhs,
mlir::ConversionPatternRewriter & rewriter )
static

Lower an arithmetic op that supports saturation, overflow flags, and an FP variant.

Used for Add and Sub which share identical dispatch logic.

Definition at line 2716 of file LowerToLLVM.cpp.

References intOverflowFlag(), and isIntTypeUnsigned().

◆ nswFlag()

mlir::LLVM::IntegerOverflowFlags cir::direct::nswFlag ( bool nsw)
static

Definition at line 2589 of file LowerToLLVM.cpp.

Referenced by lowerIncDecOp().

◆ populateCIRToLLVMPasses()

void cir::direct::populateCIRToLLVMPasses ( mlir::OpPassManager & pm)

Adds passes that fully lower CIR to the LLVMIR dialect.

Definition at line 5083 of file LowerToLLVM.cpp.

References createConvertCIRToLLVMPass(), mlir::populateCIRPreLoweringPasses(), and populateCIRToLLVMPasses().

Referenced by lowerDirectlyFromCIRToLLVMIR(), and populateCIRToLLVMPasses().

◆ prepareTypeConverter()

void cir::direct::prepareTypeConverter ( mlir::LLVMTypeConverter & converter,
mlir::DataLayout & dataLayout )
static

◆ registerCIRDialectTranslation()

void cir::direct::registerCIRDialectTranslation ( mlir::DialectRegistry & registry)

Definition at line 113 of file LowerToLLVMIR.cpp.

Referenced by mlir::registerCIRDialectTranslation().

◆ replaceOpWithCallLLVMIntrinsicOp()

mlir::LLVM::CallIntrinsicOp cir::direct::replaceOpWithCallLLVMIntrinsicOp ( mlir::ConversionPatternRewriter & rewriter,
mlir::Operation * op,
const llvm::Twine & intrinsicName,
mlir::Type resultTy,
mlir::ValueRange operands )
static

Definition at line 364 of file LowerToLLVM.cpp.

References createCallLLVMIntrinsicOp().

◆ rewriteCallOrInvoke()

mlir::LogicalResult cir::direct::rewriteCallOrInvoke ( mlir::Operation * op,
mlir::ValueRange callOperands,
mlir::ConversionPatternRewriter & rewriter,
const mlir::TypeConverter * converter,
mlir::FlatSymbolRefAttr calleeAttr,
mlir::Block * continueBlock = nullptr,
mlir::Block * landingPadBlock = nullptr )
static