blob: 85ec02899adbf7f5aa55b941a2ec979797f3f8aa [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- AlphaTargetMachine.cpp - Define TargetMachine for Alpha -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
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"
20
21using namespace llvm;
22
23namespace {
24 // Register the targets
25 RegisterTarget<AlphaTargetMachine> X("alpha", " Alpha (incomplete)");
26}
27
28const TargetAsmInfo *AlphaTargetMachine::createTargetAsmInfo() const {
29 return new AlphaTargetAsmInfo(*this);
30}
31
32unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) {
33 // We strongly match "alpha*".
34 std::string TT = M.getTargetTriple();
35 if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
36 TT[3] == 'h' && TT[4] == 'a')
37 return 20;
38 // If the target triple is something non-alpha, we don't match.
39 if (!TT.empty()) return 0;
40
41 if (M.getEndianness() == Module::LittleEndian &&
42 M.getPointerSize() == Module::Pointer64)
43 return 10; // Weak match
44 else if (M.getEndianness() != Module::AnyEndianness ||
45 M.getPointerSize() != Module::AnyPointerSize)
46 return 0; // Match for some other target
47
48 return getJITMatchQuality()/2;
49}
50
51unsigned AlphaTargetMachine::getJITMatchQuality() {
52#ifdef __alpha
53 return 10;
54#else
55 return 0;
56#endif
57}
58
59AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS)
Dale Johannesen4c39f712007-08-03 20:20:50 +000060 : DataLayout("e-f128:128:128"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000061 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
62 JITInfo(*this),
63 Subtarget(M, FS),
64 TLInfo(*this) {
65 setRelocationModel(Reloc::PIC_);
66}
67
68
69//===----------------------------------------------------------------------===//
70// Pass Pipeline Configuration
71//===----------------------------------------------------------------------===//
72
73bool AlphaTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
74 PM.add(createAlphaISelDag(*this));
75 return false;
76}
77bool AlphaTargetMachine::addPreEmitPass(FunctionPassManager &PM, bool Fast) {
78 // Must run branch selection immediately preceding the asm printer
79 PM.add(createAlphaBranchSelectionPass());
80 return false;
81}
82bool AlphaTargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast,
83 std::ostream &Out) {
84 PM.add(createAlphaLLRPPass(*this));
85 PM.add(createAlphaCodePrinterPass(Out, *this));
86 return false;
87}
88bool AlphaTargetMachine::addCodeEmitter(FunctionPassManager &PM, bool Fast,
Evan Cheng77547212007-07-20 21:56:13 +000089 bool DumpAsm, MachineCodeEmitter &MCE) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000090 PM.add(createAlphaCodeEmitterPass(*this, MCE));
Evan Cheng77547212007-07-20 21:56:13 +000091 if (DumpAsm)
92 PM.add(createAlphaCodePrinterPass(*cerr.stream(), *this));
Dan Gohmanf17a25c2007-07-18 16:29:46 +000093 return false;
94}
95bool AlphaTargetMachine::addSimpleCodeEmitter(FunctionPassManager &PM,
Evan Cheng77547212007-07-20 21:56:13 +000096 bool Fast, bool DumpAsm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000097 MachineCodeEmitter &MCE) {
Evan Cheng77547212007-07-20 21:56:13 +000098 return addCodeEmitter(PM, Fast, DumpAsm, MCE);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000099}