MLIR 22.0.0git
StructBuilder.h
Go to the documentation of this file.
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
20namespace mlir {
21
22class OpBuilder;
23
24/// Helper class to produce LLVM dialect operations extracting or inserting
25/// values to a struct.
27public:
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
36protected:
37 // LLVM value
39 // Cached struct type.
41
42protected:
43 /// Builds IR to extract a value from the struct at position pos
44 Value extractPtr(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
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
This class helps build Operations.
Definition Builders.h:207
static StructBuilder poison(OpBuilder &builder, Location loc, Type descriptorType)
Builds IR creating a poison value of the descriptor type.
void setPtr(OpBuilder &builder, Location loc, unsigned pos, Value ptr)
Builds IR to set a value in the struct at position pos.
StructBuilder(Value v)
Construct a helper for the given value.
Value extractPtr(OpBuilder &builder, Location loc, unsigned pos) const
Builds IR to extract a value from the struct at position pos.
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:96
Include the generated interface declarations.