blob: 66f72577044e049fe172a5b28fd5c29fc5213b60 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- AlphaTargetMachine.cpp - Define TargetMachine for Alpha -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10//
11//===----------------------------------------------------------------------===//
12
13#include "Alpha.h"
14#include "AlphaJITInfo.h"
15#include "AlphaTargetAsmInfo.h"
16#include "AlphaTargetMachine.h"
17#include "llvm/Module.h"
18#include "llvm/PassManager.h"
19#include "llvm/Target/TargetMachineRegistry.h"
Owen Anderson847b99b2008-08-21 00:14:44 +000020#include "llvm/Support/raw_ostream.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000021
22using namespace llvm;
23
Oscar Fuentes4f012352008-11-15 21:36:30 +000024/// AlphaTargetMachineModule - Note that this is used on hosts that cannot link
25/// in a library unless there are references into the library. In particular,
26/// it seems that it is not possible to get things to work on Win32 without
27/// this. Though it is unused, do not remove it.
28extern "C" int AlphaTargetMachineModule;
29int AlphaTargetMachineModule = 0;
30
Dan Gohman089efff2008-05-13 00:00:25 +000031// Register the targets
Chris Lattner3f83d3f2008-10-16 06:16:50 +000032static RegisterTarget<AlphaTargetMachine> X("alpha", "Alpha [experimental]");
Dan Gohmanf17a25c2007-07-18 16:29:46 +000033
Douglas Gregor1dc5ff42009-06-16 20:12:29 +000034// Force static initialization when called from llvm/InitializeAllTargets.h
35namespace llvm {
36 void InitializeAlphaTarget() { }
37}
38
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039const TargetAsmInfo *AlphaTargetMachine::createTargetAsmInfo() const {
40 return new AlphaTargetAsmInfo(*this);
41}
42
43unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) {
44 // We strongly match "alpha*".
45 std::string TT = M.getTargetTriple();
46 if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
47 TT[3] == 'h' && TT[4] == 'a')
48 return 20;
49 // If the target triple is something non-alpha, we don't match.
50 if (!TT.empty()) return 0;
51
52 if (M.getEndianness() == Module::LittleEndian &&
53 M.getPointerSize() == Module::Pointer64)
54 return 10; // Weak match
55 else if (M.getEndianness() != Module::AnyEndianness ||
56 M.getPointerSize() != Module::AnyPointerSize)
57 return 0; // Match for some other target
58
59 return getJITMatchQuality()/2;
60}
61
62unsigned AlphaTargetMachine::getJITMatchQuality() {
63#ifdef __alpha
64 return 10;
65#else
66 return 0;
67#endif
68}
69
70AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS)
Dale Johannesen4c39f712007-08-03 20:20:50 +000071 : DataLayout("e-f128:128:128"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000072 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
73 JITInfo(*this),
74 Subtarget(M, FS),
75 TLInfo(*this) {
76 setRelocationModel(Reloc::PIC_);
77}
78
79
80//===----------------------------------------------------------------------===//
81// Pass Pipeline Configuration
82//===----------------------------------------------------------------------===//
83
Bill Wendling58ed5d22009-04-29 00:15:41 +000084bool AlphaTargetMachine::addInstSelector(PassManagerBase &PM,
Bill Wendling5ed22ac2009-04-29 23:29:43 +000085 CodeGenOpt::Level OptLevel) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000086 PM.add(createAlphaISelDag(*this));
87 return false;
88}
Bill Wendling58ed5d22009-04-29 00:15:41 +000089bool AlphaTargetMachine::addPreEmitPass(PassManagerBase &PM,
Bill Wendling5ed22ac2009-04-29 23:29:43 +000090 CodeGenOpt::Level OptLevel) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000091 // Must run branch selection immediately preceding the asm printer
92 PM.add(createAlphaBranchSelectionPass());
93 return false;
94}
Bill Wendling58ed5d22009-04-29 00:15:41 +000095bool AlphaTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
Bill Wendling5ed22ac2009-04-29 23:29:43 +000096 CodeGenOpt::Level OptLevel,
Evan Cheng42ceb472009-03-25 01:47:28 +000097 bool Verbose,
Owen Anderson847b99b2008-08-21 00:14:44 +000098 raw_ostream &Out) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000099 PM.add(createAlphaLLRPPass(*this));
Bill Wendling58ed5d22009-04-29 00:15:41 +0000100 PM.add(createAlphaCodePrinterPass(Out, *this, OptLevel, Verbose));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000101 return false;
102}
Bill Wendling5ed22ac2009-04-29 23:29:43 +0000103bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM,
104 CodeGenOpt::Level OptLevel,
Evan Cheng77547212007-07-20 21:56:13 +0000105 bool DumpAsm, MachineCodeEmitter &MCE) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000106 PM.add(createAlphaCodeEmitterPass(*this, MCE));
Evan Cheng77547212007-07-20 21:56:13 +0000107 if (DumpAsm)
Bill Wendling58ed5d22009-04-29 00:15:41 +0000108 PM.add(createAlphaCodePrinterPass(errs(), *this, OptLevel, true));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000109 return false;
110}
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000111bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM,
112 CodeGenOpt::Level OptLevel,
113 bool DumpAsm, JITCodeEmitter &JCE) {
114 PM.add(createAlphaJITCodeEmitterPass(*this, JCE));
115 if (DumpAsm)
116 PM.add(createAlphaCodePrinterPass(errs(), *this, OptLevel, true));
117 return false;
118}
Dan Gohmane34aa772008-03-11 22:29:46 +0000119bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
Bill Wendling5ed22ac2009-04-29 23:29:43 +0000120 CodeGenOpt::Level OptLevel,
121 bool DumpAsm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000122 MachineCodeEmitter &MCE) {
Bill Wendling58ed5d22009-04-29 00:15:41 +0000123 return addCodeEmitter(PM, OptLevel, DumpAsm, MCE);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000124}
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000125bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
126 CodeGenOpt::Level OptLevel,
127 bool DumpAsm,
128 JITCodeEmitter &JCE) {
129 return addCodeEmitter(PM, OptLevel, DumpAsm, JCE);
130}
131