OSDN Git Service

[AVR] Add a majority of the backend code
[android-x86/external-llvm.git] / lib / Target / AVR / AVRTargetMachine.cpp
1 //===-- 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"
17 #include "llvm/IR/Module.h"
18 #include "llvm/IR/LegacyPassManager.h"
19 #include "llvm/Support/TargetRegistry.h"
20
21 #include "AVRTargetObjectFile.h"
22 #include "AVR.h"
23 #include "MCTargetDesc/AVRMCTargetDesc.h"
24
25 namespace llvm {
26
27 /// Processes a CPU name.
28 static StringRef getTargetCPU(StringRef CPU) {
29   if (CPU.empty() || CPU == "generic") {
30     return "avr2";
31   }
32
33   return CPU;
34 }
35
36 AVRTargetMachine::AVRTargetMachine(const Target &T, const Triple &TT,
37                                    StringRef CPU, StringRef FS,
38                                    const TargetOptions &Options,
39                                    Reloc::Model RM, CodeModel::Model CM,
40                                    CodeGenOpt::Level OL)
41     : LLVMTargetMachine(
42           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,
43           getTargetCPU(CPU), FS, Options, RM, CM, OL),
44       SubTarget(TT, GetTargetCPU(CPU), FS, *this) {
45   this->TLOF = make_unique<AVRTargetObjectFile>();
46   initAsmInfo();
47 }
48
49 namespace {
50 /// AVR Code Generator Pass Configuration Options.
51 class AVRPassConfig : public TargetPassConfig {
52 public:
53   AVRPassConfig(AVRTargetMachine *TM, PassManagerBase &PM)
54       : TargetPassConfig(TM, PM) {}
55
56   AVRTargetMachine &getAVRTargetMachine() const {
57     return getTM<AVRTargetMachine>();
58   }
59
60   bool addInstSelector() override;
61   void addPreSched2() override;
62   void addPreRegAlloc() override;
63   void addPreEmitPass() override;
64 };
65 } // namespace
66
67 TargetPassConfig *AVRTargetMachine::createPassConfig(PassManagerBase &PM) {
68   return new AVRPassConfig(this, PM);
69 }
70
71 extern "C" void LLVMInitializeAVRTarget() {
72   // Register the target.
73   RegisterTargetMachine<AVRTargetMachine> X(TheAVRTarget);
74 }
75
76 const AVRSubtarget *AVRTargetMachine::getSubtargetImpl() const {
77   return &SubTarget;
78 }
79
80 const AVRSubtarget *AVRTargetMachine::getSubtargetImpl(const Function &) const {
81   return &SubTarget;
82 }
83
84 //===----------------------------------------------------------------------===//
85 // Pass Pipeline Configuration
86 //===----------------------------------------------------------------------===//
87
88 bool AVRPassConfig::addInstSelector() {
89   return false;
90 }
91
92 void AVRPassConfig::addPreRegAlloc() {
93 }
94
95 void AVRPassConfig::addPreSched2() { }
96
97 void AVRPassConfig::addPreEmitPass() {
98 }
99
100 } // end of namespace llvm