MLIR  19.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 
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 SmallVector<Value> mlir::LLVM::AtomicCmpXchgOp::getAccessedOperands() {
66  return {getPtr()};
67 }
68 
69 SmallVector<Value> mlir::LLVM::AtomicRMWOp::getAccessedOperands() {
70  return {getPtr()};
71 }
72 
73 SmallVector<Value> mlir::LLVM::LoadOp::getAccessedOperands() {
74  return {getAddr()};
75 }
76 
77 SmallVector<Value> mlir::LLVM::StoreOp::getAccessedOperands() {
78  return {getAddr()};
79 }
80 
81 SmallVector<Value> mlir::LLVM::MemcpyOp::getAccessedOperands() {
82  return {getDst(), getSrc()};
83 }
84 
85 SmallVector<Value> mlir::LLVM::MemcpyInlineOp::getAccessedOperands() {
86  return {getDst(), getSrc()};
87 }
88 
89 SmallVector<Value> mlir::LLVM::MemmoveOp::getAccessedOperands() {
90  return {getDst(), getSrc()};
91 }
92 
93 SmallVector<Value> mlir::LLVM::MemsetOp::getAccessedOperands() {
94  return {getDst()};
95 }
96 
97 SmallVector<Value> mlir::LLVM::CallOp::getAccessedOperands() {
98  return llvm::to_vector(
99  llvm::make_filter_range(getArgOperands(), [](Value arg) {
100  return isa<LLVMPointerType>(arg.getType());
101  }));
102 }
103 
104 #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
InFlightDiagnostic emitOpError(const Twine &message={})
Emit an error with the op name prefixed, like "'dim' op " which is convenient for verifiers.
Definition: Operation.cpp:671
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:125
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.
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:62
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
Definition: LogicalResult.h:72
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26