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" |
| 15 | #include "PTXTargetMachine.h" |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 16 | #include "llvm/PassManager.h" |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 17 | #include "llvm/Target/TargetRegistry.h" |
Che-Liang Chiou | f48817c | 2011-03-02 07:36:48 +0000 | [diff] [blame] | 18 | #include "llvm/Support/raw_ostream.h" |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace llvm; |
| 21 | |
Rafael Espindola | a484f2c | 2010-11-28 14:48:34 +0000 | [diff] [blame] | 22 | namespace llvm { |
| 23 | MCStreamer *createPTXAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 24 | bool isVerboseAsm, bool useLoc, |
Rafael Espindola | f1a5c7e | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 25 | bool useCFI, |
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, |
Bill Wendling | e266ce6 | 2011-06-17 20:55:01 +0000 | [diff] [blame] | 29 | bool ShowInst); |
Rafael Espindola | a484f2c | 2010-11-28 14:48:34 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 32 | extern "C" void LLVMInitializePTXTarget() { |
Justin Holewinski | e1fee48 | 2011-04-20 15:37:17 +0000 | [diff] [blame] | 33 | |
| 34 | RegisterTargetMachine<PTX32TargetMachine> X(ThePTX32Target); |
| 35 | RegisterTargetMachine<PTX64TargetMachine> Y(ThePTX64Target); |
| 36 | |
Justin Holewinski | e1fee48 | 2011-04-20 15:37:17 +0000 | [diff] [blame] | 37 | TargetRegistry::RegisterAsmStreamer(ThePTX32Target, createPTXAsmStreamer); |
| 38 | TargetRegistry::RegisterAsmStreamer(ThePTX64Target, createPTXAsmStreamer); |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Che-Liang Chiou | f48817c | 2011-03-02 07:36:48 +0000 | [diff] [blame] | 41 | namespace { |
Che-Liang Chiou | 31c488c | 2011-03-02 07:58:46 +0000 | [diff] [blame] | 42 | const char* DataLayout32 = |
| 43 | "e-p:32:32-i64:32:32-f64:32:32-v128:32:128-v64:32:64-n32:64"; |
| 44 | const char* DataLayout64 = |
| 45 | "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] | 46 | } |
| 47 | |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 48 | // DataLayout and FrameLowering are filled with dummy data |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 49 | PTXTargetMachine::PTXTargetMachine(const Target &T, |
| 50 | const std::string &TT, |
Evan Cheng | 276365d | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 51 | const std::string &CPU, |
Justin Holewinski | e1fee48 | 2011-04-20 15:37:17 +0000 | [diff] [blame] | 52 | const std::string &FS, |
| 53 | bool is64Bit) |
Evan Cheng | ebdeeab | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 54 | : LLVMTargetMachine(T, TT, CPU, FS), |
Justin Holewinski | e1fee48 | 2011-04-20 15:37:17 +0000 | [diff] [blame] | 55 | DataLayout(is64Bit ? DataLayout64 : DataLayout32), |
Evan Cheng | 276365d | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 56 | Subtarget(TT, CPU, FS, is64Bit), |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 57 | FrameLowering(Subtarget), |
Che-Liang Chiou | 31c488c | 2011-03-02 07:58:46 +0000 | [diff] [blame] | 58 | InstrInfo(*this), |
| 59 | TLInfo(*this) { |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Justin Holewinski | e1fee48 | 2011-04-20 15:37:17 +0000 | [diff] [blame] | 62 | PTX32TargetMachine::PTX32TargetMachine(const Target &T, |
| 63 | const std::string& TT, |
Evan Cheng | 276365d | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 64 | const std::string& CPU, |
Justin Holewinski | e1fee48 | 2011-04-20 15:37:17 +0000 | [diff] [blame] | 65 | const std::string& FS) |
Evan Cheng | 276365d | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 66 | : PTXTargetMachine(T, TT, CPU, FS, false) { |
Justin Holewinski | e1fee48 | 2011-04-20 15:37:17 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | PTX64TargetMachine::PTX64TargetMachine(const Target &T, |
| 70 | const std::string& TT, |
Evan Cheng | 276365d | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 71 | const std::string& CPU, |
Justin Holewinski | e1fee48 | 2011-04-20 15:37:17 +0000 | [diff] [blame] | 72 | const std::string& FS) |
Evan Cheng | 276365d | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 73 | : PTXTargetMachine(T, TT, CPU, FS, true) { |
Justin Holewinski | e1fee48 | 2011-04-20 15:37:17 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 76 | bool PTXTargetMachine::addInstSelector(PassManagerBase &PM, |
| 77 | CodeGenOpt::Level OptLevel) { |
| 78 | PM.add(createPTXISelDag(*this, OptLevel)); |
Che-Liang Chiou | ad83c1d | 2011-01-01 10:50:37 +0000 | [diff] [blame] | 79 | return false; |
| 80 | } |
| 81 | |
| 82 | bool PTXTargetMachine::addPostRegAlloc(PassManagerBase &PM, |
| 83 | CodeGenOpt::Level OptLevel) { |
| 84 | // PTXMFInfoExtract must after register allocation! |
Che-Liang Chiou | 3278c42 | 2010-11-08 03:00:52 +0000 | [diff] [blame] | 85 | PM.add(createPTXMFInfoExtract(*this, OptLevel)); |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 86 | return false; |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 87 | } |