blob: 508723e91c60b41c8d6ce9285db5c3d704d7d22c [file] [log] [blame]
Dylan McKay6d8078f2016-05-06 10:12:31 +00001//===-- AVRTargetMachine.cpp - Define TargetMachine for AVR ---------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the AVR specific subclass of TargetMachine.
11//
12//===----------------------------------------------------------------------===//
13
14#include "AVRTargetMachine.h"
15
16#include "llvm/CodeGen/Passes.h"
Matthias Braun31d19d42016-05-10 03:21:59 +000017#include "llvm/CodeGen/TargetPassConfig.h"
Dylan McKay6d8078f2016-05-06 10:12:31 +000018#include "llvm/IR/Module.h"
19#include "llvm/IR/LegacyPassManager.h"
20#include "llvm/Support/TargetRegistry.h"
21
22#include "AVRTargetObjectFile.h"
23#include "AVR.h"
24#include "MCTargetDesc/AVRMCTargetDesc.h"
25
26namespace llvm {
27
28/// Processes a CPU name.
Dylan McKayf1f1c012016-05-18 11:11:38 +000029static StringRef getCPU(StringRef CPU) {
Dylan McKay6d8078f2016-05-06 10:12:31 +000030 if (CPU.empty() || CPU == "generic") {
31 return "avr2";
32 }
33
34 return CPU;
35}
36
Dylan McKaybe8e2e02016-05-20 23:39:04 +000037static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
38 return RM.hasValue() ? *RM : Reloc::Static;
39}
40
Dylan McKay6d8078f2016-05-06 10:12:31 +000041AVRTargetMachine::AVRTargetMachine(const Target &T, const Triple &TT,
42 StringRef CPU, StringRef FS,
43 const TargetOptions &Options,
Dylan McKaybe8e2e02016-05-20 23:39:04 +000044 Optional<Reloc::Model> RM, CodeModel::Model CM,
Dylan McKay6d8078f2016-05-06 10:12:31 +000045 CodeGenOpt::Level OL)
46 : LLVMTargetMachine(
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,
Dylan McKaybe8e2e02016-05-20 23:39:04 +000048 getCPU(CPU), FS, Options, getEffectiveRelocModel(RM), CM, OL),
Dylan McKayf1f1c012016-05-18 11:11:38 +000049 SubTarget(TT, getCPU(CPU), FS, *this) {
Dylan McKay6d8078f2016-05-06 10:12:31 +000050 this->TLOF = make_unique<AVRTargetObjectFile>();
51 initAsmInfo();
52}
53
54namespace {
55/// AVR Code Generator Pass Configuration Options.
56class AVRPassConfig : public TargetPassConfig {
57public:
58 AVRPassConfig(AVRTargetMachine *TM, PassManagerBase &PM)
59 : TargetPassConfig(TM, PM) {}
60
61 AVRTargetMachine &getAVRTargetMachine() const {
62 return getTM<AVRTargetMachine>();
63 }
64
65 bool addInstSelector() override;
66 void addPreSched2() override;
67 void addPreRegAlloc() override;
68 void addPreEmitPass() override;
69};
70} // namespace
71
72TargetPassConfig *AVRTargetMachine::createPassConfig(PassManagerBase &PM) {
73 return new AVRPassConfig(this, PM);
74}
Dylan McKayc498ba32015-11-12 09:26:44 +000075
76extern "C" void LLVMInitializeAVRTarget() {
Dylan McKay6d8078f2016-05-06 10:12:31 +000077 // Register the target.
78 RegisterTargetMachine<AVRTargetMachine> X(TheAVRTarget);
Dylan McKayc498ba32015-11-12 09:26:44 +000079}
Dylan McKay6d8078f2016-05-06 10:12:31 +000080
81const AVRSubtarget *AVRTargetMachine::getSubtargetImpl() const {
82 return &SubTarget;
83}
84
85const AVRSubtarget *AVRTargetMachine::getSubtargetImpl(const Function &) const {
86 return &SubTarget;
87}
88
89//===----------------------------------------------------------------------===//
90// Pass Pipeline Configuration
91//===----------------------------------------------------------------------===//
92
93bool AVRPassConfig::addInstSelector() {
94 return false;
95}
96
97void AVRPassConfig::addPreRegAlloc() {
98}
99
100void AVRPassConfig::addPreSched2() { }
101
102void AVRPassConfig::addPreEmitPass() {
103}
104
105} // end of namespace llvm