blob: 8775bb7e8d402c1e6383642bc791fdfdf78cba07 [file] [log] [blame]
Andrew Lenharth3c127722005-01-24 18:45:41 +00001//===-- AlphaTargetMachine.cpp - Define TargetMachine for Alpha -----------===//
Misha Brukman89b8c8d2005-04-21 23:13:11 +00002//
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Brukman89b8c8d2005-04-21 23:13:11 +00007//
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +00008//===----------------------------------------------------------------------===//
Misha Brukman89b8c8d2005-04-21 23:13:11 +00009//
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000010//
11//===----------------------------------------------------------------------===//
12
13#include "Alpha.h"
Andrew Lenharth55d04512005-07-22 20:52:16 +000014#include "AlphaJITInfo.h"
Jim Laskeyae92ce82006-09-07 23:39:26 +000015#include "AlphaTargetAsmInfo.h"
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000016#include "AlphaTargetMachine.h"
Andrew Lenharth8fb0d502005-02-01 20:35:11 +000017#include "llvm/Module.h"
Chris Lattner12e97302006-09-04 04:14:57 +000018#include "llvm/PassManager.h"
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000019#include "llvm/Target/TargetMachineRegistry.h"
David Greenea31f96c2009-07-14 20:18:05 +000020#include "llvm/Support/FormattedStream.h"
Andrew Lenharth8fb0d502005-02-01 20:35:11 +000021
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000022using namespace llvm;
23
Dan Gohmand78c4002008-05-13 00:00:25 +000024// Register the targets
Daniel Dunbarb22f50e2009-07-15 09:22:31 +000025extern Target TheAlphaTarget;
26static RegisterTarget<AlphaTargetMachine> X(TheAlphaTarget, "alpha",
27 "Alpha [experimental]");
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000028
Anton Korobeynikov2028e252009-06-19 19:36:55 +000029// No assembler printer by default
30AlphaTargetMachine::AsmPrinterCtorFn AlphaTargetMachine::AsmPrinterCtor = 0;
31
Bob Wilson5a495fe2009-06-23 23:59:40 +000032// Force static initialization.
33extern "C" void LLVMInitializeAlphaTarget() { }
Douglas Gregor1b731d52009-06-16 20:12:29 +000034
Jim Laskeyae92ce82006-09-07 23:39:26 +000035const TargetAsmInfo *AlphaTargetMachine::createTargetAsmInfo() const {
36 return new AlphaTargetAsmInfo(*this);
37}
38
Andrew Lenharth8fb0d502005-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 Lattner517290a2007-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 Lenharth8fb0d502005-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 Lattner5c7d7312005-10-30 16:44:01 +000055 return getJITMatchQuality()/2;
Andrew Lenharth8fb0d502005-02-01 20:35:11 +000056}
57
Andrew Lenharth55d04512005-07-22 20:52:16 +000058unsigned AlphaTargetMachine::getJITMatchQuality() {
Andrew Lenharthc32843e2005-07-22 21:00:30 +000059#ifdef __alpha
Andrew Lenharth55d04512005-07-22 20:52:16 +000060 return 10;
61#else
62 return 0;
63#endif
64}
65
Chris Lattner6f95ab72006-03-23 05:43:16 +000066AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS)
Dale Johannesenc5283ec2007-08-03 20:20:50 +000067 : DataLayout("e-f128:128:128"),
Andrew Lenharth3a18a392005-08-03 22:33:21 +000068 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
Andrew Lenhartha7a83b92005-09-29 22:54:56 +000069 JITInfo(*this),
Andrew Lenhartha6bbf332006-10-11 04:29:42 +000070 Subtarget(M, FS),
71 TLInfo(*this) {
Andrew Lenharth5e2bacd2006-09-24 19:46:56 +000072 setRelocationModel(Reloc::PIC_);
Andrew Lenhartha7a83b92005-09-29 22:54:56 +000073}
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000074
Misha Brukman89b8c8d2005-04-21 23:13:11 +000075
Chris Lattner12e97302006-09-04 04:14:57 +000076//===----------------------------------------------------------------------===//
77// Pass Pipeline Configuration
78//===----------------------------------------------------------------------===//
Andrew Lenharthed4b6482005-03-02 17:21:38 +000079
Bill Wendling084669a2009-04-29 00:15:41 +000080bool AlphaTargetMachine::addInstSelector(PassManagerBase &PM,
Bill Wendling026e5d72009-04-29 23:29:43 +000081 CodeGenOpt::Level OptLevel) {
Andrew Lenharthc0bf3772006-01-23 21:56:07 +000082 PM.add(createAlphaISelDag(*this));
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000083 return false;
84}
Bill Wendling084669a2009-04-29 00:15:41 +000085bool AlphaTargetMachine::addPreEmitPass(PassManagerBase &PM,
Bill Wendling026e5d72009-04-29 23:29:43 +000086 CodeGenOpt::Level OptLevel) {
Andrew Lenharth55d04512005-07-22 20:52:16 +000087 // Must run branch selection immediately preceding the asm printer
Andrew Lenharth692e4152006-10-31 16:49:55 +000088 PM.add(createAlphaBranchSelectionPass());
Chris Lattner12e97302006-09-04 04:14:57 +000089 return false;
Andrew Lenharth55d04512005-07-22 20:52:16 +000090}
Bill Wendling084669a2009-04-29 00:15:41 +000091bool AlphaTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
Bill Wendling026e5d72009-04-29 23:29:43 +000092 CodeGenOpt::Level OptLevel,
Evan Cheng5e5a63c2009-03-25 01:47:28 +000093 bool Verbose,
David Greenea31f96c2009-07-14 20:18:05 +000094 formatted_raw_ostream &Out) {
Andrew Lenharthf23e3bf2006-09-18 19:44:29 +000095 PM.add(createAlphaLLRPPass(*this));
Anton Korobeynikov2028e252009-06-19 19:36:55 +000096 // Output assembly language.
97 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
98 if (AsmPrinterCtor)
Daniel Dunbar75c12e12009-07-01 01:48:54 +000099 PM.add(AsmPrinterCtor(Out, *this, Verbose));
Chris Lattner12e97302006-09-04 04:14:57 +0000100 return false;
101}
Bill Wendling026e5d72009-04-29 23:29:43 +0000102bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM,
103 CodeGenOpt::Level OptLevel,
Evan Cheng9d5df0a2007-07-20 21:56:13 +0000104 bool DumpAsm, MachineCodeEmitter &MCE) {
Evan Chengf6acb342006-07-25 20:40:54 +0000105 PM.add(createAlphaCodeEmitterPass(*this, MCE));
Anton Korobeynikov2028e252009-06-19 19:36:55 +0000106 if (DumpAsm) {
107 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
108 if (AsmPrinterCtor)
David Greenea31f96c2009-07-14 20:18:05 +0000109 PM.add(AsmPrinterCtor(ferrs(), *this, true));
Anton Korobeynikov2028e252009-06-19 19:36:55 +0000110 }
Andrew Lenharth55d04512005-07-22 20:52:16 +0000111 return false;
112}
Bruno Cardoso Lopesa194c3a2009-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 Korobeynikov2028e252009-06-19 19:36:55 +0000117 if (DumpAsm) {
118 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
119 if (AsmPrinterCtor)
David Greenea31f96c2009-07-14 20:18:05 +0000120 PM.add(AsmPrinterCtor(ferrs(), *this, true));
Anton Korobeynikov2028e252009-06-19 19:36:55 +0000121 }
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000122 return false;
123}
Bruno Cardoso Lopes5661ea62009-07-06 05:09:34 +0000124bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM,
125 CodeGenOpt::Level OptLevel,
126 bool DumpAsm, ObjectCodeEmitter &OCE) {
127 PM.add(createAlphaObjectCodeEmitterPass(*this, OCE));
128 if (DumpAsm) {
129 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
130 if (AsmPrinterCtor)
David Greenea31f96c2009-07-14 20:18:05 +0000131 PM.add(AsmPrinterCtor(ferrs(), *this, true));
Bruno Cardoso Lopes5661ea62009-07-06 05:09:34 +0000132 }
133 return false;
134}
Dan Gohman24570832008-03-11 22:29:46 +0000135bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
Bill Wendling026e5d72009-04-29 23:29:43 +0000136 CodeGenOpt::Level OptLevel,
137 bool DumpAsm,
Bill Wendling59889ae2007-02-08 01:38:33 +0000138 MachineCodeEmitter &MCE) {
Bill Wendling084669a2009-04-29 00:15:41 +0000139 return addCodeEmitter(PM, OptLevel, DumpAsm, MCE);
Bill Wendling59889ae2007-02-08 01:38:33 +0000140}
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000141bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
142 CodeGenOpt::Level OptLevel,
143 bool DumpAsm,
144 JITCodeEmitter &JCE) {
145 return addCodeEmitter(PM, OptLevel, DumpAsm, JCE);
146}
Bruno Cardoso Lopes5661ea62009-07-06 05:09:34 +0000147bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
148 CodeGenOpt::Level OptLevel,
149 bool DumpAsm,
150 ObjectCodeEmitter &OCE) {
151 return addCodeEmitter(PM, OptLevel, DumpAsm, OCE);
152}
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000153