blob: c65485b061ca8bdd384a714f53cfd07806e3c8ac [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
Oscar Fuentes92adc192008-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 Gohman844731a2008-05-13 00:00:25 +000031// Register the targets
Chris Lattner0d5d05b2008-10-16 06:16:50 +000032static RegisterTarget<AlphaTargetMachine> X("alpha", "Alpha [experimental]");
Andrew Lenharth304d0f32005-01-22 23:41:55 +000033
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000034const TargetAsmInfo *AlphaTargetMachine::createTargetAsmInfo() const {
35 return new AlphaTargetAsmInfo(*this);
36}
37
Andrew Lenharth2f401632005-02-01 20:35:11 +000038unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) {
39 // We strongly match "alpha*".
40 std::string TT = M.getTargetTriple();
41 if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
42 TT[3] == 'h' && TT[4] == 'a')
43 return 20;
Chris Lattner87bdba62007-07-09 17:25:29 +000044 // If the target triple is something non-alpha, we don't match.
45 if (!TT.empty()) return 0;
Andrew Lenharth2f401632005-02-01 20:35:11 +000046
47 if (M.getEndianness() == Module::LittleEndian &&
48 M.getPointerSize() == Module::Pointer64)
49 return 10; // Weak match
50 else if (M.getEndianness() != Module::AnyEndianness ||
51 M.getPointerSize() != Module::AnyPointerSize)
52 return 0; // Match for some other target
53
Chris Lattnerc1d6f672005-10-30 16:44:01 +000054 return getJITMatchQuality()/2;
Andrew Lenharth2f401632005-02-01 20:35:11 +000055}
56
Andrew Lenharth0934ae02005-07-22 20:52:16 +000057unsigned AlphaTargetMachine::getJITMatchQuality() {
Andrew Lenharth38396f82005-07-22 21:00:30 +000058#ifdef __alpha
Andrew Lenharth0934ae02005-07-22 20:52:16 +000059 return 10;
60#else
61 return 0;
62#endif
63}
64
Chris Lattnerbc641b92006-03-23 05:43:16 +000065AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS)
Dale Johannesen8c1e6a12007-08-03 20:20:50 +000066 : DataLayout("e-f128:128:128"),
Andrew Lenharthdc7c0b82005-08-03 22:33:21 +000067 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
Andrew Lenharth120ab482005-09-29 22:54:56 +000068 JITInfo(*this),
Andrew Lenharth82c3d8f2006-10-11 04:29:42 +000069 Subtarget(M, FS),
70 TLInfo(*this) {
Andrew Lenharth0607a2f2006-09-24 19:46:56 +000071 setRelocationModel(Reloc::PIC_);
Andrew Lenharth120ab482005-09-29 22:54:56 +000072}
Andrew Lenharth304d0f32005-01-22 23:41:55 +000073
Misha Brukman4633f1c2005-04-21 23:13:11 +000074
Chris Lattner1911fd42006-09-04 04:14:57 +000075//===----------------------------------------------------------------------===//
76// Pass Pipeline Configuration
77//===----------------------------------------------------------------------===//
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000078
Dan Gohmanbfae8312008-03-11 22:29:46 +000079bool AlphaTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
Andrew Lenharthfabd5ba2006-01-23 21:56:07 +000080 PM.add(createAlphaISelDag(*this));
Andrew Lenharth304d0f32005-01-22 23:41:55 +000081 return false;
82}
Dan Gohmanbfae8312008-03-11 22:29:46 +000083bool AlphaTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) {
Andrew Lenharth0934ae02005-07-22 20:52:16 +000084 // Must run branch selection immediately preceding the asm printer
Andrew Lenharthf81173f2006-10-31 16:49:55 +000085 PM.add(createAlphaBranchSelectionPass());
Chris Lattner1911fd42006-09-04 04:14:57 +000086 return false;
Andrew Lenharth0934ae02005-07-22 20:52:16 +000087}
Dan Gohmanbfae8312008-03-11 22:29:46 +000088bool AlphaTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
Owen Andersoncb371882008-08-21 00:14:44 +000089 raw_ostream &Out) {
Andrew Lenharth2ab804c2006-09-18 19:44:29 +000090 PM.add(createAlphaLLRPPass(*this));
Chris Lattner1911fd42006-09-04 04:14:57 +000091 PM.add(createAlphaCodePrinterPass(Out, *this));
92 return false;
93}
Dan Gohmanbfae8312008-03-11 22:29:46 +000094bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast,
Evan Cheng8bd60352007-07-20 21:56:13 +000095 bool DumpAsm, MachineCodeEmitter &MCE) {
Evan Cheng55fc2802006-07-25 20:40:54 +000096 PM.add(createAlphaCodeEmitterPass(*this, MCE));
Evan Cheng8bd60352007-07-20 21:56:13 +000097 if (DumpAsm)
Owen Andersoncb371882008-08-21 00:14:44 +000098 PM.add(createAlphaCodePrinterPass(errs(), *this));
Andrew Lenharth0934ae02005-07-22 20:52:16 +000099 return false;
100}
Dan Gohmanbfae8312008-03-11 22:29:46 +0000101bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
Evan Cheng8bd60352007-07-20 21:56:13 +0000102 bool Fast, bool DumpAsm,
Bill Wendling50e4e882007-02-08 01:38:33 +0000103 MachineCodeEmitter &MCE) {
Evan Cheng8bd60352007-07-20 21:56:13 +0000104 return addCodeEmitter(PM, Fast, DumpAsm, MCE);
Bill Wendling50e4e882007-02-08 01:38:33 +0000105}