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
20namespace fir {
21
22class LLVMTypeConverter;
23
24struct NameUniquer;
25
26#define GEN_PASS_DECL_FIRTOLLVMLOWERING
27#define GEN_PASS_DECL_CODEGENREWRITE
28#define GEN_PASS_DECL_TARGETREWRITEPASS
29#define GEN_PASS_DECL_BOXEDPROCEDUREPASS
30#define GEN_PASS_DECL_LOWERREPACKARRAYSPASS
31#include "flang/Optimizer/CodeGen/CGPasses.h.inc"
32
35 // Do not fail when type descriptors are not found when translating
36 // operations that use them at the LLVM level like fir.embox. Instead,
37 // just use a null pointer.
38 // This is useful to test translating programs manually written where a
39 // frontend did not generate type descriptor data structures. However, note
40 // that such programs would crash at runtime if the derived type descriptors
41 // are required by the runtime, so this is only an option to help debugging.
42 bool ignoreMissingTypeDescriptors = false;
43 // Similar to ignoreMissingTypeDescriptors, but generate external declaration
44 // for the missing type descriptor globals instead.
45 bool skipExternalRttiDefinition = false;
46
47 // Generate TBAA information for FIR types and memory accessing operations.
48 bool applyTBAA = false;
49
50 // Force the usage of a unified tbaa tree in TBAABuilder.
51 bool forceUnifiedTBAATree = false;
52
53 // If set to true, then the global variables created
54 // for the derived types have been renamed to avoid usage
55 // of special symbols that may not be supported by all targets.
56 // The renaming is done by the CompilerGeneratedNamesConversion pass.
57 // If it is true, FIR-to-LLVM pass has to use
58 // fir::NameUniquer::getTypeDescriptorAssemblyName() to take
59 // the name of the global variable corresponding to a derived
60 // type's descriptor.
61 bool typeDescriptorsRenamedForAssembly = false;
62
63 // Specify the calculation method for complex number division used by the
64 // Conversion pass of the MLIR complex dialect.
67};
68
70std::unique_ptr<mlir::Pass> createFIRToLLVMPass();
71
73std::unique_ptr<mlir::Pass> createFIRToLLVMPass(FIRToLLVMPassOptions options);
74
75using LLVMIRLoweringPrinter =
76 std::function<void(llvm::Module &, llvm::raw_ostream &)>;
77
79std::unique_ptr<mlir::Pass> createLLVMDialectToLLVMPass(
80 llvm::raw_ostream &output,
81 LLVMIRLoweringPrinter printer =
82 [](llvm::Module &m, llvm::raw_ostream &out) { m.print(out, nullptr); });
83
86 const fir::LLVMTypeConverter &converter, mlir::RewritePatternSet &patterns,
88
90void populatePreCGRewritePatterns(mlir::RewritePatternSet &patterns,
91 bool preserveDeclare);
92
93// declarative passes
94#define GEN_PASS_REGISTRATION
95#include "flang/Optimizer/CodeGen/CGPasses.h.inc"
96
97} // namespace fir
98
99#endif // FORTRAN_OPTIMIZER_CODEGEN_CODEGEN_H
ComplexRangeKind
Controls the various implementations for complex division.
Definition: CodeGenOptions.h:196
@ CX_Full
Definition: CodeGenOptions.h:200
Definition: TypeConverter.h:50
Definition: AbstractConverter.h:34
std::unique_ptr< mlir::Pass > createFIRToLLVMPass()
Convert FIR to the LLVM IR dialect with default options.
Definition: CodeGen.cpp:4297
void populatePreCGRewritePatterns(mlir::RewritePatternSet &patterns, bool preserveDeclare)
Populate the pattern set with the PreCGRewrite patterns.
Definition: PreCGRewrite.cpp:387
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:4307
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:4312
FIR to LLVM translation pass options.
Definition: CodeGen.h:34