blob: cb4dd3ea1fa7df680b8434d6461ae256be96f33a [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"
Owen Andersoncb371882008-08-21 00:14:44 +000020#include "llvm/Support/raw_ostream.h"
Andrew Lenharth2f401632005-02-01 20:35:11 +000021
Andrew Lenharth304d0f32005-01-22 23:41:55 +000022using namespace llvm;
23
Dan Gohman844731a2008-05-13 00:00:25 +000024// Register the targets
Chris Lattner0d5d05b2008-10-16 06:16:50 +000025static RegisterTarget<AlphaTargetMachine> X("alpha", "Alpha [experimental]");
Andrew Lenharth304d0f32005-01-22 23:41:55 +000026
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000027const TargetAsmInfo *AlphaTargetMachine::createTargetAsmInfo() const {
28 return new AlphaTargetAsmInfo(*this);
29}
30
Andrew Lenharth2f401632005-02-01 20:35:11 +000031unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) {
32 // We strongly match "alpha*".
33 std::string TT = M.getTargetTriple();
34 if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
35 TT[3] == 'h' && TT[4] == 'a')
36 return 20;
Chris Lattner87bdba62007-07-09 17:25:29 +000037 // If the target triple is something non-alpha, we don't match.
38 if (!TT.empty()) return 0;
Andrew Lenharth2f401632005-02-01 20:35:11 +000039
40 if (M.getEndianness() == Module::LittleEndian &&
41 M.getPointerSize() == Module::Pointer64)
42 return 10; // Weak match
43 else if (M.getEndianness() != Module::AnyEndianness ||
44 M.getPointerSize() != Module::AnyPointerSize)
45 return 0; // Match for some other target
46
Chris Lattnerc1d6f672005-10-30 16:44:01 +000047 return getJITMatchQuality()/2;
Andrew Lenharth2f401632005-02-01 20:35:11 +000048}
49
Andrew Lenharth0934ae02005-07-22 20:52:16 +000050unsigned AlphaTargetMachine::getJITMatchQuality() {
Andrew Lenharth38396f82005-07-22 21:00:30 +000051#ifdef __alpha
Andrew Lenharth0934ae02005-07-22 20:52:16 +000052 return 10;
53#else
54 return 0;
55#endif
56}
57
Chris Lattnerbc641b92006-03-23 05:43:16 +000058AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS)
Dale Johannesen8c1e6a12007-08-03 20:20:50 +000059 : DataLayout("e-f128:128:128"),
Andrew Lenharthdc7c0b82005-08-03 22:33:21 +000060 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
Andrew Lenharth120ab482005-09-29 22:54:56 +000061 JITInfo(*this),
Andrew Lenharth82c3d8f2006-10-11 04:29:42 +000062 Subtarget(M, FS),
63 TLInfo(*this) {
Andrew Lenharth0607a2f2006-09-24 19:46:56 +000064 setRelocationModel(Reloc::PIC_);
Andrew Lenharth120ab482005-09-29 22:54:56 +000065}
Andrew Lenharth304d0f32005-01-22 23:41:55 +000066
Misha Brukman4633f1c2005-04-21 23:13:11 +000067
Chris Lattner1911fd42006-09-04 04:14:57 +000068//===----------------------------------------------------------------------===//
69// Pass Pipeline Configuration
70//===----------------------------------------------------------------------===//
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000071
Dan Gohmanbfae8312008-03-11 22:29:46 +000072bool AlphaTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
Andrew Lenharthfabd5ba2006-01-23 21:56:07 +000073 PM.add(createAlphaISelDag(*this));
Andrew Lenharth304d0f32005-01-22 23:41:55 +000074 return false;
75}
Dan Gohmanbfae8312008-03-11 22:29:46 +000076bool AlphaTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) {
Andrew Lenharth0934ae02005-07-22 20:52:16 +000077 // Must run branch selection immediately preceding the asm printer
Andrew Lenharthf81173f2006-10-31 16:49:55 +000078 PM.add(createAlphaBranchSelectionPass());
Chris Lattner1911fd42006-09-04 04:14:57 +000079 return false;
Andrew Lenharth0934ae02005-07-22 20:52:16 +000080}
Dan Gohmanbfae8312008-03-11 22:29:46 +000081bool AlphaTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
Owen Andersoncb371882008-08-21 00:14:44 +000082 raw_ostream &Out) {
Andrew Lenharth2ab804c2006-09-18 19:44:29 +000083 PM.add(createAlphaLLRPPass(*this));
Chris Lattner1911fd42006-09-04 04:14:57 +000084 PM.add(createAlphaCodePrinterPass(Out, *this));
85 return false;
86}
Dan Gohmanbfae8312008-03-11 22:29:46 +000087bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast,
Evan Cheng8bd60352007-07-20 21:56:13 +000088 bool DumpAsm, MachineCodeEmitter &MCE) {
Evan Cheng55fc2802006-07-25 20:40:54 +000089 PM.add(createAlphaCodeEmitterPass(*this, MCE));
Evan Cheng8bd60352007-07-20 21:56:13 +000090 if (DumpAsm)
Owen Andersoncb371882008-08-21 00:14:44 +000091 PM.add(createAlphaCodePrinterPass(errs(), *this));
Andrew Lenharth0934ae02005-07-22 20:52:16 +000092 return false;
93}
Dan Gohmanbfae8312008-03-11 22:29:46 +000094bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
Evan Cheng8bd60352007-07-20 21:56:13 +000095 bool Fast, bool DumpAsm,
Bill Wendling50e4e882007-02-08 01:38:33 +000096 MachineCodeEmitter &MCE) {
Evan Cheng8bd60352007-07-20 21:56:13 +000097 return addCodeEmitter(PM, Fast, DumpAsm, MCE);
Bill Wendling50e4e882007-02-08 01:38:33 +000098}