Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 1 | //===-- AMDGPUInstrInfo.cpp - Base class for AMD GPU InstrInfo ------------===// |
| 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 | /// \file |
| 11 | /// \brief Implementation of the TargetInstrInfo class that is common to all |
| 12 | /// AMD GPUs. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #include "AMDGPUInstrInfo.h" |
| 17 | #include "AMDGPURegisterInfo.h" |
| 18 | #include "AMDGPUTargetMachine.h" |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 20 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 21 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 22 | |
Chandler Carruth | d174b72 | 2014-04-22 02:03:14 +0000 | [diff] [blame] | 23 | using namespace llvm; |
| 24 | |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 25 | #define GET_INSTRINFO_CTOR_DTOR |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 26 | #include "AMDGPUGenInstrInfo.inc" |
| 27 | |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 28 | // Pin the vtable to this file. |
| 29 | void AMDGPUInstrInfo::anchor() {} |
| 30 | |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 31 | AMDGPUInstrInfo::AMDGPUInstrInfo(const AMDGPUSubtarget &ST) |
Matt Arsenault | b62a4eb | 2017-08-01 19:54:18 +0000 | [diff] [blame] | 32 | : AMDGPUGenInstrInfo(AMDGPU::ADJCALLSTACKUP, AMDGPU::ADJCALLSTACKDOWN), |
| 33 | ST(ST), |
| 34 | AMDGPUASI(ST.getAMDGPUAS()) {} |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 35 | |
Matt Arsenault | d5f4de2 | 2014-08-06 00:29:49 +0000 | [diff] [blame] | 36 | // FIXME: This behaves strangely. If, for example, you have 32 load + stores, |
| 37 | // the first 16 loads will be interleaved with the stores, and the next 16 will |
| 38 | // be clustered as expected. It should really split into 2 16 store batches. |
| 39 | // |
| 40 | // Loads are clustered until this returns false, rather than trying to schedule |
| 41 | // groups of stores. This also means we have to deal with saying different |
| 42 | // address space loads should be clustered, and ones which might cause bank |
| 43 | // conflicts. |
| 44 | // |
| 45 | // This might be deprecated so it might not be worth that much effort to fix. |
| 46 | bool AMDGPUInstrInfo::shouldScheduleLoadsNear(SDNode *Load0, SDNode *Load1, |
| 47 | int64_t Offset0, int64_t Offset1, |
| 48 | unsigned NumLoads) const { |
| 49 | assert(Offset1 > Offset0 && |
| 50 | "Second offset should be larger than first offset!"); |
| 51 | // If we have less than 16 loads in a row, and the offsets are within 64 |
| 52 | // bytes, then schedule together. |
| 53 | |
| 54 | // A cacheline is 64 bytes (for global memory). |
| 55 | return (NumLoads <= 16 && (Offset1 - Offset0) < 64); |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 58 | // This must be kept in sync with the SIEncodingFamily class in SIInstrInfo.td |
| 59 | enum SIEncodingFamily { |
| 60 | SI = 0, |
Sam Kolton | 549c89d | 2017-06-21 08:53:38 +0000 | [diff] [blame] | 61 | VI = 1, |
| 62 | SDWA = 2, |
Dmitry Preobrazhensky | 1e32550 | 2017-08-09 17:10:47 +0000 | [diff] [blame] | 63 | SDWA9 = 3, |
| 64 | GFX9 = 4 |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 67 | static SIEncodingFamily subtargetEncodingFamily(const AMDGPUSubtarget &ST) { |
| 68 | switch (ST.getGeneration()) { |
| 69 | case AMDGPUSubtarget::SOUTHERN_ISLANDS: |
| 70 | case AMDGPUSubtarget::SEA_ISLANDS: |
| 71 | return SIEncodingFamily::SI; |
Marek Olsak | a93603d | 2015-01-15 18:42:51 +0000 | [diff] [blame] | 72 | case AMDGPUSubtarget::VOLCANIC_ISLANDS: |
Matt Arsenault | e823d92 | 2017-02-18 18:29:53 +0000 | [diff] [blame] | 73 | case AMDGPUSubtarget::GFX9: |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 74 | return SIEncodingFamily::VI; |
| 75 | |
| 76 | // FIXME: This should never be called for r600 GPUs. |
| 77 | case AMDGPUSubtarget::R600: |
| 78 | case AMDGPUSubtarget::R700: |
| 79 | case AMDGPUSubtarget::EVERGREEN: |
| 80 | case AMDGPUSubtarget::NORTHERN_ISLANDS: |
| 81 | return SIEncodingFamily::SI; |
Marek Olsak | a93603d | 2015-01-15 18:42:51 +0000 | [diff] [blame] | 82 | } |
Simon Pilgrim | 634dde3 | 2016-06-27 12:58:10 +0000 | [diff] [blame] | 83 | |
| 84 | llvm_unreachable("Unknown subtarget generation!"); |
Marek Olsak | a93603d | 2015-01-15 18:42:51 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | int AMDGPUInstrInfo::pseudoToMCOpcode(int Opcode) const { |
Sam Kolton | 549c89d | 2017-06-21 08:53:38 +0000 | [diff] [blame] | 88 | SIEncodingFamily Gen = subtargetEncodingFamily(ST); |
Dmitry Preobrazhensky | a0342dc | 2017-11-20 18:24:21 +0000 | [diff] [blame] | 89 | |
| 90 | if ((get(Opcode).TSFlags & SIInstrFlags::renamedInGFX9) != 0 && |
| 91 | ST.getGeneration() >= AMDGPUSubtarget::GFX9) |
| 92 | Gen = SIEncodingFamily::GFX9; |
| 93 | |
Sam Kolton | 549c89d | 2017-06-21 08:53:38 +0000 | [diff] [blame] | 94 | if (get(Opcode).TSFlags & SIInstrFlags::SDWA) |
| 95 | Gen = ST.getGeneration() == AMDGPUSubtarget::GFX9 ? SIEncodingFamily::SDWA9 |
| 96 | : SIEncodingFamily::SDWA; |
| 97 | |
| 98 | int MCOp = AMDGPU::getMCOpcode(Opcode, Gen); |
Marek Olsak | a93603d | 2015-01-15 18:42:51 +0000 | [diff] [blame] | 99 | |
| 100 | // -1 means that Opcode is already a native instruction. |
| 101 | if (MCOp == -1) |
| 102 | return Opcode; |
| 103 | |
| 104 | // (uint16_t)-1 means that Opcode is a pseudo instruction that has |
| 105 | // no encoding in the given subtarget generation. |
| 106 | if (MCOp == (uint16_t)-1) |
| 107 | return -1; |
| 108 | |
| 109 | return MCOp; |
| 110 | } |