Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 1 | //===-- 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 Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 15 | #include "PTXMCAsmInfo.h" |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 16 | #include "PTXTargetMachine.h" |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 17 | #include "llvm/PassManager.h" |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetRegistry.h" |
Che-Liang Chiou | f48817c | 2011-03-02 07:36:48 +0000 | [diff] [blame] | 19 | #include "llvm/Support/raw_ostream.h" |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace llvm; |
| 22 | |
Rafael Espindola | a484f2c | 2010-11-28 14:48:34 +0000 | [diff] [blame] | 23 | namespace llvm { |
| 24 | MCStreamer *createPTXAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 25 | bool isVerboseAsm, bool useLoc, |
Rafael Espindola | a484f2c | 2010-11-28 14:48:34 +0000 | [diff] [blame] | 26 | MCInstPrinter *InstPrint, |
| 27 | MCCodeEmitter *CE, |
Daniel Dunbar | 745dacc | 2010-12-16 03:05:59 +0000 | [diff] [blame] | 28 | TargetAsmBackend *TAB, |
Rafael Espindola | a484f2c | 2010-11-28 14:48:34 +0000 | [diff] [blame] | 29 | bool ShowInst); |
| 30 | } |
| 31 | |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 32 | extern "C" void LLVMInitializePTXTarget() { |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 33 | RegisterTargetMachine<PTXTargetMachine> X(ThePTXTarget); |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 34 | RegisterAsmInfo<PTXMCAsmInfo> Y(ThePTXTarget); |
Che-Liang Chiou | d77f2a4 | 2010-11-08 02:58:44 +0000 | [diff] [blame] | 35 | TargetRegistry::RegisterAsmStreamer(ThePTXTarget, createPTXAsmStreamer); |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Che-Liang Chiou | f48817c | 2011-03-02 07:36:48 +0000 | [diff] [blame] | 38 | namespace { |
Che-Liang Chiou | 31c488c | 2011-03-02 07:58:46 +0000 | [diff] [blame^] | 39 | 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 Chiou | f48817c | 2011-03-02 07:36:48 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 45 | // DataLayout and FrameLowering are filled with dummy data |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 46 | PTXTargetMachine::PTXTargetMachine(const Target &T, |
| 47 | const std::string &TT, |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 48 | const std::string &FS) |
Che-Liang Chiou | 31c488c | 2011-03-02 07:58:46 +0000 | [diff] [blame^] | 49 | : LLVMTargetMachine(T, TT), |
Che-Liang Chiou | f48817c | 2011-03-02 07:36:48 +0000 | [diff] [blame] | 50 | // 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 Chiou | 31c488c | 2011-03-02 07:58:46 +0000 | [diff] [blame^] | 54 | Subtarget(TT, FS), |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 55 | FrameLowering(Subtarget), |
Che-Liang Chiou | 31c488c | 2011-03-02 07:58:46 +0000 | [diff] [blame^] | 56 | InstrInfo(*this), |
| 57 | TLInfo(*this) { |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | bool PTXTargetMachine::addInstSelector(PassManagerBase &PM, |
| 61 | CodeGenOpt::Level OptLevel) { |
| 62 | PM.add(createPTXISelDag(*this, OptLevel)); |
Che-Liang Chiou | ad83c1d | 2011-01-01 10:50:37 +0000 | [diff] [blame] | 63 | return false; |
| 64 | } |
| 65 | |
| 66 | bool PTXTargetMachine::addPostRegAlloc(PassManagerBase &PM, |
| 67 | CodeGenOpt::Level OptLevel) { |
| 68 | // PTXMFInfoExtract must after register allocation! |
Che-Liang Chiou | 3278c42 | 2010-11-08 03:00:52 +0000 | [diff] [blame] | 69 | PM.add(createPTXMFInfoExtract(*this, OptLevel)); |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 70 | return false; |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 71 | } |