[Codegen] Alter the default promotion for saturating adds and subs
[llvm-complete.git] / lib / Target / AMDGPU / AMDGPUMachineFunction.cpp
blob0d3a1f1a769f0b8b2e55dfc83dfbff0b61ff653e
1 //===-- AMDGPUMachineFunctionInfo.cpp ---------------------------------------=//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "AMDGPUMachineFunction.h"
10 #include "AMDGPUSubtarget.h"
11 #include "AMDGPUPerfHintAnalysis.h"
12 #include "llvm/CodeGen/MachineModuleInfo.h"
14 using namespace llvm;
16 AMDGPUMachineFunction::AMDGPUMachineFunction(const MachineFunction &MF) :
17 MachineFunctionInfo(),
18 LocalMemoryObjects(),
19 ExplicitKernArgSize(0),
20 MaxKernArgAlign(0),
21 LDSSize(0),
22 IsEntryFunction(AMDGPU::isEntryFunctionCC(MF.getFunction().getCallingConv())),
23 NoSignedZerosFPMath(MF.getTarget().Options.NoSignedZerosFPMath),
24 MemoryBound(false),
25 WaveLimiter(false) {
26 const AMDGPUSubtarget &ST = AMDGPUSubtarget::get(MF);
28 // FIXME: Should initialize KernArgSize based on ExplicitKernelArgOffset,
29 // except reserved size is not correctly aligned.
30 const Function &F = MF.getFunction();
32 Attribute MemBoundAttr = F.getFnAttribute("amdgpu-memory-bound");
33 MemoryBound = MemBoundAttr.isStringAttribute() &&
34 MemBoundAttr.getValueAsString() == "true";
36 Attribute WaveLimitAttr = F.getFnAttribute("amdgpu-wave-limiter");
37 WaveLimiter = WaveLimitAttr.isStringAttribute() &&
38 WaveLimitAttr.getValueAsString() == "true";
40 CallingConv::ID CC = F.getCallingConv();
41 if (CC == CallingConv::AMDGPU_KERNEL || CC == CallingConv::SPIR_KERNEL)
42 ExplicitKernArgSize = ST.getExplicitKernArgSize(F, MaxKernArgAlign);
45 unsigned AMDGPUMachineFunction::allocateLDSGlobal(const DataLayout &DL,
46 const GlobalValue &GV) {
47 auto Entry = LocalMemoryObjects.insert(std::make_pair(&GV, 0));
48 if (!Entry.second)
49 return Entry.first->second;
51 unsigned Align = GV.getAlignment();
52 if (Align == 0)
53 Align = DL.getABITypeAlignment(GV.getValueType());
55 /// TODO: We should sort these to minimize wasted space due to alignment
56 /// padding. Currently the padding is decided by the first encountered use
57 /// during lowering.
58 unsigned Offset = LDSSize = alignTo(LDSSize, Align);
60 Entry.first->second = Offset;
61 LDSSize += DL.getTypeAllocSize(GV.getValueType());
63 return Offset;