Tom Stellard | 8b1e021 | 2013-07-27 00:01:07 +0000 | [diff] [blame] | 1 | //===-- AMDGPUTargetTransformInfo.cpp - AMDGPU specific TTI pass ---------===// |
| 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 | // This file implements a TargetTransformInfo analysis pass specific to the |
| 12 | // AMDGPU target machine. It uses the target's detailed information to provide |
| 13 | // more precise answers to certain TTI queries, while letting the target |
| 14 | // independent and default TTI implementations handle the rest. |
| 15 | // |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 18 | #include "AMDGPUTargetTransformInfo.h" |
Tom Stellard | 8cce9bd | 2014-01-23 18:49:28 +0000 | [diff] [blame] | 19 | #include "llvm/Analysis/LoopInfo.h" |
Tom Stellard | 8b1e021 | 2013-07-27 00:01:07 +0000 | [diff] [blame] | 20 | #include "llvm/Analysis/TargetTransformInfo.h" |
Tom Stellard | 8cce9bd | 2014-01-23 18:49:28 +0000 | [diff] [blame] | 21 | #include "llvm/Analysis/ValueTracking.h" |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/BasicTTIImpl.h" |
Tom Stellard | 8b1e021 | 2013-07-27 00:01:07 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Debug.h" |
Tom Stellard | 8b1e021 | 2013-07-27 00:01:07 +0000 | [diff] [blame] | 24 | #include "llvm/Target/CostTable.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetLowering.h" |
Tom Stellard | 8b1e021 | 2013-07-27 00:01:07 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 28 | #define DEBUG_TYPE "AMDGPUtti" |
| 29 | |
Chandler Carruth | ab5cb36 | 2015-02-01 14:31:23 +0000 | [diff] [blame] | 30 | void AMDGPUTTIImpl::getUnrollingPreferences(Loop *L, |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 31 | TTI::UnrollingPreferences &UP) { |
Matt Arsenault | c824458 | 2014-07-25 23:02:42 +0000 | [diff] [blame] | 32 | UP.Threshold = 300; // Twice the default. |
Tom Stellard | eea3f70 | 2015-02-05 15:32:18 +0000 | [diff] [blame^] | 33 | UP.MaxCount = UINT_MAX; |
Matt Arsenault | c824458 | 2014-07-25 23:02:42 +0000 | [diff] [blame] | 34 | UP.Partial = true; |
| 35 | |
| 36 | // TODO: Do we want runtime unrolling? |
| 37 | |
Matt Arsenault | ac6e39c | 2014-07-17 06:19:06 +0000 | [diff] [blame] | 38 | for (const BasicBlock *BB : L->getBlocks()) { |
| 39 | for (const Instruction &I : *BB) { |
| 40 | const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(&I); |
Matt Arsenault | 5e2b0f5 | 2014-07-17 06:13:41 +0000 | [diff] [blame] | 41 | if (!GEP || GEP->getAddressSpace() != AMDGPUAS::PRIVATE_ADDRESS) |
Tom Stellard | 8cce9bd | 2014-01-23 18:49:28 +0000 | [diff] [blame] | 42 | continue; |
Matt Arsenault | ac6e39c | 2014-07-17 06:19:06 +0000 | [diff] [blame] | 43 | |
Tom Stellard | 8cce9bd | 2014-01-23 18:49:28 +0000 | [diff] [blame] | 44 | const Value *Ptr = GEP->getPointerOperand(); |
| 45 | const AllocaInst *Alloca = dyn_cast<AllocaInst>(GetUnderlyingObject(Ptr)); |
| 46 | if (Alloca) { |
| 47 | // We want to do whatever we can to limit the number of alloca |
| 48 | // instructions that make it through to the code generator. allocas |
| 49 | // require us to use indirect addressing, which is slow and prone to |
| 50 | // compiler bugs. If this loop does an address calculation on an |
Tom Stellard | fd0d86c | 2014-02-25 21:36:21 +0000 | [diff] [blame] | 51 | // alloca ptr, then we want to use a higher than normal loop unroll |
Matt Arsenault | 5e1e431 | 2014-04-04 20:13:08 +0000 | [diff] [blame] | 52 | // threshold. This will give SROA a better chance to eliminate these |
| 53 | // allocas. |
| 54 | // |
| 55 | // Don't use the maximum allowed value here as it will make some |
| 56 | // programs way too big. |
Matt Arsenault | c824458 | 2014-07-25 23:02:42 +0000 | [diff] [blame] | 57 | UP.Threshold = 800; |
Tom Stellard | 8cce9bd | 2014-01-23 18:49:28 +0000 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
Matt Arsenault | 3dd43fc | 2014-07-18 06:07:13 +0000 | [diff] [blame] | 62 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 63 | unsigned AMDGPUTTIImpl::getNumberOfRegisters(bool Vec) { |
Matt Arsenault | a93441f | 2014-07-19 18:15:16 +0000 | [diff] [blame] | 64 | if (Vec) |
| 65 | return 0; |
| 66 | |
| 67 | // Number of VGPRs on SI. |
| 68 | if (ST->getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS) |
| 69 | return 256; |
| 70 | |
| 71 | return 4 * 128; // XXX - 4 channels. Should these count as vector instead? |
| 72 | } |
| 73 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 74 | unsigned AMDGPUTTIImpl::getRegisterBitWidth(bool) { return 32; } |
Matt Arsenault | a93441f | 2014-07-19 18:15:16 +0000 | [diff] [blame] | 75 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 76 | unsigned AMDGPUTTIImpl::getMaxInterleaveFactor() { |
Matt Arsenault | a93441f | 2014-07-19 18:15:16 +0000 | [diff] [blame] | 77 | // Semi-arbitrary large amount. |
| 78 | return 64; |
| 79 | } |