2012-12-12 05:25:42 +08:00
|
|
|
//===-- SILowerControlFlow.cpp - Use predicates for control flow ----------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2012-12-12 05:25:42 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
2018-05-01 23:54:18 +08:00
|
|
|
/// This pass lowers the pseudo control flow instructions to real
|
2012-12-20 06:10:31 +08:00
|
|
|
/// machine instructions.
|
2012-12-12 05:25:42 +08:00
|
|
|
///
|
2012-12-20 06:10:31 +08:00
|
|
|
/// All control flow is handled using predicated instructions and
|
2012-12-12 05:25:42 +08:00
|
|
|
/// a predicate stack. Each Scalar ALU controls the operations of 64 Vector
|
|
|
|
/// ALUs. The Scalar ALU can update the predicate for any of the Vector ALUs
|
|
|
|
/// by writting to the 64-bit EXEC register (each bit corresponds to a
|
|
|
|
/// single vector ALU). Typically, for predicates, a vector ALU will write
|
|
|
|
/// to its bit of the VCC register (like EXEC VCC is 64-bits, one for each
|
|
|
|
/// Vector ALU) and then the ScalarALU will AND the VCC register with the
|
|
|
|
/// EXEC to update the predicates.
|
|
|
|
///
|
|
|
|
/// For example:
|
2017-11-29 01:15:09 +08:00
|
|
|
/// %vcc = V_CMP_GT_F32 %vgpr1, %vgpr2
|
|
|
|
/// %sgpr0 = SI_IF %vcc
|
|
|
|
/// %vgpr0 = V_ADD_F32 %vgpr0, %vgpr0
|
|
|
|
/// %sgpr0 = SI_ELSE %sgpr0
|
|
|
|
/// %vgpr0 = V_SUB_F32 %vgpr0, %vgpr0
|
|
|
|
/// SI_END_CF %sgpr0
|
2012-12-12 05:25:42 +08:00
|
|
|
///
|
|
|
|
/// becomes:
|
|
|
|
///
|
2017-11-29 01:15:09 +08:00
|
|
|
/// %sgpr0 = S_AND_SAVEEXEC_B64 %vcc // Save and update the exec mask
|
|
|
|
/// %sgpr0 = S_XOR_B64 %sgpr0, %exec // Clear live bits from saved exec mask
|
2012-12-20 06:10:31 +08:00
|
|
|
/// S_CBRANCH_EXECZ label0 // This instruction is an optional
|
2012-12-12 05:25:42 +08:00
|
|
|
/// // optimization which allows us to
|
|
|
|
/// // branch if all the bits of
|
|
|
|
/// // EXEC are zero.
|
2017-11-29 01:15:09 +08:00
|
|
|
/// %vgpr0 = V_ADD_F32 %vgpr0, %vgpr0 // Do the IF block of the branch
|
2012-12-12 05:25:42 +08:00
|
|
|
///
|
|
|
|
/// label0:
|
2020-04-06 23:44:08 +08:00
|
|
|
/// %sgpr0 = S_OR_SAVEEXEC_B64 %sgpr0 // Restore the exec mask for the Then block
|
|
|
|
/// %exec = S_XOR_B64 %sgpr0, %exec // Update the exec mask
|
2012-12-12 05:25:42 +08:00
|
|
|
/// S_BRANCH_EXECZ label1 // Use our branch optimization
|
|
|
|
/// // instruction again.
|
2017-11-29 01:15:09 +08:00
|
|
|
/// %vgpr0 = V_SUB_F32 %vgpr0, %vgpr // Do the THEN block
|
2012-12-12 05:25:42 +08:00
|
|
|
/// label1:
|
2017-11-29 01:15:09 +08:00
|
|
|
/// %exec = S_OR_B64 %exec, %sgpr0 // Re-enable saved exec mask bits
|
2012-12-12 05:25:42 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "AMDGPU.h"
|
2014-08-05 05:25:23 +08:00
|
|
|
#include "AMDGPUSubtarget.h"
|
2012-12-12 05:25:42 +08:00
|
|
|
#include "SIInstrInfo.h"
|
AMDGPU: Remove #include "MCTargetDesc/AMDGPUMCTargetDesc.h" from common headers
Summary:
MCTargetDesc/AMDGPUMCTargetDesc.h contains enums for all the instuction
and register defintions, which are huge so we only want to include
them where needed.
This will also make it easier if we want to split the R600 and GCN
definitions into separate tablegenerated files.
I was unable to remove AMDGPUMCTargetDesc.h from SIMachineFunctionInfo.h
because it uses some enums from the header to initialize default values
for the SIMachineFunction class, so I ended up having to remove includes of
SIMachineFunctionInfo.h from headers too.
Reviewers: arsenm, nhaehnle
Reviewed By: nhaehnle
Subscribers: MatzeB, kzhuravl, wdng, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46272
llvm-svn: 332930
2018-05-22 10:03:23 +08:00
|
|
|
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
|
2020-03-12 04:17:32 +08:00
|
|
|
#include "llvm/ADT/SmallSet.h"
|
2017-01-21 01:52:16 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2017-12-13 10:51:04 +08:00
|
|
|
#include "llvm/CodeGen/LiveIntervals.h"
|
2017-01-21 01:52:16 +08:00
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
2012-12-12 05:25:42 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2017-01-21 01:52:16 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2012-12-12 05:25:42 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2017-01-21 01:52:16 +08:00
|
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
2012-12-12 05:25:42 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2017-01-21 01:52:16 +08:00
|
|
|
#include "llvm/CodeGen/SlotIndexes.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetRegisterInfo.h"
|
2017-01-21 01:52:16 +08:00
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include <iterator>
|
2012-12-12 05:25:42 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2016-02-12 10:16:10 +08:00
|
|
|
#define DEBUG_TYPE "si-lower-control-flow"
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2020-03-14 01:58:19 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
RemoveRedundantEndcf("amdgpu-remove-redundant-endcf",
|
2020-03-14 03:44:59 +08:00
|
|
|
cl::init(true), cl::ReallyHidden);
|
2020-03-14 01:58:19 +08:00
|
|
|
|
2016-02-12 10:16:10 +08:00
|
|
|
namespace {
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2016-02-12 10:16:10 +08:00
|
|
|
class SILowerControlFlow : public MachineFunctionPass {
|
2012-12-12 05:25:42 +08:00
|
|
|
private:
|
2017-01-21 01:52:16 +08:00
|
|
|
const SIRegisterInfo *TRI = nullptr;
|
|
|
|
const SIInstrInfo *TII = nullptr;
|
2019-08-01 09:25:27 +08:00
|
|
|
LiveIntervals *LIS = nullptr;
|
2019-08-21 01:45:25 +08:00
|
|
|
MachineRegisterInfo *MRI = nullptr;
|
2020-03-12 04:17:32 +08:00
|
|
|
DenseSet<const MachineInstr*> LoweredEndCf;
|
2020-03-14 03:44:59 +08:00
|
|
|
DenseSet<Register> LoweredIf;
|
2012-12-20 06:10:33 +08:00
|
|
|
|
2019-06-17 01:13:09 +08:00
|
|
|
const TargetRegisterClass *BoolRC = nullptr;
|
|
|
|
unsigned AndOpc;
|
|
|
|
unsigned OrOpc;
|
|
|
|
unsigned XorOpc;
|
|
|
|
unsigned MovTermOpc;
|
|
|
|
unsigned Andn2TermOpc;
|
|
|
|
unsigned XorTermrOpc;
|
|
|
|
unsigned OrSaveExecOpc;
|
|
|
|
unsigned Exec;
|
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
void emitIf(MachineInstr &MI);
|
|
|
|
void emitElse(MachineInstr &MI);
|
|
|
|
void emitIfBreak(MachineInstr &MI);
|
|
|
|
void emitLoop(MachineInstr &MI);
|
2019-08-21 01:45:25 +08:00
|
|
|
void emitEndCf(MachineInstr &MI);
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2016-11-29 02:58:49 +08:00
|
|
|
void findMaskOperands(MachineInstr &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MachineOperand> &Src) const;
|
|
|
|
|
|
|
|
void combineMasks(MachineInstr &MI);
|
|
|
|
|
2020-03-12 04:17:32 +08:00
|
|
|
// Skip to the next instruction, ignoring debug instructions, and trivial
|
|
|
|
// block boundaries (blocks that have one (typically fallthrough) successor,
|
|
|
|
// and the successor has one predecessor.
|
|
|
|
MachineBasicBlock::iterator
|
|
|
|
skipIgnoreExecInstsTrivialSucc(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator It) const;
|
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
public:
|
2016-02-12 10:16:10 +08:00
|
|
|
static char ID;
|
|
|
|
|
2017-01-21 01:52:16 +08:00
|
|
|
SILowerControlFlow() : MachineFunctionPass(ID) {}
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2014-04-29 15:57:24 +08:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2016-10-01 10:56:57 +08:00
|
|
|
StringRef getPassName() const override {
|
2016-02-12 10:16:10 +08:00
|
|
|
return "SI Lower control flow pseudo instructions";
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
2016-08-23 03:33:16 +08:00
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2016-09-29 09:44:16 +08:00
|
|
|
// Should preserve the same set that TwoAddressInstructions does.
|
2016-08-23 03:33:16 +08:00
|
|
|
AU.addPreserved<SlotIndexes>();
|
2016-09-29 09:44:16 +08:00
|
|
|
AU.addPreserved<LiveIntervals>();
|
|
|
|
AU.addPreservedID(LiveVariablesID);
|
|
|
|
AU.addPreservedID(MachineLoopInfoID);
|
|
|
|
AU.addPreservedID(MachineDominatorsID);
|
2019-08-21 01:45:25 +08:00
|
|
|
AU.setPreservesCFG();
|
2016-08-23 03:33:16 +08:00
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
2012-12-12 05:25:42 +08:00
|
|
|
};
|
|
|
|
|
2017-01-21 01:52:16 +08:00
|
|
|
} // end anonymous namespace
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2016-02-12 10:16:10 +08:00
|
|
|
char SILowerControlFlow::ID = 0;
|
|
|
|
|
|
|
|
INITIALIZE_PASS(SILowerControlFlow, DEBUG_TYPE,
|
2016-08-23 03:33:16 +08:00
|
|
|
"SI lower control flow", false, false)
|
2016-02-12 10:16:10 +08:00
|
|
|
|
2016-09-29 09:44:16 +08:00
|
|
|
static void setImpSCCDefDead(MachineInstr &MI, bool IsDead) {
|
|
|
|
MachineOperand &ImpDefSCC = MI.getOperand(3);
|
|
|
|
assert(ImpDefSCC.getReg() == AMDGPU::SCC && ImpDefSCC.isDef());
|
|
|
|
|
|
|
|
ImpDefSCC.setIsDead(IsDead);
|
|
|
|
}
|
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
char &llvm::SILowerControlFlowID = SILowerControlFlow::ID;
|
2016-02-12 10:16:10 +08:00
|
|
|
|
2017-10-24 18:27:13 +08:00
|
|
|
static bool isSimpleIf(const MachineInstr &MI, const MachineRegisterInfo *MRI,
|
|
|
|
const SIInstrInfo *TII) {
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register SaveExecReg = MI.getOperand(0).getReg();
|
2017-08-04 14:58:42 +08:00
|
|
|
auto U = MRI->use_instr_nodbg_begin(SaveExecReg);
|
|
|
|
|
|
|
|
if (U == MRI->use_instr_nodbg_end() ||
|
|
|
|
std::next(U) != MRI->use_instr_nodbg_end() ||
|
|
|
|
U->getOpcode() != AMDGPU::SI_END_CF)
|
|
|
|
return false;
|
|
|
|
|
2017-10-24 18:27:13 +08:00
|
|
|
// Check for SI_KILL_*_TERMINATOR on path from if to endif.
|
2017-08-04 14:58:42 +08:00
|
|
|
// if there is any such terminator simplififcations are not safe.
|
|
|
|
auto SMBB = MI.getParent();
|
|
|
|
auto EMBB = U->getParent();
|
|
|
|
DenseSet<const MachineBasicBlock*> Visited;
|
|
|
|
SmallVector<MachineBasicBlock*, 4> Worklist(SMBB->succ_begin(),
|
|
|
|
SMBB->succ_end());
|
|
|
|
|
|
|
|
while (!Worklist.empty()) {
|
|
|
|
MachineBasicBlock *MBB = Worklist.pop_back_val();
|
|
|
|
|
|
|
|
if (MBB == EMBB || !Visited.insert(MBB).second)
|
|
|
|
continue;
|
|
|
|
for(auto &Term : MBB->terminators())
|
2017-10-24 18:27:13 +08:00
|
|
|
if (TII->isKillTerminator(Term.getOpcode()))
|
2017-08-04 14:58:42 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
Worklist.append(MBB->succ_begin(), MBB->succ_end());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
void SILowerControlFlow::emitIf(MachineInstr &MI) {
|
|
|
|
MachineBasicBlock &MBB = *MI.getParent();
|
|
|
|
const DebugLoc &DL = MI.getDebugLoc();
|
|
|
|
MachineBasicBlock::iterator I(&MI);
|
2019-12-28 02:11:06 +08:00
|
|
|
Register SaveExecReg = MI.getOperand(0).getReg();
|
2019-09-17 17:08:58 +08:00
|
|
|
MachineOperand& Cond = MI.getOperand(1);
|
|
|
|
assert(Cond.getSubReg() == AMDGPU::NoSubRegister);
|
2013-01-19 05:15:50 +08:00
|
|
|
|
2016-09-29 09:44:16 +08:00
|
|
|
MachineOperand &ImpDefSCC = MI.getOperand(4);
|
|
|
|
assert(ImpDefSCC.getReg() == AMDGPU::SCC && ImpDefSCC.isDef());
|
|
|
|
|
2017-07-27 05:29:15 +08:00
|
|
|
// If there is only one use of save exec register and that use is SI_END_CF,
|
|
|
|
// we can optimize SI_IF by returning the full saved exec mask instead of
|
|
|
|
// just cleared bits.
|
2017-10-24 18:27:13 +08:00
|
|
|
bool SimpleIf = isSimpleIf(MI, MRI, TII);
|
2017-07-27 05:29:15 +08:00
|
|
|
|
2016-09-29 09:44:16 +08:00
|
|
|
// Add an implicit def of exec to discourage scheduling VALU after this which
|
|
|
|
// will interfere with trying to form s_and_saveexec_b64 later.
|
2019-06-24 23:50:29 +08:00
|
|
|
Register CopyReg = SimpleIf ? SaveExecReg
|
2019-06-17 01:13:09 +08:00
|
|
|
: MRI->createVirtualRegister(BoolRC);
|
2016-09-29 09:44:16 +08:00
|
|
|
MachineInstr *CopyExec =
|
2016-11-22 09:42:34 +08:00
|
|
|
BuildMI(MBB, I, DL, TII->get(AMDGPU::COPY), CopyReg)
|
2019-06-17 01:13:09 +08:00
|
|
|
.addReg(Exec)
|
|
|
|
.addReg(Exec, RegState::ImplicitDefine);
|
2020-03-14 03:44:59 +08:00
|
|
|
LoweredIf.insert(CopyReg);
|
2016-09-29 09:44:16 +08:00
|
|
|
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register Tmp = MRI->createVirtualRegister(BoolRC);
|
2016-09-29 09:44:16 +08:00
|
|
|
|
|
|
|
MachineInstr *And =
|
2019-06-17 01:13:09 +08:00
|
|
|
BuildMI(MBB, I, DL, TII->get(AndOpc), Tmp)
|
2016-11-22 09:42:34 +08:00
|
|
|
.addReg(CopyReg)
|
2019-03-06 02:38:00 +08:00
|
|
|
.add(Cond);
|
|
|
|
|
2016-09-29 09:44:16 +08:00
|
|
|
setImpSCCDefDead(*And, true);
|
2013-01-19 05:15:50 +08:00
|
|
|
|
2017-07-27 05:29:15 +08:00
|
|
|
MachineInstr *Xor = nullptr;
|
|
|
|
if (!SimpleIf) {
|
|
|
|
Xor =
|
2019-06-17 01:13:09 +08:00
|
|
|
BuildMI(MBB, I, DL, TII->get(XorOpc), SaveExecReg)
|
2017-07-27 05:29:15 +08:00
|
|
|
.addReg(Tmp)
|
|
|
|
.addReg(CopyReg);
|
|
|
|
setImpSCCDefDead(*Xor, ImpDefSCC.isDead());
|
|
|
|
}
|
2016-09-29 09:44:16 +08:00
|
|
|
|
|
|
|
// Use a copy that is a terminator to get correct spill code placement it with
|
|
|
|
// fast regalloc.
|
|
|
|
MachineInstr *SetExec =
|
2019-06-17 01:13:09 +08:00
|
|
|
BuildMI(MBB, I, DL, TII->get(MovTermOpc), Exec)
|
2016-09-29 09:44:16 +08:00
|
|
|
.addReg(Tmp, RegState::Kill);
|
2016-07-13 03:01:23 +08:00
|
|
|
|
2020-01-22 12:07:55 +08:00
|
|
|
// Insert the S_CBRANCH_EXECZ instruction which will be optimized later
|
|
|
|
// during SIRemoveShortExecBranches.
|
|
|
|
MachineInstr *NewBr = BuildMI(MBB, I, DL, TII->get(AMDGPU::S_CBRANCH_EXECZ))
|
2017-01-13 17:58:52 +08:00
|
|
|
.add(MI.getOperand(2));
|
2013-01-19 05:15:50 +08:00
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
if (!LIS) {
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return;
|
|
|
|
}
|
2016-07-13 03:01:23 +08:00
|
|
|
|
2016-09-29 09:44:16 +08:00
|
|
|
LIS->InsertMachineInstrInMaps(*CopyExec);
|
|
|
|
|
|
|
|
// Replace with and so we don't need to fix the live interval for condition
|
|
|
|
// register.
|
|
|
|
LIS->ReplaceMachineInstrInMaps(MI, *And);
|
2013-01-19 05:15:50 +08:00
|
|
|
|
2017-07-27 05:29:15 +08:00
|
|
|
if (!SimpleIf)
|
|
|
|
LIS->InsertMachineInstrInMaps(*Xor);
|
2016-09-29 09:44:16 +08:00
|
|
|
LIS->InsertMachineInstrInMaps(*SetExec);
|
2016-08-23 03:33:16 +08:00
|
|
|
LIS->InsertMachineInstrInMaps(*NewBr);
|
2016-07-13 03:01:23 +08:00
|
|
|
|
2019-08-21 01:45:25 +08:00
|
|
|
LIS->removeAllRegUnitsForPhysReg(AMDGPU::EXEC);
|
2016-08-23 03:33:16 +08:00
|
|
|
MI.eraseFromParent();
|
2016-07-13 03:01:23 +08:00
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
// FIXME: Is there a better way of adjusting the liveness? It shouldn't be
|
|
|
|
// hard to add another def here but I'm not sure how to correctly update the
|
|
|
|
// valno.
|
|
|
|
LIS->removeInterval(SaveExecReg);
|
|
|
|
LIS->createAndComputeVirtRegInterval(SaveExecReg);
|
2016-09-29 09:44:16 +08:00
|
|
|
LIS->createAndComputeVirtRegInterval(Tmp);
|
2017-07-27 05:29:15 +08:00
|
|
|
if (!SimpleIf)
|
|
|
|
LIS->createAndComputeVirtRegInterval(CopyReg);
|
2013-01-19 05:15:50 +08:00
|
|
|
}
|
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
void SILowerControlFlow::emitElse(MachineInstr &MI) {
|
2012-12-20 06:10:31 +08:00
|
|
|
MachineBasicBlock &MBB = *MI.getParent();
|
2016-08-23 03:33:16 +08:00
|
|
|
const DebugLoc &DL = MI.getDebugLoc();
|
2012-12-20 06:10:31 +08:00
|
|
|
|
2019-12-28 02:11:06 +08:00
|
|
|
Register DstReg = MI.getOperand(0).getReg();
|
2012-12-20 06:10:31 +08:00
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
bool ExecModified = MI.getOperand(3).getImm() != 0;
|
|
|
|
MachineBasicBlock::iterator Start = MBB.begin();
|
2012-12-20 06:10:31 +08:00
|
|
|
|
2016-09-29 09:44:16 +08:00
|
|
|
// We are running before TwoAddressInstructions, and si_else's operands are
|
|
|
|
// tied. In order to correctly tie the registers, split this into a copy of
|
|
|
|
// the src like it does.
|
2019-06-24 23:50:29 +08:00
|
|
|
Register CopyReg = MRI->createVirtualRegister(BoolRC);
|
2017-01-20 05:26:22 +08:00
|
|
|
MachineInstr *CopyExec =
|
|
|
|
BuildMI(MBB, Start, DL, TII->get(AMDGPU::COPY), CopyReg)
|
2017-01-13 17:58:52 +08:00
|
|
|
.add(MI.getOperand(1)); // Saved EXEC
|
2016-09-29 09:44:16 +08:00
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
// This must be inserted before phis and any spill code inserted before the
|
|
|
|
// else.
|
2019-06-24 23:50:29 +08:00
|
|
|
Register SaveReg = ExecModified ?
|
2019-06-17 01:13:09 +08:00
|
|
|
MRI->createVirtualRegister(BoolRC) : DstReg;
|
2016-08-23 03:33:16 +08:00
|
|
|
MachineInstr *OrSaveExec =
|
2019-06-17 01:13:09 +08:00
|
|
|
BuildMI(MBB, Start, DL, TII->get(OrSaveExecOpc), SaveReg)
|
2016-11-22 09:42:34 +08:00
|
|
|
.addReg(CopyReg);
|
2016-09-29 09:44:16 +08:00
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
MachineBasicBlock *DestBB = MI.getOperand(2).getMBB();
|
2016-08-11 03:11:42 +08:00
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
MachineBasicBlock::iterator ElsePt(MI);
|
2012-12-20 06:10:33 +08:00
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
if (ExecModified) {
|
|
|
|
MachineInstr *And =
|
2019-06-17 01:13:09 +08:00
|
|
|
BuildMI(MBB, ElsePt, DL, TII->get(AndOpc), DstReg)
|
|
|
|
.addReg(Exec)
|
2016-11-22 09:42:34 +08:00
|
|
|
.addReg(SaveReg);
|
2016-06-23 04:15:28 +08:00
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
if (LIS)
|
|
|
|
LIS->InsertMachineInstrInMaps(*And);
|
2016-03-22 04:28:33 +08:00
|
|
|
}
|
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
MachineInstr *Xor =
|
2019-06-17 01:13:09 +08:00
|
|
|
BuildMI(MBB, ElsePt, DL, TII->get(XorTermrOpc), Exec)
|
|
|
|
.addReg(Exec)
|
2016-08-23 03:33:16 +08:00
|
|
|
.addReg(DstReg);
|
2012-12-20 06:10:33 +08:00
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
MachineInstr *Branch =
|
2020-01-22 12:07:55 +08:00
|
|
|
BuildMI(MBB, ElsePt, DL, TII->get(AMDGPU::S_CBRANCH_EXECZ))
|
|
|
|
.addMBB(DestBB);
|
2016-08-23 03:33:16 +08:00
|
|
|
|
|
|
|
if (!LIS) {
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return;
|
|
|
|
}
|
2016-06-23 04:15:28 +08:00
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
LIS->RemoveMachineInstrFromMaps(MI);
|
2012-12-20 06:10:31 +08:00
|
|
|
MI.eraseFromParent();
|
|
|
|
|
2017-01-20 05:26:22 +08:00
|
|
|
LIS->InsertMachineInstrInMaps(*CopyExec);
|
2016-08-23 03:33:16 +08:00
|
|
|
LIS->InsertMachineInstrInMaps(*OrSaveExec);
|
2016-07-10 01:18:39 +08:00
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
LIS->InsertMachineInstrInMaps(*Xor);
|
|
|
|
LIS->InsertMachineInstrInMaps(*Branch);
|
2016-07-10 01:18:39 +08:00
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
// src reg is tied to dst reg.
|
|
|
|
LIS->removeInterval(DstReg);
|
|
|
|
LIS->createAndComputeVirtRegInterval(DstReg);
|
2016-11-22 09:42:34 +08:00
|
|
|
LIS->createAndComputeVirtRegInterval(CopyReg);
|
|
|
|
if (ExecModified)
|
|
|
|
LIS->createAndComputeVirtRegInterval(SaveReg);
|
2016-07-10 01:18:39 +08:00
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
// Let this be recomputed.
|
2019-08-21 01:45:25 +08:00
|
|
|
LIS->removeAllRegUnitsForPhysReg(AMDGPU::EXEC);
|
2016-07-10 01:18:39 +08:00
|
|
|
}
|
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
void SILowerControlFlow::emitIfBreak(MachineInstr &MI) {
|
2018-05-25 15:55:04 +08:00
|
|
|
MachineBasicBlock &MBB = *MI.getParent();
|
|
|
|
const DebugLoc &DL = MI.getDebugLoc();
|
2019-12-28 02:11:06 +08:00
|
|
|
auto Dst = MI.getOperand(0).getReg();
|
2018-05-25 15:55:04 +08:00
|
|
|
|
|
|
|
// Skip ANDing with exec if the break condition is already masked by exec
|
|
|
|
// because it is a V_CMP in the same basic block. (We know the break
|
|
|
|
// condition operand was an i1 in IR, so if it is a VALU instruction it must
|
|
|
|
// be one with a carry-out.)
|
|
|
|
bool SkipAnding = false;
|
|
|
|
if (MI.getOperand(1).isReg()) {
|
|
|
|
if (MachineInstr *Def = MRI->getUniqueVRegDef(MI.getOperand(1).getReg())) {
|
|
|
|
SkipAnding = Def->getParent() == MI.getParent()
|
|
|
|
&& SIInstrInfo::isVALU(*Def);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AND the break condition operand with exec, then OR that into the "loop
|
|
|
|
// exit" mask.
|
|
|
|
MachineInstr *And = nullptr, *Or = nullptr;
|
|
|
|
if (!SkipAnding) {
|
2019-11-19 01:06:48 +08:00
|
|
|
Register AndReg = MRI->createVirtualRegister(BoolRC);
|
|
|
|
And = BuildMI(MBB, &MI, DL, TII->get(AndOpc), AndReg)
|
2019-06-17 01:13:09 +08:00
|
|
|
.addReg(Exec)
|
2018-05-25 15:55:04 +08:00
|
|
|
.add(MI.getOperand(1));
|
2019-06-17 01:13:09 +08:00
|
|
|
Or = BuildMI(MBB, &MI, DL, TII->get(OrOpc), Dst)
|
2019-11-19 01:06:48 +08:00
|
|
|
.addReg(AndReg)
|
2018-05-25 15:55:04 +08:00
|
|
|
.add(MI.getOperand(2));
|
2019-11-19 01:06:48 +08:00
|
|
|
if (LIS)
|
|
|
|
LIS->createAndComputeVirtRegInterval(AndReg);
|
2018-05-25 15:55:04 +08:00
|
|
|
} else
|
2019-06-17 01:13:09 +08:00
|
|
|
Or = BuildMI(MBB, &MI, DL, TII->get(OrOpc), Dst)
|
2018-05-25 15:55:04 +08:00
|
|
|
.add(MI.getOperand(1))
|
|
|
|
.add(MI.getOperand(2));
|
|
|
|
|
|
|
|
if (LIS) {
|
|
|
|
if (And)
|
|
|
|
LIS->InsertMachineInstrInMaps(*And);
|
|
|
|
LIS->ReplaceMachineInstrInMaps(MI, *Or);
|
|
|
|
}
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
2016-08-23 03:33:16 +08:00
|
|
|
}
|
2012-12-20 06:10:31 +08:00
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
void SILowerControlFlow::emitLoop(MachineInstr &MI) {
|
2012-12-20 06:10:31 +08:00
|
|
|
MachineBasicBlock &MBB = *MI.getParent();
|
2016-08-23 03:33:16 +08:00
|
|
|
const DebugLoc &DL = MI.getDebugLoc();
|
2012-12-20 06:10:31 +08:00
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
MachineInstr *AndN2 =
|
2019-06-17 01:13:09 +08:00
|
|
|
BuildMI(MBB, &MI, DL, TII->get(Andn2TermOpc), Exec)
|
|
|
|
.addReg(Exec)
|
2017-01-13 17:58:52 +08:00
|
|
|
.add(MI.getOperand(0));
|
2012-12-20 06:10:31 +08:00
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
MachineInstr *Branch =
|
2017-01-13 17:58:52 +08:00
|
|
|
BuildMI(MBB, &MI, DL, TII->get(AMDGPU::S_CBRANCH_EXECNZ))
|
|
|
|
.add(MI.getOperand(1));
|
2012-12-20 06:10:31 +08:00
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
if (LIS) {
|
|
|
|
LIS->ReplaceMachineInstrInMaps(MI, *AndN2);
|
|
|
|
LIS->InsertMachineInstrInMaps(*Branch);
|
|
|
|
}
|
2012-12-20 06:10:31 +08:00
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
}
|
|
|
|
|
2020-03-12 04:17:32 +08:00
|
|
|
MachineBasicBlock::iterator
|
|
|
|
SILowerControlFlow::skipIgnoreExecInstsTrivialSucc(
|
|
|
|
MachineBasicBlock &MBB, MachineBasicBlock::iterator It) const {
|
|
|
|
|
|
|
|
SmallSet<const MachineBasicBlock *, 4> Visited;
|
|
|
|
MachineBasicBlock *B = &MBB;
|
|
|
|
do {
|
|
|
|
if (!Visited.insert(B).second)
|
|
|
|
return MBB.end();
|
|
|
|
|
|
|
|
auto E = B->end();
|
|
|
|
for ( ; It != E; ++It) {
|
|
|
|
if (TII->mayReadEXEC(*MRI, *It))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (It != E)
|
|
|
|
return It;
|
|
|
|
|
|
|
|
if (B->succ_size() != 1)
|
|
|
|
return MBB.end();
|
|
|
|
|
|
|
|
// If there is one trivial successor, advance to the next block.
|
|
|
|
MachineBasicBlock *Succ = *B->succ_begin();
|
|
|
|
|
|
|
|
It = Succ->begin();
|
|
|
|
B = Succ;
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
2019-08-21 01:45:25 +08:00
|
|
|
void SILowerControlFlow::emitEndCf(MachineInstr &MI) {
|
2013-01-19 05:15:50 +08:00
|
|
|
MachineBasicBlock &MBB = *MI.getParent();
|
2019-09-17 17:08:58 +08:00
|
|
|
MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
|
|
|
|
unsigned CFMask = MI.getOperand(0).getReg();
|
|
|
|
MachineInstr *Def = MRI.getUniqueVRegDef(CFMask);
|
2016-08-23 03:33:16 +08:00
|
|
|
const DebugLoc &DL = MI.getDebugLoc();
|
2013-01-19 05:15:50 +08:00
|
|
|
|
2020-03-12 04:17:32 +08:00
|
|
|
// If the only instruction immediately following this END_CF is an another
|
|
|
|
// END_CF in the only successor we can avoid emitting exec mask restore here.
|
2020-03-14 01:58:19 +08:00
|
|
|
if (RemoveRedundantEndcf) {
|
|
|
|
auto Next =
|
|
|
|
skipIgnoreExecInstsTrivialSucc(MBB, std::next(MI.getIterator()));
|
|
|
|
if (Next != MBB.end() && (Next->getOpcode() == AMDGPU::SI_END_CF ||
|
|
|
|
LoweredEndCf.count(&*Next))) {
|
2020-03-14 03:44:59 +08:00
|
|
|
// Only skip inner END_CF if outer ENDCF belongs to SI_IF.
|
|
|
|
// If that belongs to SI_ELSE then saved mask has an inverted value.
|
|
|
|
Register SavedExec = Next->getOperand(0).getReg();
|
|
|
|
const MachineInstr *Def = MRI.getUniqueVRegDef(SavedExec);
|
|
|
|
// A lowered SI_IF turns definition into COPY of exec.
|
|
|
|
if (Def && (Def->getOpcode() == AMDGPU::SI_IF ||
|
|
|
|
LoweredIf.count(SavedExec))) {
|
|
|
|
LLVM_DEBUG(dbgs() << "Skip redundant "; MI.dump());
|
|
|
|
if (LIS)
|
|
|
|
LIS->RemoveMachineInstrFromMaps(MI);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return;
|
|
|
|
}
|
2020-03-14 01:58:19 +08:00
|
|
|
}
|
2020-03-12 04:17:32 +08:00
|
|
|
}
|
|
|
|
|
2019-09-17 17:08:58 +08:00
|
|
|
MachineBasicBlock::iterator InsPt =
|
|
|
|
Def && Def->getParent() == &MBB ? std::next(MachineBasicBlock::iterator(Def))
|
|
|
|
: MBB.begin();
|
|
|
|
MachineInstr *NewMI = BuildMI(MBB, InsPt, DL, TII->get(OrOpc), Exec)
|
|
|
|
.addReg(Exec)
|
|
|
|
.add(MI.getOperand(0));
|
2016-07-13 05:41:32 +08:00
|
|
|
|
2020-03-12 04:17:32 +08:00
|
|
|
LoweredEndCf.insert(NewMI);
|
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
if (LIS)
|
2019-08-21 01:45:25 +08:00
|
|
|
LIS->ReplaceMachineInstrInMaps(MI, *NewMI);
|
2016-07-13 05:41:32 +08:00
|
|
|
|
2019-08-21 01:45:25 +08:00
|
|
|
MI.eraseFromParent();
|
2016-07-13 05:41:32 +08:00
|
|
|
|
2019-08-21 01:45:25 +08:00
|
|
|
if (LIS)
|
|
|
|
LIS->handleMove(*NewMI);
|
2016-07-13 05:41:32 +08:00
|
|
|
}
|
|
|
|
|
2016-11-29 02:58:49 +08:00
|
|
|
// Returns replace operands for a logical operation, either single result
|
|
|
|
// for exec or two operands if source was another equivalent operation.
|
|
|
|
void SILowerControlFlow::findMaskOperands(MachineInstr &MI, unsigned OpNo,
|
|
|
|
SmallVectorImpl<MachineOperand> &Src) const {
|
|
|
|
MachineOperand &Op = MI.getOperand(OpNo);
|
2019-08-02 07:27:28 +08:00
|
|
|
if (!Op.isReg() || !Register::isVirtualRegister(Op.getReg())) {
|
2016-11-29 02:58:49 +08:00
|
|
|
Src.push_back(Op);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MachineInstr *Def = MRI->getUniqueVRegDef(Op.getReg());
|
|
|
|
if (!Def || Def->getParent() != MI.getParent() ||
|
|
|
|
!(Def->isFullCopy() || (Def->getOpcode() == MI.getOpcode())))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Make sure we do not modify exec between def and use.
|
|
|
|
// A copy with implcitly defined exec inserted earlier is an exclusion, it
|
|
|
|
// does not really modify exec.
|
|
|
|
for (auto I = Def->getIterator(); I != MI.getIterator(); ++I)
|
2019-08-21 01:45:25 +08:00
|
|
|
if (I->modifiesRegister(AMDGPU::EXEC, TRI) &&
|
2019-06-17 01:13:09 +08:00
|
|
|
!(I->isCopy() && I->getOperand(0).getReg() != Exec))
|
2016-11-29 02:58:49 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (const auto &SrcOp : Def->explicit_operands())
|
2018-06-12 08:41:26 +08:00
|
|
|
if (SrcOp.isReg() && SrcOp.isUse() &&
|
2019-08-02 07:27:28 +08:00
|
|
|
(Register::isVirtualRegister(SrcOp.getReg()) || SrcOp.getReg() == Exec))
|
2016-11-29 02:58:49 +08:00
|
|
|
Src.push_back(SrcOp);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search and combine pairs of equivalent instructions, like
|
|
|
|
// S_AND_B64 x, (S_AND_B64 x, y) => S_AND_B64 x, y
|
|
|
|
// S_OR_B64 x, (S_OR_B64 x, y) => S_OR_B64 x, y
|
|
|
|
// One of the operands is exec mask.
|
|
|
|
void SILowerControlFlow::combineMasks(MachineInstr &MI) {
|
|
|
|
assert(MI.getNumExplicitOperands() == 3);
|
|
|
|
SmallVector<MachineOperand, 4> Ops;
|
|
|
|
unsigned OpToReplace = 1;
|
|
|
|
findMaskOperands(MI, 1, Ops);
|
|
|
|
if (Ops.size() == 1) OpToReplace = 2; // First operand can be exec or its copy
|
|
|
|
findMaskOperands(MI, 2, Ops);
|
|
|
|
if (Ops.size() != 3) return;
|
|
|
|
|
|
|
|
unsigned UniqueOpndIdx;
|
|
|
|
if (Ops[0].isIdenticalTo(Ops[1])) UniqueOpndIdx = 2;
|
|
|
|
else if (Ops[0].isIdenticalTo(Ops[2])) UniqueOpndIdx = 1;
|
|
|
|
else if (Ops[1].isIdenticalTo(Ops[2])) UniqueOpndIdx = 1;
|
|
|
|
else return;
|
|
|
|
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register Reg = MI.getOperand(OpToReplace).getReg();
|
2016-11-29 02:58:49 +08:00
|
|
|
MI.RemoveOperand(OpToReplace);
|
|
|
|
MI.addOperand(Ops[UniqueOpndIdx]);
|
|
|
|
if (MRI->use_empty(Reg))
|
|
|
|
MRI->getUniqueVRegDef(Reg)->eraseFromParent();
|
|
|
|
}
|
|
|
|
|
2016-02-12 10:16:10 +08:00
|
|
|
bool SILowerControlFlow::runOnMachineFunction(MachineFunction &MF) {
|
2018-07-12 04:59:01 +08:00
|
|
|
const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
|
2016-06-24 14:30:11 +08:00
|
|
|
TII = ST.getInstrInfo();
|
|
|
|
TRI = &TII->getRegisterInfo();
|
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
// This doesn't actually need LiveIntervals, but we can preserve them.
|
|
|
|
LIS = getAnalysisIfAvailable<LiveIntervals>();
|
2016-09-29 09:44:16 +08:00
|
|
|
MRI = &MF.getRegInfo();
|
2019-06-17 01:13:09 +08:00
|
|
|
BoolRC = TRI->getBoolRC();
|
|
|
|
|
|
|
|
if (ST.isWave32()) {
|
|
|
|
AndOpc = AMDGPU::S_AND_B32;
|
|
|
|
OrOpc = AMDGPU::S_OR_B32;
|
|
|
|
XorOpc = AMDGPU::S_XOR_B32;
|
|
|
|
MovTermOpc = AMDGPU::S_MOV_B32_term;
|
|
|
|
Andn2TermOpc = AMDGPU::S_ANDN2_B32_term;
|
|
|
|
XorTermrOpc = AMDGPU::S_XOR_B32_term;
|
|
|
|
OrSaveExecOpc = AMDGPU::S_OR_SAVEEXEC_B32;
|
|
|
|
Exec = AMDGPU::EXEC_LO;
|
|
|
|
} else {
|
|
|
|
AndOpc = AMDGPU::S_AND_B64;
|
|
|
|
OrOpc = AMDGPU::S_OR_B64;
|
|
|
|
XorOpc = AMDGPU::S_XOR_B64;
|
|
|
|
MovTermOpc = AMDGPU::S_MOV_B64_term;
|
|
|
|
Andn2TermOpc = AMDGPU::S_ANDN2_B64_term;
|
|
|
|
XorTermrOpc = AMDGPU::S_XOR_B64_term;
|
|
|
|
OrSaveExecOpc = AMDGPU::S_OR_SAVEEXEC_B64;
|
|
|
|
Exec = AMDGPU::EXEC;
|
|
|
|
}
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2016-06-23 04:15:28 +08:00
|
|
|
MachineFunction::iterator NextBB;
|
|
|
|
for (MachineFunction::iterator BI = MF.begin(), BE = MF.end();
|
|
|
|
BI != BE; BI = NextBB) {
|
|
|
|
NextBB = std::next(BI);
|
2019-08-21 01:45:25 +08:00
|
|
|
MachineBasicBlock &MBB = *BI;
|
2016-06-23 04:15:28 +08:00
|
|
|
|
2016-11-29 02:58:49 +08:00
|
|
|
MachineBasicBlock::iterator I, Next, Last;
|
2016-03-22 04:28:33 +08:00
|
|
|
|
2019-08-21 01:45:25 +08:00
|
|
|
for (I = MBB.begin(), Last = MBB.end(); I != MBB.end(); I = Next) {
|
2014-03-02 20:27:27 +08:00
|
|
|
Next = std::next(I);
|
2012-12-12 05:25:42 +08:00
|
|
|
MachineInstr &MI = *I;
|
2014-02-11 00:58:30 +08:00
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
switch (MI.getOpcode()) {
|
2016-08-23 03:33:16 +08:00
|
|
|
case AMDGPU::SI_IF:
|
|
|
|
emitIf(MI);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AMDGPU::SI_ELSE:
|
|
|
|
emitElse(MI);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AMDGPU::SI_IF_BREAK:
|
|
|
|
emitIfBreak(MI);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AMDGPU::SI_LOOP:
|
|
|
|
emitLoop(MI);
|
|
|
|
break;
|
|
|
|
|
2019-08-21 01:45:25 +08:00
|
|
|
case AMDGPU::SI_END_CF:
|
|
|
|
emitEndCf(MI);
|
2019-08-01 09:25:27 +08:00
|
|
|
break;
|
2019-08-21 01:45:25 +08:00
|
|
|
|
2016-11-29 02:58:49 +08:00
|
|
|
case AMDGPU::S_AND_B64:
|
|
|
|
case AMDGPU::S_OR_B64:
|
2019-06-17 01:13:09 +08:00
|
|
|
case AMDGPU::S_AND_B32:
|
|
|
|
case AMDGPU::S_OR_B32:
|
2016-11-29 02:58:49 +08:00
|
|
|
// Cleanup bit manipulations on exec mask
|
|
|
|
combineMasks(MI);
|
|
|
|
Last = I;
|
|
|
|
continue;
|
|
|
|
|
2016-08-23 03:33:16 +08:00
|
|
|
default:
|
2016-11-29 02:58:49 +08:00
|
|
|
Last = I;
|
|
|
|
continue;
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
2016-11-29 02:58:49 +08:00
|
|
|
|
|
|
|
// Replay newly inserted code to combine masks
|
2019-08-21 01:45:25 +08:00
|
|
|
Next = (Last == MBB.end()) ? MBB.begin() : Last;
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
}
|
2016-08-23 03:33:16 +08:00
|
|
|
|
2020-03-12 04:17:32 +08:00
|
|
|
LoweredEndCf.clear();
|
2020-03-14 03:44:59 +08:00
|
|
|
LoweredIf.clear();
|
2020-03-12 04:17:32 +08:00
|
|
|
|
2012-12-20 06:10:31 +08:00
|
|
|
return true;
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|