Files
TheRock/compiler/amd-llvm/llvm/lib/Target/AVR/AVRTargetObjectFile.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

84 lines
3.3 KiB
C++

//===-- AVRTargetObjectFile.cpp - AVR Object Files ------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "AVRTargetObjectFile.h"
#include "AVRTargetMachine.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/Mangler.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCSectionELF.h"
#include "AVR.h"
namespace llvm {
void AVRTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) {
Base::Initialize(Ctx, TM);
ProgmemDataSection =
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(
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
// Global values in flash memory are placed in the progmem*.data section
// unless they already have a user assigned section.
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;
}
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.
return Base::SelectSectionForGlobal(GO, Kind, TM);
}
} // end of namespace llvm