brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.2 KiB · fc64e16 Raw
146 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEFUNCTION_H10#define LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEFUNCTION_H11 12#include "Utils/AMDGPUBaseInfo.h"13#include "llvm/ADT/DenseMap.h"14#include "llvm/CodeGen/MachineFunction.h"15#include "llvm/IR/DataLayout.h"16#include "llvm/IR/Function.h"17#include "llvm/IR/GlobalValue.h"18#include "llvm/IR/GlobalVariable.h"19 20namespace llvm {21 22class AMDGPUSubtarget;23 24class AMDGPUMachineFunction : public MachineFunctionInfo {25  /// A map to keep track of local memory objects and their offsets within the26  /// local memory space.27  SmallDenseMap<const GlobalValue *, unsigned, 4> LocalMemoryObjects;28 29protected:30  uint64_t ExplicitKernArgSize = 0; // Cache for this.31  Align MaxKernArgAlign;        // Cache for this.32 33  /// Number of bytes in the LDS that are being used.34  uint32_t LDSSize = 0;35  uint32_t GDSSize = 0;36 37  /// Number of bytes in the LDS allocated statically. This field is only used38  /// in the instruction selector and not part of the machine function info.39  uint32_t StaticLDSSize = 0;40  uint32_t StaticGDSSize = 0;41 42  /// Align for dynamic shared memory if any. Dynamic shared memory is43  /// allocated directly after the static one, i.e., LDSSize. Need to pad44  /// LDSSize to ensure that dynamic one is aligned accordingly.45  /// The maximal alignment is updated during IR translation or lowering46  /// stages.47  Align DynLDSAlign;48 49  // Flag to check dynamic LDS usage by kernel.50  bool UsesDynamicLDS = false;51 52  uint32_t NumNamedBarriers = 0;53 54  // Kernels + shaders. i.e. functions called by the hardware and not called55  // by other functions.56  bool IsEntryFunction = false;57 58  // Entry points called by other functions instead of directly by the hardware.59  bool IsModuleEntryFunction = false;60 61  // Functions with the amdgpu_cs_chain or amdgpu_cs_chain_preserve CC.62  bool IsChainFunction = false;63 64  bool NoSignedZerosFPMath = false;65 66  // Function may be memory bound.67  bool MemoryBound = false;68 69  // Kernel may need limited waves per EU for better performance.70  bool WaveLimiter = false;71 72  bool HasInitWholeWave = false;73 74public:75  AMDGPUMachineFunction(const Function &F, const AMDGPUSubtarget &ST);76 77  uint64_t getExplicitKernArgSize() const {78    return ExplicitKernArgSize;79  }80 81  Align getMaxKernArgAlign() const { return MaxKernArgAlign; }82 83  uint32_t getLDSSize() const {84    return LDSSize;85  }86 87  uint32_t getGDSSize() const {88    return GDSSize;89  }90 91  void recordNumNamedBarriers(uint32_t GVAddr, unsigned BarCnt) {92    NumNamedBarriers =93        std::max(NumNamedBarriers, ((GVAddr & 0x1ff) >> 4) + BarCnt - 1);94  }95  uint32_t getNumNamedBarriers() const { return NumNamedBarriers; }96 97  bool isEntryFunction() const {98    return IsEntryFunction;99  }100 101  bool isModuleEntryFunction() const { return IsModuleEntryFunction; }102 103  bool isChainFunction() const { return IsChainFunction; }104 105  // The stack is empty upon entry to this function.106  bool isBottomOfStack() const {107    return isEntryFunction() || isChainFunction();108  }109 110  bool hasNoSignedZerosFPMath() const {111    return NoSignedZerosFPMath;112  }113 114  bool isMemoryBound() const {115    return MemoryBound;116  }117 118  bool needsWaveLimiter() const {119    return WaveLimiter;120  }121 122  bool hasInitWholeWave() const { return HasInitWholeWave; }123  void setInitWholeWave() { HasInitWholeWave = true; }124 125  unsigned allocateLDSGlobal(const DataLayout &DL, const GlobalVariable &GV) {126    return allocateLDSGlobal(DL, GV, DynLDSAlign);127  }128 129  unsigned allocateLDSGlobal(const DataLayout &DL, const GlobalVariable &GV,130                             Align Trailing);131 132  static std::optional<uint32_t> getLDSKernelIdMetadata(const Function &F);133  static std::optional<uint32_t> getLDSAbsoluteAddress(const GlobalValue &GV);134 135  Align getDynLDSAlign() const { return DynLDSAlign; }136 137  void setDynLDSAlign(const Function &F, const GlobalVariable &GV);138 139  void setUsesDynamicLDS(bool DynLDS);140 141  bool isDynamicLDSUsed() const;142};143 144}145#endif146