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 "mlir/IR/BuiltinOps.h"
13#include "mlir/Pass/Pass.h"
14#include "mlir/Pass/PassRegistry.h"
15#include "llvm/IR/Module.h"
16#include "llvm/Support/raw_ostream.h"
17#include <memory>
18
19namespace fir {
20
21class LLVMTypeConverter;
22
23struct NameUniquer;
24
25#define GEN_PASS_DECL_FIRTOLLVMLOWERING
26#define GEN_PASS_DECL_CODEGENREWRITE
27#define GEN_PASS_DECL_TARGETREWRITEPASS
28#define GEN_PASS_DECL_BOXEDPROCEDUREPASS
29#include "flang/Optimizer/CodeGen/CGPasses.h.inc"
30
33 // Do not fail when type descriptors are not found when translating
34 // operations that use them at the LLVM level like fir.embox. Instead,
35 // just use a null pointer.
36 // This is useful to test translating programs manually written where a
37 // frontend did not generate type descriptor data structures. However, note
38 // that such programs would crash at runtime if the derived type descriptors
39 // are required by the runtime, so this is only an option to help debugging.
40 bool ignoreMissingTypeDescriptors = false;
41
42 // Generate TBAA information for FIR types and memory accessing operations.
43 bool applyTBAA = false;
44
45 // Force the usage of a unified tbaa tree in TBAABuilder.
46 bool forceUnifiedTBAATree = false;
47
48 // If set to true, then the global variables created
49 // for the derived types have been renamed to avoid usage
50 // of special symbols that may not be supported by all targets.
51 // The renaming is done by the CompilerGeneratedNamesConversion pass.
52 // If it is true, FIR-to-LLVM pass has to use
53 // fir::NameUniquer::getTypeDescriptorAssemblyName() to take
54 // the name of the global variable corresponding to a derived
55 // type's descriptor.
56 bool typeDescriptorsRenamedForAssembly = false;
57};
58
60std::unique_ptr<mlir::Pass> createFIRToLLVMPass();
61
63std::unique_ptr<mlir::Pass> createFIRToLLVMPass(FIRToLLVMPassOptions options);
64
65using LLVMIRLoweringPrinter =
66 std::function<void(llvm::Module &, llvm::raw_ostream &)>;
67
69std::unique_ptr<mlir::Pass> createLLVMDialectToLLVMPass(
70 llvm::raw_ostream &output,
71 LLVMIRLoweringPrinter printer =
72 [](llvm::Module &m, llvm::raw_ostream &out) { m.print(out, nullptr); });
73
76 const fir::LLVMTypeConverter &converter, mlir::RewritePatternSet &patterns,
78
80void populatePreCGRewritePatterns(mlir::RewritePatternSet &patterns,
81 bool preserveDeclare);
82
83// declarative passes
84#define GEN_PASS_REGISTRATION
85#include "flang/Optimizer/CodeGen/CGPasses.h.inc"
86
87} // namespace fir
88
89#endif // FORTRAN_OPTIMIZER_CODEGEN_CODEGEN_H
Definition: TypeConverter.h:50
Definition: AbstractConverter.h:31
std::unique_ptr< mlir::Pass > createFIRToLLVMPass()
Convert FIR to the LLVM IR dialect with default options.
Definition: CodeGen.cpp:4027
void populatePreCGRewritePatterns(mlir::RewritePatternSet &patterns, bool preserveDeclare)
Populate the pattern set with the PreCGRewrite patterns.
Definition: PreCGRewrite.cpp:384
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:4037
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:4042
FIR to LLVM translation pass options.
Definition: CodeGen.h:32