[PM] Switch the TargetMachine interface from accepting a pass manager
[oota-llvm.git] / lib / Target / R600 / AMDGPUTargetTransformInfo.cpp
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
18 #include "AMDGPUTargetTransformInfo.h"
19 #include "llvm/Analysis/LoopInfo.h"
20 #include "llvm/Analysis/TargetTransformInfo.h"
21 #include "llvm/Analysis/ValueTracking.h"
22 #include "llvm/CodeGen/BasicTTIImpl.h"
23 #include "llvm/Support/Debug.h"
24 #include "llvm/Target/CostTable.h"
25 #include "llvm/Target/TargetLowering.h"
26 using namespace llvm;
27
28 #define DEBUG_TYPE "AMDGPUtti"
29
30 void AMDGPUTTIImpl::getUnrollingPreferences(const Function *, Loop *L,
31                                             TTI::UnrollingPreferences &UP) {
32   UP.Threshold = 300; // Twice the default.
33   UP.Count = UINT_MAX;
34   UP.Partial = true;
35
36   // TODO: Do we want runtime unrolling?
37
38   for (const BasicBlock *BB : L->getBlocks()) {
39     for (const Instruction &I : *BB) {
40       const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(&I);
41       if (!GEP || GEP->getAddressSpace() != AMDGPUAS::PRIVATE_ADDRESS)
42         continue;
43
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
51         // alloca ptr, then we want to use a higher than normal loop unroll
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.
57         UP.Threshold = 800;
58       }
59     }
60   }
61 }
62
63 unsigned AMDGPUTTIImpl::getNumberOfRegisters(bool Vec) {
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
74 unsigned AMDGPUTTIImpl::getRegisterBitWidth(bool) { return 32; }
75
76 unsigned AMDGPUTTIImpl::getMaxInterleaveFactor() {
77   // Semi-arbitrary large amount.
78   return 64;
79 }