Skip to content

Commit c3201dd

Browse files
authored
[flang][NFC] Refactor to remove .inc file containing shared code (#109874)
Remove flang/include/flang/Tools/CLOptions.inc - which was included as is in - several places. Move the code in it to header and source files which are used used in the "standard" way. Some minor cleanup such as removing trailing whitespace and excessive newlines and reordering entries alphabetically for files that were modified along the way. Update the documentation that referenced CLOptions.inc.
1 parent eb48aac commit c3201dd

File tree

15 files changed

+671
-473
lines changed

15 files changed

+671
-473
lines changed

flang/docs/FlangDriver.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ e.g. during the semantic checks.
521521
## FIR Optimizer Pass Pipeline Extension Points
522522

523523
The default FIR optimizer pass pipeline `createDefaultFIROptimizerPassPipeline`
524-
in `flang/include/flang/Tools/CLOptions.inc` contains extension point callback
524+
in `flang/lib/Optimizer/Passes/Pipelines.cpp` contains extension point callback
525525
invocations `invokeFIROptEarlyEPCallbacks`, `invokeFIRInlinerCallback`, and
526526
`invokeFIROptLastEPCallbacks` for Flang drivers to be able to insert additonal
527527
passes at different points of the default pass pipeline. An example use of these
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//===-- CommandLineOpts.h -- shared command line options --------*- 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+
/// This file declares some shared command-line options that can be used when
10+
/// debugging the test tools.
11+
12+
#ifndef FORTRAN_OPTIMIZER_PASSES_COMMANDLINEOPTS_H
13+
#define FORTRAN_OPTIMIZER_PASSES_COMMANDLINEOPTS_H
14+
15+
#include "llvm/Frontend/Debug/Options.h"
16+
#include "llvm/Passes/OptimizationLevel.h"
17+
#include "llvm/Support/CommandLine.h"
18+
19+
/// Shared option in tools to control whether dynamically sized array
20+
/// allocations should always be on the heap.
21+
extern llvm::cl::opt<bool> dynamicArrayStackToHeapAllocation;
22+
23+
/// Shared option in tools to set a maximum value for the number of elements in
24+
/// a compile-time sized array that can be allocated on the stack.
25+
extern llvm::cl::opt<std::size_t> arrayStackAllocationThreshold;
26+
27+
/// Shared option in tools to ignore missing runtime type descriptor objects
28+
/// when translating FIR to LLVM. The resulting program will crash if the
29+
/// runtime needs the derived type descriptors, this is only a debug option to
30+
/// allow compiling manually written FIR programs involving derived types
31+
/// without having to write the derived type descriptors which are normally
32+
/// generated by the frontend.
33+
extern llvm::cl::opt<bool> ignoreMissingTypeDescriptors;
34+
35+
/// Default optimization level used to create Flang pass pipeline is O0.
36+
extern llvm::OptimizationLevel defaultOptLevel;
37+
38+
extern llvm::codegenoptions::DebugInfoKind noDebugInfo;
39+
40+
/// Optimizer Passes
41+
extern llvm::cl::opt<bool> disableCfgConversion;
42+
extern llvm::cl::opt<bool> disableFirAvc;
43+
extern llvm::cl::opt<bool> disableFirMao;
44+
45+
extern llvm::cl::opt<bool> disableFirAliasTags;
46+
extern llvm::cl::opt<bool> useOldAliasTags;
47+
48+
/// CodeGen Passes
49+
extern llvm::cl::opt<bool> disableCodeGenRewrite;
50+
extern llvm::cl::opt<bool> disableTargetRewrite;
51+
extern llvm::cl::opt<bool> disableDebugInfo;
52+
extern llvm::cl::opt<bool> disableFirToLlvmIr;
53+
extern llvm::cl::opt<bool> disableLlvmIrToLlvm;
54+
extern llvm::cl::opt<bool> disableBoxedProcedureRewrite;
55+
56+
extern llvm::cl::opt<bool> disableExternalNameConversion;
57+
extern llvm::cl::opt<bool> enableConstantArgumentGlobalisation;
58+
extern llvm::cl::opt<bool> disableCompilerGeneratedNamesConversion;
59+
60+
#endif // FORTRAN_OPTIMIZER_PASSES_COMMANDLINE_OPTS_H
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
//===-- Pipelines.h -- FIR pass pipelines -----------------------*- 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+
/// This file declares some utilties to setup FIR pass pipelines. These are
10+
/// common to flang and the test tools.
11+
12+
#ifndef FORTRAN_OPTIMIZER_PASSES_PIPELINES_H
13+
#define FORTRAN_OPTIMIZER_PASSES_PIPELINES_H
14+
15+
#include "flang/Optimizer/CodeGen/CodeGen.h"
16+
#include "flang/Optimizer/HLFIR/Passes.h"
17+
#include "flang/Optimizer/OpenMP/Passes.h"
18+
#include "flang/Optimizer/Passes/CommandLineOpts.h"
19+
#include "flang/Optimizer/Transforms/Passes.h"
20+
#include "flang/Tools/CrossToolHelpers.h"
21+
#include "mlir/Conversion/ReconcileUnrealizedCasts/ReconcileUnrealizedCasts.h"
22+
#include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h"
23+
#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
24+
#include "mlir/Pass/PassManager.h"
25+
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
26+
#include "mlir/Transforms/Passes.h"
27+
#include "llvm/Frontend/Debug/Options.h"
28+
#include "llvm/Passes/OptimizationLevel.h"
29+
#include "llvm/Support/CommandLine.h"
30+
31+
namespace fir {
32+
33+
using PassConstructor = std::unique_ptr<mlir::Pass>();
34+
35+
template <typename OP>
36+
void addNestedPassToOps(mlir::PassManager &pm, PassConstructor ctor) {
37+
pm.addNestedPass<OP>(ctor());
38+
}
39+
40+
template <typename OP, typename... OPS,
41+
typename = std::enable_if_t<sizeof...(OPS) != 0>>
42+
void addNestedPassToOps(mlir::PassManager &pm, PassConstructor ctor) {
43+
addNestedPassToOps<OP>(pm, ctor);
44+
addNestedPassToOps<OPS...>(pm, ctor);
45+
}
46+
47+
/// Generic for adding a pass to the pass manager if it is not disabled.
48+
template <typename F>
49+
void addPassConditionally(mlir::PassManager &pm, llvm::cl::opt<bool> &disabled,
50+
F ctor) {
51+
if (!disabled)
52+
pm.addPass(ctor());
53+
}
54+
55+
template <typename OP, typename F>
56+
void addNestedPassConditionally(mlir::PassManager &pm,
57+
llvm::cl::opt<bool> &disabled, F ctor) {
58+
if (!disabled)
59+
pm.addNestedPass<OP>(ctor());
60+
}
61+
62+
void addNestedPassToAllTopLevelOperations(mlir::PassManager &pm,
63+
PassConstructor ctor);
64+
65+
void addNestedPassToAllTopLevelOperationsConditionally(
66+
mlir::PassManager &pm, llvm::cl::opt<bool> &disabled, PassConstructor ctor);
67+
68+
/// Add MLIR Canonicalizer pass with region simplification disabled.
69+
/// FIR does not support the promotion of some SSA value to block arguments (or
70+
/// into arith.select operands) that may be done by mlir block merging in the
71+
/// region simplification (e.g., !fir.shape<> SSA values are not supported as
72+
/// block arguments).
73+
/// Aside from the fir.shape issue, moving some abstract SSA value into block
74+
/// arguments may have a heavy cost since it forces their code generation that
75+
/// may be expensive (array temporary). The MLIR pass does not take these
76+
/// extra costs into account when doing block merging.
77+
void addCanonicalizerPassWithoutRegionSimplification(mlir::OpPassManager &pm);
78+
79+
void addCfgConversionPass(mlir::PassManager &pm,
80+
const MLIRToLLVMPassPipelineConfig &config);
81+
82+
void addAVC(mlir::PassManager &pm, const llvm::OptimizationLevel &optLevel);
83+
84+
void addMemoryAllocationOpt(mlir::PassManager &pm);
85+
86+
void addCodeGenRewritePass(mlir::PassManager &pm, bool preserveDeclare);
87+
88+
void addTargetRewritePass(mlir::PassManager &pm);
89+
90+
mlir::LLVM::DIEmissionKind
91+
getEmissionKind(llvm::codegenoptions::DebugInfoKind kind);
92+
93+
void addBoxedProcedurePass(mlir::PassManager &pm);
94+
95+
void addExternalNameConversionPass(mlir::PassManager &pm,
96+
bool appendUnderscore = true);
97+
98+
void addCompilerGeneratedNamesConversionPass(mlir::PassManager &pm);
99+
100+
void addDebugInfoPass(mlir::PassManager &pm,
101+
llvm::codegenoptions::DebugInfoKind debugLevel,
102+
llvm::OptimizationLevel optLevel,
103+
llvm::StringRef inputFilename);
104+
105+
void addFIRToLLVMPass(mlir::PassManager &pm,
106+
const MLIRToLLVMPassPipelineConfig &config);
107+
108+
void addLLVMDialectToLLVMPass(mlir::PassManager &pm, llvm::raw_ostream &output);
109+
110+
/// Use inliner extension point callback to register the default inliner pass.
111+
void registerDefaultInlinerPass(MLIRToLLVMPassPipelineConfig &config);
112+
113+
/// Create a pass pipeline for running default optimization passes for
114+
/// incremental conversion of FIR.
115+
///
116+
/// \param pm - MLIR pass manager that will hold the pipeline definition
117+
void createDefaultFIROptimizerPassPipeline(mlir::PassManager &pm,
118+
MLIRToLLVMPassPipelineConfig &pc);
119+
120+
/// Create a pass pipeline for lowering from HLFIR to FIR
121+
///
122+
/// \param pm - MLIR pass manager that will hold the pipeline definition
123+
/// \param optLevel - optimization level used for creating FIR optimization
124+
/// passes pipeline
125+
void createHLFIRToFIRPassPipeline(
126+
mlir::PassManager &pm, llvm::OptimizationLevel optLevel = defaultOptLevel);
127+
128+
/// Create a pass pipeline for handling certain OpenMP transformations needed
129+
/// prior to FIR lowering.
130+
///
131+
/// WARNING: These passes must be run immediately after the lowering to ensure
132+
/// that the FIR is correct with respect to OpenMP operations/attributes.
133+
///
134+
/// \param pm - MLIR pass manager that will hold the pipeline definition.
135+
/// \param isTargetDevice - Whether code is being generated for a target device
136+
/// rather than the host device.
137+
void createOpenMPFIRPassPipeline(mlir::PassManager &pm, bool isTargetDevice);
138+
139+
#if !defined(FLANG_EXCLUDE_CODEGEN)
140+
void createDebugPasses(mlir::PassManager &pm,
141+
llvm::codegenoptions::DebugInfoKind debugLevel,
142+
llvm::OptimizationLevel OptLevel,
143+
llvm::StringRef inputFilename);
144+
145+
void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
146+
MLIRToLLVMPassPipelineConfig config,
147+
llvm::StringRef inputFilename = {});
148+
149+
/// Create a pass pipeline for lowering from MLIR to LLVM IR
150+
///
151+
/// \param pm - MLIR pass manager that will hold the pipeline definition
152+
/// \param optLevel - optimization level used for creating FIR optimization
153+
/// passes pipeline
154+
void createMLIRToLLVMPassPipeline(mlir::PassManager &pm,
155+
MLIRToLLVMPassPipelineConfig &config,
156+
llvm::StringRef inputFilename = {});
157+
#undef FLANG_EXCLUDE_CODEGEN
158+
#endif
159+
160+
} // namespace fir
161+
162+
#endif // FORTRAN_OPTIMIZER_PASSES_PIPELINES_H

0 commit comments

Comments
 (0)