blob: 9725b53274843303c9076342080dee3f2ced3f15 [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"
David Greene71847812009-07-14 20:18:05 +000020#include "llvm/Support/FormattedStream.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
Daniel Dunbar42467902009-07-15 09:22:31 +000025extern Target TheAlphaTarget;
26static RegisterTarget<AlphaTargetMachine> X(TheAlphaTarget, "alpha",
27 "Alpha [experimental]");
Andrew Lenharth304d0f32005-01-22 23:41:55 +000028
Anton Korobeynikove494b9e2009-06-19 19:36:55 +000029// No assembler printer by default
30AlphaTargetMachine::AsmPrinterCtorFn AlphaTargetMachine::AsmPrinterCtor = 0;
31
Bob Wilsona96751f2009-06-23 23:59:40 +000032// Force static initialization.
33extern "C" void LLVMInitializeAlphaTarget() { }
Douglas Gregor1555a232009-06-16 20:12:29 +000034
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
Daniel Dunbar03f4bc52009-07-15 12:11:05 +000066AlphaTargetMachine::AlphaTargetMachine(const Target &T, const Module &M,
67 const std::string &FS)
68 : LLVMTargetMachine(T),
69 DataLayout("e-f128:128:128"),
Andrew Lenharthdc7c0b82005-08-03 22:33:21 +000070 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
Andrew Lenharth120ab482005-09-29 22:54:56 +000071 JITInfo(*this),
Andrew Lenharth82c3d8f2006-10-11 04:29:42 +000072 Subtarget(M, FS),
73 TLInfo(*this) {
Andrew Lenharth0607a2f2006-09-24 19:46:56 +000074 setRelocationModel(Reloc::PIC_);
Andrew Lenharth120ab482005-09-29 22:54:56 +000075}
Andrew Lenharth304d0f32005-01-22 23:41:55 +000076
Misha Brukman4633f1c2005-04-21 23:13:11 +000077
Chris Lattner1911fd42006-09-04 04:14:57 +000078//===----------------------------------------------------------------------===//
79// Pass Pipeline Configuration
80//===----------------------------------------------------------------------===//
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000081
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000082bool AlphaTargetMachine::addInstSelector(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +000083 CodeGenOpt::Level OptLevel) {
Andrew Lenharthfabd5ba2006-01-23 21:56:07 +000084 PM.add(createAlphaISelDag(*this));
Andrew Lenharth304d0f32005-01-22 23:41:55 +000085 return false;
86}
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000087bool AlphaTargetMachine::addPreEmitPass(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +000088 CodeGenOpt::Level OptLevel) {
Andrew Lenharth0934ae02005-07-22 20:52:16 +000089 // Must run branch selection immediately preceding the asm printer
Andrew Lenharthf81173f2006-10-31 16:49:55 +000090 PM.add(createAlphaBranchSelectionPass());
Chris Lattner1911fd42006-09-04 04:14:57 +000091 return false;
Andrew Lenharth0934ae02005-07-22 20:52:16 +000092}
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000093bool AlphaTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +000094 CodeGenOpt::Level OptLevel,
Evan Cheng42bf74b2009-03-25 01:47:28 +000095 bool Verbose,
David Greene71847812009-07-14 20:18:05 +000096 formatted_raw_ostream &Out) {
Andrew Lenharth2ab804c2006-09-18 19:44:29 +000097 PM.add(createAlphaLLRPPass(*this));
Anton Korobeynikove494b9e2009-06-19 19:36:55 +000098 // Output assembly language.
99 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
100 if (AsmPrinterCtor)
Daniel Dunbar5bcc8bd2009-07-01 01:48:54 +0000101 PM.add(AsmPrinterCtor(Out, *this, Verbose));
Chris Lattner1911fd42006-09-04 04:14:57 +0000102 return false;
103}
Bill Wendling98a366d2009-04-29 23:29:43 +0000104bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM,
105 CodeGenOpt::Level OptLevel,
Evan Cheng8bd60352007-07-20 21:56:13 +0000106 bool DumpAsm, MachineCodeEmitter &MCE) {
Evan Cheng55fc2802006-07-25 20:40:54 +0000107 PM.add(createAlphaCodeEmitterPass(*this, MCE));
Anton Korobeynikove494b9e2009-06-19 19:36:55 +0000108 if (DumpAsm) {
109 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
110 if (AsmPrinterCtor)
David Greene71847812009-07-14 20:18:05 +0000111 PM.add(AsmPrinterCtor(ferrs(), *this, true));
Anton Korobeynikove494b9e2009-06-19 19:36:55 +0000112 }
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000113 return false;
114}
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000115bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM,
116 CodeGenOpt::Level OptLevel,
117 bool DumpAsm, JITCodeEmitter &JCE) {
118 PM.add(createAlphaJITCodeEmitterPass(*this, JCE));
Anton Korobeynikove494b9e2009-06-19 19:36:55 +0000119 if (DumpAsm) {
120 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
121 if (AsmPrinterCtor)
David Greene71847812009-07-14 20:18:05 +0000122 PM.add(AsmPrinterCtor(ferrs(), *this, true));
Anton Korobeynikove494b9e2009-06-19 19:36:55 +0000123 }
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000124 return false;
125}
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000126bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM,
127 CodeGenOpt::Level OptLevel,
128 bool DumpAsm, ObjectCodeEmitter &OCE) {
129 PM.add(createAlphaObjectCodeEmitterPass(*this, OCE));
130 if (DumpAsm) {
131 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
132 if (AsmPrinterCtor)
David Greene71847812009-07-14 20:18:05 +0000133 PM.add(AsmPrinterCtor(ferrs(), *this, true));
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000134 }
135 return false;
136}
Dan Gohmanbfae8312008-03-11 22:29:46 +0000137bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +0000138 CodeGenOpt::Level OptLevel,
139 bool DumpAsm,
Bill Wendling50e4e882007-02-08 01:38:33 +0000140 MachineCodeEmitter &MCE) {
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +0000141 return addCodeEmitter(PM, OptLevel, DumpAsm, MCE);
Bill Wendling50e4e882007-02-08 01:38:33 +0000142}
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000143bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
144 CodeGenOpt::Level OptLevel,
145 bool DumpAsm,
146 JITCodeEmitter &JCE) {
147 return addCodeEmitter(PM, OptLevel, DumpAsm, JCE);
148}
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000149bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
150 CodeGenOpt::Level OptLevel,
151 bool DumpAsm,
152 ObjectCodeEmitter &OCE) {
153 return addCodeEmitter(PM, OptLevel, DumpAsm, OCE);
154}
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000155