|
| 1 | +//===-- AMDGPURegBankSelect.cpp -------------------------------------------===// |
| 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 | +/// Assign register banks to all register operands of G_ instructions using |
| 10 | +/// machine uniformity analysis. |
| 11 | +/// Sgpr - uniform values and some lane masks |
| 12 | +/// Vgpr - divergent, non S1, values |
| 13 | +/// Vcc - divergent S1 values(lane masks) |
| 14 | +/// However in some cases G_ instructions with this register bank assignment |
| 15 | +/// can't be inst-selected. This is solved in AMDGPURegBankLegalize. |
| 16 | +//===----------------------------------------------------------------------===// |
| 17 | + |
| 18 | +#include "AMDGPU.h" |
| 19 | +#include "llvm/CodeGen/MachineFunctionPass.h" |
| 20 | +#include "llvm/InitializePasses.h" |
| 21 | + |
| 22 | +#define DEBUG_TYPE "amdgpu-regbankselect" |
| 23 | + |
| 24 | +using namespace llvm; |
| 25 | + |
| 26 | +namespace { |
| 27 | + |
| 28 | +class AMDGPURegBankSelect : public MachineFunctionPass { |
| 29 | +public: |
| 30 | + static char ID; |
| 31 | + |
| 32 | + AMDGPURegBankSelect() : MachineFunctionPass(ID) { |
| 33 | + initializeAMDGPURegBankSelectPass(*PassRegistry::getPassRegistry()); |
| 34 | + } |
| 35 | + |
| 36 | + bool runOnMachineFunction(MachineFunction &MF) override; |
| 37 | + |
| 38 | + StringRef getPassName() const override { |
| 39 | + return "AMDGPU Register Bank Select"; |
| 40 | + } |
| 41 | + |
| 42 | + void getAnalysisUsage(AnalysisUsage &AU) const override { |
| 43 | + MachineFunctionPass::getAnalysisUsage(AU); |
| 44 | + } |
| 45 | + |
| 46 | + // This pass assigns register banks to all virtual registers, and we maintain |
| 47 | + // this property in subsequent passes |
| 48 | + MachineFunctionProperties getSetProperties() const override { |
| 49 | + return MachineFunctionProperties().set( |
| 50 | + MachineFunctionProperties::Property::RegBankSelected); |
| 51 | + } |
| 52 | +}; |
| 53 | + |
| 54 | +} // End anonymous namespace. |
| 55 | + |
| 56 | +INITIALIZE_PASS_BEGIN(AMDGPURegBankSelect, DEBUG_TYPE, |
| 57 | + "AMDGPU Register Bank Select", false, false) |
| 58 | +INITIALIZE_PASS_END(AMDGPURegBankSelect, DEBUG_TYPE, |
| 59 | + "AMDGPU Register Bank Select", false, false) |
| 60 | + |
| 61 | +char AMDGPURegBankSelect::ID = 0; |
| 62 | + |
| 63 | +char &llvm::AMDGPURegBankSelectID = AMDGPURegBankSelect::ID; |
| 64 | + |
| 65 | +FunctionPass *llvm::createAMDGPURegBankSelectPass() { |
| 66 | + return new AMDGPURegBankSelect(); |
| 67 | +} |
| 68 | + |
| 69 | +bool AMDGPURegBankSelect::runOnMachineFunction(MachineFunction &MF) { |
| 70 | + if (MF.getProperties().hasProperty( |
| 71 | + MachineFunctionProperties::Property::FailedISel)) |
| 72 | + return false; |
| 73 | + return true; |
| 74 | +} |
0 commit comments