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 fir {
22
24
25struct NameUniquer;
26
27#define GEN_PASS_DECL_FIRTOLLVMLOWERING
28#define GEN_PASS_DECL_CODEGENREWRITE
29#define GEN_PASS_DECL_REMATERIALIZEFIRBOXOPSPASS
30#define GEN_PASS_DECL_TARGETREWRITEPASS
31#define GEN_PASS_DECL_BOXEDPROCEDUREPASS
32#define GEN_PASS_DECL_LOWERREPACKARRAYSPASS
33#include "flang/Optimizer/CodeGen/CGPasses.h.inc"
34
37 // Do not fail when type descriptors are not found when translating
38 // operations that use them at the LLVM level like fir.embox. Instead,
39 // just use a null pointer.
40 // This is useful to test translating programs manually written where a
41 // frontend did not generate type descriptor data structures. However, note
42 // that such programs would crash at runtime if the derived type descriptors
43 // are required by the runtime, so this is only an option to help debugging.
44 bool ignoreMissingTypeDescriptors = false;
45 // Similar to ignoreMissingTypeDescriptors, but generate external declaration
46 // for the missing type descriptor globals instead.
47 bool skipExternalRttiDefinition = false;
48
49 // Generate TBAA information for FIR types and memory accessing operations.
50 bool applyTBAA = false;
51
52 // Force the usage of a unified tbaa tree in TBAABuilder.
53 bool forceUnifiedTBAATree = false;
54
55 // If set to true, then the global variables created
56 // for the derived types have been renamed to avoid usage
57 // of special symbols that may not be supported by all targets.
58 // The renaming is done by the CompilerGeneratedNamesConversion pass.
59 // If it is true, FIR-to-LLVM pass has to use
60 // fir::NameUniquer::getTypeDescriptorAssemblyName() to take
61 // the name of the global variable corresponding to a derived
62 // type's descriptor.
63 bool typeDescriptorsRenamedForAssembly = false;
64
65 // Name of the function to call when allocating CUDA Fortran descriptors
66 // during FIR-to-LLVM lowering. Must have the same signature as
67 // CUFAllocDescriptor. Empty defaults to CUFAllocDescriptor.
68 std::string cudaDescriptorAllocFunction;
69
70 // Specify the calculation method for complex number division used by the
71 // Conversion pass of the MLIR complex dialect.
74
75 // Suffix appended to the libc allocator name (malloc, free, aligned_alloc,
76 // posix_memalign) for allocations marked with a heap allocation mode, e.g.
77 // malloc -> malloc_unified. Lets a runtime name its entry points otherwise.
78 std::string unifiedHeapAllocSuffix = "_unified";
79 std::string managedHeapAllocSuffix = "_managed";
80};
81
83std::unique_ptr<mlir::Pass> createFIRToLLVMPass();
84
86std::unique_ptr<mlir::Pass> createFIRToLLVMPass(FIRToLLVMPassOptions options);
87
88using LLVMIRLoweringPrinter =
89 std::function<void(llvm::Module &, llvm::raw_ostream &)>;
90
92std::unique_ptr<mlir::Pass> createLLVMDialectToLLVMPass(
93 llvm::raw_ostream &output,
94 LLVMIRLoweringPrinter printer =
95 [](llvm::Module &m, llvm::raw_ostream &out) { m.print(out, nullptr); });
96
99 const fir::LLVMTypeConverter &converter, mlir::RewritePatternSet &patterns,
101
103void populatePreCGRewritePatterns(mlir::RewritePatternSet &patterns,
104 bool preserveDeclare);
105
106// declarative passes
107#define GEN_PASS_REGISTRATION
108#include "flang/Optimizer/CodeGen/CGPasses.h.inc"
109
110} // namespace fir
111
112#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
std::unique_ptr< mlir::Pass > createFIRToLLVMPass()
Convert FIR to the LLVM IR dialect with default options.
Definition CodeGen.cpp:4954
void populatePreCGRewritePatterns(mlir::RewritePatternSet &patterns, bool preserveDeclare)
Populate the pattern set with the PreCGRewrite patterns.
Definition PreCGRewrite.cpp:473
std::unique_ptr< mlir::Pass > createLLVMDialectToLLVMPass(llvm::raw_ostream &output, LLVMIRLoweringPrinter printer=[](llvm::Module &m, llvm::raw_ostream &out) { m.print(out, nullptr);})
Convert the LLVM IR dialect to LLVM-IR proper.
Definition CodeGen.cpp:4964
void populateFIRToLLVMConversionPatterns(const fir::LLVMTypeConverter &converter, mlir::RewritePatternSet &patterns, fir::FIRToLLVMPassOptions &options)
Populate the given list with patterns that convert from FIR to LLVM.
Definition CodeGen.cpp:4969
FIR to LLVM translation pass options.
Definition CodeGen.h:36
Definition InternalNames.h:44