Skip to content

Commit 3121da5

Browse files
committed
Revert "[flang] In AllocMemOp lowering, convert types for calling malloc on 32-bit (#129308)"
This reverts commit cf1964a. This causes breakage on all the non-x86 buildbots as they don't have the i686 target enabled. This was missed in pre-commit CI.
1 parent d8747ea commit 3121da5

File tree

7 files changed

+9
-74
lines changed

7 files changed

+9
-74
lines changed

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -982,8 +982,7 @@ struct EmboxCharOpConversion : public fir::FIROpConversion<fir::EmboxCharOp> {
982982
template <typename ModuleOp>
983983
static mlir::SymbolRefAttr
984984
getMallocInModule(ModuleOp mod, fir::AllocMemOp op,
985-
mlir::ConversionPatternRewriter &rewriter,
986-
mlir::Type indexType) {
985+
mlir::ConversionPatternRewriter &rewriter) {
987986
static constexpr char mallocName[] = "malloc";
988987
if (auto mallocFunc =
989988
mod.template lookupSymbol<mlir::LLVM::LLVMFuncOp>(mallocName))
@@ -993,6 +992,7 @@ getMallocInModule(ModuleOp mod, fir::AllocMemOp op,
993992
return mlir::SymbolRefAttr::get(userMalloc);
994993

995994
mlir::OpBuilder moduleBuilder(mod.getBodyRegion());
995+
auto indexType = mlir::IntegerType::get(op.getContext(), 64);
996996
auto mallocDecl = moduleBuilder.create<mlir::LLVM::LLVMFuncOp>(
997997
op.getLoc(), mallocName,
998998
mlir::LLVM::LLVMFunctionType::get(getLlvmPtrType(op.getContext()),
@@ -1002,13 +1002,12 @@ getMallocInModule(ModuleOp mod, fir::AllocMemOp op,
10021002
}
10031003

10041004
/// Return the LLVMFuncOp corresponding to the standard malloc call.
1005-
static mlir::SymbolRefAttr getMalloc(fir::AllocMemOp op,
1006-
mlir::ConversionPatternRewriter &rewriter,
1007-
mlir::Type indexType) {
1005+
static mlir::SymbolRefAttr
1006+
getMalloc(fir::AllocMemOp op, mlir::ConversionPatternRewriter &rewriter) {
10081007
if (auto mod = op->getParentOfType<mlir::gpu::GPUModuleOp>())
1009-
return getMallocInModule(mod, op, rewriter, indexType);
1008+
return getMallocInModule(mod, op, rewriter);
10101009
auto mod = op->getParentOfType<mlir::ModuleOp>();
1011-
return getMallocInModule(mod, op, rewriter, indexType);
1010+
return getMallocInModule(mod, op, rewriter);
10121011
}
10131012

10141013
/// Helper function for generating the LLVM IR that computes the distance
@@ -1068,12 +1067,7 @@ struct AllocMemOpConversion : public fir::FIROpConversion<fir::AllocMemOp> {
10681067
for (mlir::Value opnd : adaptor.getOperands())
10691068
size = rewriter.create<mlir::LLVM::MulOp>(
10701069
loc, ity, size, integerCast(loc, rewriter, ity, opnd));
1071-
auto mallocTyWidth = lowerTy().getIndexTypeBitwidth();
1072-
auto mallocTy =
1073-
mlir::IntegerType::get(rewriter.getContext(), mallocTyWidth);
1074-
if (mallocTyWidth != ity.getIntOrFloatBitWidth())
1075-
size = integerCast(loc, rewriter, mallocTy, size);
1076-
heap->setAttr("callee", getMalloc(heap, rewriter, mallocTy));
1070+
heap->setAttr("callee", getMalloc(heap, rewriter));
10771071
rewriter.replaceOpWithNewOp<mlir::LLVM::CallOp>(
10781072
heap, ::getLlvmPtrType(heap.getContext()), size,
10791073
addLLVMOpBundleAttrs(rewriter, heap->getAttrs(), 1));

flang/lib/Optimizer/CodeGen/TypeConverter.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,10 @@
2828

2929
namespace fir {
3030

31-
static mlir::LowerToLLVMOptions MakeLowerOptions(mlir::ModuleOp module) {
32-
llvm::StringRef dataLayoutString;
33-
auto dataLayoutAttr = module->template getAttrOfType<mlir::StringAttr>(
34-
mlir::LLVM::LLVMDialect::getDataLayoutAttrName());
35-
if (dataLayoutAttr)
36-
dataLayoutString = dataLayoutAttr.getValue();
37-
38-
auto options = mlir::LowerToLLVMOptions(module.getContext());
39-
auto llvmDL = llvm::DataLayout(dataLayoutString);
40-
if (llvmDL.getPointerSizeInBits(0) == 32) {
41-
// FIXME: Should translateDataLayout in the MLIR layer be doing this?
42-
options.overrideIndexBitwidth(32);
43-
}
44-
options.dataLayout = llvmDL;
45-
return options;
46-
}
47-
4831
LLVMTypeConverter::LLVMTypeConverter(mlir::ModuleOp module, bool applyTBAA,
4932
bool forceUnifiedTBAATree,
5033
const mlir::DataLayout &dl)
51-
: mlir::LLVMTypeConverter(module.getContext(), MakeLowerOptions(module)),
34+
: mlir::LLVMTypeConverter(module.getContext()),
5235
kindMapping(getKindMapping(module)),
5336
specifics(CodeGenSpecifics::get(
5437
module.getContext(), getTargetTriple(module), getKindMapping(module),

flang/test/Fir/alloc-32.fir

Lines changed: 0 additions & 29 deletions
This file was deleted.

flang/test/Fir/alloc.fir

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// RUN: %flang_fc1 -emit-llvm %s -o - | FileCheck %s
33

44
// UNSUPPORTED: system-windows
5-
// UNSUPPORTED: target-x86
6-
// UNSUPPORTED: target=sparc-{{.*}}
7-
// UNSUPPORTED: target=sparcel-{{.*}}
85

96
// CHECK-LABEL: define ptr @alloca_scalar_nonchar()
107
// CHECK: alloca i32, i64 1

flang/test/Integration/OpenMP/private-global.f90

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
!RUN: %flang_fc1 -emit-llvm -fopenmp %s -o - | FileCheck %s
2-
!UNSUPPORTED: target-x86
3-
!UNSUPPORTED: target=sparc-{{.*}}
4-
!UNSUPPORTED: target=sparcel-{{.*}}
52

63
! Regression test for https://github.com/llvm/llvm-project/issues/106297
74

@@ -39,7 +36,7 @@ program bug
3936
! CHECK: %[[FIFTY_BOX_VAL:.*]] = insertvalue { ptr, i64, i32, i8, i8, i8, i8 } { ptr undef, i64 4, i32 20240719, i8 0, i8 9, i8 0, i8 0 }, ptr %[[FIFTY]], 0
4037
! CHECK: store { ptr, i64, i32, i8, i8, i8, i8 } %[[FIFTY_BOX_VAL]], ptr %[[BOXED_FIFTY]], align 8
4138
! CHECK: call void @llvm.memcpy.p0.p0.i32(ptr %[[TABLE_BOX_ADDR2]], ptr %[[INTERMEDIATE]], i32 48, i1 false)
42-
! CHECK: call void @_FortranAAssign(ptr %[[TABLE_BOX_ADDR2]], ptr %[[BOXED_FIFTY]], ptr @{{.*}}, i32 12)
39+
! CHECK: call void @_FortranAAssign(ptr %[[TABLE_BOX_ADDR2]], ptr %[[BOXED_FIFTY]], ptr @{{.*}}, i32 9)
4340
! CHECK: call void @llvm.memcpy.p0.p0.i32(ptr %[[TABLE_BOX_ADDR]], ptr %[[PRIV_BOX_ALLOC]], i32 48, i1 false)
4441
! CHECK: %[[PRIV_TABLE:.*]] = call ptr @malloc(i64 40)
4542
! ...

flang/test/Lower/OpenMP/parallel-reduction-mixed.f90

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
! RUN: %flang_fc1 -emit-llvm -fopenmp -o - %s 2>&1 \
55
! RUN: | FileCheck %s
66

7-
! UNSUPPORTED: target-x86
8-
! UNSUPPORTED: target=sparc-{{.*}}
9-
! UNSUPPORTED: target=sparcel-{{.*}}
10-
117
subroutine proc
128
implicit none
139
real(8),allocatable :: F(:)

flang/test/Lower/forall/character-1.f90

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
! RUN: %flang -emit-llvm -flang-deprecated-no-hlfir -S -mmlir -disable-external-name-interop %s -o - | FileCheck %s
33
! Test from Fortran source through to LLVM IR.
44
! UNSUPPORTED: system-windows
5-
! UNSUPPORTED: target-x86
6-
! UNSUPPORTED: target=sparc-{{.*}}
7-
! UNSUPPORTED: target=sparcel-{{.*}}
85

96
! Assumed size array of assumed length character.
107
program test

0 commit comments

Comments
 (0)