[AVR][MC] Generate section '.progmemX.data' for extended flash banks
Reviewed By: aykevl Differential Revision: https://reviews.llvm.org/D115987
This commit is contained in:
parent
34570f4faf
commit
c1dd607463
|
@ -38,17 +38,43 @@ void initializeAVRRelaxMemPass(PassRegistry &);
|
||||||
namespace AVR {
|
namespace AVR {
|
||||||
|
|
||||||
/// An integer that identifies all of the supported AVR address spaces.
|
/// An integer that identifies all of the supported AVR address spaces.
|
||||||
enum AddressSpace { DataMemory, ProgramMemory };
|
enum AddressSpace {
|
||||||
|
DataMemory,
|
||||||
|
ProgramMemory,
|
||||||
|
ProgramMemory1,
|
||||||
|
ProgramMemory2,
|
||||||
|
ProgramMemory3,
|
||||||
|
ProgramMemory4,
|
||||||
|
ProgramMemory5,
|
||||||
|
NumAddrSpaces,
|
||||||
|
};
|
||||||
|
|
||||||
/// Checks if a given type is a pointer to program memory.
|
/// Checks if a given type is a pointer to program memory.
|
||||||
template <typename T> bool isProgramMemoryAddress(T *V) {
|
template <typename T> bool isProgramMemoryAddress(T *V) {
|
||||||
return cast<PointerType>(V->getType())->getAddressSpace() == ProgramMemory;
|
auto *PT = cast<PointerType>(V->getType());
|
||||||
|
assert(PT != nullptr && "unexpected MemSDNode");
|
||||||
|
return PT->getAddressSpace() == ProgramMemory ||
|
||||||
|
PT->getAddressSpace() == ProgramMemory1 ||
|
||||||
|
PT->getAddressSpace() == ProgramMemory2 ||
|
||||||
|
PT->getAddressSpace() == ProgramMemory3 ||
|
||||||
|
PT->getAddressSpace() == ProgramMemory4 ||
|
||||||
|
PT->getAddressSpace() == ProgramMemory5;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> AddressSpace getAddressSpace(T *V) {
|
||||||
|
auto *PT = cast<PointerType>(V->getType());
|
||||||
|
assert(PT != nullptr && "unexpected MemSDNode");
|
||||||
|
unsigned AS = PT->getAddressSpace();
|
||||||
|
if (AS < NumAddrSpaces)
|
||||||
|
return static_cast<AddressSpace>(AS);
|
||||||
|
return NumAddrSpaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool isProgramMemoryAccess(MemSDNode const *N) {
|
inline bool isProgramMemoryAccess(MemSDNode const *N) {
|
||||||
auto V = N->getMemOperand()->getValue();
|
auto *V = N->getMemOperand()->getValue();
|
||||||
|
if (V != nullptr && isProgramMemoryAddress(V))
|
||||||
return (V != nullptr) ? isProgramMemoryAddress(V) : false;
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end of namespace AVR
|
} // end of namespace AVR
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "AVRTargetObjectFile.h"
|
#include "AVRTargetObjectFile.h"
|
||||||
|
#include "AVRTargetMachine.h"
|
||||||
|
|
||||||
#include "llvm/BinaryFormat/ELF.h"
|
#include "llvm/BinaryFormat/ELF.h"
|
||||||
#include "llvm/IR/DerivedTypes.h"
|
#include "llvm/IR/DerivedTypes.h"
|
||||||
|
@ -22,14 +23,60 @@ void AVRTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) {
|
||||||
Base::Initialize(Ctx, TM);
|
Base::Initialize(Ctx, TM);
|
||||||
ProgmemDataSection =
|
ProgmemDataSection =
|
||||||
Ctx.getELFSection(".progmem.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
|
Ctx.getELFSection(".progmem.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
|
||||||
|
Progmem1DataSection =
|
||||||
|
Ctx.getELFSection(".progmem1.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
|
||||||
|
Progmem2DataSection =
|
||||||
|
Ctx.getELFSection(".progmem2.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
|
||||||
|
Progmem3DataSection =
|
||||||
|
Ctx.getELFSection(".progmem3.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
|
||||||
|
Progmem4DataSection =
|
||||||
|
Ctx.getELFSection(".progmem4.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
|
||||||
|
Progmem5DataSection =
|
||||||
|
Ctx.getELFSection(".progmem5.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
|
||||||
}
|
}
|
||||||
|
|
||||||
MCSection *AVRTargetObjectFile::SelectSectionForGlobal(
|
MCSection *AVRTargetObjectFile::SelectSectionForGlobal(
|
||||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||||
// Global values in flash memory are placed in the progmem.data section
|
// Global values in flash memory are placed in the progmem*.data section
|
||||||
// unless they already have a user assigned section.
|
// unless they already have a user assigned section.
|
||||||
if (AVR::isProgramMemoryAddress(GO) && !GO->hasSection() && Kind.isReadOnly())
|
const auto &AVRTM = static_cast<const AVRTargetMachine &>(TM);
|
||||||
|
if (AVR::isProgramMemoryAddress(GO) && !GO->hasSection() &&
|
||||||
|
Kind.isReadOnly()) {
|
||||||
|
// The AVR subtarget should support LPM to access section '.progmem*.data'.
|
||||||
|
if (!AVRTM.getSubtargetImpl()->hasLPM()) {
|
||||||
|
// TODO: Get the global object's location in source file.
|
||||||
|
getContext().reportError(
|
||||||
|
SMLoc(),
|
||||||
|
"Current AVR subtarget does not support accessing program memory");
|
||||||
|
return Base::SelectSectionForGlobal(GO, Kind, TM);
|
||||||
|
}
|
||||||
|
// The AVR subtarget should support ELPM to access section
|
||||||
|
// '.progmem[1|2|3|4|5].data'.
|
||||||
|
if (!AVRTM.getSubtargetImpl()->hasELPM() &&
|
||||||
|
AVR::getAddressSpace(GO) != AVR::ProgramMemory) {
|
||||||
|
// TODO: Get the global object's location in source file.
|
||||||
|
getContext().reportError(SMLoc(),
|
||||||
|
"Current AVR subtarget does not support "
|
||||||
|
"accessing extended program memory");
|
||||||
return ProgmemDataSection;
|
return ProgmemDataSection;
|
||||||
|
}
|
||||||
|
switch (AVR::getAddressSpace(GO)) {
|
||||||
|
case AVR::ProgramMemory: // address space 1
|
||||||
|
return ProgmemDataSection;
|
||||||
|
case AVR::ProgramMemory1: // address space 2
|
||||||
|
return Progmem1DataSection;
|
||||||
|
case AVR::ProgramMemory2: // address space 3
|
||||||
|
return Progmem2DataSection;
|
||||||
|
case AVR::ProgramMemory3: // address space 4
|
||||||
|
return Progmem3DataSection;
|
||||||
|
case AVR::ProgramMemory4: // address space 5
|
||||||
|
return Progmem4DataSection;
|
||||||
|
case AVR::ProgramMemory5: // address space 6
|
||||||
|
return Progmem5DataSection;
|
||||||
|
default:
|
||||||
|
llvm_unreachable("unexpected program memory index");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Otherwise, we work the same way as ELF.
|
// Otherwise, we work the same way as ELF.
|
||||||
return Base::SelectSectionForGlobal(GO, Kind, TM);
|
return Base::SelectSectionForGlobal(GO, Kind, TM);
|
||||||
|
|
|
@ -25,6 +25,11 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MCSection *ProgmemDataSection;
|
MCSection *ProgmemDataSection;
|
||||||
|
MCSection *Progmem1DataSection;
|
||||||
|
MCSection *Progmem2DataSection;
|
||||||
|
MCSection *Progmem3DataSection;
|
||||||
|
MCSection *Progmem4DataSection;
|
||||||
|
MCSection *Progmem5DataSection;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
; RUN: llc < %s -march=avr | FileCheck --check-prefixes=CHECK,NOSECTIONS %s
|
; RUN: llc < %s -march=avr --mcpu=atxmega384d3 \
|
||||||
; RUN: llc -function-sections -data-sections < %s -march=avr | FileCheck --check-prefixes=CHECK,SECTIONS %s
|
; RUN: | FileCheck --check-prefixes=CHECK,NOSECTIONS %s
|
||||||
|
; RUN: llc -function-sections -data-sections < %s -march=avr --mcpu=atxmega384d3 \
|
||||||
|
; RUN: | FileCheck --check-prefixes=CHECK,SECTIONS %s
|
||||||
|
; RUN: not llc -function-sections -data-sections < %s -march=avr --mcpu=at90s8515 2>&1 \
|
||||||
|
; RUN: | FileCheck --check-prefixes=CHECK-8515 %s
|
||||||
|
; RUN: not llc -function-sections -data-sections < %s -march=avr --mcpu=attiny40 2>&1 \
|
||||||
|
; RUN: | FileCheck --check-prefixes=CHECK-tiny40 %s
|
||||||
|
|
||||||
; Test that functions (in address space 1) are not considered .progmem data.
|
; Test that functions (in address space 1) are not considered .progmem data.
|
||||||
|
|
||||||
|
@ -16,10 +22,41 @@ define void @somefunc() addrspace(1) {
|
||||||
; Note: avr-gcc would place this global in .progmem.data.flash with
|
; 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
|
; -fdata-sections. The AVR backend does not yet respect -fdata-sections in this
|
||||||
; case.
|
; case.
|
||||||
|
|
||||||
; CHECK: .section .progmem.data,"a",@progbits
|
; CHECK: .section .progmem.data,"a",@progbits
|
||||||
; CHECK-LABEL: flash:
|
; CHECK-LABEL: flash:
|
||||||
@flash = addrspace(1) constant i16 3
|
@flash = addrspace(1) constant i16 3
|
||||||
|
|
||||||
|
; CHECK: .section .progmem1.data,"a",@progbits
|
||||||
|
; CHECK-LABEL: flash1:
|
||||||
|
; CHECK-8515: error: Current AVR subtarget does not support accessing extended program memory
|
||||||
|
; CHECK-tiny40: error: Current AVR subtarget does not support accessing program memory
|
||||||
|
@flash1 = addrspace(2) constant i16 4
|
||||||
|
|
||||||
|
; CHECK: .section .progmem2.data,"a",@progbits
|
||||||
|
; CHECK-LABEL: flash2:
|
||||||
|
; CHECK-8515: error: Current AVR subtarget does not support accessing extended program memory
|
||||||
|
; CHECK-tiny40: error: Current AVR subtarget does not support accessing program memory
|
||||||
|
@flash2 = addrspace(3) constant i16 5
|
||||||
|
|
||||||
|
; CHECK: .section .progmem3.data,"a",@progbits
|
||||||
|
; CHECK-LABEL: flash3:
|
||||||
|
; CHECK-8515: error: Current AVR subtarget does not support accessing extended program memory
|
||||||
|
; CHECK-tiny40: error: Current AVR subtarget does not support accessing program memory
|
||||||
|
@flash3 = addrspace(4) constant i16 6
|
||||||
|
|
||||||
|
; CHECK: .section .progmem4.data,"a",@progbits
|
||||||
|
; CHECK-LABEL: flash4:
|
||||||
|
; CHECK-8515: error: Current AVR subtarget does not support accessing extended program memory
|
||||||
|
; CHECK-tiny40: error: Current AVR subtarget does not support accessing program memory
|
||||||
|
@flash4 = addrspace(5) constant i16 7
|
||||||
|
|
||||||
|
; CHECK: .section .progmem5.data,"a",@progbits
|
||||||
|
; CHECK-LABEL: flash5:
|
||||||
|
; CHECK-8515: error: Current AVR subtarget does not support accessing extended program memory
|
||||||
|
; CHECK-tiny40: error: Current AVR subtarget does not support accessing program memory
|
||||||
|
@flash5 = addrspace(6) constant i16 8
|
||||||
|
|
||||||
; NOSECTIONS: .section .rodata,"a",@progbits
|
; NOSECTIONS: .section .rodata,"a",@progbits
|
||||||
; SECTIONS: .section .rodata.ram1,"a",@progbits
|
; SECTIONS: .section .rodata.ram1,"a",@progbits
|
||||||
; CHECK-LABEL: ram1:
|
; CHECK-LABEL: ram1:
|
||||||
|
|
Loading…
Reference in New Issue