-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AMDGPU/GlobalISel: Add skeletons for new register bank select passes
New register bank select for AMDGPU will be split in two passes: - AMDGPURegBankSelect: select banks based on machine uniformity analysis - AMDGPURegBankLegalize: lower instructions that can't be inst-selected with register banks assigned by AMDGPURegBankSelect. AMDGPURegBankLegalize is similar to legalizer but with context of uniformity analysis. Does not change already assigned banks. Main goal of AMDGPURegBankLegalize is to provide high level table-like overview of how to lower generic instructions based on available target features and uniformity info (uniform vs divergent). See RegBankLegalizeRules. Summary of new features: At the moment register bank select assigns register bank to output register using simple algorithm: - one of the inputs is vgpr output is vgpr - all inputs are sgpr output is sgpr. When function does not contain divergent control flow propagating register banks like this works. In general, first point is still correct but second is not when function contains divergent control flow. Examples: - Phi with uniform inputs that go through divergent branch - Instruction with temporal divergent use. To fix this AMDGPURegBankSelect will use machine uniformity analysis to assign vgpr to each divergent and sgpr to each uniform instruction. But some instructions are only available on VALU (for example floating point instructions before gfx1150) and we need to assign vgpr to them. Since we are no longer propagating register banks we need to ensure that uniform instructions get their inputs in sgpr in some way. In AMDGPURegBankLegalize uniform instructions that are only available on VALU will be reassigned to vgpr on all operands and read-any-lane vgpr output to original sgpr output.
- Loading branch information
1 parent
5fa4bae
commit 623266f
Showing
11 changed files
with
4,048 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//===-- AMDGPURegBankLegalize.cpp -----------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
/// Lower G_ instructions that can't be inst-selected with register bank | ||
/// assignment from AMDGPURegBankSelect based on machine uniformity info. | ||
/// Given types on all operands, some register bank assignments require lowering | ||
/// while others do not. | ||
/// Note: cases where all register bank assignments would require lowering are | ||
/// lowered in legalizer. | ||
/// For example vgpr S64 G_AND requires lowering to S32 while sgpr S64 does not. | ||
/// Eliminate sgpr S1 by lowering to sgpr S32. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "AMDGPU.h" | ||
#include "llvm/CodeGen/MachineFunctionPass.h" | ||
#include "llvm/InitializePasses.h" | ||
|
||
#define DEBUG_TYPE "amdgpu-regbanklegalize" | ||
|
||
using namespace llvm; | ||
|
||
namespace { | ||
|
||
class AMDGPURegBankLegalize : public MachineFunctionPass { | ||
public: | ||
static char ID; | ||
|
||
public: | ||
AMDGPURegBankLegalize() : MachineFunctionPass(ID) { | ||
initializeAMDGPURegBankLegalizePass(*PassRegistry::getPassRegistry()); | ||
} | ||
|
||
bool runOnMachineFunction(MachineFunction &MF) override; | ||
|
||
StringRef getPassName() const override { | ||
return "AMDGPU Register Bank Legalize"; | ||
} | ||
|
||
void getAnalysisUsage(AnalysisUsage &AU) const override { | ||
MachineFunctionPass::getAnalysisUsage(AU); | ||
} | ||
|
||
// If there were no phis and we do waterfall expansion machine verifier would | ||
// fail. | ||
MachineFunctionProperties getClearedProperties() const override { | ||
return MachineFunctionProperties().set( | ||
MachineFunctionProperties::Property::NoPHIs); | ||
} | ||
}; | ||
|
||
} // End anonymous namespace. | ||
|
||
INITIALIZE_PASS_BEGIN(AMDGPURegBankLegalize, DEBUG_TYPE, | ||
"AMDGPU Register Bank Legalize", false, false) | ||
INITIALIZE_PASS_END(AMDGPURegBankLegalize, DEBUG_TYPE, | ||
"AMDGPU Register Bank Legalize", false, false) | ||
|
||
char AMDGPURegBankLegalize::ID = 0; | ||
|
||
char &llvm::AMDGPURegBankLegalizeID = AMDGPURegBankLegalize::ID; | ||
|
||
FunctionPass *llvm::createAMDGPURegBankLegalizePass() { | ||
return new AMDGPURegBankLegalize(); | ||
} | ||
|
||
using namespace AMDGPU; | ||
|
||
bool AMDGPURegBankLegalize::runOnMachineFunction(MachineFunction &MF) { | ||
if (MF.getProperties().hasProperty( | ||
MachineFunctionProperties::Property::FailedISel)) | ||
return false; | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
//===-- AMDGPURegBankSelect.cpp -------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
/// Assign register banks to all register operands of G_ instructions using | ||
/// machine uniformity analysis. | ||
/// Sgpr - uniform values and some lane masks | ||
/// Vgpr - divergent, non S1, values | ||
/// Vcc - divergent S1 values(lane masks) | ||
/// However in some cases G_ instructions with this register bank assignment | ||
/// can't be inst-selected. This is solved in AMDGPURegBankLegalize. | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "AMDGPU.h" | ||
#include "llvm/CodeGen/MachineFunctionPass.h" | ||
#include "llvm/InitializePasses.h" | ||
|
||
#define DEBUG_TYPE "amdgpu-regbankselect" | ||
|
||
using namespace llvm; | ||
|
||
namespace { | ||
|
||
class AMDGPURegBankSelect : public MachineFunctionPass { | ||
public: | ||
static char ID; | ||
|
||
AMDGPURegBankSelect() : MachineFunctionPass(ID) { | ||
initializeAMDGPURegBankSelectPass(*PassRegistry::getPassRegistry()); | ||
} | ||
|
||
bool runOnMachineFunction(MachineFunction &MF) override; | ||
|
||
StringRef getPassName() const override { | ||
return "AMDGPU Register Bank Select"; | ||
} | ||
|
||
void getAnalysisUsage(AnalysisUsage &AU) const override { | ||
MachineFunctionPass::getAnalysisUsage(AU); | ||
} | ||
|
||
// This pass assigns register banks to all virtual registers, and we maintain | ||
// this property in subsequent passes | ||
MachineFunctionProperties getSetProperties() const override { | ||
return MachineFunctionProperties().set( | ||
MachineFunctionProperties::Property::RegBankSelected); | ||
} | ||
}; | ||
|
||
} // End anonymous namespace. | ||
|
||
INITIALIZE_PASS_BEGIN(AMDGPURegBankSelect, DEBUG_TYPE, | ||
"AMDGPU Register Bank Select", false, false) | ||
INITIALIZE_PASS_END(AMDGPURegBankSelect, DEBUG_TYPE, | ||
"AMDGPU Register Bank Select", false, false) | ||
|
||
char AMDGPURegBankSelect::ID = 0; | ||
|
||
char &llvm::AMDGPURegBankSelectID = AMDGPURegBankSelect::ID; | ||
|
||
FunctionPass *llvm::createAMDGPURegBankSelectPass() { | ||
return new AMDGPURegBankSelect(); | ||
} | ||
|
||
bool AMDGPURegBankSelect::runOnMachineFunction(MachineFunction &MF) { | ||
if (MF.getProperties().hasProperty( | ||
MachineFunctionProperties::Property::FailedISel)) | ||
return false; | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.