forked from OSchip/llvm-project
AMDGPU/GlobalISel: Add new utils file
There are some things that are shareable between the legalizer, regbankselect, and the selector that don't have an obvious place to go.
This commit is contained in:
parent
92ff017a85
commit
9861a8538c
|
@ -0,0 +1,45 @@
|
|||
//===- AMDGPUGlobalISelUtils.cpp ---------------------------------*- C++ -*-==//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "AMDGPUGlobalISelUtils.h"
|
||||
#include "llvm/CodeGen/GlobalISel/MIPatternMatch.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace MIPatternMatch;
|
||||
|
||||
std::tuple<Register, unsigned, MachineInstr *>
|
||||
AMDGPU::getBaseWithConstantOffset(MachineRegisterInfo &MRI, Register Reg) {
|
||||
MachineInstr *Def = getDefIgnoringCopies(Reg, MRI);
|
||||
if (!Def)
|
||||
return std::make_tuple(Reg, 0, nullptr);
|
||||
|
||||
if (Def->getOpcode() == TargetOpcode::G_CONSTANT) {
|
||||
unsigned Offset;
|
||||
const MachineOperand &Op = Def->getOperand(1);
|
||||
if (Op.isImm())
|
||||
Offset = Op.getImm();
|
||||
else
|
||||
Offset = Op.getCImm()->getZExtValue();
|
||||
|
||||
return std::make_tuple(Register(), Offset, Def);
|
||||
}
|
||||
|
||||
int64_t Offset;
|
||||
if (Def->getOpcode() == TargetOpcode::G_ADD) {
|
||||
// TODO: Handle G_OR used for add case
|
||||
if (mi_match(Def->getOperand(2).getReg(), MRI, m_ICst(Offset)))
|
||||
return std::make_tuple(Def->getOperand(1).getReg(), Offset, Def);
|
||||
|
||||
// FIXME: matcher should ignore copies
|
||||
if (mi_match(Def->getOperand(2).getReg(), MRI, m_Copy(m_ICst(Offset))))
|
||||
return std::make_tuple(Def->getOperand(1).getReg(), Offset, Def);
|
||||
}
|
||||
|
||||
return std::make_tuple(Reg, 0, Def);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
//===- AMDGPUGlobalISelUtils -------------------------------------*- C++ -*-==//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUGLOBALISELUTILS_H
|
||||
#define LLVM_LIB_TARGET_AMDGPU_AMDGPUGLOBALISELUTILS_H
|
||||
|
||||
#include "llvm/CodeGen/Register.h"
|
||||
#include <tuple>
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class MachineInstr;
|
||||
class MachineRegisterInfo;
|
||||
|
||||
namespace AMDGPU {
|
||||
|
||||
/// Returns Base register, constant offset, and offset def point.
|
||||
std::tuple<Register, unsigned, MachineInstr *>
|
||||
getBaseWithConstantOffset(MachineRegisterInfo &MRI, Register Reg);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include "AMDGPUInstructionSelector.h"
|
||||
#include "AMDGPUInstrInfo.h"
|
||||
#include "AMDGPUGlobalISelUtils.h"
|
||||
#include "AMDGPURegisterBankInfo.h"
|
||||
#include "AMDGPURegisterInfo.h"
|
||||
#include "AMDGPUSubtarget.h"
|
||||
|
@ -801,38 +802,6 @@ static unsigned extractSWZ(unsigned AuxiliaryData) {
|
|||
return (AuxiliaryData >> 3) & 1;
|
||||
}
|
||||
|
||||
// Returns Base register, constant offset, and offset def point.
|
||||
static std::tuple<Register, unsigned, MachineInstr *>
|
||||
getBaseWithConstantOffset(MachineRegisterInfo &MRI, Register Reg) {
|
||||
MachineInstr *Def = getDefIgnoringCopies(Reg, MRI);
|
||||
if (!Def)
|
||||
return std::make_tuple(Reg, 0, nullptr);
|
||||
|
||||
if (Def->getOpcode() == AMDGPU::G_CONSTANT) {
|
||||
unsigned Offset;
|
||||
const MachineOperand &Op = Def->getOperand(1);
|
||||
if (Op.isImm())
|
||||
Offset = Op.getImm();
|
||||
else
|
||||
Offset = Op.getCImm()->getZExtValue();
|
||||
|
||||
return std::make_tuple(Register(), Offset, Def);
|
||||
}
|
||||
|
||||
int64_t Offset;
|
||||
if (Def->getOpcode() == AMDGPU::G_ADD) {
|
||||
// TODO: Handle G_OR used for add case
|
||||
if (mi_match(Def->getOperand(2).getReg(), MRI, m_ICst(Offset)))
|
||||
return std::make_tuple(Def->getOperand(1).getReg(), Offset, Def);
|
||||
|
||||
// FIXME: matcher should ignore copies
|
||||
if (mi_match(Def->getOperand(2).getReg(), MRI, m_Copy(m_ICst(Offset))))
|
||||
return std::make_tuple(Def->getOperand(1).getReg(), Offset, Def);
|
||||
}
|
||||
|
||||
return std::make_tuple(Reg, 0, Def);
|
||||
}
|
||||
|
||||
static unsigned getBufferStoreOpcode(LLT Ty,
|
||||
const unsigned MemSize,
|
||||
const bool Offen) {
|
||||
|
@ -929,7 +898,7 @@ AMDGPUInstructionSelector::splitBufferOffsets(MachineIRBuilder &B,
|
|||
MachineInstr *OffsetDef;
|
||||
|
||||
std::tie(BaseReg, TotalConstOffset, OffsetDef)
|
||||
= getBaseWithConstantOffset(*MRI, OrigOffset);
|
||||
= AMDGPU::getBaseWithConstantOffset(*MRI, OrigOffset);
|
||||
|
||||
unsigned ImmOffset = TotalConstOffset;
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ add_llvm_target(AMDGPUCodeGen
|
|||
AMDGPUInstructionSelector.cpp
|
||||
AMDGPUISelDAGToDAG.cpp
|
||||
AMDGPUISelLowering.cpp
|
||||
AMDGPUGlobalISelUtils.cpp
|
||||
AMDGPULegalizerInfo.cpp
|
||||
AMDGPULibCalls.cpp
|
||||
AMDGPULibFunc.cpp
|
||||
|
|
Loading…
Reference in New Issue