MLIR  19.0.0git
Go to the documentation of this file.
1 //===- StructBuilder.cpp - Helper for building LLVM structs --------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
12 #include "mlir/IR/Builders.h"
14 using namespace mlir;
16 //===----------------------------------------------------------------------===//
17 // StructBuilder implementation
18 //===----------------------------------------------------------------------===//
20 StructBuilder::StructBuilder(Value v) : value(v), structType(v.getType()) {
21  assert(value != nullptr && "value cannot be null");
22  assert(LLVM::isCompatibleType(structType) && "expected llvm type");
23 }
26  unsigned pos) const {
27  return builder.create<LLVM::ExtractValueOp>(loc, value, pos);
28 }
30 void StructBuilder::setPtr(OpBuilder &builder, Location loc, unsigned pos,
31  Value ptr) {
32  value = builder.create<LLVM::InsertValueOp>(loc, value, ptr, pos);
33 }
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:63
This class helps build Operations.
Definition: Builders.h:209
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
Definition: Builders.cpp:464
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.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:96
bool isCompatibleType(Type type)
Returns true if the given type is compatible with the LLVM dialect.
Definition: LLVMTypes.cpp:858
Include the generated interface declarations.