Skip to content

Commit 2e4aa61

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:5434b04234a86273d719f96e9efa6332a53c0eba into amd-gfx:17b97598a1e4
Local branch amd-gfx 17b9759 Merged main:430729d71e4e582aa04b5d30796de14404fed56a into amd-gfx:cccd99d0cdce Remote branch main 5434b04 [flang][debug] Add support for fixed size arrays. (llvm#92568)
2 parents 17b9759 + 5434b04 commit 2e4aa61

File tree

14 files changed

+155
-1280
lines changed

14 files changed

+155
-1280
lines changed

flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,45 @@ static mlir::LLVM::DITypeAttr genPlaceholderType(mlir::MLIRContext *context) {
3737
llvm::dwarf::DW_ATE_signed);
3838
}
3939

40+
mlir::LLVM::DITypeAttr DebugTypeGenerator::convertSequenceType(
41+
fir::SequenceType seqTy, mlir::LLVM::DIFileAttr fileAttr,
42+
mlir::LLVM::DIScopeAttr scope, mlir::Location loc) {
43+
44+
mlir::MLIRContext *context = module.getContext();
45+
// FIXME: Only fixed sizes arrays handled at the moment.
46+
if (seqTy.hasDynamicExtents())
47+
return genPlaceholderType(context);
48+
49+
llvm::SmallVector<mlir::LLVM::DINodeAttr> elements;
50+
mlir::LLVM::DITypeAttr elemTy =
51+
convertType(seqTy.getEleTy(), fileAttr, scope, loc);
52+
53+
for (fir::SequenceType::Extent dim : seqTy.getShape()) {
54+
auto intTy = mlir::IntegerType::get(context, 64);
55+
// FIXME: Only supporting lower bound of 1 at the moment. The
56+
// 'SequenceType' has information about the shape but not the shift. In
57+
// cases where the conversion originated during the processing of
58+
// 'DeclareOp', it may be possible to pass on this information. But the
59+
// type conversion should ideally be based on what information present in
60+
// the type class so that it works from everywhere (e.g. when it is part
61+
// of a module or a derived type.)
62+
auto countAttr = mlir::IntegerAttr::get(intTy, llvm::APInt(64, dim));
63+
auto lowerAttr = mlir::IntegerAttr::get(intTy, llvm::APInt(64, 1));
64+
auto subrangeTy = mlir::LLVM::DISubrangeAttr::get(
65+
context, countAttr, lowerAttr, nullptr, nullptr);
66+
elements.push_back(subrangeTy);
67+
}
68+
// Apart from arrays, the `DICompositeTypeAttr` is used for other things like
69+
// structure types. Many of its fields which are not applicable to arrays
70+
// have been set to some valid default values.
71+
72+
return mlir::LLVM::DICompositeTypeAttr::get(
73+
context, llvm::dwarf::DW_TAG_array_type, /*recursive id*/ {},
74+
/* name */ nullptr, /* file */ nullptr, /* line */ 0, /* scope */ nullptr,
75+
elemTy, mlir::LLVM::DIFlags::Zero, /* sizeInBits */ 0,
76+
/*alignInBits*/ 0, elements);
77+
}
78+
4079
mlir::LLVM::DITypeAttr
4180
DebugTypeGenerator::convertType(mlir::Type Ty, mlir::LLVM::DIFileAttr fileAttr,
4281
mlir::LLVM::DIScopeAttr scope,
@@ -69,6 +108,8 @@ DebugTypeGenerator::convertType(mlir::Type Ty, mlir::LLVM::DIFileAttr fileAttr,
69108
}
70109
return genBasicType(context, mlir::StringAttr::get(context, "complex"),
71110
bitWidth * 2, llvm::dwarf::DW_ATE_complex_float);
111+
} else if (auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(Ty)) {
112+
return convertSequenceType(seqTy, fileAttr, scope, loc);
72113
} else {
73114
// FIXME: These types are currently unhandled. We are generating a
74115
// placeholder type to allow us to test supported bits.

flang/lib/Optimizer/Transforms/DebugTypeGenerator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class DebugTypeGenerator {
3131
mlir::Location loc);
3232

3333
private:
34+
mlir::LLVM::DITypeAttr convertSequenceType(fir::SequenceType seqTy,
35+
mlir::LLVM::DIFileAttr fileAttr,
36+
mlir::LLVM::DIScopeAttr scope,
37+
mlir::Location loc);
3438
mlir::ModuleOp module;
3539
KindMapping kindMapping;
3640
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck %s
2+
3+
program mn
4+
5+
integer d1(3)
6+
integer d2(2, 5)
7+
real d3(6, 8, 7)
8+
9+
i8 = fn1(d1, d2, d3)
10+
contains
11+
function fn1(a1, b1, c1) result (res)
12+
integer a1(3)
13+
integer b1(2, 5)
14+
real c1(6, 8, 7)
15+
integer res
16+
res = a1(1) + b1(1,2) + c1(3, 3, 4)
17+
end function
18+
19+
end program
20+
21+
! CHECK-DAG: ![[INT:.*]] = !DIBasicType(name: "integer", size: 32, encoding: DW_ATE_signed)
22+
! CHECK-DAG: ![[REAL:.*]] = !DIBasicType(name: "real", size: 32, encoding: DW_ATE_float)
23+
! CHECK-DAG: ![[R1:.*]] = !DISubrange(count: 3, lowerBound: 1)
24+
! CHECK-DAG: ![[SUB1:.*]] = !{![[R1]]}
25+
! CHECK-DAG: ![[D1TY:.*]] = !DICompositeType(tag: DW_TAG_array_type, baseType: ![[INT]], elements: ![[SUB1]])
26+
! CHECK-DAG: !DILocalVariable(name: "d1"{{.*}}type: ![[D1TY]])
27+
28+
! CHECK-DAG: ![[R21:.*]] = !DISubrange(count: 2, lowerBound: 1)
29+
! CHECK-DAG: ![[R22:.*]] = !DISubrange(count: 5, lowerBound: 1)
30+
! CHECK-DAG: ![[SUB2:.*]] = !{![[R21]], ![[R22]]}
31+
! CHECK-DAG: ![[D2TY:.*]] = !DICompositeType(tag: DW_TAG_array_type, baseType: ![[INT]], elements: ![[SUB2]])
32+
! CHECK-DAG: !DILocalVariable(name: "d2"{{.*}}type: ![[D2TY]])
33+
34+
! CHECK-DAG: ![[R31:.*]] = !DISubrange(count: 6, lowerBound: 1)
35+
! CHECK-DAG: ![[R32:.*]] = !DISubrange(count: 8, lowerBound: 1)
36+
! CHECK-DAG: ![[R33:.*]] = !DISubrange(count: 7, lowerBound: 1)
37+
! CHECK-DAG: ![[SUB3:.*]] = !{![[R31]], ![[R32]], ![[R33]]}
38+
! CHECK-DAG: ![[D3TY:.*]] = !DICompositeType(tag: DW_TAG_array_type, baseType: ![[REAL]], elements: ![[SUB3]])
39+
! CHECK-DAG: !DILocalVariable(name: "d3"{{.*}}type: ![[D3TY]])
40+
41+
! CHECK-DAG: !DILocalVariable(name: "a1", arg: 1{{.*}}type: ![[D1TY]])
42+
! CHECK-DAG: !DILocalVariable(name: "b1", arg: 2{{.*}}type: ![[D2TY]])
43+
! CHECK-DAG: !DILocalVariable(name: "c1", arg: 3{{.*}}type: ![[D3TY]])
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
2+
3+
module attributes {} {
4+
func.func @_QQmain() attributes {fir.bindc_name = "mn"} {
5+
%c7 = arith.constant 7 : index
6+
%c8 = arith.constant 8 : index
7+
%c6 = arith.constant 6 : index
8+
%c5 = arith.constant 5 : index
9+
%c2 = arith.constant 2 : index
10+
%c3 = arith.constant 3 : index
11+
%0 = fir.alloca !fir.array<3xi32> {bindc_name = "d1", uniq_name = "_QFEd1"}
12+
%1 = fircg.ext_declare %0(%c3) {uniq_name = "_QFEd1"} : (!fir.ref<!fir.array<3xi32>>, index) -> !fir.ref<!fir.array<3xi32>> loc(#loc1)
13+
%2 = fir.address_of(@_QFEd2) : !fir.ref<!fir.array<2x5xi32>>
14+
%3 = fircg.ext_declare %2(%c2, %c5) {uniq_name = "_QFEd2"} : (!fir.ref<!fir.array<2x5xi32>>, index, index) -> !fir.ref<!fir.array<2x5xi32>> loc(#loc2)
15+
%4 = fir.address_of(@_QFEd3) : !fir.ref<!fir.array<6x8x7xf32>>
16+
%5 = fircg.ext_declare %4(%c6, %c8, %c7) {uniq_name = "_QFEd3"} : (!fir.ref<!fir.array<6x8x7xf32>>, index, index, index) -> !fir.ref<!fir.array<6x8x7xf32>> loc(#loc3)
17+
return
18+
} loc(#loc4)
19+
}
20+
21+
#loc1 = loc("test.f90":5:1)
22+
#loc2 = loc("test.f90":6:11)
23+
#loc3 = loc("test.f90":7:11)
24+
#loc4 = loc("test.f90":2:8)
25+
26+
27+
// CHECK-DAG: #[[INT:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer", sizeInBits = 32, encoding = DW_ATE_signed>
28+
// CHECK-DAG: #[[REAL:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "real", sizeInBits = 32, encoding = DW_ATE_float>
29+
// CHECK-DAG: #[[D1TY:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type{{.*}}baseType = #[[INT]], elements = #llvm.di_subrange<count = 3 : i64, lowerBound = 1 : i64>>
30+
// CHECK-DAG: #[[D2TY:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type{{.*}}baseType = #[[INT]], elements = #llvm.di_subrange<count = 2 : i64, lowerBound = 1 : i64>, #llvm.di_subrange<count = 5 : i64, lowerBound = 1 : i64>>
31+
// CHECK-DAG: #[[D3TY:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type{{.*}}baseType = #[[REAL]], elements = #llvm.di_subrange<count = 6 : i64, lowerBound = 1 : i64>, #llvm.di_subrange<count = 8 : i64, lowerBound = 1 : i64>, #llvm.di_subrange<count = 7 : i64, lowerBound = 1 : i64>>
32+
// CHECK-DAG: #llvm.di_local_variable<{{.*}}name = "d1"{{.*}}type = #[[D1TY]]>
33+
// CHECK-DAG: #llvm.di_local_variable<{{.*}}name = "d2"{{.*}}type = #[[D2TY]]>
34+
// CHECK-DAG: #llvm.di_local_variable<{{.*}}name = "d3"{{.*}}type = #[[D3TY]]>

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 499704
19+
#define LLVM_MAIN_REVISION 499708
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42930,7 +42930,6 @@ bool X86TargetLowering::isGuaranteedNotToBeUndefOrPoisonForTargetNode(
4293042930
bool PoisonOnly, unsigned Depth) const {
4293142931
unsigned NumElts = DemandedElts.getBitWidth();
4293242932

42933-
// TODO: Add more target shuffles.
4293442933
switch (Op.getOpcode()) {
4293542934
case X86ISD::PSHUFD:
4293642935
case X86ISD::VPERMILPI: {
@@ -42966,8 +42965,12 @@ bool X86TargetLowering::canCreateUndefOrPoisonForTargetNode(
4296642965
SDValue Op, const APInt &DemandedElts, const SelectionDAG &DAG,
4296742966
bool PoisonOnly, bool ConsiderFlags, unsigned Depth) const {
4296842967

42969-
// TODO: Add more target shuffles.
4297042968
switch (Op.getOpcode()) {
42969+
// SSE vector shifts handle out of bounds shift amounts.
42970+
case X86ISD::VSHLI:
42971+
case X86ISD::VSRLI:
42972+
case X86ISD::VSRAI:
42973+
return false;
4297142974
case X86ISD::PSHUFD:
4297242975
case X86ISD::VPERMILPI:
4297342976
case X86ISD::UNPCKH:

llvm/test/CodeGen/X86/freeze-binary.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,8 @@ define <8 x i16> @freeze_ashr_vec(<8 x i16> %a0) nounwind {
546546
define <4 x i32> @freeze_ashr_vec_outofrange(<4 x i32> %a0) nounwind {
547547
; X86-LABEL: freeze_ashr_vec_outofrange:
548548
; X86: # %bb.0:
549-
; X86-NEXT: psrad $1, %xmm0
550549
; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,3,2,3]
551-
; X86-NEXT: psrad $2, %xmm0
550+
; X86-NEXT: psrad $3, %xmm0
552551
; X86-NEXT: retl
553552
;
554553
; X64-LABEL: freeze_ashr_vec_outofrange:
@@ -660,9 +659,8 @@ define <8 x i16> @freeze_lshr_vec(<8 x i16> %a0) nounwind {
660659
define <4 x i32> @freeze_lshr_vec_outofrange(<4 x i32> %a0) nounwind {
661660
; X86-LABEL: freeze_lshr_vec_outofrange:
662661
; X86: # %bb.0:
663-
; X86-NEXT: psrld $1, %xmm0
664662
; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,3,2,3]
665-
; X86-NEXT: psrld $2, %xmm0
663+
; X86-NEXT: psrld $3, %xmm0
666664
; X86-NEXT: retl
667665
;
668666
; X64-LABEL: freeze_lshr_vec_outofrange:

mlir/include/mlir/Dialect/LLVMIR/Transforms/Passes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "mlir/Dialect/LLVMIR/Transforms/LegalizeForExport.h"
1414
#include "mlir/Dialect/LLVMIR/Transforms/OptimizeForNVVM.h"
1515
#include "mlir/Dialect/LLVMIR/Transforms/RequestCWrappers.h"
16-
#include "mlir/Dialect/LLVMIR/Transforms/TypeConsistency.h"
1716
#include "mlir/Pass/Pass.h"
1817

1918
namespace mlir {

mlir/include/mlir/Dialect/LLVMIR/Transforms/Passes.td

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,6 @@ def LLVMRequestCWrappers
4343
let constructor = "::mlir::LLVM::createRequestCWrappersPass()";
4444
}
4545

46-
def LLVMTypeConsistency
47-
: Pass<"llvm-type-consistency", "::mlir::LLVM::LLVMFuncOp"> {
48-
let summary = "Rewrites to improve type consistency";
49-
let description = [{
50-
Set of rewrites to improve the coherency of types within an LLVM dialect
51-
program. This will adjust operations operating on pointers so they interpret
52-
their associated pointee type as consistently as possible.
53-
}];
54-
let constructor = "::mlir::LLVM::createTypeConsistencyPass()";
55-
56-
let options = [
57-
Option<"maxVectorSplitSize", "max-vector-split-size", "unsigned",
58-
/*default=*/"512",
59-
"Maximum size in bits of a vector value in a load or store operation"
60-
" operating on multiple elements that should still be split">,
61-
];
62-
}
63-
6446
def NVVMOptimizeForTarget : Pass<"llvm-optimize-for-nvvm-target"> {
6547
let summary = "Optimize NVVM IR";
6648
let constructor = "::mlir::NVVM::createOptimizeForTargetPass()";

mlir/include/mlir/Dialect/LLVMIR/Transforms/TypeConsistency.h

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

0 commit comments

Comments
 (0)