MSP430TargetMachine.cpp revision 4246790aa84a530b0378d917023584c2c7adb4a9
1//===-- 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
35extern Target TheMSP430Target;
36static RegisterTarget<MSP430TargetMachine>
37X(TheMSP430Target, "msp430", "MSP430 [experimental]");
38
39// Force static initialization.
40extern "C" void LLVMInitializeMSP430Target() { }
41
42MSP430TargetMachine::MSP430TargetMachine(const Module &M,
43                                         const std::string &FS) :
44  Subtarget(*this, M, FS),
45  // FIXME: Check TargetData string.
46  DataLayout("e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8"),
47  InstrInfo(*this), TLInfo(*this),
48  FrameInfo(TargetFrameInfo::StackGrowsDown, 2, -2) { }
49
50const TargetAsmInfo *MSP430TargetMachine::createTargetAsmInfo() const {
51  return new MSP430TargetAsmInfo(*this);
52}
53
54bool MSP430TargetMachine::addInstSelector(PassManagerBase &PM,
55                                          CodeGenOpt::Level OptLevel) {
56  // Install an instruction selector.
57  PM.add(createMSP430ISelDag(*this, OptLevel));
58  return false;
59}
60
61bool MSP430TargetMachine::addAssemblyEmitter(PassManagerBase &PM,
62                                             CodeGenOpt::Level OptLevel,
63                                             bool Verbose,
64                                             formatted_raw_ostream &Out) {
65  // Output assembly language.
66  PM.add(createMSP430CodePrinterPass(Out, *this, Verbose));
67  return false;
68}
69
70unsigned MSP430TargetMachine::getModuleMatchQuality(const Module &M) {
71  std::string TT = M.getTargetTriple();
72
73  // We strongly match msp430
74  if (TT.size() >= 6 && TT[0] == 'm' && TT[1] == 's' && TT[2] == 'p' &&
75      TT[3] == '4' &&  TT[4] == '3' && TT[5] == '0')
76    return 20;
77
78  return 0;
79}
80
81