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 | |
13 | #include "mlir/Dialect/LLVMIR/LLVMInterfaces.h" |
14 | #include "mlir/Dialect/LLVMIR/LLVMDialect.h" |
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 | |
33 | LogicalResult mlir::LLVM::detail::verifyAccessGroupOpInterface(Operation *op) { |
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 |
47 | mlir::LLVM::detail::verifyAliasAnalysisOpInterface(Operation *op) { |
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" |
105 | |