FLANG
CodeGen.h
1//===-- Optimizer/CodeGen/CodeGen.h -- code generation ----------*- 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 FORTRAN_OPTIMIZER_CODEGEN_CODEGEN_H
10#define FORTRAN_OPTIMIZER_CODEGEN_CODEGEN_H
11
12#include "flang/Frontend/CodeGenOptions.h"
13#include "mlir/IR/BuiltinOps.h"
14#include "mlir/Pass/Pass.h"
15#include "mlir/Pass/PassRegistry.h"
16#include "llvm/IR/Module.h"
17#include "llvm/Support/raw_ostream.h"
18#include <memory>
19#include <string>
20
21namespace mlir {
22class SymbolTableCollection;
23} // namespace mlir
24
25namespace fir {
26
28
29struct NameUniquer;
30
31#define GEN_PASS_DECL_FIRTOLLVMLOWERING
32#define GEN_PASS_DECL_CODEGENREWRITE
33#define GEN_PASS_DECL_REMATERIALIZEFIRBOXOPSPASS
34#define GEN_PASS_DECL_TARGETREWRITEPASS
35#define GEN_PASS_DECL_BOXEDPROCEDUREPASS
36#define GEN_PASS_DECL_LOWERREPACKARRAYSPASS
37#include "flang/Optimizer/CodeGen/CGPasses.h.inc"
38
41 // Do not fail when type descriptors are not found when translating
42 // operations that use them at the LLVM level like fir.embox. Instead,
43 // just use a null pointer.
44 // This is useful to test translating programs manually written where a
45 // frontend did not generate type descriptor data structures. However, note
46 // that such programs would crash at runtime if the derived type descriptors
47 // are required by the runtime, so this is only an option to help debugging.
48 bool ignoreMissingTypeDescriptors = false;
49 // Similar to ignoreMissingTypeDescriptors, but generate external declaration
50 // for the missing type descriptor globals instead.
51 bool skipExternalRttiDefinition = false;
52
53 // Generate TBAA information for FIR types and memory accessing operations.
54 bool applyTBAA = false;
55
56 // Force the usage of a unified tbaa tree in TBAABuilder.
57 bool forceUnifiedTBAATree = false;
58
59 // If set to true, then the global variables created
60 // for the derived types have been renamed to avoid usage
61 // of special symbols that may not be supported by all targets.
62 // The renaming is done by the CompilerGeneratedNamesConversion pass.
63 // If it is true, FIR-to-LLVM pass has to use
64 // fir::NameUniquer::getTypeDescriptorAssemblyName() to take
65 // the name of the global variable corresponding to a derived
66 // type's descriptor.
67 bool typeDescriptorsRenamedForAssembly = false;
68
69 // Name of the function to call when allocating CUDA Fortran descriptors
70 // during FIR-to-LLVM lowering. Must have the same signature as
71 // CUFAllocDescriptor. Empty defaults to CUFAllocDescriptor.
72 std::string cudaDescriptorAllocFunction;
73
74 // Specify the calculation method for complex number division used by the
75 // Conversion pass of the MLIR complex dialect.
78
79 // Suffix appended to the libc allocator name (malloc, free, aligned_alloc,
80 // posix_memalign) for allocations marked with a heap allocation mode, e.g.
81 // malloc -> malloc_unified. Lets a runtime name its entry points otherwise.
82 std::string unifiedHeapAllocSuffix = "_unified";
83 std::string managedHeapAllocSuffix = "_managed";
84};
85
87std::unique_ptr<mlir::Pass> createFIRToLLVMPass();
88
90std::unique_ptr<mlir::Pass> createFIRToLLVMPass(FIRToLLVMPassOptions options);
91
92using LLVMIRLoweringPrinter =
93 std::function<void(llvm::Module &, llvm::raw_ostream &)>;
94
96std::unique_ptr<mlir::Pass> createLLVMDialectToLLVMPass(
97 llvm::raw_ostream &output, LLVMIRLoweringPrinter printer =
98 [](llvm::Module &m, llvm::raw_ostream &out) {
99 m.renumberMetadataForAssembly();
100 m.print(out, nullptr);
101 });
102
109 const fir::LLVMTypeConverter &converter, mlir::RewritePatternSet &patterns,
111 mlir::SymbolTableCollection *symbolTables = nullptr);
112
114void populatePreCGRewritePatterns(mlir::RewritePatternSet &patterns,
115 bool preserveDeclare);
116
117// declarative passes
118#define GEN_PASS_REGISTRATION
119#include "flang/Optimizer/CodeGen/CGPasses.h.inc"
120
121} // namespace fir
122
123#endif // FORTRAN_OPTIMIZER_CODEGEN_CODEGEN_H
ComplexRangeKind
Controls the various implementations for complex division.
Definition CodeGenOptions.h:211
@ CX_Full
Definition CodeGenOptions.h:215
Definition TypeConverter.h:49
Definition AbstractConverter.h:37
void populateFIRToLLVMConversionPatterns(const fir::LLVMTypeConverter &converter, mlir::RewritePatternSet &patterns, fir::FIRToLLVMPassOptions &options, mlir::SymbolTableCollection *symbolTables=nullptr)
Definition CodeGen.cpp:5385
std::unique_ptr< mlir::Pass > createFIRToLLVMPass()
Convert FIR to the LLVM IR dialect with default options.
Definition CodeGen.cpp:5370
void populatePreCGRewritePatterns(mlir::RewritePatternSet &patterns, bool preserveDeclare)
Populate the pattern set with the PreCGRewrite patterns.
Definition PreCGRewrite.cpp:621
std::unique_ptr< mlir::Pass > createLLVMDialectToLLVMPass(llvm::raw_ostream &output, LLVMIRLoweringPrinter printer=[](llvm::Module &m, llvm::raw_ostream &out) { m.renumberMetadataForAssembly();m.print(out, nullptr);})
Convert the LLVM IR dialect to LLVM-IR proper.
Definition CodeGen.cpp:5380
Definition AbstractConverter.h:32
FIR to LLVM translation pass options.
Definition CodeGen.h:40
Definition InternalNames.h:44