blob: 10952eb096ae78e9a94b1b04b4d5e8ed658797bc [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
Anton Korobeynikove494b9e2009-06-19 19:36:55 +000027// No assembler printer by default
28AlphaTargetMachine::AsmPrinterCtorFn AlphaTargetMachine::AsmPrinterCtor = 0;
29
Bob Wilsona96751f2009-06-23 23:59:40 +000030// Force static initialization.
31extern "C" void LLVMInitializeAlphaTarget() { }
Douglas Gregor1555a232009-06-16 20:12:29 +000032
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000033const TargetAsmInfo *AlphaTargetMachine::createTargetAsmInfo() const {
34 return new AlphaTargetAsmInfo(*this);
35}
36
Andrew Lenharth2f401632005-02-01 20:35:11 +000037unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) {
38 // We strongly match "alpha*".
39 std::string TT = M.getTargetTriple();
40 if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
41 TT[3] == 'h' && TT[4] == 'a')
42 return 20;
Chris Lattner87bdba62007-07-09 17:25:29 +000043 // If the target triple is something non-alpha, we don't match.
44 if (!TT.empty()) return 0;
Andrew Lenharth2f401632005-02-01 20:35:11 +000045
46 if (M.getEndianness() == Module::LittleEndian &&
47 M.getPointerSize() == Module::Pointer64)
48 return 10; // Weak match
49 else if (M.getEndianness() != Module::AnyEndianness ||
50 M.getPointerSize() != Module::AnyPointerSize)
51 return 0; // Match for some other target
52
Chris Lattnerc1d6f672005-10-30 16:44:01 +000053 return getJITMatchQuality()/2;
Andrew Lenharth2f401632005-02-01 20:35:11 +000054}
55
Andrew Lenharth0934ae02005-07-22 20:52:16 +000056unsigned AlphaTargetMachine::getJITMatchQuality() {
Andrew Lenharth38396f82005-07-22 21:00:30 +000057#ifdef __alpha
Andrew Lenharth0934ae02005-07-22 20:52:16 +000058 return 10;
59#else
60 return 0;
61#endif
62}
63
Chris Lattnerbc641b92006-03-23 05:43:16 +000064AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS)
Dale Johannesen8c1e6a12007-08-03 20:20:50 +000065 : DataLayout("e-f128:128:128"),
Andrew Lenharthdc7c0b82005-08-03 22:33:21 +000066 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
Andrew Lenharth120ab482005-09-29 22:54:56 +000067 JITInfo(*this),
Andrew Lenharth82c3d8f2006-10-11 04:29:42 +000068 Subtarget(M, FS),
69 TLInfo(*this) {
Andrew Lenharth0607a2f2006-09-24 19:46:56 +000070 setRelocationModel(Reloc::PIC_);
Andrew Lenharth120ab482005-09-29 22:54:56 +000071}
Andrew Lenharth304d0f32005-01-22 23:41:55 +000072
Misha Brukman4633f1c2005-04-21 23:13:11 +000073
Chris Lattner1911fd42006-09-04 04:14:57 +000074//===----------------------------------------------------------------------===//
75// Pass Pipeline Configuration
76//===----------------------------------------------------------------------===//
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000077
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000078bool AlphaTargetMachine::addInstSelector(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +000079 CodeGenOpt::Level OptLevel) {
Andrew Lenharthfabd5ba2006-01-23 21:56:07 +000080 PM.add(createAlphaISelDag(*this));
Andrew Lenharth304d0f32005-01-22 23:41:55 +000081 return false;
82}
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000083bool AlphaTargetMachine::addPreEmitPass(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +000084 CodeGenOpt::Level OptLevel) {
Andrew Lenharth0934ae02005-07-22 20:52:16 +000085 // Must run branch selection immediately preceding the asm printer
Andrew Lenharthf81173f2006-10-31 16:49:55 +000086 PM.add(createAlphaBranchSelectionPass());
Chris Lattner1911fd42006-09-04 04:14:57 +000087 return false;
Andrew Lenharth0934ae02005-07-22 20:52:16 +000088}
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000089bool AlphaTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +000090 CodeGenOpt::Level OptLevel,
Evan Cheng42bf74b2009-03-25 01:47:28 +000091 bool Verbose,
Owen Andersoncb371882008-08-21 00:14:44 +000092 raw_ostream &Out) {
Andrew Lenharth2ab804c2006-09-18 19:44:29 +000093 PM.add(createAlphaLLRPPass(*this));
Anton Korobeynikove494b9e2009-06-19 19:36:55 +000094 // Output assembly language.
95 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
96 if (AsmPrinterCtor)
97 PM.add(AsmPrinterCtor(Out, *this, OptLevel, Verbose));
Chris Lattner1911fd42006-09-04 04:14:57 +000098 return false;
99}
Bill Wendling98a366d2009-04-29 23:29:43 +0000100bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM,
101 CodeGenOpt::Level OptLevel,
Evan Cheng8bd60352007-07-20 21:56:13 +0000102 bool DumpAsm, MachineCodeEmitter &MCE) {
Evan Cheng55fc2802006-07-25 20:40:54 +0000103 PM.add(createAlphaCodeEmitterPass(*this, MCE));
Anton Korobeynikove494b9e2009-06-19 19:36:55 +0000104 if (DumpAsm) {
105 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
106 if (AsmPrinterCtor)
107 PM.add(AsmPrinterCtor(errs(), *this, OptLevel, true));
108 }
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000109 return false;
110}
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000111bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM,
112 CodeGenOpt::Level OptLevel,
113 bool DumpAsm, JITCodeEmitter &JCE) {
114 PM.add(createAlphaJITCodeEmitterPass(*this, JCE));
Anton Korobeynikove494b9e2009-06-19 19:36:55 +0000115 if (DumpAsm) {
116 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
117 if (AsmPrinterCtor)
118 PM.add(AsmPrinterCtor(errs(), *this, OptLevel, true));
119 }
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000120 return false;
121}
Dan Gohmanbfae8312008-03-11 22:29:46 +0000122bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +0000123 CodeGenOpt::Level OptLevel,
124 bool DumpAsm,
Bill Wendling50e4e882007-02-08 01:38:33 +0000125 MachineCodeEmitter &MCE) {
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +0000126 return addCodeEmitter(PM, OptLevel, DumpAsm, MCE);
Bill Wendling50e4e882007-02-08 01:38:33 +0000127}
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000128bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
129 CodeGenOpt::Level OptLevel,
130 bool DumpAsm,
131 JITCodeEmitter &JCE) {
132 return addCodeEmitter(PM, OptLevel, DumpAsm, JCE);
133}
134