1 //===-- PIC16TargetMachine.cpp - Define TargetMachine for PIC16 -----------===//
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 // Top-level implementation for the PIC16 target.
12 //===----------------------------------------------------------------------===//
15 #include "PIC16TargetAsmInfo.h"
16 #include "PIC16TargetMachine.h"
17 #include "llvm/Module.h"
18 #include "llvm/PassManager.h"
19 #include "llvm/CodeGen/Passes.h"
20 #include "llvm/Target/TargetAsmInfo.h"
21 #include "llvm/Target/TargetMachineRegistry.h"
25 /// PIC16TargetMachineModule - Note that this is used on hosts that
26 /// cannot link in a library unless there are references into the
27 /// library. In particular, it seems that it is not possible to get
28 /// things to work on Win32 without this. Though it is unused, do not
30 extern "C" int PIC16TargetMachineModule;
31 int PIC16TargetMachineModule = 0;
34 // Register the targets
35 extern Target ThePIC16Target;
36 static RegisterTarget<PIC16TargetMachine>
37 X(ThePIC16Target, "pic16", "PIC16 14-bit [experimental].");
39 extern Target TheCooperTarget;
40 static RegisterTarget<CooperTargetMachine>
41 Y(TheCooperTarget, "cooper", "PIC16 Cooper [experimental].");
43 // Force static initialization.
44 extern "C" void LLVMInitializePIC16Target() {
45 TargetRegistry::RegisterAsmPrinter(ThePIC16Target,
46 &createPIC16CodePrinterPass);
47 TargetRegistry::RegisterAsmPrinter(TheCooperTarget,
48 &createPIC16CodePrinterPass);
51 // PIC16TargetMachine - Traditional PIC16 Machine.
52 PIC16TargetMachine::PIC16TargetMachine(const Target &T, const Module &M,
53 const std::string &FS, bool Cooper)
54 : LLVMTargetMachine(T),
55 Subtarget(M, FS, Cooper),
56 DataLayout("e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8"),
57 InstrInfo(*this), TLInfo(*this),
58 FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0) { }
60 // CooperTargetMachine - Uses the same PIC16TargetMachine, but makes IsCooper
62 CooperTargetMachine::CooperTargetMachine(const Target &T, const Module &M,
63 const std::string &FS)
64 : PIC16TargetMachine(T, M, FS, true) {}
67 const TargetAsmInfo *PIC16TargetMachine::createTargetAsmInfo() const {
68 return new PIC16TargetAsmInfo(*this);
71 bool PIC16TargetMachine::addInstSelector(PassManagerBase &PM,
72 CodeGenOpt::Level OptLevel) {
73 // Install an instruction selector.
74 PM.add(createPIC16ISelDag(*this));
78 bool PIC16TargetMachine::addPostRegAlloc(PassManagerBase &PM,
79 CodeGenOpt::Level OptLevel) {
80 PM.add(createPIC16MemSelOptimizerPass());
81 return true; // -print-machineinstr should print after this.