MLIR  16.0.0git
ConvertOpenACCToLLVM.h
Go to the documentation of this file.
1 //===- ConvertOpenACCToLLVM.h - OpenACC conversion pass entrypoint --------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #ifndef MLIR_CONVERSION_OPENACCTOLLVM_CONVERTOPENACCTOLLVM_H
9 #define MLIR_CONVERSION_OPENACCTOLLVM_CONVERTOPENACCTOLLVM_H
10 
12 #include <memory>
13 
14 namespace mlir {
15 class LLVMTypeConverter;
16 class ModuleOp;
17 template <typename T>
18 class OperationPass;
19 class RewritePatternSet;
20 
21 #define GEN_PASS_DECL_CONVERTOPENACCTOLLVM
22 #include "mlir/Conversion/Passes.h.inc"
23 
24 static constexpr unsigned kPtrBasePosInDataDescriptor = 0;
25 static constexpr unsigned kPtrPosInDataDescriptor = 1;
26 static constexpr unsigned kSizePosInDataDescriptor = 2;
27 
28 /// Helper class to produce LLVM dialect operations inserting
29 /// elements to a Data descriptor. Wraps a Value pointing to the descriptor.
30 /// The Value may be null, in which case none of the operations are valid.
31 ///
32 /// The data descriptor holds information needed to perform data operations
33 /// and movements with the runtime.
34 /// `BasePointer`: base of the pointer being mapped.
35 /// `Pointer`: actual pointer of the data being mapped.
36 /// `Size`: size of the data being mapped.
37 ///
38 /// Example:
39 ///
40 /// ```c
41 /// struct S {
42 /// int x;
43 /// int y;
44 /// };
45 /// ```
46 ///
47 /// Mapping `s.y` will result if the following information in the data
48 /// descriptor:
49 /// - `BasePointer`: address of `s`
50 /// - `Pointer`: address of `s.y`
51 /// - `Size`: size of `s.y`
52 ///
53 /// For a scalar variable BasePointer and Pointer will be the same.
54 class DataDescriptor : public StructBuilder {
55 public:
56  /// Construct a helper for the given descriptor value.
57  explicit DataDescriptor(Value descriptor);
58  /// Builds IR creating an `undef` value of the descriptor type.
59  static DataDescriptor undef(OpBuilder &builder, Location loc, Type basePtrTy,
60  Type ptrTy);
61 
62  static bool isValid(Value descriptor);
63 
64  void setPointer(OpBuilder &builder, Location loc, Value ptr);
65  void setBasePointer(OpBuilder &builder, Location loc, Value basePtr);
66  void setSize(OpBuilder &builder, Location loc, Value size);
67 };
68 
69 /// Collect the patterns to convert from the OpenACC dialect LLVMIR dialect.
71  RewritePatternSet &patterns);
72 
73 /// Create a pass to convert the OpenACC dialect into the LLVMIR dialect.
74 std::unique_ptr<OperationPass<ModuleOp>> createConvertOpenACCToLLVMPass();
75 
76 } // namespace mlir
77 
78 #endif // MLIR_CONVERSION_OPENACCTOLLVM_CONVERTOPENACCTOLLVM_H
Include the generated interface declarations.
void setBasePointer(OpBuilder &builder, Location loc, Value basePtr)
Builds IR inserting the base pointer value into the descriptor.
static constexpr unsigned kPtrBasePosInDataDescriptor
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:48
static constexpr unsigned kPtrPosInDataDescriptor
Helper class to produce LLVM dialect operations extracting or inserting values to a struct...
Definition: StructBuilder.h:26
void populateOpenACCToLLVMConversionPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns)
Collect the patterns to convert from the OpenACC dialect LLVMIR dialect.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:85
Helper class to produce LLVM dialect operations inserting elements to a Data descriptor.
void setSize(OpBuilder &builder, Location loc, Value size)
Builds IR inserting the size value into the descriptor.
static DataDescriptor undef(OpBuilder &builder, Location loc, Type basePtrTy, Type ptrTy)
Builds IR creating an undef value of the descriptor type.
static constexpr unsigned kSizePosInDataDescriptor
std::unique_ptr< OperationPass< ModuleOp > > createConvertOpenACCToLLVMPass()
Create a pass to convert the OpenACC dialect into the LLVMIR dialect.
static bool isValid(Value descriptor)
Check whether the type is a valid data descriptor.
Conversion from types to the LLVM IR dialect.
Definition: TypeConverter.h:30
DataDescriptor(Value descriptor)
Construct a helper for the given descriptor value.
This class helps build Operations.
Definition: Builders.h:196
void setPointer(OpBuilder &builder, Location loc, Value ptr)
Builds IR inserting the pointer value into the descriptor.