| Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 1 | //===-- 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 Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 15 | #include "PIC16TargetAsmInfo.h" | 
| Sanjiv Gupta | 2010b3e | 2008-05-14 11:31:39 +0000 | [diff] [blame] | 16 | #include "PIC16TargetMachine.h" | 
| Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 17 | #include "llvm/Module.h" | 
|  | 18 | #include "llvm/PassManager.h" | 
| Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/Passes.h" | 
| Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetAsmInfo.h" | 
| Sanjiv Gupta | 2010b3e | 2008-05-14 11:31:39 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetMachineRegistry.h" | 
| Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 22 |  | 
|  | 23 | using namespace llvm; | 
|  | 24 |  | 
| Oscar Fuentes | 92adc19 | 2008-11-15 21:36:30 +0000 | [diff] [blame] | 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 | 
|  | 29 | /// remove it. | 
|  | 30 | extern "C" int PIC16TargetMachineModule; | 
|  | 31 | int PIC16TargetMachineModule = 0; | 
|  | 32 |  | 
| Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 33 |  | 
| Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 34 | // Register the targets | 
| Daniel Dunbar | 51b198a | 2009-07-15 20:24:03 +0000 | [diff] [blame] | 35 | extern Target ThePIC16Target; | 
| Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 36 | static RegisterTarget<PIC16TargetMachine> | 
| Daniel Dunbar | 51b198a | 2009-07-15 20:24:03 +0000 | [diff] [blame] | 37 | X(ThePIC16Target, "pic16", "PIC16 14-bit [experimental]."); | 
|  | 38 |  | 
|  | 39 | extern Target TheCooperTarget; | 
| Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 40 | static RegisterTarget<CooperTargetMachine> | 
| Daniel Dunbar | 51b198a | 2009-07-15 20:24:03 +0000 | [diff] [blame] | 41 | Y(TheCooperTarget, "cooper", "PIC16 Cooper [experimental]."); | 
| Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 42 |  | 
| Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 43 | // Force static initialization. | 
|  | 44 | extern "C" void LLVMInitializePIC16Target() { } | 
| Douglas Gregor | 1555a23 | 2009-06-16 20:12:29 +0000 | [diff] [blame] | 45 |  | 
| Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 46 | // PIC16TargetMachine - Traditional PIC16 Machine. | 
| Daniel Dunbar | 51b198a | 2009-07-15 20:24:03 +0000 | [diff] [blame] | 47 | PIC16TargetMachine::PIC16TargetMachine(const Target &T, const Module &M, | 
|  | 48 | const std::string &FS, bool Cooper) | 
|  | 49 | : LLVMTargetMachine(T), | 
|  | 50 | Subtarget(M, FS, Cooper), | 
| Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 51 | DataLayout("e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8"), | 
| Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 52 | InstrInfo(*this), TLInfo(*this), | 
|  | 53 | FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0) { } | 
|  | 54 |  | 
| Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 55 | // CooperTargetMachine - Uses the same PIC16TargetMachine, but makes IsCooper | 
|  | 56 | // as true. | 
| Daniel Dunbar | 51b198a | 2009-07-15 20:24:03 +0000 | [diff] [blame] | 57 | CooperTargetMachine::CooperTargetMachine(const Target &T, const Module &M, | 
|  | 58 | const std::string &FS) | 
|  | 59 | : PIC16TargetMachine(T, M, FS, true) {} | 
| Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 60 |  | 
| Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 61 |  | 
|  | 62 | const TargetAsmInfo *PIC16TargetMachine::createTargetAsmInfo() const { | 
| Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 63 | return new PIC16TargetAsmInfo(*this); | 
|  | 64 | } | 
|  | 65 |  | 
| Bill Wendling | be8cc2a | 2009-04-29 00:15:41 +0000 | [diff] [blame] | 66 | bool PIC16TargetMachine::addInstSelector(PassManagerBase &PM, | 
| Bill Wendling | 98a366d | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 67 | CodeGenOpt::Level OptLevel) { | 
| Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 68 | // Install an instruction selector. | 
|  | 69 | PM.add(createPIC16ISelDag(*this)); | 
|  | 70 | return false; | 
|  | 71 | } | 
|  | 72 |  | 
| Daniel Dunbar | 5bcc8bd | 2009-07-01 01:48:54 +0000 | [diff] [blame] | 73 | bool PIC16TargetMachine::addAssemblyEmitter(PassManagerBase &PM, | 
|  | 74 | CodeGenOpt::Level OptLevel, | 
| David Greene | 7184781 | 2009-07-14 20:18:05 +0000 | [diff] [blame] | 75 | bool Verbose, | 
|  | 76 | formatted_raw_ostream &Out) { | 
| Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 77 | // Output assembly language. | 
| Daniel Dunbar | 5bcc8bd | 2009-07-01 01:48:54 +0000 | [diff] [blame] | 78 | PM.add(createPIC16CodePrinterPass(Out, *this, Verbose)); | 
| Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 79 | return false; | 
|  | 80 | } | 
|  | 81 |  | 
| Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 82 | bool PIC16TargetMachine::addPostRegAlloc(PassManagerBase &PM, | 
|  | 83 | CodeGenOpt::Level OptLevel) { | 
|  | 84 | PM.add(createPIC16MemSelOptimizerPass()); | 
|  | 85 | return true;  // -print-machineinstr should print after this. | 
|  | 86 | } | 
|  | 87 |  | 
| Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 88 |  |