blob: cdd4fa4b2445adc265f60a4698ac3a96ec26dbf9 [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
Douglas Gregor1555a232009-06-16 20:12:29 +000030// Force static initialization when called from llvm/InitializeAllTargets.h
31namespace llvm {
32 void InitializeAlphaTarget() { }
33}
34
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000035const TargetAsmInfo *AlphaTargetMachine::createTargetAsmInfo() const {
36 return new AlphaTargetAsmInfo(*this);
37}
38
Andrew Lenharth2f401632005-02-01 20:35:11 +000039unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) {
40 // We strongly match "alpha*".
41 std::string TT = M.getTargetTriple();
42 if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
43 TT[3] == 'h' && TT[4] == 'a')
44 return 20;
Chris Lattner87bdba62007-07-09 17:25:29 +000045 // If the target triple is something non-alpha, we don't match.
46 if (!TT.empty()) return 0;
Andrew Lenharth2f401632005-02-01 20:35:11 +000047
48 if (M.getEndianness() == Module::LittleEndian &&
49 M.getPointerSize() == Module::Pointer64)
50 return 10; // Weak match
51 else if (M.getEndianness() != Module::AnyEndianness ||
52 M.getPointerSize() != Module::AnyPointerSize)
53 return 0; // Match for some other target
54
Chris Lattnerc1d6f672005-10-30 16:44:01 +000055 return getJITMatchQuality()/2;
Andrew Lenharth2f401632005-02-01 20:35:11 +000056}
57
Andrew Lenharth0934ae02005-07-22 20:52:16 +000058unsigned AlphaTargetMachine::getJITMatchQuality() {
Andrew Lenharth38396f82005-07-22 21:00:30 +000059#ifdef __alpha
Andrew Lenharth0934ae02005-07-22 20:52:16 +000060 return 10;
61#else
62 return 0;
63#endif
64}
65
Chris Lattnerbc641b92006-03-23 05:43:16 +000066AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS)
Dale Johannesen8c1e6a12007-08-03 20:20:50 +000067 : DataLayout("e-f128:128:128"),
Andrew Lenharthdc7c0b82005-08-03 22:33:21 +000068 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
Andrew Lenharth120ab482005-09-29 22:54:56 +000069 JITInfo(*this),
Andrew Lenharth82c3d8f2006-10-11 04:29:42 +000070 Subtarget(M, FS),
71 TLInfo(*this) {
Andrew Lenharth0607a2f2006-09-24 19:46:56 +000072 setRelocationModel(Reloc::PIC_);
Andrew Lenharth120ab482005-09-29 22:54:56 +000073}
Andrew Lenharth304d0f32005-01-22 23:41:55 +000074
Misha Brukman4633f1c2005-04-21 23:13:11 +000075
Chris Lattner1911fd42006-09-04 04:14:57 +000076//===----------------------------------------------------------------------===//
77// Pass Pipeline Configuration
78//===----------------------------------------------------------------------===//
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000079
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000080bool AlphaTargetMachine::addInstSelector(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +000081 CodeGenOpt::Level OptLevel) {
Andrew Lenharthfabd5ba2006-01-23 21:56:07 +000082 PM.add(createAlphaISelDag(*this));
Andrew Lenharth304d0f32005-01-22 23:41:55 +000083 return false;
84}
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000085bool AlphaTargetMachine::addPreEmitPass(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +000086 CodeGenOpt::Level OptLevel) {
Andrew Lenharth0934ae02005-07-22 20:52:16 +000087 // Must run branch selection immediately preceding the asm printer
Andrew Lenharthf81173f2006-10-31 16:49:55 +000088 PM.add(createAlphaBranchSelectionPass());
Chris Lattner1911fd42006-09-04 04:14:57 +000089 return false;
Andrew Lenharth0934ae02005-07-22 20:52:16 +000090}
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000091bool AlphaTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +000092 CodeGenOpt::Level OptLevel,
Evan Cheng42bf74b2009-03-25 01:47:28 +000093 bool Verbose,
Owen Andersoncb371882008-08-21 00:14:44 +000094 raw_ostream &Out) {
Andrew Lenharth2ab804c2006-09-18 19:44:29 +000095 PM.add(createAlphaLLRPPass(*this));
Anton Korobeynikove494b9e2009-06-19 19:36:55 +000096 // Output assembly language.
97 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
98 if (AsmPrinterCtor)
99 PM.add(AsmPrinterCtor(Out, *this, OptLevel, Verbose));
Chris Lattner1911fd42006-09-04 04:14:57 +0000100 return false;
101}
Bill Wendling98a366d2009-04-29 23:29:43 +0000102bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM,
103 CodeGenOpt::Level OptLevel,
Evan Cheng8bd60352007-07-20 21:56:13 +0000104 bool DumpAsm, MachineCodeEmitter &MCE) {
Evan Cheng55fc2802006-07-25 20:40:54 +0000105 PM.add(createAlphaCodeEmitterPass(*this, MCE));
Anton Korobeynikove494b9e2009-06-19 19:36:55 +0000106 if (DumpAsm) {
107 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
108 if (AsmPrinterCtor)
109 PM.add(AsmPrinterCtor(errs(), *this, OptLevel, true));
110 }
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000111 return false;
112}
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000113bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM,
114 CodeGenOpt::Level OptLevel,
115 bool DumpAsm, JITCodeEmitter &JCE) {
116 PM.add(createAlphaJITCodeEmitterPass(*this, JCE));
Anton Korobeynikove494b9e2009-06-19 19:36:55 +0000117 if (DumpAsm) {
118 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
119 if (AsmPrinterCtor)
120 PM.add(AsmPrinterCtor(errs(), *this, OptLevel, true));
121 }
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000122 return false;
123}
Dan Gohmanbfae8312008-03-11 22:29:46 +0000124bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +0000125 CodeGenOpt::Level OptLevel,
126 bool DumpAsm,
Bill Wendling50e4e882007-02-08 01:38:33 +0000127 MachineCodeEmitter &MCE) {
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +0000128 return addCodeEmitter(PM, OptLevel, DumpAsm, MCE);
Bill Wendling50e4e882007-02-08 01:38:33 +0000129}
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000130bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
131 CodeGenOpt::Level OptLevel,
132 bool DumpAsm,
133 JITCodeEmitter &JCE) {
134 return addCodeEmitter(PM, OptLevel, DumpAsm, JCE);
135}
136