Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 1 | //===- AMDGPULegalizerInfo.cpp -----------------------------------*- C++ -*-==// |
| 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 | /// \file |
| 10 | /// This file implements the targeting of the Machinelegalizer class for |
| 11 | /// AMDGPU. |
| 12 | /// \todo This should be generated by TableGen. |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "AMDGPULegalizerInfo.h" |
| 16 | #include "llvm/CodeGen/ValueTypes.h" |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 17 | #include "llvm/IR/DerivedTypes.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 18 | #include "llvm/IR/Type.h" |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Debug.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetOpcodes.h" |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace llvm; |
| 23 | |
| 24 | #ifndef LLVM_BUILD_GLOBAL_ISEL |
| 25 | #error "You shouldn't build this" |
| 26 | #endif |
| 27 | |
| 28 | AMDGPULegalizerInfo::AMDGPULegalizerInfo() { |
| 29 | using namespace TargetOpcode; |
| 30 | |
Tom Stellard | e042412 | 2017-06-03 01:13:33 +0000 | [diff] [blame] | 31 | const LLT S1= LLT::scalar(1); |
Tom Stellard | ff63ee0 | 2017-06-19 13:15:45 +0000 | [diff] [blame^] | 32 | const LLT V2S16 = LLT::vector(2, 16); |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 33 | const LLT S32 = LLT::scalar(32); |
| 34 | const LLT S64 = LLT::scalar(64); |
| 35 | const LLT P1 = LLT::pointer(1, 64); |
| 36 | const LLT P2 = LLT::pointer(2, 64); |
| 37 | |
Tom Stellard | ee6e645 | 2017-06-12 20:54:56 +0000 | [diff] [blame] | 38 | setAction({G_ADD, S32}, Legal); |
| 39 | |
Tom Stellard | ff63ee0 | 2017-06-19 13:15:45 +0000 | [diff] [blame^] | 40 | setAction({G_BITCAST, V2S16}, Legal); |
| 41 | setAction({G_BITCAST, 1, S32}, Legal); |
| 42 | |
| 43 | setAction({G_BITCAST, S32}, Legal); |
| 44 | setAction({G_BITCAST, 1, V2S16}, Legal); |
| 45 | |
Tom Stellard | e042412 | 2017-06-03 01:13:33 +0000 | [diff] [blame] | 46 | // FIXME: i1 operands to intrinsics should always be legal, but other i1 |
| 47 | // values may not be legal. We need to figure out how to distinguish |
| 48 | // between these two scenarios. |
| 49 | setAction({G_CONSTANT, S1}, Legal); |
Tom Stellard | a0d67c7 | 2017-05-12 16:46:46 +0000 | [diff] [blame] | 50 | setAction({G_CONSTANT, S32}, Legal); |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 51 | setAction({G_CONSTANT, S64}, Legal); |
| 52 | |
Tom Stellard | dde28a8 | 2017-05-26 16:40:03 +0000 | [diff] [blame] | 53 | setAction({G_FCONSTANT, S32}, Legal); |
| 54 | |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 55 | setAction({G_GEP, P1}, Legal); |
| 56 | setAction({G_GEP, P2}, Legal); |
| 57 | setAction({G_GEP, 1, S64}, Legal); |
| 58 | |
Tom Stellard | 8cd60a5 | 2017-06-06 14:16:50 +0000 | [diff] [blame] | 59 | setAction({G_ICMP, S1}, Legal); |
| 60 | setAction({G_ICMP, 1, S32}, Legal); |
| 61 | |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 62 | setAction({G_LOAD, P1}, Legal); |
| 63 | setAction({G_LOAD, P2}, Legal); |
| 64 | setAction({G_LOAD, S32}, Legal); |
| 65 | setAction({G_LOAD, 1, P1}, Legal); |
| 66 | setAction({G_LOAD, 1, P2}, Legal); |
| 67 | |
Tom Stellard | 2860a42 | 2017-06-07 13:54:51 +0000 | [diff] [blame] | 68 | setAction({G_SELECT, S32}, Legal); |
| 69 | setAction({G_SELECT, 1, S1}, Legal); |
| 70 | |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 71 | setAction({G_STORE, S32}, Legal); |
| 72 | setAction({G_STORE, 1, P1}, Legal); |
| 73 | |
| 74 | // FIXME: When RegBankSelect inserts copies, it will only create new |
| 75 | // registers with scalar types. This means we can end up with |
| 76 | // G_LOAD/G_STORE/G_GEP instruction with scalar types for their pointer |
| 77 | // operands. In assert builds, the instruction selector will assert |
| 78 | // if it sees a generic instruction which isn't legal, so we need to |
| 79 | // tell it that scalar types are legal for pointer operands |
| 80 | setAction({G_GEP, S64}, Legal); |
| 81 | setAction({G_LOAD, 1, S64}, Legal); |
| 82 | setAction({G_STORE, 1, S64}, Legal); |
| 83 | |
| 84 | computeTables(); |
| 85 | } |