llvm-project/llvm/lib/Target/AVR/AVRTargetMachine.h
Ayke van Laethem 8202a3da3c
[AVR] Support most address space casts
All hardware address spaces on AVR can be freely cast between (they keep
the same bit pattern). They just aren't dereferenceable when they're in
a different address space as they really do point to a separate address
space.

This is supported in avr-gcc: https://godbolt.org/z/9Gfvhnhv9

avr-gcc also supports the `__memx` address space which is 24 bits. We
don't support this address space yet but I've added a safeguard just in
case.

Differential Revison: https://reviews.llvm.org/D142107
2023-01-24 18:41:14 +01:00

68 lines
2.3 KiB
C++

//===-- AVRTargetMachine.h - Define TargetMachine for AVR -------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// This file declares the AVR specific subclass of TargetMachine.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_AVR_TARGET_MACHINE_H
#define LLVM_AVR_TARGET_MACHINE_H
#include "llvm/IR/DataLayout.h"
#include "llvm/Target/TargetMachine.h"
#include "AVRFrameLowering.h"
#include "AVRISelLowering.h"
#include "AVRInstrInfo.h"
#include "AVRSelectionDAGInfo.h"
#include "AVRSubtarget.h"
#include <optional>
namespace llvm {
/// A generic AVR implementation.
class AVRTargetMachine : public LLVMTargetMachine {
public:
AVRTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
StringRef FS, const TargetOptions &Options,
std::optional<Reloc::Model> RM,
std::optional<CodeModel::Model> CM, CodeGenOpt::Level OL,
bool JIT);
const AVRSubtarget *getSubtargetImpl() const;
const AVRSubtarget *getSubtargetImpl(const Function &) const override;
TargetLoweringObjectFile *getObjFileLowering() const override {
return this->TLOF.get();
}
TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
MachineFunctionInfo *
createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
const TargetSubtargetInfo *STI) const override;
bool isNoopAddrSpaceCast(unsigned SrcAs, unsigned DestAs) const override {
// While AVR has different address spaces, they are all represented by
// 16-bit pointers that can be freely casted between (of course, a pointer
// must be cast back to its original address space to be dereferenceable).
// To be safe, also check the pointer size in case we implement __memx
// pointers.
return getPointerSize(SrcAs) == getPointerSize(DestAs);
}
private:
std::unique_ptr<TargetLoweringObjectFile> TLOF;
AVRSubtarget SubTarget;
};
} // end namespace llvm
#endif // LLVM_AVR_TARGET_MACHINE_H