MLIR  21.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 
15 
16 using namespace mlir;
17 using namespace mlir::LLVM;
18 
19 /// Verifies that all elements of `array` are instances of `Attr`.
20 template <class AttrT>
21 static LogicalResult isArrayOf(Operation *op, ArrayAttr array) {
22  for (Attribute iter : array)
23  if (!isa<AttrT>(iter))
24  return op->emitOpError("expected op to return array of ")
25  << AttrT::getMnemonic() << " attributes";
26  return success();
27 }
28 
29 //===----------------------------------------------------------------------===//
30 // AccessGroupOpInterface
31 //===----------------------------------------------------------------------===//
32 
34  auto iface = cast<AccessGroupOpInterface>(op);
35  ArrayAttr accessGroups = iface.getAccessGroupsOrNull();
36  if (!accessGroups)
37  return success();
38 
39  return isArrayOf<AccessGroupAttr>(op, accessGroups);
40 }
41 
42 //===----------------------------------------------------------------------===//
43 // AliasAnalysisOpInterface
44 //===----------------------------------------------------------------------===//
45 
46 LogicalResult
48  auto iface = cast<AliasAnalysisOpInterface>(op);
49 
50  if (auto aliasScopes = iface.getAliasScopesOrNull())
51  if (failed(isArrayOf<AliasScopeAttr>(op, aliasScopes)))
52  return failure();
53 
54  if (auto noAliasScopes = iface.getNoAliasScopesOrNull())
55  if (failed(isArrayOf<AliasScopeAttr>(op, noAliasScopes)))
56  return failure();
57 
58  ArrayAttr tags = iface.getTBAATagsOrNull();
59  if (!tags)
60  return success();
61 
62  return isArrayOf<TBAATagAttr>(op, tags);
63 }
64 
65 //===----------------------------------------------------------------------===//
66 // DereferenceableOpInterface
67 //===----------------------------------------------------------------------===//
68 
69 LogicalResult
71  auto iface = cast<DereferenceableOpInterface>(op);
72 
73  if (auto derefAttr = iface.getDereferenceableOrNull())
74  if (op->getNumResults() != 1 ||
75  !mlir::isa<LLVMPointerType>(op->getResult(0).getType()))
76  return op->emitOpError(
77  "expected op to return a single LLVM pointer type");
78 
79  return success();
80 }
81 
82 SmallVector<Value> mlir::LLVM::AtomicCmpXchgOp::getAccessedOperands() {
83  return {getPtr()};
84 }
85 
86 SmallVector<Value> mlir::LLVM::AtomicRMWOp::getAccessedOperands() {
87  return {getPtr()};
88 }
89 
90 SmallVector<Value> mlir::LLVM::LoadOp::getAccessedOperands() {
91  return {getAddr()};
92 }
93 
94 SmallVector<Value> mlir::LLVM::StoreOp::getAccessedOperands() {
95  return {getAddr()};
96 }
97 
98 SmallVector<Value> mlir::LLVM::MemcpyOp::getAccessedOperands() {
99  return {getDst(), getSrc()};
100 }
101 
102 SmallVector<Value> mlir::LLVM::MemcpyInlineOp::getAccessedOperands() {
103  return {getDst(), getSrc()};
104 }
105 
106 SmallVector<Value> mlir::LLVM::MemmoveOp::getAccessedOperands() {
107  return {getDst(), getSrc()};
108 }
109 
110 SmallVector<Value> mlir::LLVM::MemsetOp::getAccessedOperands() {
111  return {getDst()};
112 }
113 
114 SmallVector<Value> mlir::LLVM::MemsetInlineOp::getAccessedOperands() {
115  return {getDst()};
116 }
117 
118 SmallVector<Value> mlir::LLVM::CallOp::getAccessedOperands() {
119  return llvm::filter_to_vector(getArgOperands(), [](Value arg) {
120  return isa<LLVMPointerType>(arg.getType());
121  });
122 }
123 
124 #include "mlir/Dialect/LLVMIR/LLVMInterfaces.cpp.inc"
static LogicalResult isArrayOf(Operation *op, ArrayAttr array)
Verifies that all elements of array are instances of Attr.
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.
Definition: Operation.cpp:673
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.