2017-08-04 00:30:46 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-08-04 00:30:46 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "AMDGPUArgumentUsageInfo.h"
|
2020-12-25 16:52:14 +01:00
|
|
|
#include "AMDGPU.h"
|
2020-03-11 21:13:52 +01:00
|
|
|
#include "AMDGPUTargetMachine.h"
|
|
|
|
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
|
2017-08-04 00:30:46 +02:00
|
|
|
#include "SIRegisterInfo.h"
|
2020-12-25 16:52:14 +01:00
|
|
|
#include "llvm/CodeGen/TargetRegisterInfo.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
2019-06-28 03:52:13 +02:00
|
|
|
#include "llvm/Support/NativeFormatting.h"
|
2017-08-04 00:30:46 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "amdgpu-argument-reg-usage-info"
|
|
|
|
|
|
|
|
INITIALIZE_PASS(AMDGPUArgumentUsageInfo, DEBUG_TYPE,
|
|
|
|
"Argument Register Usage Information Storage", false, true)
|
|
|
|
|
|
|
|
void ArgDescriptor::print(raw_ostream &OS,
|
|
|
|
const TargetRegisterInfo *TRI) const {
|
|
|
|
if (!isSet()) {
|
|
|
|
OS << "<not set>\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isRegister())
|
2019-06-28 03:52:13 +02:00
|
|
|
OS << "Reg " << printReg(getRegister(), TRI);
|
2017-08-04 00:30:46 +02:00
|
|
|
else
|
2019-06-28 03:52:13 +02:00
|
|
|
OS << "Stack offset " << getStackOffset();
|
|
|
|
|
|
|
|
if (isMasked()) {
|
|
|
|
OS << " & ";
|
|
|
|
llvm::write_hex(OS, Mask, llvm::HexPrintStyle::PrefixLower);
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << '\n';
|
2017-08-04 00:30:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
char AMDGPUArgumentUsageInfo::ID = 0;
|
|
|
|
|
|
|
|
const AMDGPUFunctionArgInfo AMDGPUArgumentUsageInfo::ExternFunctionInfo{};
|
|
|
|
|
2020-03-11 21:13:52 +01:00
|
|
|
// Hardcoded registers from fixed function ABI
|
|
|
|
const AMDGPUFunctionArgInfo AMDGPUArgumentUsageInfo::FixedABIFunctionInfo
|
|
|
|
= AMDGPUFunctionArgInfo::fixedABILayout();
|
|
|
|
|
2017-08-04 00:30:46 +02:00
|
|
|
bool AMDGPUArgumentUsageInfo::doInitialization(Module &M) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUArgumentUsageInfo::doFinalization(Module &M) {
|
|
|
|
ArgInfoMap.clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUArgumentUsageInfo::print(raw_ostream &OS, const Module *M) const {
|
|
|
|
for (const auto &FI : ArgInfoMap) {
|
|
|
|
OS << "Arguments for " << FI.first->getName() << '\n'
|
|
|
|
<< " PrivateSegmentBuffer: " << FI.second.PrivateSegmentBuffer
|
|
|
|
<< " DispatchPtr: " << FI.second.DispatchPtr
|
|
|
|
<< " QueuePtr: " << FI.second.QueuePtr
|
|
|
|
<< " KernargSegmentPtr: " << FI.second.KernargSegmentPtr
|
|
|
|
<< " DispatchID: " << FI.second.DispatchID
|
|
|
|
<< " FlatScratchInit: " << FI.second.FlatScratchInit
|
|
|
|
<< " PrivateSegmentSize: " << FI.second.PrivateSegmentSize
|
|
|
|
<< " WorkGroupIDX: " << FI.second.WorkGroupIDX
|
|
|
|
<< " WorkGroupIDY: " << FI.second.WorkGroupIDY
|
|
|
|
<< " WorkGroupIDZ: " << FI.second.WorkGroupIDZ
|
|
|
|
<< " WorkGroupInfo: " << FI.second.WorkGroupInfo
|
|
|
|
<< " PrivateSegmentWaveByteOffset: "
|
|
|
|
<< FI.second.PrivateSegmentWaveByteOffset
|
|
|
|
<< " ImplicitBufferPtr: " << FI.second.ImplicitBufferPtr
|
2017-08-04 01:12:44 +02:00
|
|
|
<< " ImplicitArgPtr: " << FI.second.ImplicitArgPtr
|
2017-08-04 00:30:46 +02:00
|
|
|
<< " WorkItemIDX " << FI.second.WorkItemIDX
|
|
|
|
<< " WorkItemIDY " << FI.second.WorkItemIDY
|
|
|
|
<< " WorkItemIDZ " << FI.second.WorkItemIDZ
|
|
|
|
<< '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-05 19:17:02 +02:00
|
|
|
std::tuple<const ArgDescriptor *, const TargetRegisterClass *, LLT>
|
2017-08-04 00:30:46 +02:00
|
|
|
AMDGPUFunctionArgInfo::getPreloadedValue(
|
2020-07-05 19:17:02 +02:00
|
|
|
AMDGPUFunctionArgInfo::PreloadedValue Value) const {
|
2017-08-04 00:30:46 +02:00
|
|
|
switch (Value) {
|
|
|
|
case AMDGPUFunctionArgInfo::PRIVATE_SEGMENT_BUFFER: {
|
2020-07-05 19:17:02 +02:00
|
|
|
return std::make_tuple(PrivateSegmentBuffer ? &PrivateSegmentBuffer
|
|
|
|
: nullptr,
|
2021-06-24 10:58:21 +02:00
|
|
|
&AMDGPU::SGPR_128RegClass, LLT::fixed_vector(4, 32));
|
2017-08-04 00:30:46 +02:00
|
|
|
}
|
|
|
|
case AMDGPUFunctionArgInfo::IMPLICIT_BUFFER_PTR:
|
2020-07-05 19:17:02 +02:00
|
|
|
return std::make_tuple(ImplicitBufferPtr ? &ImplicitBufferPtr : nullptr,
|
|
|
|
&AMDGPU::SGPR_64RegClass,
|
|
|
|
LLT::pointer(AMDGPUAS::CONSTANT_ADDRESS, 64));
|
2017-08-04 00:30:46 +02:00
|
|
|
case AMDGPUFunctionArgInfo::WORKGROUP_ID_X:
|
2020-07-05 19:17:02 +02:00
|
|
|
return std::make_tuple(WorkGroupIDX ? &WorkGroupIDX : nullptr,
|
|
|
|
&AMDGPU::SGPR_32RegClass, LLT::scalar(32));
|
2017-08-04 00:30:46 +02:00
|
|
|
case AMDGPUFunctionArgInfo::WORKGROUP_ID_Y:
|
2020-07-05 19:17:02 +02:00
|
|
|
return std::make_tuple(WorkGroupIDY ? &WorkGroupIDY : nullptr,
|
|
|
|
&AMDGPU::SGPR_32RegClass, LLT::scalar(32));
|
2017-08-04 00:30:46 +02:00
|
|
|
case AMDGPUFunctionArgInfo::WORKGROUP_ID_Z:
|
2020-07-05 19:17:02 +02:00
|
|
|
return std::make_tuple(WorkGroupIDZ ? &WorkGroupIDZ : nullptr,
|
|
|
|
&AMDGPU::SGPR_32RegClass, LLT::scalar(32));
|
2017-08-04 00:30:46 +02:00
|
|
|
case AMDGPUFunctionArgInfo::PRIVATE_SEGMENT_WAVE_BYTE_OFFSET:
|
2020-07-05 19:17:02 +02:00
|
|
|
return std::make_tuple(
|
|
|
|
PrivateSegmentWaveByteOffset ? &PrivateSegmentWaveByteOffset : nullptr,
|
|
|
|
&AMDGPU::SGPR_32RegClass, LLT::scalar(32));
|
2017-08-04 00:30:46 +02:00
|
|
|
case AMDGPUFunctionArgInfo::KERNARG_SEGMENT_PTR:
|
2020-07-05 19:17:02 +02:00
|
|
|
return std::make_tuple(KernargSegmentPtr ? &KernargSegmentPtr : nullptr,
|
|
|
|
&AMDGPU::SGPR_64RegClass,
|
|
|
|
LLT::pointer(AMDGPUAS::CONSTANT_ADDRESS, 64));
|
2017-08-04 01:12:44 +02:00
|
|
|
case AMDGPUFunctionArgInfo::IMPLICIT_ARG_PTR:
|
2020-07-05 19:17:02 +02:00
|
|
|
return std::make_tuple(ImplicitArgPtr ? &ImplicitArgPtr : nullptr,
|
|
|
|
&AMDGPU::SGPR_64RegClass,
|
|
|
|
LLT::pointer(AMDGPUAS::CONSTANT_ADDRESS, 64));
|
2017-08-04 00:30:46 +02:00
|
|
|
case AMDGPUFunctionArgInfo::DISPATCH_ID:
|
2020-07-05 19:17:02 +02:00
|
|
|
return std::make_tuple(DispatchID ? &DispatchID : nullptr,
|
|
|
|
&AMDGPU::SGPR_64RegClass, LLT::scalar(64));
|
2017-08-04 00:30:46 +02:00
|
|
|
case AMDGPUFunctionArgInfo::FLAT_SCRATCH_INIT:
|
2020-07-05 19:17:02 +02:00
|
|
|
return std::make_tuple(FlatScratchInit ? &FlatScratchInit : nullptr,
|
|
|
|
&AMDGPU::SGPR_64RegClass, LLT::scalar(64));
|
2017-08-04 00:30:46 +02:00
|
|
|
case AMDGPUFunctionArgInfo::DISPATCH_PTR:
|
2020-07-05 19:17:02 +02:00
|
|
|
return std::make_tuple(DispatchPtr ? &DispatchPtr : nullptr,
|
|
|
|
&AMDGPU::SGPR_64RegClass,
|
|
|
|
LLT::pointer(AMDGPUAS::CONSTANT_ADDRESS, 64));
|
2017-08-04 00:30:46 +02:00
|
|
|
case AMDGPUFunctionArgInfo::QUEUE_PTR:
|
2020-07-05 19:17:02 +02:00
|
|
|
return std::make_tuple(QueuePtr ? &QueuePtr : nullptr,
|
|
|
|
&AMDGPU::SGPR_64RegClass,
|
|
|
|
LLT::pointer(AMDGPUAS::CONSTANT_ADDRESS, 64));
|
2017-08-04 00:30:46 +02:00
|
|
|
case AMDGPUFunctionArgInfo::WORKITEM_ID_X:
|
2020-07-05 19:17:02 +02:00
|
|
|
return std::make_tuple(WorkItemIDX ? &WorkItemIDX : nullptr,
|
|
|
|
&AMDGPU::VGPR_32RegClass, LLT::scalar(32));
|
2017-08-04 00:30:46 +02:00
|
|
|
case AMDGPUFunctionArgInfo::WORKITEM_ID_Y:
|
2020-07-05 19:17:02 +02:00
|
|
|
return std::make_tuple(WorkItemIDY ? &WorkItemIDY : nullptr,
|
|
|
|
&AMDGPU::VGPR_32RegClass, LLT::scalar(32));
|
2017-08-04 00:30:46 +02:00
|
|
|
case AMDGPUFunctionArgInfo::WORKITEM_ID_Z:
|
2020-07-05 19:17:02 +02:00
|
|
|
return std::make_tuple(WorkItemIDZ ? &WorkItemIDZ : nullptr,
|
|
|
|
&AMDGPU::VGPR_32RegClass, LLT::scalar(32));
|
2017-08-04 00:30:46 +02:00
|
|
|
}
|
|
|
|
llvm_unreachable("unexpected preloaded value type");
|
|
|
|
}
|
2020-03-11 21:13:52 +01:00
|
|
|
|
|
|
|
constexpr AMDGPUFunctionArgInfo AMDGPUFunctionArgInfo::fixedABILayout() {
|
|
|
|
AMDGPUFunctionArgInfo AI;
|
2020-07-05 19:55:29 +02:00
|
|
|
AI.PrivateSegmentBuffer
|
|
|
|
= ArgDescriptor::createRegister(AMDGPU::SGPR0_SGPR1_SGPR2_SGPR3);
|
|
|
|
AI.DispatchPtr = ArgDescriptor::createRegister(AMDGPU::SGPR4_SGPR5);
|
|
|
|
AI.QueuePtr = ArgDescriptor::createRegister(AMDGPU::SGPR6_SGPR7);
|
2020-03-11 21:13:52 +01:00
|
|
|
|
|
|
|
// Do not pass kernarg segment pointer, only pass increment version in its
|
|
|
|
// place.
|
2020-07-05 19:55:29 +02:00
|
|
|
AI.ImplicitArgPtr = ArgDescriptor::createRegister(AMDGPU::SGPR8_SGPR9);
|
|
|
|
AI.DispatchID = ArgDescriptor::createRegister(AMDGPU::SGPR10_SGPR11);
|
2020-03-11 21:13:52 +01:00
|
|
|
|
|
|
|
// Skip FlatScratchInit/PrivateSegmentSize
|
2020-07-05 19:55:29 +02:00
|
|
|
AI.WorkGroupIDX = ArgDescriptor::createRegister(AMDGPU::SGPR12);
|
|
|
|
AI.WorkGroupIDY = ArgDescriptor::createRegister(AMDGPU::SGPR13);
|
|
|
|
AI.WorkGroupIDZ = ArgDescriptor::createRegister(AMDGPU::SGPR14);
|
2020-03-11 21:13:52 +01:00
|
|
|
|
|
|
|
const unsigned Mask = 0x3ff;
|
|
|
|
AI.WorkItemIDX = ArgDescriptor::createRegister(AMDGPU::VGPR31, Mask);
|
|
|
|
AI.WorkItemIDY = ArgDescriptor::createRegister(AMDGPU::VGPR31, Mask << 10);
|
|
|
|
AI.WorkItemIDZ = ArgDescriptor::createRegister(AMDGPU::VGPR31, Mask << 20);
|
|
|
|
return AI;
|
|
|
|
}
|
|
|
|
|
|
|
|
const AMDGPUFunctionArgInfo &
|
|
|
|
AMDGPUArgumentUsageInfo::lookupFuncArgInfo(const Function &F) const {
|
|
|
|
auto I = ArgInfoMap.find(&F);
|
|
|
|
if (I == ArgInfoMap.end()) {
|
|
|
|
if (AMDGPUTargetMachine::EnableFixedFunctionABI)
|
|
|
|
return FixedABIFunctionInfo;
|
|
|
|
|
|
|
|
// Without the fixed ABI, we assume no function has special inputs.
|
|
|
|
assert(F.isDeclaration());
|
|
|
|
return ExternFunctionInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
return I->second;
|
|
|
|
}
|