blob: 0f5244d666fc75eefab1dee197ee64c054ce93d9 [file] [log] [blame]
Anton Korobeynikovf2c3e172009-05-03 12:57:15 +00001//===-- MSP430TargetMachine.cpp - Define TargetMachine for MSP430 ---------===//
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 MSP430 target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "MSP430.h"
15#include "MSP430TargetAsmInfo.h"
16#include "MSP430TargetMachine.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"
22
23using namespace llvm;
24
25/// MSP430TargetMachineModule - 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 MSP430TargetMachineModule;
31int MSP430TargetMachineModule = 0;
32
33
34// Register the targets
35static RegisterTarget<MSP430TargetMachine>
36X("msp430", "MSP430 [experimental]");
37
Douglas Gregor1555a232009-06-16 20:12:29 +000038// Force static initialization when called from llvm/InitializeAllTargets.h
39namespace llvm {
40 void InitializeMSP430Target() { }
41}
42
Anton Korobeynikovf2c3e172009-05-03 12:57:15 +000043MSP430TargetMachine::MSP430TargetMachine(const Module &M,
44 const std::string &FS) :
45 Subtarget(*this, M, FS),
Anton Korobeynikovfe3fc5a2009-05-03 12:58:05 +000046 // FIXME: Check TargetData string.
Anton Korobeynikovf2c3e172009-05-03 12:57:15 +000047 DataLayout("e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8"),
48 InstrInfo(*this), TLInfo(*this),
Anton Korobeynikovce45d302009-05-03 13:11:20 +000049 FrameInfo(TargetFrameInfo::StackGrowsDown, 2, -2) { }
Anton Korobeynikovf2c3e172009-05-03 12:57:15 +000050
Anton Korobeynikovf2c3e172009-05-03 12:57:15 +000051const TargetAsmInfo *MSP430TargetMachine::createTargetAsmInfo() const {
52 return new MSP430TargetAsmInfo(*this);
53}
54
Anton Korobeynikov60871cb2009-05-03 13:19:42 +000055bool MSP430TargetMachine::addInstSelector(PassManagerBase &PM,
56 CodeGenOpt::Level OptLevel) {
Anton Korobeynikovf2c3e172009-05-03 12:57:15 +000057 // Install an instruction selector.
Anton Korobeynikov60871cb2009-05-03 13:19:42 +000058 PM.add(createMSP430ISelDag(*this, OptLevel));
Anton Korobeynikovf2c3e172009-05-03 12:57:15 +000059 return false;
60}
61
Anton Korobeynikovf3085ac2009-05-03 13:01:23 +000062bool MSP430TargetMachine::addAssemblyEmitter(PassManagerBase &PM,
Anton Korobeynikov60871cb2009-05-03 13:19:42 +000063 CodeGenOpt::Level OptLevel,
64 bool Verbose,
Anton Korobeynikovf3085ac2009-05-03 13:01:23 +000065 raw_ostream &Out) {
Anton Korobeynikovf2c3e172009-05-03 12:57:15 +000066 // Output assembly language.
Anton Korobeynikov60871cb2009-05-03 13:19:42 +000067 PM.add(createMSP430CodePrinterPass(Out, *this, OptLevel, Verbose));
Anton Korobeynikovf2c3e172009-05-03 12:57:15 +000068 return false;
69}
Anton Korobeynikovf3085ac2009-05-03 13:01:23 +000070
71unsigned MSP430TargetMachine::getModuleMatchQuality(const Module &M) {
72 std::string TT = M.getTargetTriple();
73
74 // We strongly match msp430
75 if (TT.size() >= 6 && TT[0] == 'm' && TT[1] == 's' && TT[2] == 'p' &&
76 TT[3] == '4' && TT[4] == '3' && TT[5] == '0')
77 return 20;
78
79 return 0;
80}
81