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 
17 using namespace mlir;
18 using namespace mlir::LLVM;
19 
20 /// Verifies that all elements of `array` are instances of `Attr`.
21 template <class AttrT>
22 static 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 
47 LogicalResult
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 
70 LogicalResult
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 
83 SmallVector<Value> mlir::LLVM::AtomicCmpXchgOp::getAccessedOperands() {
84  return {getPtr()};
85 }
86 
87 SmallVector<Value> mlir::LLVM::AtomicRMWOp::getAccessedOperands() {
88  return {getPtr()};
89 }
90 
91 SmallVector<Value> mlir::LLVM::LoadOp::getAccessedOperands() {
92  return {getAddr()};
93 }
94 
95 SmallVector<Value> mlir::LLVM::StoreOp::getAccessedOperands() {
96  return {getAddr()};
97 }
98 
99 SmallVector<Value> mlir::LLVM::MemcpyOp::getAccessedOperands() {
100  return {getDst(), getSrc()};
101 }
102 
103 SmallVector<Value> mlir::LLVM::MemcpyInlineOp::getAccessedOperands() {
104  return {getDst(), getSrc()};
105 }
106 
107 SmallVector<Value> mlir::LLVM::MemmoveOp::getAccessedOperands() {
108  return {getDst(), getSrc()};
109 }
110 
111 SmallVector<Value> mlir::LLVM::MemsetOp::getAccessedOperands() {
112  return {getDst()};
113 }
114 
115 SmallVector<Value> mlir::LLVM::MemsetInlineOp::getAccessedOperands() {
116  return {getDst()};
117 }
118 
119 SmallVector<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"
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:672
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.