FLANG

FIROpsSupport.h
1 //===-- Optimizer/Dialect/FIROpsSupport.h -- FIR op support -----*- 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 #ifndef OPTIMIZER_DIALECT_FIROPSSUPPORT_H
10 #define OPTIMIZER_DIALECT_FIROPSSUPPORT_H
11
12 #include "flang/Optimizer/Dialect/FIROps.h"
13 #include "mlir/Dialect/StandardOps/IR/Ops.h"
14
15 namespace fir {
16
18 inline bool nonVolatileLoad(mlir::Operation *op) {
19 if (auto load = dyn_cast<fir::LoadOp>(op))
20 return !load.getAttr("volatile");
21 return false;
22 }
23
25 inline bool isaCall(mlir::Operation *op) {
26 return isa<fir::CallOp>(op) || isa<fir::DispatchOp>(op) ||
27 isa<mlir::CallOp>(op) || isa<mlir::CallIndirectOp>(op);
28 }
29
33 inline bool impureCall(mlir::Operation *op) {
34 // Should we also auto-detect that the called function is pure if its
35 // arguments are not references? For now, rely on a "pure" attribute.
36 return op && isaCall(op) && !op->getAttr("pure");
37 }
38
42 inline bool pureCall(mlir::Operation *op) {
43 // Should we also auto-detect that the called function is pure if its
44 // arguments are not references? For now, rely on a "pure" attribute.
45 return op && isaCall(op) && op->getAttr("pure");
46 }
47
52 mlir::FuncOp createFuncOp(mlir::Location loc, mlir::ModuleOp module,
53 llvm::StringRef name, mlir::FunctionType type,
54 llvm::ArrayRef<mlir::NamedAttribute> attrs = {});
55
57 fir::GlobalOp createGlobalOp(mlir::Location loc, mlir::ModuleOp module,
58 llvm::StringRef name, mlir::Type type,
59 llvm::ArrayRef<mlir::NamedAttribute> attrs = {});
60
61 } // namespace fir
62
63 #endif // OPTIMIZER_DIALECT_FIROPSSUPPORT_H
llvm::ArrayRef
Definition: FIRType.h:20