1//===-- AMDGPUInstrInfo.cpp - Base class for AMD GPU InstrInfo ------------===//
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/// \file
10/// \brief Implementation of the TargetInstrInfo class that is common to all
11/// AMD GPUs.
12//
13//===----------------------------------------------------------------------===//
14
15#include "AMDGPUInstrInfo.h"
16#include "llvm/CodeGen/MachineInstr.h"
17#include "llvm/CodeGen/MachineMemOperand.h"
18#include "llvm/IR/Constants.h"
19#include "llvm/IR/Instruction.h"
20#include "llvm/IR/Value.h"
21
22using namespace llvm;
23
24Intrinsic::ID AMDGPU::getIntrinsicID(const MachineInstr &I) {
25 return I.getOperand(i: I.getNumExplicitDefs()).getIntrinsicID();
26}
27
28// TODO: Should largely merge with AMDGPUTTIImpl::isSourceOfDivergence.
29bool AMDGPU::isUniformMMO(const MachineMemOperand *MMO) {
30 const Value *Ptr = MMO->getValue();
31 if (!Ptr) {
32 if (const PseudoSourceValue *PSV = MMO->getPseudoValue()) {
33 return PSV->isConstantPool() || PSV->isStack() || PSV->isGOT() ||
34 PSV->isJumpTable();
35 }
36
37 // Unknown value.
38 return false;
39 }
40
41 // UndefValue means this is a load of a kernel input. These are uniform.
42 // Sometimes LDS instructions have constant pointers.
43 if (isa<UndefValue, Constant, GlobalValue>(Val: Ptr))
44 return true;
45
46 if (MMO->getAddrSpace() == AMDGPUAS::CONSTANT_ADDRESS_32BIT)
47 return true;
48
49 if (const Argument *Arg = dyn_cast<Argument>(Val: Ptr))
50 return AMDGPU::isArgPassedInSGPR(Arg);
51
52 const Instruction *I = dyn_cast<Instruction>(Val: Ptr);
53 return I && I->getMetadata(Kind: "amdgpu.uniform");
54}
55