[PATCH] D78212: [AVR] Do not place functions in .progmem.data

Ayke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 15 08:44:35 PDT 2020


aykevl created this revision.
aykevl added a reviewer: dylanmckay.
Herald added subscribers: luismarques, s.egerton, lenary, Jim, PkmX, simoncook, hiraditya.
Herald added a project: LLVM.
aykevl updated this revision to Diff 257736.

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).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78212

Files:
  llvm/lib/Target/AVR/AVRTargetObjectFile.cpp
  llvm/test/CodeGen/AVR/sections.ll


Index: llvm/test/CodeGen/AVR/sections.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AVR/sections.ll
@@ -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", at 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", at progbits
+; CHECK-LABEL: flash:
+ at flash = addrspace(1) constant i16 3
+
+; NOSECTIONS: .section .rodata,"a", at progbits
+; SECTIONS:   .section .rodata.ram1,"a", at progbits
+; CHECK-LABEL: ram1:
+ at ram1 = constant i16 3
+
+; NOSECTIONS: .data
+; SECTIONS:   .section .data.ram2,"aw", at progbits
+; CHECK-LABEL: ram2:
+ at ram2 = global i16 3
Index: llvm/lib/Target/AVR/AVRTargetObjectFile.cpp
===================================================================
--- llvm/lib/Target/AVR/AVRTargetObjectFile.cpp
+++ llvm/lib/Target/AVR/AVRTargetObjectFile.cpp
@@ -30,7 +30,7 @@
                                             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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78212.257736.patch
Type: text/x-patch
Size: 1854 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200415/0aec7b77/attachment.bin>


More information about the llvm-commits mailing list