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