blob: cdd4fa4b2445adc265f60a4698ac3a96ec26dbf9 [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"
Owen Anderson93719642008-08-21 00:14:44 +000020#include "llvm/Support/raw_ostream.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
Chris Lattner122c9b12008-10-16 06:16:50 +000025static RegisterTarget<AlphaTargetMachine> X("alpha", "Alpha [experimental]");
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000026
Anton Korobeynikov2028e252009-06-19 19:36:55 +000027// No assembler printer by default
28AlphaTargetMachine::AsmPrinterCtorFn AlphaTargetMachine::AsmPrinterCtor = 0;
29
Douglas Gregor1b731d52009-06-16 20:12:29 +000030// Force static initialization when called from llvm/InitializeAllTargets.h
31namespace llvm {
32 void InitializeAlphaTarget() { }
33}
34
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,
Owen Anderson93719642008-08-21 00:14:44 +000094 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)
99 PM.add(AsmPrinterCtor(Out, *this, OptLevel, 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)
109 PM.add(AsmPrinterCtor(errs(), *this, OptLevel, true));
110 }
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)
120 PM.add(AsmPrinterCtor(errs(), *this, OptLevel, true));
121 }
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000122 return false;
123}
Dan Gohman24570832008-03-11 22:29:46 +0000124bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
Bill Wendling026e5d72009-04-29 23:29:43 +0000125 CodeGenOpt::Level OptLevel,
126 bool DumpAsm,
Bill Wendling59889ae2007-02-08 01:38:33 +0000127 MachineCodeEmitter &MCE) {
Bill Wendling084669a2009-04-29 00:15:41 +0000128 return addCodeEmitter(PM, OptLevel, DumpAsm, MCE);
Bill Wendling59889ae2007-02-08 01:38:33 +0000129}
Bruno Cardoso Lopesa194c3a2009-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