2014-04-30 17:31:33 +02:00
|
|
|
//===-- SILowerI1Copies.cpp - Lower I1 Copies -----------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
/// i1 values are usually inserted by the CFG Structurize pass and they are
|
|
|
|
/// unique in that they can be copied from VALU to SALU registers.
|
|
|
|
/// This is not possible for any other value type. Since there are no
|
|
|
|
/// MOV instructions for i1, we to use V_CMP_* and V_CNDMASK to move the i1.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "si-i1-copies"
|
|
|
|
#include "AMDGPU.h"
|
2014-08-04 23:25:23 +02:00
|
|
|
#include "AMDGPUSubtarget.h"
|
2014-04-30 17:31:33 +02:00
|
|
|
#include "SIInstrInfo.h"
|
|
|
|
#include "llvm/CodeGen/LiveIntervalAnalysis.h"
|
|
|
|
#include "llvm/CodeGen/MachineDominators.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class SILowerI1Copies : public MachineFunctionPass {
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SILowerI1Copies() : MachineFunctionPass(ID) {
|
|
|
|
initializeSILowerI1CopiesPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
2014-08-30 18:48:34 +02:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
2014-04-30 17:31:33 +02:00
|
|
|
|
2014-08-30 18:48:34 +02:00
|
|
|
const char *getPassName() const override {
|
2014-10-09 21:15:15 +02:00
|
|
|
return "SI Lower i1 Copies";
|
2014-04-30 17:31:33 +02:00
|
|
|
}
|
|
|
|
|
2014-08-30 18:48:34 +02:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.addRequired<MachineDominatorTree>();
|
2014-04-30 17:31:33 +02:00
|
|
|
AU.setPreservesCFG();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End anonymous namespace.
|
|
|
|
|
|
|
|
INITIALIZE_PASS_BEGIN(SILowerI1Copies, DEBUG_TYPE,
|
2014-10-09 21:15:15 +02:00
|
|
|
"SI Lower i1 Copies", false, false)
|
2014-04-30 17:31:33 +02:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
|
|
|
|
INITIALIZE_PASS_END(SILowerI1Copies, DEBUG_TYPE,
|
2014-10-09 21:15:15 +02:00
|
|
|
"SI Lower i1 Copies", false, false)
|
2014-04-30 17:31:33 +02:00
|
|
|
|
|
|
|
char SILowerI1Copies::ID = 0;
|
|
|
|
|
|
|
|
char &llvm::SILowerI1CopiesID = SILowerI1Copies::ID;
|
|
|
|
|
|
|
|
FunctionPass *llvm::createSILowerI1CopiesPass() {
|
|
|
|
return new SILowerI1Copies();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SILowerI1Copies::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
MachineRegisterInfo &MRI = MF.getRegInfo();
|
2014-08-05 04:39:49 +02:00
|
|
|
const SIInstrInfo *TII =
|
|
|
|
static_cast<const SIInstrInfo *>(MF.getSubtarget().getInstrInfo());
|
|
|
|
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
|
2014-05-15 16:41:50 +02:00
|
|
|
std::vector<unsigned> I1Defs;
|
2014-04-30 17:31:33 +02:00
|
|
|
|
|
|
|
for (MachineFunction::iterator BI = MF.begin(), BE = MF.end();
|
|
|
|
BI != BE; ++BI) {
|
|
|
|
|
|
|
|
MachineBasicBlock &MBB = *BI;
|
|
|
|
MachineBasicBlock::iterator I, Next;
|
|
|
|
for (I = MBB.begin(); I != MBB.end(); I = Next) {
|
|
|
|
Next = std::next(I);
|
|
|
|
MachineInstr &MI = *I;
|
|
|
|
|
2014-11-14 19:43:41 +01:00
|
|
|
if (MI.getOpcode() == AMDGPU::IMPLICIT_DEF) {
|
|
|
|
unsigned Reg = MI.getOperand(0).getReg();
|
|
|
|
const TargetRegisterClass *RC = MRI.getRegClass(Reg);
|
|
|
|
if (RC == &AMDGPU::VReg_1RegClass)
|
|
|
|
MRI.setRegClass(Reg, &AMDGPU::SReg_64RegClass);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-12-03 06:22:35 +01:00
|
|
|
if (MI.getOpcode() != AMDGPU::COPY)
|
2014-04-30 17:31:33 +02:00
|
|
|
continue;
|
|
|
|
|
2014-12-03 06:22:35 +01:00
|
|
|
const MachineOperand &Dst = MI.getOperand(0);
|
|
|
|
const MachineOperand &Src = MI.getOperand(1);
|
|
|
|
|
|
|
|
if (!TargetRegisterInfo::isVirtualRegister(Src.getReg()) ||
|
|
|
|
!TargetRegisterInfo::isVirtualRegister(Dst.getReg()))
|
|
|
|
continue;
|
2014-04-30 17:31:33 +02:00
|
|
|
|
2014-12-03 06:22:35 +01:00
|
|
|
const TargetRegisterClass *DstRC = MRI.getRegClass(Dst.getReg());
|
|
|
|
const TargetRegisterClass *SrcRC = MRI.getRegClass(Src.getReg());
|
2014-04-30 17:31:33 +02:00
|
|
|
|
|
|
|
if (DstRC == &AMDGPU::VReg_1RegClass &&
|
|
|
|
TRI->getCommonSubClass(SrcRC, &AMDGPU::SGPR_64RegClass)) {
|
2014-12-03 06:22:35 +01:00
|
|
|
I1Defs.push_back(Dst.getReg());
|
|
|
|
DebugLoc DL = MI.getDebugLoc();
|
|
|
|
|
|
|
|
MachineInstr *DefInst = MRI.getUniqueVRegDef(Src.getReg());
|
|
|
|
if (DefInst->getOpcode() == AMDGPU::S_MOV_B64) {
|
|
|
|
if (DefInst->getOperand(1).isImm()) {
|
|
|
|
I1Defs.push_back(Dst.getReg());
|
|
|
|
|
|
|
|
int64_t Val = DefInst->getOperand(1).getImm();
|
|
|
|
assert(Val == 0 || Val == -1);
|
|
|
|
|
|
|
|
BuildMI(MBB, &MI, DL, TII->get(AMDGPU::V_MOV_B32_e32))
|
|
|
|
.addOperand(Dst)
|
|
|
|
.addImm(Val);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BuildMI(MBB, &MI, DL, TII->get(AMDGPU::V_CNDMASK_B32_e64))
|
|
|
|
.addOperand(Dst)
|
|
|
|
.addImm(0)
|
|
|
|
.addImm(-1)
|
|
|
|
.addOperand(Src);
|
2014-04-30 17:31:33 +02:00
|
|
|
MI.eraseFromParent();
|
|
|
|
} else if (TRI->getCommonSubClass(DstRC, &AMDGPU::SGPR_64RegClass) &&
|
|
|
|
SrcRC == &AMDGPU::VReg_1RegClass) {
|
|
|
|
BuildMI(MBB, &MI, MI.getDebugLoc(), TII->get(AMDGPU::V_CMP_NE_I32_e64))
|
2014-12-03 06:22:35 +01:00
|
|
|
.addOperand(Dst)
|
|
|
|
.addOperand(Src)
|
|
|
|
.addImm(0);
|
2014-04-30 17:31:33 +02:00
|
|
|
MI.eraseFromParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-15 16:41:50 +02:00
|
|
|
|
|
|
|
for (unsigned Reg : I1Defs)
|
2015-01-07 21:59:25 +01:00
|
|
|
MRI.setRegClass(Reg, &AMDGPU::VGPR_32RegClass);
|
2014-05-15 16:41:50 +02:00
|
|
|
|
2014-04-30 17:31:33 +02:00
|
|
|
return false;
|
|
|
|
}
|