| 1 | //===- StructBuilder.h - Helper for building LLVM structs -------*- C++ -*-===// |
| 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 | // |
| 9 | // Provides a convenience API for emitting IR that inspects or constructs values |
| 10 | // of LLVM dialect structure types. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef MLIR_CONVERSION_LLVMCOMMON_STRUCTBUILDER_H |
| 15 | #define MLIR_CONVERSION_LLVMCOMMON_STRUCTBUILDER_H |
| 16 | |
| 17 | #include "mlir/IR/Types.h" |
| 18 | #include "mlir/IR/Value.h" |
| 19 | |
| 20 | namespace mlir { |
| 21 | |
| 22 | class OpBuilder; |
| 23 | |
| 24 | /// Helper class to produce LLVM dialect operations extracting or inserting |
| 25 | /// values to a struct. |
| 26 | class StructBuilder { |
| 27 | public: |
| 28 | /// Construct a helper for the given value. |
| 29 | explicit StructBuilder(Value v); |
| 30 | /// Builds IR creating a `poison` value of the descriptor type. |
| 31 | static StructBuilder poison(OpBuilder &builder, Location loc, |
| 32 | Type descriptorType); |
| 33 | |
| 34 | /*implicit*/ operator Value() { return value; } |
| 35 | |
| 36 | protected: |
| 37 | // LLVM value |
| 38 | Value value; |
| 39 | // Cached struct type. |
| 40 | Type structType; |
| 41 | |
| 42 | protected: |
| 43 | /// Builds IR to extract a value from the struct at position pos |
| 44 | Value (OpBuilder &builder, Location loc, unsigned pos) const; |
| 45 | /// Builds IR to set a value in the struct at position pos |
| 46 | void setPtr(OpBuilder &builder, Location loc, unsigned pos, Value ptr); |
| 47 | }; |
| 48 | |
| 49 | } // namespace mlir |
| 50 | |
| 51 | #endif // MLIR_CONVERSION_LLVMCOMMON_STRUCTBUILDER_H |
| 52 | |