Skip to content

Commit 51a60d1

Browse files
author
Tarun Prabhu
committed
[flang] Refactor to remove .inc file containing shared code
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 e584278 commit 51a60d1

File tree

15 files changed

+622
-447
lines changed

15 files changed

+622
-447
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+
//===-- CommandLineOptions.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_COMMON_COMMANDLINEOPTS_H
13+
#define FORTRAN_COMMON_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_COMMON_COMMANDLINE_OPTS_H
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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/Common/CommandLineOpts.h"
16+
#include "flang/Optimizer/CodeGen/CodeGen.h"
17+
#include "flang/Optimizer/HLFIR/Passes.h"
18+
#include "flang/Optimizer/OpenMP/Passes.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 {
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+
} // namespace
63+
64+
namespace fir {
65+
66+
void addDebugInfoPass(mlir::PassManager &pm,
67+
llvm::codegenoptions::DebugInfoKind debugLevel,
68+
llvm::OptimizationLevel optLevel,
69+
llvm::StringRef inputFilename);
70+
71+
void addFIRToLLVMPass(mlir::PassManager &pm,
72+
const MLIRToLLVMPassPipelineConfig &config);
73+
74+
void addLLVMDialectToLLVMPass(mlir::PassManager &pm, llvm::raw_ostream &output);
75+
76+
/// Use inliner extension point callback to register the default inliner pass.
77+
void registerDefaultInlinerPass(MLIRToLLVMPassPipelineConfig &config);
78+
79+
/// Create a pass pipeline for running default optimization passes for
80+
/// incremental conversion of FIR.
81+
///
82+
/// \param pm - MLIR pass manager that will hold the pipeline definition
83+
void createDefaultFIROptimizerPassPipeline(mlir::PassManager &pm,
84+
MLIRToLLVMPassPipelineConfig &pc);
85+
86+
/// Create a pass pipeline for lowering from HLFIR to FIR
87+
///
88+
/// \param pm - MLIR pass manager that will hold the pipeline definition
89+
/// \param optLevel - optimization level used for creating FIR optimization
90+
/// passes pipeline
91+
void createHLFIRToFIRPassPipeline(
92+
mlir::PassManager &pm, llvm::OptimizationLevel optLevel = defaultOptLevel);
93+
94+
/// Create a pass pipeline for handling certain OpenMP transformations needed
95+
/// prior to FIR lowering.
96+
///
97+
/// WARNING: These passes must be run immediately after the lowering to ensure
98+
/// that the FIR is correct with respect to OpenMP operations/attributes.
99+
///
100+
/// \param pm - MLIR pass manager that will hold the pipeline definition.
101+
/// \param isTargetDevice - Whether code is being generated for a target device
102+
/// rather than the host device.
103+
void createOpenMPFIRPassPipeline(mlir::PassManager &pm, bool isTargetDevice);
104+
105+
#if !defined(FLANG_EXCLUDE_CODEGEN)
106+
void createDebugPasses(mlir::PassManager &pm,
107+
llvm::codegenoptions::DebugInfoKind debugLevel,
108+
llvm::OptimizationLevel OptLevel,
109+
llvm::StringRef inputFilename);
110+
111+
void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
112+
MLIRToLLVMPassPipelineConfig config,
113+
llvm::StringRef inputFilename = {});
114+
115+
/// Create a pass pipeline for lowering from MLIR to LLVM IR
116+
///
117+
/// \param pm - MLIR pass manager that will hold the pipeline definition
118+
/// \param optLevel - optimization level used for creating FIR optimization
119+
/// passes pipeline
120+
void createMLIRToLLVMPassPipeline(mlir::PassManager &pm,
121+
MLIRToLLVMPassPipelineConfig &config,
122+
llvm::StringRef inputFilename = {});
123+
#undef FLANG_EXCLUDE_CODEGEN
124+
#endif
125+
126+
} // namespace fir
127+
128+
#endif // FORTRAN_OPTIMIZER_PASSES_PIPELINES_H

0 commit comments

Comments
 (0)