Dylan McKay | 6d8078f | 2016-05-06 10:12:31 +0000 | [diff] [blame] | 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" |
Matthias Braun | 31d19d4 | 2016-05-10 03:21:59 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/TargetPassConfig.h" |
Dylan McKay | 6d8078f | 2016-05-06 10:12:31 +0000 | [diff] [blame] | 18 | #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 | |
| 26 | namespace llvm { |
| 27 | |
Dylan McKay | b967d16 | 2016-09-28 13:29:10 +0000 | [diff] [blame^] | 28 | static const char *AVRDataLayout = "e-p:16:16:16-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-n8"; |
| 29 | |
Dylan McKay | 6d8078f | 2016-05-06 10:12:31 +0000 | [diff] [blame] | 30 | /// Processes a CPU name. |
Dylan McKay | f1f1c01 | 2016-05-18 11:11:38 +0000 | [diff] [blame] | 31 | static StringRef getCPU(StringRef CPU) { |
Dylan McKay | 6d8078f | 2016-05-06 10:12:31 +0000 | [diff] [blame] | 32 | if (CPU.empty() || CPU == "generic") { |
| 33 | return "avr2"; |
| 34 | } |
| 35 | |
| 36 | return CPU; |
| 37 | } |
| 38 | |
Dylan McKay | be8e2e0 | 2016-05-20 23:39:04 +0000 | [diff] [blame] | 39 | static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) { |
| 40 | return RM.hasValue() ? *RM : Reloc::Static; |
| 41 | } |
| 42 | |
Dylan McKay | 6d8078f | 2016-05-06 10:12:31 +0000 | [diff] [blame] | 43 | AVRTargetMachine::AVRTargetMachine(const Target &T, const Triple &TT, |
| 44 | StringRef CPU, StringRef FS, |
| 45 | const TargetOptions &Options, |
Dylan McKay | be8e2e0 | 2016-05-20 23:39:04 +0000 | [diff] [blame] | 46 | Optional<Reloc::Model> RM, CodeModel::Model CM, |
Dylan McKay | 6d8078f | 2016-05-06 10:12:31 +0000 | [diff] [blame] | 47 | CodeGenOpt::Level OL) |
| 48 | : LLVMTargetMachine( |
Dylan McKay | b967d16 | 2016-09-28 13:29:10 +0000 | [diff] [blame^] | 49 | T, AVRDataLayout, TT, |
Dylan McKay | be8e2e0 | 2016-05-20 23:39:04 +0000 | [diff] [blame] | 50 | getCPU(CPU), FS, Options, getEffectiveRelocModel(RM), CM, OL), |
Dylan McKay | f1f1c01 | 2016-05-18 11:11:38 +0000 | [diff] [blame] | 51 | SubTarget(TT, getCPU(CPU), FS, *this) { |
Dylan McKay | 6d8078f | 2016-05-06 10:12:31 +0000 | [diff] [blame] | 52 | this->TLOF = make_unique<AVRTargetObjectFile>(); |
| 53 | initAsmInfo(); |
| 54 | } |
| 55 | |
| 56 | namespace { |
| 57 | /// AVR Code Generator Pass Configuration Options. |
| 58 | class AVRPassConfig : public TargetPassConfig { |
| 59 | public: |
| 60 | AVRPassConfig(AVRTargetMachine *TM, PassManagerBase &PM) |
| 61 | : TargetPassConfig(TM, PM) {} |
| 62 | |
| 63 | AVRTargetMachine &getAVRTargetMachine() const { |
| 64 | return getTM<AVRTargetMachine>(); |
| 65 | } |
| 66 | |
| 67 | bool addInstSelector() override; |
| 68 | void addPreSched2() override; |
| 69 | void addPreRegAlloc() override; |
| 70 | void addPreEmitPass() override; |
| 71 | }; |
| 72 | } // namespace |
| 73 | |
| 74 | TargetPassConfig *AVRTargetMachine::createPassConfig(PassManagerBase &PM) { |
| 75 | return new AVRPassConfig(this, PM); |
| 76 | } |
Dylan McKay | c498ba3 | 2015-11-12 09:26:44 +0000 | [diff] [blame] | 77 | |
| 78 | extern "C" void LLVMInitializeAVRTarget() { |
Dylan McKay | 6d8078f | 2016-05-06 10:12:31 +0000 | [diff] [blame] | 79 | // Register the target. |
| 80 | RegisterTargetMachine<AVRTargetMachine> X(TheAVRTarget); |
Dylan McKay | c498ba3 | 2015-11-12 09:26:44 +0000 | [diff] [blame] | 81 | } |
Dylan McKay | 6d8078f | 2016-05-06 10:12:31 +0000 | [diff] [blame] | 82 | |
| 83 | const AVRSubtarget *AVRTargetMachine::getSubtargetImpl() const { |
| 84 | return &SubTarget; |
| 85 | } |
| 86 | |
| 87 | const AVRSubtarget *AVRTargetMachine::getSubtargetImpl(const Function &) const { |
| 88 | return &SubTarget; |
| 89 | } |
| 90 | |
| 91 | //===----------------------------------------------------------------------===// |
| 92 | // Pass Pipeline Configuration |
| 93 | //===----------------------------------------------------------------------===// |
| 94 | |
| 95 | bool AVRPassConfig::addInstSelector() { |
| 96 | return false; |
| 97 | } |
| 98 | |
| 99 | void AVRPassConfig::addPreRegAlloc() { |
| 100 | } |
| 101 | |
| 102 | void AVRPassConfig::addPreSched2() { } |
| 103 | |
| 104 | void AVRPassConfig::addPreEmitPass() { |
| 105 | } |
| 106 | |
| 107 | } // end of namespace llvm |