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