blob: 4c7ca8fbf66725949c0ff1df0ec018c333da2d7a [file] [log] [blame]
Sanjiv Gupta0e687712008-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 Gupta0e687712008-05-13 09:02:57 +000015#include "PIC16TargetAsmInfo.h"
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +000016#include "PIC16TargetMachine.h"
Sanjiv Gupta0e687712008-05-13 09:02:57 +000017#include "llvm/Module.h"
18#include "llvm/PassManager.h"
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000019#include "llvm/CodeGen/Passes.h"
Sanjiv Gupta0e687712008-05-13 09:02:57 +000020#include "llvm/Target/TargetAsmInfo.h"
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +000021#include "llvm/Target/TargetMachineRegistry.h"
Sanjiv Gupta0e687712008-05-13 09:02:57 +000022
23using namespace llvm;
24
Oscar Fuentes92adc192008-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 Gupta0e687712008-05-13 09:02:57 +000033
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000034// Register the targets
Daniel Dunbar51b198a2009-07-15 20:24:03 +000035extern Target ThePIC16Target;
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000036static RegisterTarget<PIC16TargetMachine>
Daniel Dunbar51b198a2009-07-15 20:24:03 +000037X(ThePIC16Target, "pic16", "PIC16 14-bit [experimental].");
38
39extern Target TheCooperTarget;
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000040static RegisterTarget<CooperTargetMachine>
Daniel Dunbar51b198a2009-07-15 20:24:03 +000041Y(TheCooperTarget, "cooper", "PIC16 Cooper [experimental].");
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000042
Bob Wilsona96751f2009-06-23 23:59:40 +000043// Force static initialization.
Daniel Dunbar1e1f8ba2009-07-15 23:17:20 +000044extern "C" void LLVMInitializePIC16Target() {
45 TargetRegistry::RegisterAsmPrinter(ThePIC16Target,
46 &createPIC16CodePrinterPass);
47 TargetRegistry::RegisterAsmPrinter(TheCooperTarget,
48 &createPIC16CodePrinterPass);
49}
Douglas Gregor1555a232009-06-16 20:12:29 +000050
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000051// PIC16TargetMachine - Traditional PIC16 Machine.
Daniel Dunbar51b198a2009-07-15 20:24:03 +000052PIC16TargetMachine::PIC16TargetMachine(const Target &T, const Module &M,
53 const std::string &FS, bool Cooper)
54: LLVMTargetMachine(T),
55 Subtarget(M, FS, Cooper),
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000056 DataLayout("e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8"),
Sanjiv Gupta0e687712008-05-13 09:02:57 +000057 InstrInfo(*this), TLInfo(*this),
58 FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0) { }
59
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000060// CooperTargetMachine - Uses the same PIC16TargetMachine, but makes IsCooper
61// as true.
Daniel Dunbar51b198a2009-07-15 20:24:03 +000062CooperTargetMachine::CooperTargetMachine(const Target &T, const Module &M,
63 const std::string &FS)
64 : PIC16TargetMachine(T, M, FS, true) {}
Sanjiv Gupta0e687712008-05-13 09:02:57 +000065
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000066
67const TargetAsmInfo *PIC16TargetMachine::createTargetAsmInfo() const {
Sanjiv Gupta0e687712008-05-13 09:02:57 +000068 return new PIC16TargetAsmInfo(*this);
69}
70
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000071bool PIC16TargetMachine::addInstSelector(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +000072 CodeGenOpt::Level OptLevel) {
Sanjiv Gupta0e687712008-05-13 09:02:57 +000073 // Install an instruction selector.
74 PM.add(createPIC16ISelDag(*this));
75 return false;
76}
77
Sanjiv Guptad8d27f42009-05-06 08:02:01 +000078bool PIC16TargetMachine::addPostRegAlloc(PassManagerBase &PM,
79 CodeGenOpt::Level OptLevel) {
80 PM.add(createPIC16MemSelOptimizerPass());
81 return true; // -print-machineinstr should print after this.
82}
83
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000084