Skip to content

Commit ca6751e

Browse files
committed
[flang][driver] add command line arguments for alias tags pass
The ultimate intention is to have this pass enabled by default whenever we are optimizing for speed. But for now, just add the arguments so this can be more easily tested. Previous PR in this series: #68437
1 parent 56ed3a6 commit ca6751e

File tree

9 files changed

+48
-1
lines changed

9 files changed

+48
-1
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6247,6 +6247,9 @@ defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays",
62476247
defm loop_versioning : BoolOptionWithoutMarshalling<"f", "version-loops-for-stride",
62486248
PosFlag<SetTrue, [], [ClangOption], "Create unit-strided versions of loops">,
62496249
NegFlag<SetFalse, [], [ClangOption], "Do not create unit-strided loops (default)">>;
6250+
defm alias_analysis : BoolOptionWithoutMarshalling<"f", "alias-analysis",
6251+
PosFlag<SetTrue, [], [], "Pass alias information on to LLVM (default when optimizing for speed)">,
6252+
NegFlag<SetFalse, [], [], "Do not pass alias information on to LLVM (default for unoptimized builds)">>;
62506253
} // let Visibility = [FC1Option, FlangOption]
62516254

62526255
def J : JoinedOrSeparate<["-"], "J">,

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ void Flang::addCodegenOptions(const ArgList &Args,
145145
Args.AddAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
146146
options::OPT_flang_experimental_polymorphism,
147147
options::OPT_fno_ppc_native_vec_elem_order,
148-
options::OPT_fppc_native_vec_elem_order});
148+
options::OPT_fppc_native_vec_elem_order,
149+
options::OPT_falias_analysis,
150+
options::OPT_fno_alias_analysis});
149151
}
150152

151153
void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {

flang/include/flang/Frontend/CodeGenOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ CODEGENOPT(PrepareForThinLTO , 1, 0) ///< Set when -flto=thin is enabled on the
3232
///< compile step.
3333
CODEGENOPT(StackArrays, 1, 0) ///< -fstack-arrays (enable the stack-arrays pass)
3434
CODEGENOPT(LoopVersioning, 1, 0) ///< Enable loop versioning.
35+
CODEGENOPT(AliasAnalysis, 1, 0) ///< Enable alias analysis pass
3536

3637
CODEGENOPT(Underscoring, 1, 1)
3738
ENUM_CODEGENOPT(RelocationModel, llvm::Reloc::Model, 3, llvm::Reloc::PIC_) ///< Name of the relocation model to use.

flang/include/flang/Tools/CLOptions.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ DisableOption(CfgConversion, "cfg-conversion", "disable FIR to CFG pass");
6464
DisableOption(FirAvc, "avc", "array value copy analysis and transformation");
6565
DisableOption(
6666
FirMao, "memory-allocation-opt", "memory allocation optimization");
67+
DisableOption(FirAliasTags, "fir-alias-tags", "fir alias analysis");
6768

6869
/// CodeGen Passes
6970
#if !defined(FLANG_EXCLUDE_CODEGEN)
@@ -220,6 +221,9 @@ inline void createDefaultFIROptimizerPassPipeline(
220221
// Polymorphic types
221222
pm.addPass(fir::createPolymorphicOpConversionPass());
222223

224+
if (pc.AliasAnalysis && !disableFirAliasTags)
225+
pm.addPass(fir::createAliasTagsPass());
226+
223227
// convert control flow to CFG form
224228
fir::addCfgConversionPass(pm);
225229
pm.addPass(mlir::createConvertSCFToCFPass());

flang/include/flang/Tools/CrossToolHelpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ struct MLIRToLLVMPassPipelineConfig {
3434
Underscoring = opts.Underscoring;
3535
LoopVersioning = opts.LoopVersioning;
3636
DebugInfo = opts.getDebugInfo();
37+
AliasAnalysis = opts.AliasAnalysis;
3738
}
3839

3940
llvm::OptimizationLevel OptLevel; ///< optimisation level
4041
bool StackArrays = false; ///< convert memory allocations to alloca.
4142
bool Underscoring = true; ///< add underscores to function names.
4243
bool LoopVersioning = false; ///< Run the version loop pass.
44+
bool AliasAnalysis = false; ///< Add TBAA tags to generated LLVMIR
4345
llvm::codegenoptions::DebugInfoKind DebugInfo =
4446
llvm::codegenoptions::NoDebugInfo; ///< Debug info generation.
4547
unsigned VScaleMin = 0; ///< SVE vector range minimum.

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
214214
clang::driver::options::OPT_fno_loop_versioning, false))
215215
opts.LoopVersioning = 1;
216216

217+
opts.AliasAnalysis = false;
218+
if (auto *arg =
219+
args.getLastArg(clang::driver::options::OPT_falias_analysis,
220+
clang::driver::options::OPT_fno_alias_analysis)) {
221+
if (arg->getOption().matches(clang::driver::options::OPT_falias_analysis))
222+
opts.AliasAnalysis = true;
223+
}
224+
217225
for (auto *a : args.filtered(clang::driver::options::OPT_fpass_plugin_EQ))
218226
opts.LLVMPassPlugins.push_back(a->getValue());
219227

flang/test/Driver/driver-help-hidden.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
! CHECK-NEXT: -D <macro>=<value> Define <macro> to <value> (or 1 if <value> omitted)
2525
! CHECK-NEXT: -emit-llvm Use the LLVM representation for assembler and object files
2626
! CHECK-NEXT: -E Only run the preprocessor
27+
! CHECK-NEXT: -falias-analysis Pass alias information on to LLVM (default when optimizing for speed)
2728
! CHECK-NEXT: -falternative-parameter-statement
2829
! CHECK-NEXT: Enable the old style PARAMETER statement
2930
! CHECK-NEXT: -fapprox-func Allow certain math function calls to be replaced with an approximately equivalent calculation
@@ -56,6 +57,7 @@
5657
! CHECK-NEXT: -flto=jobserver Enable LTO in 'full' mode
5758
! CHECK-NEXT: -flto=<value> Set LTO mode
5859
! CHECK-NEXT: -flto Enable LTO in 'full' mode
60+
! CHECK-NEXT: -fno-alias-analysis Do not pass alias information on to LLVM (default for unoptimized builds)
5961
! CHECK-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
6062
! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
6163
! CHECK-NEXT: -fno-integrated-as Disable the integrated assembler

flang/test/Driver/driver-help.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
! HELP-NEXT: -D <macro>=<value> Define <macro> to <value> (or 1 if <value> omitted)
2121
! HELP-NEXT: -emit-llvm Use the LLVM representation for assembler and object files
2222
! HELP-NEXT: -E Only run the preprocessor
23+
! HELP-NEXT: -falias-analysis Pass alias information on to LLVM (default when optimizing for speed)
2324
! HELP-NEXT: -falternative-parameter-statement
2425
! HELP-NEXT: Enable the old style PARAMETER statement
2526
! HELP-NEXT: -fapprox-func Allow certain math function calls to be replaced with an approximately equivalent calculation
@@ -48,6 +49,7 @@
4849
! HELP-NEXT: -flto=jobserver Enable LTO in 'full' mode
4950
! HELP-NEXT: -flto=<value> Set LTO mode
5051
! HELP-NEXT: -flto Enable LTO in 'full' mode
52+
! HELP-NEXT: -fno-alias-analysis Do not pass alias information on to LLVM (default for unoptimized builds)
5153
! HELP-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
5254
! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
5355
! HELP-NEXT: -fno-integrated-as Disable the integrated assembler
@@ -141,6 +143,7 @@
141143
! HELP-FC1-NEXT: -emit-llvm Use the LLVM representation for assembler and object files
142144
! HELP-FC1-NEXT: -emit-obj Emit native object files
143145
! HELP-FC1-NEXT: -E Only run the preprocessor
146+
! HELP-FC1-NEXT: -falias-analysis Pass alias information on to LLVM (default when optimizing for speed)
144147
! HELP-FC1-NEXT: -falternative-parameter-statement
145148
! HELP-FC1-NEXT: Enable the old style PARAMETER statement
146149
! HELP-FC1-NEXT: -fapprox-func Allow certain math function calls to be replaced with an approximately equivalent calculation
@@ -187,6 +190,7 @@
187190
! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
188191
! HELP-FC1-NEXT: -flto=<value> Set LTO mode
189192
! HELP-FC1-NEXT: -flto Enable LTO in 'full' mode
193+
! HELP-FC1-NEXT: -fno-alias-analysis Do not pass alias information on to LLVM (default for unoptimized builds)
190194
! HELP-FC1-NEXT: -fno-analyzed-objects-for-unparse
191195
! HELP-FC1-NEXT: Do not use the analyzed objects when unparsing
192196
! HELP-FC1-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE

flang/test/Driver/falias-analysis.f90

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
! Check that -falias-analysis and -fno-alias-analysis work as expected
2+
! See flang/test/Fir/tbaa-codegen.fir for a test that the output is correct
3+
4+
! RUN: %flang -c -emit-llvm -falias-analysis %s -o - | llvm-dis | FileCheck %s --check-prefix=CHECK-AA --check-prefix=CHECK-ALL
5+
! RUN: %flang -c -emit-llvm -falias-analysis -fno-alias-analysis %s -o - | llvm-dis | FileCheck %s --check-prefix=CHECK-NOAA --check-prefix=CHECK-ALL
6+
! RUN: %flang -c -emit-llvm %s -o - | llvm-dis | FileCheck %s --check-prefix=CHECK-NOAA --check-prefix=CHECK-ALL
7+
8+
! RUN: %flang -fc1 -emit-llvm -falias-analysis %s -o - | FileCheck %s --check-prefix=CHECK-AA --check-prefix=CHECK-ALL
9+
! RUN: %flang -fc1 -emit-llvm -falias-analysis -fno-alias-analysis %s -o - | FileCheck %s --check-prefix=CHECK-NOAA --check-prefix=CHECK-ALL
10+
! RUN: %flang -fc1 -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-NOAA --check-prefix=CHECK-ALL
11+
12+
subroutine simple(a)
13+
integer, intent(inout) :: a(:)
14+
a(1) = a(2)
15+
end subroutine
16+
! CHECK-ALL-LABEL: define void @simple
17+
! CHECK-ALL: ret
18+
! CHECK-ALL: }
19+
20+
! CHECK-AA: ![[ROOT:.*]] = !{!"Flang function root _QPsimple"}
21+
! CHECK-NOAA-NOT: ![[ROOT:.*]] = !{!"Flang function root _QPsimple"}

0 commit comments

Comments
 (0)