MLIR 22.0.0git
LLVMInterfaces.cpp
Go to the documentation of this file.
1//===- LLVMInterfaces.cpp - LLVM Interfaces ---------------------*- 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// This file defines op interfaces for the LLVM dialect in MLIR.
10//
11//===----------------------------------------------------------------------===//
12
14
16
17using namespace mlir;
18using namespace mlir::LLVM;
19
20/// Verifies that all elements of `array` are instances of `Attr`.
21template <class AttrT>
22static LogicalResult isArrayOf(Operation *op, ArrayAttr array) {
23 for (Attribute iter : array)
24 if (!isa<AttrT>(iter))
25 return op->emitOpError("expected op to return array of ")
26 << AttrT::getMnemonic() << " attributes";
27 return success();
28}
29
30//===----------------------------------------------------------------------===//
31// AccessGroupOpInterface
32//===----------------------------------------------------------------------===//
33
35 auto iface = cast<AccessGroupOpInterface>(op);
36 ArrayAttr accessGroups = iface.getAccessGroupsOrNull();
37 if (!accessGroups)
38 return success();
39
40 return isArrayOf<AccessGroupAttr>(op, accessGroups);
41}
42
43//===----------------------------------------------------------------------===//
44// AliasAnalysisOpInterface
45//===----------------------------------------------------------------------===//
46
47LogicalResult
49 auto iface = cast<AliasAnalysisOpInterface>(op);
50
51 if (auto aliasScopes = iface.getAliasScopesOrNull())
52 if (failed(isArrayOf<AliasScopeAttr>(op, aliasScopes)))
53 return failure();
54
55 if (auto noAliasScopes = iface.getNoAliasScopesOrNull())
56 if (failed(isArrayOf<AliasScopeAttr>(op, noAliasScopes)))
57 return failure();
58
59 ArrayAttr tags = iface.getTBAATagsOrNull();
60 if (!tags)
61 return success();
62
63 return isArrayOf<TBAATagAttr>(op, tags);
64}
65
66//===----------------------------------------------------------------------===//
67// DereferenceableOpInterface
68//===----------------------------------------------------------------------===//
69
70LogicalResult
72 auto iface = cast<DereferenceableOpInterface>(op);
73
74 if (auto derefAttr = iface.getDereferenceableOrNull())
75 if (op->getNumResults() != 1 ||
76 !mlir::isa<LLVMPointerType>(op->getResult(0).getType()))
77 return op->emitOpError(
78 "expected op to return a single LLVM pointer type");
79
80 return success();
81}
82
83SmallVector<Value> mlir::LLVM::AtomicCmpXchgOp::getAccessedOperands() {
84 return {getPtr()};
85}
86
87SmallVector<Value> mlir::LLVM::AtomicRMWOp::getAccessedOperands() {
88 return {getPtr()};
89}
90
91SmallVector<Value> mlir::LLVM::LoadOp::getAccessedOperands() {
92 return {getAddr()};
93}
94
95SmallVector<Value> mlir::LLVM::StoreOp::getAccessedOperands() {
96 return {getAddr()};
97}
98
99SmallVector<Value> mlir::LLVM::MemcpyOp::getAccessedOperands() {
100 return {getDst(), getSrc()};
101}
102
103SmallVector<Value> mlir::LLVM::MemcpyInlineOp::getAccessedOperands() {
104 return {getDst(), getSrc()};
105}
106
107SmallVector<Value> mlir::LLVM::MemmoveOp::getAccessedOperands() {
108 return {getDst(), getSrc()};
109}
110
111SmallVector<Value> mlir::LLVM::MemsetOp::getAccessedOperands() {
112 return {getDst()};
113}
114
115SmallVector<Value> mlir::LLVM::MemsetInlineOp::getAccessedOperands() {
116 return {getDst()};
117}
118
119SmallVector<Value> mlir::LLVM::CallOp::getAccessedOperands() {
120 return llvm::filter_to_vector(getArgOperands(), [](Value arg) {
121 return isa<LLVMPointerType>(arg.getType());
122 });
123}
124
125#include "mlir/Dialect/LLVMIR/LLVMInterfaces.cpp.inc"
return success()
static LogicalResult isArrayOf(Operation *op, ArrayAttr array)
Verifies that all elements of array are instances of Attr.
ArrayAttr()
Attributes are known-constant values of operations.
Definition Attributes.h:25
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
OpResult getResult(unsigned idx)
Get the 'idx'th result of this operation.
Definition Operation.h:407
InFlightDiagnostic emitOpError(const Twine &message={})
Emit an error with the op name prefixed, like "'dim' op " which is convenient for verifiers.
unsigned getNumResults()
Return the number of results held by this operation.
Definition Operation.h:404
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
Type getType() const
Return the type of this value.
Definition Value.h:105
LogicalResult verifyAliasAnalysisOpInterface(Operation *op)
Verifies the alias analysis attributes of memory operations that implement the alias analysis interfa...
LogicalResult verifyAccessGroupOpInterface(Operation *op)
Verifies the access groups attribute of memory operations that implement the access group interface.
LogicalResult verifyDereferenceableOpInterface(Operation *op)
Verifies that the operation implementing the dereferenceable interface has exactly one result of LLVM...
Include the generated interface declarations.