blob: 45a61fa29be2c431966a27800ca3c3681b6e06cc [file] [log] [blame]
Sanjiv Gupta09bb4202008-05-13 09:02:57 +00001//===-- PIC16TargetMachine.cpp - Define TargetMachine for PIC16 -----------===//
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// Top-level implementation for the PIC16 target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "PIC16.h"
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000015#include "PIC16TargetAsmInfo.h"
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +000016#include "PIC16TargetMachine.h"
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000017#include "llvm/Module.h"
18#include "llvm/PassManager.h"
Sanjiv Gupta085ae4f2008-11-19 11:00:54 +000019#include "llvm/CodeGen/Passes.h"
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000020#include "llvm/Target/TargetAsmInfo.h"
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +000021#include "llvm/Target/TargetMachineRegistry.h"
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000022
23using namespace llvm;
24
Oscar Fuentes4f012352008-11-15 21:36:30 +000025/// 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
29/// remove it.
30extern "C" int PIC16TargetMachineModule;
31int PIC16TargetMachineModule = 0;
32
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000033
Sanjiv Gupta085ae4f2008-11-19 11:00:54 +000034// Register the targets
Daniel Dunbar6fa4f572009-07-15 09:22:31 +000035extern Target ThePIC16Target;
Sanjiv Gupta085ae4f2008-11-19 11:00:54 +000036static RegisterTarget<PIC16TargetMachine>
Daniel Dunbar6fa4f572009-07-15 09:22:31 +000037X(ThePIC16Target, "pic16", "PIC16 14-bit [experimental].");
38
39extern Target TheCooperTarget;
Sanjiv Gupta085ae4f2008-11-19 11:00:54 +000040static RegisterTarget<CooperTargetMachine>
Daniel Dunbar6fa4f572009-07-15 09:22:31 +000041Y(TheCooperTarget, "cooper", "PIC16 Cooper [experimental].");
Sanjiv Gupta085ae4f2008-11-19 11:00:54 +000042
Bob Wilsonebbc1c42009-06-23 23:59:40 +000043// Force static initialization.
44extern "C" void LLVMInitializePIC16Target() { }
Douglas Gregor1dc5ff42009-06-16 20:12:29 +000045
Sanjiv Gupta085ae4f2008-11-19 11:00:54 +000046// PIC16TargetMachine - Traditional PIC16 Machine.
Daniel Dunbar8ea70212009-07-15 12:11:05 +000047PIC16TargetMachine::PIC16TargetMachine(const Target &T, const Module &M,
48 const std::string &FS, bool Cooper)
49: LLVMTargetMachine(T),
50 Subtarget(M, FS, Cooper),
Sanjiv Gupta085ae4f2008-11-19 11:00:54 +000051 DataLayout("e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8"),
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000052 InstrInfo(*this), TLInfo(*this),
53 FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0) { }
54
Sanjiv Gupta085ae4f2008-11-19 11:00:54 +000055// CooperTargetMachine - Uses the same PIC16TargetMachine, but makes IsCooper
56// as true.
Daniel Dunbar8ea70212009-07-15 12:11:05 +000057CooperTargetMachine::CooperTargetMachine(const Target &T, const Module &M,
58 const std::string &FS)
59 : PIC16TargetMachine(T, M, FS, true) {}
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000060
Sanjiv Gupta085ae4f2008-11-19 11:00:54 +000061
62const TargetAsmInfo *PIC16TargetMachine::createTargetAsmInfo() const {
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000063 return new PIC16TargetAsmInfo(*this);
64}
65
Bill Wendling58ed5d22009-04-29 00:15:41 +000066bool PIC16TargetMachine::addInstSelector(PassManagerBase &PM,
Bill Wendling5ed22ac2009-04-29 23:29:43 +000067 CodeGenOpt::Level OptLevel) {
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000068 // Install an instruction selector.
69 PM.add(createPIC16ISelDag(*this));
70 return false;
71}
72
Daniel Dunbarb10d2222009-07-01 01:48:54 +000073bool PIC16TargetMachine::addAssemblyEmitter(PassManagerBase &PM,
74 CodeGenOpt::Level OptLevel,
David Greene302008d2009-07-14 20:18:05 +000075 bool Verbose,
76 formatted_raw_ostream &Out) {
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000077 // Output assembly language.
Daniel Dunbarb10d2222009-07-01 01:48:54 +000078 PM.add(createPIC16CodePrinterPass(Out, *this, Verbose));
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000079 return false;
80}
81
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000082bool PIC16TargetMachine::addPostRegAlloc(PassManagerBase &PM,
83 CodeGenOpt::Level OptLevel) {
84 PM.add(createPIC16MemSelOptimizerPass());
85 return true; // -print-machineinstr should print after this.
86}
87
Sanjiv Gupta085ae4f2008-11-19 11:00:54 +000088