blob: 569f2a0f13d032a55a19f524050342e76bdfdd43 [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//
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.
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;
38
39 if (M.getEndianness() == Module::LittleEndian &&
40 M.getPointerSize() == Module::Pointer64)
41 return 10; // Weak match
42 else if (M.getEndianness() != Module::AnyEndianness ||
43 M.getPointerSize() != Module::AnyPointerSize)
44 return 0; // Match for some other target
45
Chris Lattnerc1d6f672005-10-30 16:44:01 +000046 return getJITMatchQuality()/2;
Andrew Lenharth2f401632005-02-01 20:35:11 +000047}
48
Andrew Lenharth0934ae02005-07-22 20:52:16 +000049unsigned AlphaTargetMachine::getJITMatchQuality() {
Andrew Lenharth38396f82005-07-22 21:00:30 +000050#ifdef __alpha
Andrew Lenharth0934ae02005-07-22 20:52:16 +000051 return 10;
52#else
53 return 0;
54#endif
55}
56
Chris Lattnerbc641b92006-03-23 05:43:16 +000057AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS)
Chris Lattnerc4fa3862006-09-03 18:44:02 +000058 : DataLayout("e"),
Andrew Lenharthdc7c0b82005-08-03 22:33:21 +000059 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
Andrew Lenharth120ab482005-09-29 22:54:56 +000060 JITInfo(*this),
Andrew Lenharth82c3d8f2006-10-11 04:29:42 +000061 Subtarget(M, FS),
62 TLInfo(*this) {
Andrew Lenharth0607a2f2006-09-24 19:46:56 +000063 setRelocationModel(Reloc::PIC_);
Andrew Lenharth120ab482005-09-29 22:54:56 +000064}
Andrew Lenharth304d0f32005-01-22 23:41:55 +000065
Misha Brukman4633f1c2005-04-21 23:13:11 +000066
Chris Lattner1911fd42006-09-04 04:14:57 +000067//===----------------------------------------------------------------------===//
68// Pass Pipeline Configuration
69//===----------------------------------------------------------------------===//
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000070
Chris Lattner1911fd42006-09-04 04:14:57 +000071bool AlphaTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
Andrew Lenharthfabd5ba2006-01-23 21:56:07 +000072 PM.add(createAlphaISelDag(*this));
Andrew Lenharth304d0f32005-01-22 23:41:55 +000073 return false;
74}
Chris Lattner1911fd42006-09-04 04:14:57 +000075bool AlphaTargetMachine::addPreEmitPass(FunctionPassManager &PM, bool Fast) {
Andrew Lenharth0934ae02005-07-22 20:52:16 +000076 // Must run branch selection immediately preceding the asm printer
Andrew Lenharthf81173f2006-10-31 16:49:55 +000077 PM.add(createAlphaBranchSelectionPass());
Chris Lattner1911fd42006-09-04 04:14:57 +000078 return false;
Andrew Lenharth0934ae02005-07-22 20:52:16 +000079}
Chris Lattner1911fd42006-09-04 04:14:57 +000080bool AlphaTargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast,
81 std::ostream &Out) {
Andrew Lenharth2ab804c2006-09-18 19:44:29 +000082 PM.add(createAlphaLLRPPass(*this));
Chris Lattner1911fd42006-09-04 04:14:57 +000083 PM.add(createAlphaCodePrinterPass(Out, *this));
84 return false;
85}
86bool AlphaTargetMachine::addCodeEmitter(FunctionPassManager &PM, bool Fast,
87 MachineCodeEmitter &MCE) {
Evan Cheng55fc2802006-07-25 20:40:54 +000088 PM.add(createAlphaCodeEmitterPass(*this, MCE));
Andrew Lenharth0934ae02005-07-22 20:52:16 +000089 return false;
90}