Skip to content

Commit 44b8a85

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:702198fc9ac5dba392f9d9ba7c56467996343c0a into amd-gfx:ddd6f4a278f2
Local branch amd-gfx ddd6f4a Merged main:1e9324a8c734aaa933d2672522cc22d5022c6200 into amd-gfx:ab63de878b82 Remote branch main 702198f [flang][cuda] Add data attribute to program globals (llvm#92610)
2 parents ddd6f4a + 702198f commit 44b8a85

File tree

9 files changed

+39
-49
lines changed

9 files changed

+39
-49
lines changed

flang/lib/Lower/ConvertVariable.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,10 @@ static void instantiateGlobal(Fortran::lower::AbstractConverter &converter,
656656
// Emit only a declaration if the global does not exist.
657657
global = declareGlobal(converter, var, globalName, linkage);
658658
} else {
659-
global = defineGlobal(converter, var, globalName, linkage);
659+
cuf::DataAttributeAttr dataAttr =
660+
Fortran::lower::translateSymbolCUFDataAttribute(builder.getContext(),
661+
sym);
662+
global = defineGlobal(converter, var, globalName, linkage, dataAttr);
660663
}
661664
auto addrOf = builder.create<fir::AddrOfOp>(loc, global.resultType(),
662665
global.getSymbol());
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
2+
3+
! Test lowering of program local variable that are global
4+
5+
program test
6+
integer, device :: a(10)
7+
integer :: b(10)
8+
integer :: i
9+
print*,i
10+
end
11+
12+
! CHECK-LABEL: func.func @_QQmain()
13+
! CHECK: fir.address_of(@_QFEa) : !fir.ref<!fir.array<10xi32>>
14+
! CHECK: fir.address_of(@_QFEb) : !fir.ref<!fir.array<10xi32>>
15+
! CHECK: %[[ALLOCA:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"}
16+
! CHECK: hlfir.declare %[[ALLOCA]] {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
17+
18+
! CHECK: fir.global internal @_QFEa {data_attr = #cuf.cuda<device>} : !fir.array<10xi32> {{{$}}
19+
! CHECK: fir.global internal @_QFEb : !fir.array<10xi32> {{{$}}

lld/ELF/InputSection.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -471,11 +471,7 @@ void InputSection::copyRelocations(uint8_t *buf,
471471
addend += sec->getFile<ELFT>()->mipsGp0;
472472
}
473473

474-
if (config->emachine == EM_LOONGARCH && type == R_LARCH_ALIGN)
475-
// LoongArch psABI v2.30, the R_LARCH_ALIGN requires symbol index.
476-
// If it use the section symbol, the addend should not be changed.
477-
p->r_addend = addend;
478-
else if (RelTy::IsRela)
474+
if (RelTy::IsRela)
479475
p->r_addend = sym.getVA(addend) - section->getOutputSection()->addr;
480476
// For SHF_ALLOC sections relocated by REL, append a relocation to
481477
// sec->relocations so that relocateAlloc transitively called by

lld/test/ELF/loongarch-relax-align-ldr.s

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

lld/test/ELF/loongarch-relax-emit-relocs.s

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# CHECK-NEXT: R_LARCH_PCALA_LO12 _start
2626
# CHECK-NEXT: R_LARCH_RELAX *ABS*
2727
# CHECK-NEXT: nop
28-
# CHECK-NEXT: R_LARCH_ALIGN .text+0x4
28+
# CHECK-NEXT: R_LARCH_ALIGN .Lla-relax-align0+0x4
2929
# CHECK-NEXT: nop
3030
# CHECK-NEXT: ret
3131

@@ -37,12 +37,11 @@
3737
# CHECKR-NEXT: R_LARCH_PCALA_LO12 _start
3838
# CHECKR-NEXT: R_LARCH_RELAX *ABS*
3939
# CHECKR-NEXT: nop
40-
# CHECKR-NEXT: R_LARCH_ALIGN .text+0x4
40+
# CHECKR-NEXT: R_LARCH_ALIGN .Lla-relax-align0+0x4
4141
# CHECKR-NEXT: nop
4242
# CHECKR-NEXT: nop
4343
# CHECKR-NEXT: ret
4444

45-
.text
4645
.global _start
4746
_start:
4847
la.pcrel $a0, _start

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 499088
19+
#define LLVM_MAIN_REVISION 499090
2020

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

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,11 @@ bool LoongArchAsmBackend::shouldInsertFixupForCodeAlign(
226226
MCFixup::create(0, Dummy, MCFixupKind(LoongArch::fixup_loongarch_align));
227227
const MCSymbolRefExpr *MCSym = getSecToAlignSym()[Sec];
228228
if (MCSym == nullptr) {
229-
// Use section symbol directly.
230-
MCSym = MCSymbolRefExpr::create(Sec->getBeginSymbol(), Ctx);
229+
// Create a symbol and make the value of symbol is zero.
230+
MCSymbol *Sym = Ctx.createNamedTempSymbol("la-relax-align");
231+
Sym->setFragment(&*Sec->getBeginSymbol()->getFragment());
232+
Asm.registerSymbol(*Sym);
233+
MCSym = MCSymbolRefExpr::create(Sym, Ctx);
231234
getSecToAlignSym()[Sec] = MCSym;
232235
}
233236

llvm/test/MC/LoongArch/Relocations/relax-addsub.s

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

2929
# RELAX: Relocations [
3030
# RELAX-NEXT: Section ({{.*}}) .rela.text {
31-
# RELAX-NEXT: 0x4 R_LARCH_ALIGN .text 0x4
31+
# RELAX-NEXT: 0x4 R_LARCH_ALIGN {{.*}} 0x4
3232
# RELAX-NEXT: 0x10 R_LARCH_PCALA_HI20 .L1 0x0
3333
# RELAX-NEXT: 0x10 R_LARCH_RELAX - 0x0
3434
# RELAX-NEXT: 0x14 R_LARCH_PCALA_LO12 .L1 0x0

llvm/test/MC/LoongArch/Relocations/relax-align.s

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,17 @@ ret
6363
## Test the symbol index is different from .text.
6464
.section .text2, "ax"
6565
.p2align 4
66-
.p2align 4, , 4
6766
break 7
6867

6968
# RELOC: Relocations [
7069
# RELAX-RELOC-NEXT: Section ({{.*}}) .rela.text {
71-
# RELAX-RELOC-NEXT: 0x24 R_LARCH_ALIGN .text 0x4
72-
# RELAX-RELOC-NEXT: 0x34 R_LARCH_ALIGN .text 0x5
73-
# RELAX-RELOC-NEXT: 0x50 R_LARCH_ALIGN .text 0x4
74-
# RELAX-RELOC-NEXT: 0x60 R_LARCH_ALIGN .text 0xB04
75-
# RELAX-RELOC-NEXT: 0x70 R_LARCH_ALIGN .text 0x4
70+
# RELAX-RELOC-NEXT: 0x24 R_LARCH_ALIGN .Lla-relax-align0 0x4
71+
# RELAX-RELOC-NEXT: 0x34 R_LARCH_ALIGN .Lla-relax-align0 0x5
72+
# RELAX-RELOC-NEXT: 0x50 R_LARCH_ALIGN .Lla-relax-align0 0x4
73+
# RELAX-RELOC-NEXT: 0x60 R_LARCH_ALIGN .Lla-relax-align0 0xB04
74+
# RELAX-RELOC-NEXT: 0x70 R_LARCH_ALIGN .Lla-relax-align0 0x4
7675
# RELAX-RELOC-NEXT: }
7776
# RELAX-RELOC-NEXT: Section ({{.*}}) .rela.text2 {
78-
# RELAX-RELOC-NEXT: 0x0 R_LARCH_ALIGN .text2 0x4
79-
# RELAX-RELOC-NEXT: 0xC R_LARCH_ALIGN .text2 0x404
77+
# RELAX-RELOC-NEXT: 0x0 R_LARCH_ALIGN .Lla-relax-align1 0x4
8078
# RELAX-RELOC-NEXT: }
8179
# RELOC-NEXT: ]

0 commit comments

Comments
 (0)