xref: /llvm-project/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h (revision 839344f025fb7eff529735873f327330618b2ebb)
1 //===-- Optimizer/Support/FIRContext.h --------------------------*- 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 // Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
10 //
11 //===----------------------------------------------------------------------===//
12 /// Setters and getters for associating context with an instance of a ModuleOp.
13 /// The context is typically set by the tool and needed in later stages to
14 /// determine how to correctly generate code.
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef FORTRAN_OPTIMIZER_SUPPORT_FIRCONTEXT_H
18 #define FORTRAN_OPTIMIZER_SUPPORT_FIRCONTEXT_H
19 
20 #include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/TargetParser/Triple.h"
23 
24 namespace mlir {
25 class ModuleOp;
26 class Operation;
27 } // namespace mlir
28 
29 namespace fir {
30 class KindMapping;
31 struct NameUniquer;
32 
33 /// Set the target triple for the module. `triple` must not be deallocated while
34 /// module `mod` is still live.
35 void setTargetTriple(mlir::ModuleOp mod, llvm::StringRef triple);
36 
37 /// Get the Triple instance from the Module or return the default Triple.
38 llvm::Triple getTargetTriple(mlir::ModuleOp mod);
39 
40 /// Set the kind mapping for the module. `kindMap` must not be deallocated while
41 /// module `mod` is still live.
42 void setKindMapping(mlir::ModuleOp mod, KindMapping &kindMap);
43 
44 /// Get the KindMapping instance from the Module. If none was set, returns a
45 /// default.
46 KindMapping getKindMapping(mlir::ModuleOp mod);
47 
48 /// Get the KindMapping instance that is in effect for the specified
49 /// operation. The KindMapping is taken from the operation itself,
50 /// if the operation is a ModuleOp, or from its parent ModuleOp.
51 /// If a ModuleOp cannot be reached, the function returns default KindMapping.
52 KindMapping getKindMapping(mlir::Operation *op);
53 
54 /// Set the target CPU for the module. `cpu` must not be deallocated while
55 /// module `mod` is still live.
56 void setTargetCPU(mlir::ModuleOp mod, llvm::StringRef cpu);
57 
58 /// Get the target CPU string from the Module or return a null reference.
59 llvm::StringRef getTargetCPU(mlir::ModuleOp mod);
60 
61 /// Set the tune CPU for the module. `cpu` must not be deallocated while
62 /// module `mod` is still live.
63 void setTuneCPU(mlir::ModuleOp mod, llvm::StringRef cpu);
64 
65 /// Get the tune CPU string from the Module or return a null reference.
66 llvm::StringRef getTuneCPU(mlir::ModuleOp mod);
67 
68 /// Set the target features for the module.
69 void setTargetFeatures(mlir::ModuleOp mod, llvm::StringRef features);
70 
71 /// Get the target features from the Module.
72 mlir::LLVM::TargetFeaturesAttr getTargetFeatures(mlir::ModuleOp mod);
73 
74 /// Set the compiler identifier for the module.
75 void setIdent(mlir::ModuleOp mod, llvm::StringRef ident);
76 
77 /// Get the compiler identifier from the Module.
78 llvm::StringRef getIdent(mlir::ModuleOp mod);
79 
80 /// Set the command line used in this invocation.
81 void setCommandline(mlir::ModuleOp mod, llvm::StringRef cmdLine);
82 
83 /// Get the command line used in this invocation.
84 llvm::StringRef getCommandline(mlir::ModuleOp mod);
85 
86 /// Helper for determining the target from the host, etc. Tools may use this
87 /// function to provide a consistent interpretation of the `--target=<string>`
88 /// command-line option.
89 /// An empty string ("") or "default" will specify that the default triple
90 /// should be used. "native" will specify that the host machine be used to
91 /// construct the triple.
92 std::string determineTargetTriple(llvm::StringRef triple);
93 
94 } // namespace fir
95 
96 #endif // FORTRAN_OPTIMIZER_SUPPORT_FIRCONTEXT_H
97