24 #define GEN_PASS_DEF_CONVERTOPENMPTOLLVMPASS
25 #include "mlir/Conversion/Passes.h.inc"
46 matchAndRewrite(T op,
typename T::Adaptor adaptor,
51 if (failed(converter->
convertTypes(op->getResultTypes(), resTypes)))
58 if (
auto typeAttr = dyn_cast<TypeAttr>(attr.getValue())) {
60 convertedAttrs.emplace_back(attr.getName(),
63 convertedAttrs.push_back(attr);
69 convertedOperands.reserve(op->getNumOperands());
70 for (
auto [originalOperand, convertedOperand] :
71 llvm::zip_equal(op->getOperands(), adaptor.getOperands())) {
77 if constexpr (llvm::is_one_of<T, omp::AtomicUpdateOp, omp::AtomicWriteOp,
78 omp::FlushOp, omp::MapBoundsOp,
79 omp::ThreadprivateOp>::value) {
80 if (isa<MemRefType>(originalOperand.getType())) {
85 convertedOperands.push_back(convertedOperand);
89 auto newOp = rewriter.
create<T>(op.getLoc(), resTypes, convertedOperands,
93 for (
auto [originalRegion, convertedRegion] :
94 llvm::zip_equal(op->getRegions(), newOp->getRegions())) {
96 convertedRegion.end());
98 *this->getTypeConverter())))
103 rewriter.
replaceOp(op, newOp->getResults());
114 #include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc"
116 return typeConverter.
isLegal(op->getOperandTypes()) &&
117 typeConverter.
isLegal(op->getResultTypes()) &&
118 llvm::all_of(op->getRegions(),
120 return typeConverter.
isLegal(®ion);
123 auto typeAttr = dyn_cast<TypeAttr>(attr.getValue());
124 return !typeAttr || typeConverter.
isLegal(typeAttr.getValue());
131 template <
typename... Ts>
135 return patterns.add<OpenMPOpConversion<Ts>...>(converter);
144 [&](omp::MapBoundsType type) ->
Type {
return type; });
149 #include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc"
154 struct ConvertOpenMPToLLVMPass
155 :
public impl::ConvertOpenMPToLLVMPassBase<ConvertOpenMPToLLVMPass> {
158 void runOnOperation()
override;
162 void ConvertOpenMPToLLVMPass::runOnOperation() {
163 auto module = getOperation();
176 target.addLegalOp<omp::BarrierOp, omp::FlushOp, omp::TaskwaitOp,
177 omp::TaskyieldOp, omp::TerminatorOp>();
190 void loadDependentDialects(
MLIRContext *context)
const final {
191 context->loadDialect<LLVM::LLVMDialect>();
196 void populateConvertToLLVMConversionPatterns(
207 dialect->addInterfaces<OpenMPToLLVMDialectInterface>();
static MLIRContext * getContext(OpFoldResult val)
static RewritePatternSet & addOpenMPOpConversions(LLVMTypeConverter &converter, RewritePatternSet &patterns)
Add an OpenMPOpConversion<T> conversion pattern for each operation type passed as template argument.
This class implements a pattern rewriter for use with ConversionPatterns.
void replaceOp(Operation *op, ValueRange newValues) override
Replace the given operation with the new values.
FailureOr< Block * > convertRegionTypes(Region *region, const TypeConverter &converter, TypeConverter::SignatureConversion *entryConversion=nullptr)
Apply a signature conversion to each block in the given region.
This class describes a specific conversion target.
void addDynamicallyLegalOp(OperationName op, const DynamicLegalityCallbackFn &callback)
Register the given operation as dynamically legal and set the dynamic legalization callback to the on...
Utility class for operation conversions targeting the LLVM dialect that match exactly one source oper...
Base class for dialect interfaces providing translation to LLVM IR.
ConvertToLLVMPatternInterface(Dialect *dialect)
const LLVMTypeConverter * getTypeConverter() const
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
Derived class that automatically populates legalization information for different LLVM ops.
Conversion from types to the LLVM IR dialect.
MLIRContext is the top-level object for a collection of MLIR operations.
NamedAttribute represents a combination of a name and an Attribute value.
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
Operation is the basic unit of execution within MLIR.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
std::enable_if_t<!std::is_convertible< CallbackT, Twine >::value, LogicalResult > notifyMatchFailure(Location loc, CallbackT &&reasonCallback)
Used to notify the listener that the IR failed to be rewritten because of a match failure,...
void inlineRegionBefore(Region ®ion, Region &parent, Region::iterator before)
Move the blocks that belong to "region" before the given position in another region "parent".
void addConversion(FnT &&callback)
Register a conversion function.
bool isLegal(Type type) const
Return true if the given type is legal for this type converter, i.e.
LogicalResult convertType(Type t, SmallVectorImpl< Type > &results) const
Convert the given type.
LogicalResult convertTypes(TypeRange types, SmallVectorImpl< Type > &results) const
Convert the given set of types, filling 'results' as necessary.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
void populateArithToLLVMConversionPatterns(const LLVMTypeConverter &converter, RewritePatternSet &patterns)
void populateControlFlowToLLVMConversionPatterns(const LLVMTypeConverter &converter, RewritePatternSet &patterns)
Collect the patterns to convert from the ControlFlow dialect to LLVM.
void populateAssertToLLVMConversionPattern(const LLVMTypeConverter &converter, RewritePatternSet &patterns, bool abortOnFailure=true, SymbolTableCollection *symbolTables=nullptr)
Populate the cf.assert to LLVM conversion pattern.
Include the generated interface declarations.
void populateOpenMPToLLVMConversionPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns)
Populate the given list with patterns that convert from OpenMP to LLVM.
void populateFuncToLLVMConversionPatterns(const LLVMTypeConverter &converter, RewritePatternSet &patterns, SymbolTableCollection *symbolTables=nullptr)
Collect the patterns to convert from the Func dialect to LLVM.
void populateFinalizeMemRefToLLVMConversionPatterns(const LLVMTypeConverter &converter, RewritePatternSet &patterns, SymbolTableCollection *symbolTables=nullptr)
Collect a set of patterns to convert memory-related operations from the MemRef dialect to the LLVM di...
const FrozenRewritePatternSet & patterns
void registerConvertOpenMPToLLVMInterface(DialectRegistry ®istry)
Registers the ConvertToLLVMPatternInterface interface in the OpenMP dialect.
void configureOpenMPToLLVMConversionLegality(ConversionTarget &target, const LLVMTypeConverter &typeConverter)
Configure dynamic conversion legality of regionless operations from OpenMP to LLVM.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
LogicalResult applyPartialConversion(ArrayRef< Operation * > ops, const ConversionTarget &target, const FrozenRewritePatternSet &patterns, ConversionConfig config=ConversionConfig())
Below we define several entry points for operation conversion.