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 std::all_of(op->getRegions().begin(), op->getRegions().end(),
120 return typeConverter.
isLegal(®ion);
122 std::all_of(op->getAttrs().begin(), op->getAttrs().end(),
124 auto typeAttr = dyn_cast<TypeAttr>(attr.getValue());
126 typeConverter.
isLegal(typeAttr.getValue());
133 template <
typename... Ts>
137 return patterns.add<OpenMPOpConversion<Ts>...>(converter);
146 [&](omp::MapBoundsType type) ->
Type {
return type; });
151 #include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc"
156 struct ConvertOpenMPToLLVMPass
157 :
public impl::ConvertOpenMPToLLVMPassBase<ConvertOpenMPToLLVMPass> {
160 void runOnOperation()
override;
164 void ConvertOpenMPToLLVMPass::runOnOperation() {
165 auto module = getOperation();
178 target.addLegalOp<omp::BarrierOp, omp::FlushOp, omp::TaskwaitOp,
179 omp::TaskyieldOp, omp::TerminatorOp>();
192 void loadDependentDialects(
MLIRContext *context)
const final {
193 context->loadDialect<LLVM::LLVMDialect>();
198 void populateConvertToLLVMConversionPatterns(
209 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 populateAssertToLLVMConversionPattern(const LLVMTypeConverter &converter, RewritePatternSet &patterns, bool abortOnFailure=true)
Populate the cf.assert to LLVM conversion pattern.
void populateControlFlowToLLVMConversionPatterns(const LLVMTypeConverter &converter, RewritePatternSet &patterns)
Collect the patterns to convert from the ControlFlow dialect to LLVM.
Include the generated interface declarations.
void populateOpenMPToLLVMConversionPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns)
Populate the given list with patterns that convert from OpenMP to LLVM.
void populateFinalizeMemRefToLLVMConversionPatterns(const LLVMTypeConverter &converter, RewritePatternSet &patterns)
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...
void populateFuncToLLVMConversionPatterns(const LLVMTypeConverter &converter, RewritePatternSet &patterns, const SymbolTable *symbolTable=nullptr)
Collect the patterns to convert from the Func dialect to LLVM.
LogicalResult applyPartialConversion(ArrayRef< Operation * > ops, const ConversionTarget &target, const FrozenRewritePatternSet &patterns, ConversionConfig config=ConversionConfig())
Below we define several entry points for operation conversion.