8000 [AVR] Cherry-pick 17 upstream AVR backend fixes into the Rust LLVM fork by dylanmckay · Pull Request #66 · rust-lang/llvm-project · GitHub
[go: up one dir, main page]

Skip to content

[AVR] Cherry-pick 17 upstream AVR backend fixes into the Rust LLVM fork #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[AVR] Do not place functions in .progmem.data
Previously, the AVR backend would put functions in .progmem.data. This
is probably a regression from when functions still lived in address
space 0. With this change, only global constants are placed in
.progmem.data.

This is not complete: avr-gcc additionally respects -fdata-sections for
progmem global constants, which LLVM doesn't yet do. But fixing that is
a bit more complicated (and I believe other backends such as RISC-V
might also have similar issues).

Differential Revision: https://reviews.llvm.org/D78212
  • Loading branch information
aykevl authored and dylanmckay committed Jun 23, 2020
commit 962c2415ffbd9ef9e3be66b84c286159591e8d9e
2 changes: 1 addition & 1 deletion llvm/lib/Target/AVR/AVRTargetObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ AVRTargetObjectFile::SelectSectionForGlobal(const GlobalObject *GO,
const TargetMachine &TM) const {
// Global values in flash memory are placed in the progmem.data section
// unless they already have a user assigned section.
if (AVR::isProgramMemoryAddress(GO) && !GO->hasSection())
if (AVR::isProgramMemoryAddress(GO) && !GO->hasSection() && Kind.isReadOnly())
return ProgmemDataSection;

// Otherwise, we work the same way as ELF.
Expand Down
31 changes: 31 additions & 0 deletions llvm/test/CodeGen/AVR/sections.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
; RUN: llc < %s -march=avr | FileCheck --check-prefixes=CHECK,NOSECTIONS %s
; RUN: llc -function-sections -data-sections < %s -march=avr | FileCheck --check-prefixes=CHECK,SECTIONS %s

; Test that functions (in address space 1) are not considered .progmem data.

; CHECK: .text
; SECTIONS: .text.somefunc,"ax",@progbits
; CHECK-LABEL: somefunc:
define void @somefunc() addrspace(1) {
ret void
}


; Test whether global variables are placed in the correct section.

; Note: avr-gcc would place this global in .progmem.data.flash with
; -fdata-sections. The AVR backend does not yet respect -fdata-sections in this
; case.
; CHECK: .section .progmem.data,"a",@progbits
; CHECK-LABEL: flash:
@flash = addrspace(1) constant i16 3

; NOSECTIONS: .section .rodata,"a",@progbits
; SECTIONS: .section .rodata.ram1,"a",@progbits
; CHECK-LABEL: ram1:
@ram1 = constant i16 3

; NOSECTIONS: .data
; SECTIONS: .section .data.ram2,"aw",@progbits
; CHECK-LABEL: ram2:
@ram2 = global i16 3
0