blob: 23ce3131d606a6aac9a76241152f4f41631b5f16 [file] [log] [blame]
Andrew Lenharth886470e2005-01-24 18:45:41 +00001//===-- AlphaTargetMachine.cpp - Define TargetMachine for Alpha -----------===//
Misha Brukman4633f1c2005-04-21 23:13:11 +00002//
Andrew Lenharth304d0f32005-01-22 23:41:55 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman4633f1c2005-04-21 23:13:11 +00007//
Andrew Lenharth304d0f32005-01-22 23:41:55 +00008//===----------------------------------------------------------------------===//
Misha Brukman4633f1c2005-04-21 23:13:11 +00009//
Andrew Lenharth304d0f32005-01-22 23:41:55 +000010//
11//===----------------------------------------------------------------------===//
12
13#include "Alpha.h"
Andrew Lenharth0934ae02005-07-22 20:52:16 +000014#include "AlphaJITInfo.h"
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000015#include "AlphaTargetAsmInfo.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000016#include "AlphaTargetMachine.h"
Andrew Lenharth2f401632005-02-01 20:35:11 +000017#include "llvm/Module.h"
Chris Lattner1911fd42006-09-04 04:14:57 +000018#include "llvm/PassManager.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000019#include "llvm/Target/TargetMachineRegistry.h"
Andrew Lenharth2f401632005-02-01 20:35:11 +000020
Andrew Lenharth304d0f32005-01-22 23:41:55 +000021using namespace llvm;
22
23namespace {
24 // Register the targets
25 RegisterTarget<AlphaTargetMachine> X("alpha", " Alpha (incomplete)");
26}
27
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000028const TargetAsmInfo *AlphaTargetMachine::createTargetAsmInfo() const {
29 return new AlphaTargetAsmInfo(*this);
30}
31
Andrew Lenharth2f401632005-02-01 20:35:11 +000032unsigned 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;
Chris Lattner87bdba62007-07-09 17:25:29 +000038 // If the target triple is something non-alpha, we don't match.
39 if (!TT.empty()) return 0;
Andrew Lenharth2f401632005-02-01 20:35:11 +000040
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
Chris Lattnerc1d6f672005-10-30 16:44:01 +000048 return getJITMatchQuality()/2;
Andrew Lenharth2f401632005-02-01 20:35:11 +000049}
50
Andrew Lenharth0934ae02005-07-22 20:52:16 +000051unsigned AlphaTargetMachine::getJITMatchQuality() {
Andrew Lenharth38396f82005-07-22 21:00:30 +000052#ifdef __alpha
Andrew Lenharth0934ae02005-07-22 20:52:16 +000053 return 10;
54#else
55 return 0;
56#endif
57}
58
Chris Lattnerbc641b92006-03-23 05:43:16 +000059AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS)
Dale Johannesen8c1e6a12007-08-03 20:20:50 +000060 : DataLayout("e-f128:128:128"),
Andrew Lenharthdc7c0b82005-08-03 22:33:21 +000061 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
Andrew Lenharth120ab482005-09-29 22:54:56 +000062 JITInfo(*this),
Andrew Lenharth82c3d8f2006-10-11 04:29:42 +000063 Subtarget(M, FS),
64 TLInfo(*this) {
Andrew Lenharth0607a2f2006-09-24 19:46:56 +000065 setRelocationModel(Reloc::PIC_);
Andrew Lenharth120ab482005-09-29 22:54:56 +000066}
Andrew Lenharth304d0f32005-01-22 23:41:55 +000067
Misha Brukman4633f1c2005-04-21 23:13:11 +000068
Chris Lattner1911fd42006-09-04 04:14:57 +000069//===----------------------------------------------------------------------===//
70// Pass Pipeline Configuration
71//===----------------------------------------------------------------------===//
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000072
Chris Lattner1911fd42006-09-04 04:14:57 +000073bool AlphaTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
Andrew Lenharthfabd5ba2006-01-23 21:56:07 +000074 PM.add(createAlphaISelDag(*this));
Andrew Lenharth304d0f32005-01-22 23:41:55 +000075 return false;
76}
Chris Lattner1911fd42006-09-04 04:14:57 +000077bool AlphaTargetMachine::addPreEmitPass(FunctionPassManager &PM, bool Fast) {
Andrew Lenharth0934ae02005-07-22 20:52:16 +000078 // Must run branch selection immediately preceding the asm printer
Andrew Lenharthf81173f2006-10-31 16:49:55 +000079 PM.add(createAlphaBranchSelectionPass());
Chris Lattner1911fd42006-09-04 04:14:57 +000080 return false;
Andrew Lenharth0934ae02005-07-22 20:52:16 +000081}
Chris Lattner1911fd42006-09-04 04:14:57 +000082bool AlphaTargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast,
83 std::ostream &Out) {
Andrew Lenharth2ab804c2006-09-18 19:44:29 +000084 PM.add(createAlphaLLRPPass(*this));
Chris Lattner1911fd42006-09-04 04:14:57 +000085 PM.add(createAlphaCodePrinterPass(Out, *this));
86 return false;
87}
88bool AlphaTargetMachine::addCodeEmitter(FunctionPassManager &PM, bool Fast,
Evan Cheng8bd60352007-07-20 21:56:13 +000089 bool DumpAsm, MachineCodeEmitter &MCE) {
Evan Cheng55fc2802006-07-25 20:40:54 +000090 PM.add(createAlphaCodeEmitterPass(*this, MCE));
Evan Cheng8bd60352007-07-20 21:56:13 +000091 if (DumpAsm)
92 PM.add(createAlphaCodePrinterPass(*cerr.stream(), *this));
Andrew Lenharth0934ae02005-07-22 20:52:16 +000093 return false;
94}
Bill Wendling50e4e882007-02-08 01:38:33 +000095bool AlphaTargetMachine::addSimpleCodeEmitter(FunctionPassManager &PM,
Evan Cheng8bd60352007-07-20 21:56:13 +000096 bool Fast, bool DumpAsm,
Bill Wendling50e4e882007-02-08 01:38:33 +000097 MachineCodeEmitter &MCE) {
Evan Cheng8bd60352007-07-20 21:56:13 +000098 return addCodeEmitter(PM, Fast, DumpAsm, MCE);
Bill Wendling50e4e882007-02-08 01:38:33 +000099}