1 //===-- AVRTargetMachine.cpp - Define TargetMachine for AVR ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the AVR specific subclass of TargetMachine.
12 //===----------------------------------------------------------------------===//
14 #include "AVRTargetMachine.h"
16 #include "llvm/CodeGen/Passes.h"
17 #include "llvm/CodeGen/TargetPassConfig.h"
18 #include "llvm/IR/Module.h"
19 #include "llvm/IR/LegacyPassManager.h"
20 #include "llvm/Support/TargetRegistry.h"
22 #include "AVRTargetObjectFile.h"
24 #include "MCTargetDesc/AVRMCTargetDesc.h"
28 /// Processes a CPU name.
29 static StringRef getCPU(StringRef CPU) {
30 if (CPU.empty() || CPU == "generic") {
37 static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
38 return RM.hasValue() ? *RM : Reloc::Static;
41 AVRTargetMachine::AVRTargetMachine(const Target &T, const Triple &TT,
42 StringRef CPU, StringRef FS,
43 const TargetOptions &Options,
44 Optional<Reloc::Model> RM, CodeModel::Model CM,
47 T, "e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8-i64:8:8-f32:8:8-f64:8:8-n8", TT,
48 getCPU(CPU), FS, Options, getEffectiveRelocModel(RM), CM, OL),
49 SubTarget(TT, getCPU(CPU), FS, *this) {
50 this->TLOF = make_unique<AVRTargetObjectFile>();
55 /// AVR Code Generator Pass Configuration Options.
56 class AVRPassConfig : public TargetPassConfig {
58 AVRPassConfig(AVRTargetMachine *TM, PassManagerBase &PM)
59 : TargetPassConfig(TM, PM) {}
61 AVRTargetMachine &getAVRTargetMachine() const {
62 return getTM<AVRTargetMachine>();
65 bool addInstSelector() override;
66 void addPreSched2() override;
67 void addPreRegAlloc() override;
68 void addPreEmitPass() override;
72 TargetPassConfig *AVRTargetMachine::createPassConfig(PassManagerBase &PM) {
73 return new AVRPassConfig(this, PM);
76 extern "C" void LLVMInitializeAVRTarget() {
77 // Register the target.
78 RegisterTargetMachine<AVRTargetMachine> X(TheAVRTarget);
81 const AVRSubtarget *AVRTargetMachine::getSubtargetImpl() const {
85 const AVRSubtarget *AVRTargetMachine::getSubtargetImpl(const Function &) const {
89 //===----------------------------------------------------------------------===//
90 // Pass Pipeline Configuration
91 //===----------------------------------------------------------------------===//
93 bool AVRPassConfig::addInstSelector() {
97 void AVRPassConfig::addPreRegAlloc() {
100 void AVRPassConfig::addPreSched2() { }
102 void AVRPassConfig::addPreEmitPass() {
105 } // end of namespace llvm