blob: 4701a941d181806845a37228b080a8d413b331cc [file] [log] [blame]
Nick Lewyckyf7a3c502010-09-07 18:14:24 +00001//===-- PTXTargetMachine.cpp - Define TargetMachine for PTX ---------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Top-level implementation for the PTX target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "PTX.h"
Eric Christopher50880d02010-09-18 18:52:28 +000015#include "PTXMCAsmInfo.h"
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000016#include "PTXTargetMachine.h"
Eric Christopher50880d02010-09-18 18:52:28 +000017#include "llvm/PassManager.h"
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000018#include "llvm/Target/TargetRegistry.h"
Che-Liang Chiouf48817c2011-03-02 07:36:48 +000019#include "llvm/Support/raw_ostream.h"
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000020
21using namespace llvm;
22
Rafael Espindolaa484f2c2010-11-28 14:48:34 +000023namespace llvm {
24 MCStreamer *createPTXAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
Rafael Espindola89b93722010-12-10 07:39:47 +000025 bool isVerboseAsm, bool useLoc,
Rafael Espindolaa484f2c2010-11-28 14:48:34 +000026 MCInstPrinter *InstPrint,
27 MCCodeEmitter *CE,
Daniel Dunbar745dacc2010-12-16 03:05:59 +000028 TargetAsmBackend *TAB,
Rafael Espindolaa484f2c2010-11-28 14:48:34 +000029 bool ShowInst);
30}
31
Eric Christopher50880d02010-09-18 18:52:28 +000032extern "C" void LLVMInitializePTXTarget() {
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000033 RegisterTargetMachine<PTXTargetMachine> X(ThePTXTarget);
Eric Christopher50880d02010-09-18 18:52:28 +000034 RegisterAsmInfo<PTXMCAsmInfo> Y(ThePTXTarget);
Che-Liang Chioud77f2a42010-11-08 02:58:44 +000035 TargetRegistry::RegisterAsmStreamer(ThePTXTarget, createPTXAsmStreamer);
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000036}
37
Che-Liang Chiouf48817c2011-03-02 07:36:48 +000038namespace {
Che-Liang Chiou31c488c2011-03-02 07:58:46 +000039 const char* DataLayout32 =
40 "e-p:32:32-i64:32:32-f64:32:32-v128:32:128-v64:32:64-n32:64";
41 const char* DataLayout64 =
42 "e-p:64:64-i64:32:32-f64:32:32-v128:32:128-v64:32:64-n32:64";
Che-Liang Chiouf48817c2011-03-02 07:36:48 +000043}
44
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000045// DataLayout and FrameLowering are filled with dummy data
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000046PTXTargetMachine::PTXTargetMachine(const Target &T,
47 const std::string &TT,
Eric Christopher50880d02010-09-18 18:52:28 +000048 const std::string &FS)
Che-Liang Chiou31c488c2011-03-02 07:58:46 +000049 : LLVMTargetMachine(T, TT),
Che-Liang Chiouf48817c2011-03-02 07:36:48 +000050 // FIXME: This feels like a dirty hack, but Subtarget does not appear to be
51 // initialized at this point, and we need to finish initialization of
52 // DataLayout.
53 DataLayout((FS.find("64bit") != FS.npos) ? DataLayout64 : DataLayout32),
Che-Liang Chiou31c488c2011-03-02 07:58:46 +000054 Subtarget(TT, FS),
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000055 FrameLowering(Subtarget),
Che-Liang Chiou31c488c2011-03-02 07:58:46 +000056 InstrInfo(*this),
57 TLInfo(*this) {
Eric Christopher50880d02010-09-18 18:52:28 +000058}
59
60bool PTXTargetMachine::addInstSelector(PassManagerBase &PM,
61 CodeGenOpt::Level OptLevel) {
62 PM.add(createPTXISelDag(*this, OptLevel));
Che-Liang Chiouad83c1d2011-01-01 10:50:37 +000063 return false;
64}
65
66bool PTXTargetMachine::addPostRegAlloc(PassManagerBase &PM,
67 CodeGenOpt::Level OptLevel) {
68 // PTXMFInfoExtract must after register allocation!
Che-Liang Chiou3278c422010-11-08 03:00:52 +000069 PM.add(createPTXMFInfoExtract(*this, OptLevel));
Eric Christopher50880d02010-09-18 18:52:28 +000070 return false;
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000071}