xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.h (revision 3e8eb5c7f4909209c042403ddee340b2ee7003a5)
1 //===-- AMDGPUMachineFunctionInfo.h -------------------------------*- C++ -*-=//
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 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEFUNCTION_H
10 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEFUNCTION_H
11 
12 #include "Utils/AMDGPUBaseInfo.h"
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/CodeGen/MachineFunction.h"
15 
16 namespace llvm {
17 
18 class AMDGPUMachineFunction : public MachineFunctionInfo {
19   /// A map to keep track of local memory objects and their offsets within the
20   /// local memory space.
21   SmallDenseMap<const GlobalValue *, unsigned, 4> LocalMemoryObjects;
22 
23 protected:
24   uint64_t ExplicitKernArgSize = 0; // Cache for this.
25   Align MaxKernArgAlign;        // Cache for this.
26 
27   /// Number of bytes in the LDS that are being used.
28   unsigned LDSSize = 0;
29 
30   /// Number of bytes in the LDS allocated statically. This field is only used
31   /// in the instruction selector and not part of the machine function info.
32   unsigned StaticLDSSize = 0;
33 
34   /// Align for dynamic shared memory if any. Dynamic shared memory is
35   /// allocated directly after the static one, i.e., LDSSize. Need to pad
36   /// LDSSize to ensure that dynamic one is aligned accordingly.
37   /// The maximal alignment is updated during IR translation or lowering
38   /// stages.
39   Align DynLDSAlign;
40 
41   // State of MODE register, assumed FP mode.
42   AMDGPU::SIModeRegisterDefaults Mode;
43 
44   // Kernels + shaders. i.e. functions called by the hardware and not called
45   // by other functions.
46   bool IsEntryFunction = false;
47 
48   // Entry points called by other functions instead of directly by the hardware.
49   bool IsModuleEntryFunction = false;
50 
51   bool NoSignedZerosFPMath = false;
52 
53   // Function may be memory bound.
54   bool MemoryBound = false;
55 
56   // Kernel may need limited waves per EU for better performance.
57   bool WaveLimiter = false;
58 
59 public:
60   AMDGPUMachineFunction(const MachineFunction &MF);
61 
62   uint64_t getExplicitKernArgSize() const {
63     return ExplicitKernArgSize;
64   }
65 
66   unsigned getMaxKernArgAlign() const { return MaxKernArgAlign.value(); }
67 
68   unsigned getLDSSize() const {
69     return LDSSize;
70   }
71 
72   AMDGPU::SIModeRegisterDefaults getMode() const {
73     return Mode;
74   }
75 
76   bool isEntryFunction() const {
77     return IsEntryFunction;
78   }
79 
80   bool isModuleEntryFunction() const { return IsModuleEntryFunction; }
81 
82   bool hasNoSignedZerosFPMath() const {
83     return NoSignedZerosFPMath;
84   }
85 
86   bool isMemoryBound() const {
87     return MemoryBound;
88   }
89 
90   bool needsWaveLimiter() const {
91     return WaveLimiter;
92   }
93 
94   unsigned allocateLDSGlobal(const DataLayout &DL, const GlobalVariable &GV);
95   void allocateModuleLDSGlobal(const Module *M);
96 
97   Align getDynLDSAlign() const { return DynLDSAlign; }
98 
99   void setDynLDSAlign(const DataLayout &DL, const GlobalVariable &GV);
100 };
101 
102 }
103 #endif
104