blob: bda632608ea768df9b6a61f62f7b458c57471e9e [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
35static RegisterTarget<PIC16TargetMachine>
Evan Cheng07213cb2008-11-26 18:00:00 +000036X("pic16", "PIC16 14-bit [experimental].");
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000037static RegisterTarget<CooperTargetMachine>
Evan Cheng07213cb2008-11-26 18:00:00 +000038Y("cooper", "PIC16 Cooper [experimental].");
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000039
40// PIC16TargetMachine - Traditional PIC16 Machine.
41PIC16TargetMachine::PIC16TargetMachine(const Module &M, const std::string &FS,
42 bool Cooper)
43: Subtarget(M, FS, Cooper),
44 DataLayout("e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8"),
Sanjiv Gupta0e687712008-05-13 09:02:57 +000045 InstrInfo(*this), TLInfo(*this),
46 FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0) { }
47
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000048// CooperTargetMachine - Uses the same PIC16TargetMachine, but makes IsCooper
49// as true.
50CooperTargetMachine::CooperTargetMachine(const Module &M, const std::string &FS)
51 : PIC16TargetMachine(M, FS, true) {}
Sanjiv Gupta0e687712008-05-13 09:02:57 +000052
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000053
54const TargetAsmInfo *PIC16TargetMachine::createTargetAsmInfo() const {
Sanjiv Gupta0e687712008-05-13 09:02:57 +000055 return new PIC16TargetAsmInfo(*this);
56}
57
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000058bool PIC16TargetMachine::addInstSelector(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +000059 CodeGenOpt::Level OptLevel) {
Sanjiv Gupta0e687712008-05-13 09:02:57 +000060 // Install an instruction selector.
61 PM.add(createPIC16ISelDag(*this));
62 return false;
63}
64
65bool PIC16TargetMachine::
Bill Wendling98a366d2009-04-29 23:29:43 +000066addAssemblyEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel,
67 bool Verbose, raw_ostream &Out) {
Sanjiv Gupta0e687712008-05-13 09:02:57 +000068 // Output assembly language.
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000069 PM.add(createPIC16CodePrinterPass(Out, *this, OptLevel, Verbose));
Sanjiv Gupta0e687712008-05-13 09:02:57 +000070 return false;
71}
72
Sanjiv Guptad8d27f42009-05-06 08:02:01 +000073bool PIC16TargetMachine::addPostRegAlloc(PassManagerBase &PM,
74 CodeGenOpt::Level OptLevel) {
75 PM.add(createPIC16MemSelOptimizerPass());
76 return true; // -print-machineinstr should print after this.
77}
78
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000079