Skip to content

Commit 9168aa0

Browse files
committed
Add flag to return to the old tbaa behaviour
1 parent ca6751e commit 9168aa0

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

flang/include/flang/Optimizer/CodeGen/CodeGen.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ struct FIRToLLVMPassOptions {
5454

5555
// Generate TBAA information for FIR types and memory accessing operations.
5656
bool applyTBAA = false;
57+
58+
// force the usage of a unified tbaa tree in TBAABuilder
59+
bool forceUnifiedTBAATree = false;
5760
};
5861

5962
/// Convert FIR to the LLVM IR dialect with default options.

flang/include/flang/Optimizer/CodeGen/TypeConverter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ namespace fir {
4545
/// This converts FIR types to LLVM types (for now)
4646
class LLVMTypeConverter : public mlir::LLVMTypeConverter {
4747
public:
48-
LLVMTypeConverter(mlir::ModuleOp module, bool applyTBAA);
48+
LLVMTypeConverter(mlir::ModuleOp module, bool applyTBAA,
49+
bool forceUnifiedTBAATree);
4950

5051
// i32 is used here because LLVM wants i32 constants when indexing into struct
5152
// types. Indexing into other aggregate types is more flexible.

flang/include/flang/Tools/CLOptions.inc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ 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+
6768
DisableOption(FirAliasTags, "fir-alias-tags", "fir alias analysis");
69+
static llvm::cl::opt<bool> useOldAliasTags("use-old-alias-tags",
70+
llvm::cl::desc("Use a single TBAA tree for all functions and do not use "
71+
"the FIR alias tags pass"),
72+
llvm::cl::init(false), llvm::cl::Hidden);
6873

6974
/// CodeGen Passes
7075
#if !defined(FLANG_EXCLUDE_CODEGEN)
@@ -157,6 +162,7 @@ inline void addFIRToLLVMPass(
157162
fir::FIRToLLVMPassOptions options;
158163
options.ignoreMissingTypeDescriptors = ignoreMissingTypeDescriptors;
159164
options.applyTBAA = optLevel.isOptimizingForSpeed();
165+
options.forceUnifiedTBAATree = useOldAliasTags;
160166
addPassConditionally(pm, disableFirToLlvmIr,
161167
[&]() { return fir::createFIRToLLVMPass(options); });
162168
}
@@ -221,7 +227,7 @@ inline void createDefaultFIROptimizerPassPipeline(
221227
// Polymorphic types
222228
pm.addPass(fir::createPolymorphicOpConversionPass());
223229

224-
if (pc.AliasAnalysis && !disableFirAliasTags)
230+
if (pc.AliasAnalysis && !disableFirAliasTags && !useOldAliasTags)
225231
pm.addPass(fir::createAliasTagsPass());
226232

227233
// convert control flow to CFG form

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3786,7 +3786,8 @@ class FIRToLLVMLowering
37863786

37873787
auto *context = getModule().getContext();
37883788
fir::LLVMTypeConverter typeConverter{getModule(),
3789-
options.applyTBAA || applyTBAA};
3789+
options.applyTBAA || applyTBAA,
3790+
options.forceUnifiedTBAATree};
37903791
mlir::RewritePatternSet pattern(context);
37913792
pattern.insert<
37923793
AbsentOpConversion, AddcOpConversion, AddrOfOpConversion,

flang/lib/Optimizer/CodeGen/TypeConverter.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
namespace fir {
2828

29-
LLVMTypeConverter::LLVMTypeConverter(mlir::ModuleOp module, bool applyTBAA)
29+
LLVMTypeConverter::LLVMTypeConverter(mlir::ModuleOp module, bool applyTBAA,
30+
bool forceUnifiedTBAATree)
3031
: mlir::LLVMTypeConverter(module.getContext(),
3132
[&] {
3233
mlir::LowerToLLVMOptions options(
@@ -38,8 +39,8 @@ LLVMTypeConverter::LLVMTypeConverter(mlir::ModuleOp module, bool applyTBAA)
3839
specifics(CodeGenSpecifics::get(module.getContext(),
3940
getTargetTriple(module),
4041
getKindMapping(module))),
41-
tbaaBuilder(
42-
std::make_unique<TBAABuilder>(module->getContext(), applyTBAA)) {
42+
tbaaBuilder(std::make_unique<TBAABuilder>(module->getContext(), applyTBAA,
43+
forceUnifiedTBAATree)) {
4344
LLVM_DEBUG(llvm::dbgs() << "FIR type converter\n");
4445

4546
// Each conversion should return a value of type mlir::Type.

0 commit comments

Comments
 (0)