2013-04-02 05:47:42 +08:00
|
|
|
//===-- R600EmitClauseMarkers.cpp - Emit CF_ALU ---------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
|
|
|
/// Add CF_ALU. R600 Alu instructions are grouped in clause which can hold
|
|
|
|
/// 128 Alu instructions ; these instructions can access up to 4 prefetched
|
|
|
|
/// 4 lines of 16 registers from constant buffers. Such ALU clauses are
|
|
|
|
/// initiated by CF_ALU instructions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "AMDGPU.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "AMDGPUSubtarget.h"
|
2013-04-02 05:47:42 +08:00
|
|
|
#include "R600Defines.h"
|
|
|
|
#include "R600InstrInfo.h"
|
|
|
|
#include "R600RegisterInfo.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"
|
2017-01-21 01:52:16 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2013-04-02 05:47:42 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2017-01-21 01:52:16 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2013-04-02 05:47:42 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2017-01-21 01:52:16 +08:00
|
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2013-04-02 05:47:42 +08:00
|
|
|
|
2013-05-24 01:10:37 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2013-12-12 01:51:41 +08:00
|
|
|
namespace llvm {
|
2017-01-21 01:52:16 +08:00
|
|
|
|
2013-12-12 01:51:41 +08:00
|
|
|
void initializeR600EmitClauseMarkersPass(PassRegistry&);
|
2017-01-21 01:52:16 +08:00
|
|
|
|
|
|
|
} // end namespace llvm
|
2013-12-12 01:51:41 +08:00
|
|
|
|
2013-05-24 01:10:37 +08:00
|
|
|
namespace {
|
2013-04-02 05:47:42 +08:00
|
|
|
|
2013-12-12 01:51:41 +08:00
|
|
|
class R600EmitClauseMarkers : public MachineFunctionPass {
|
2013-04-02 05:47:42 +08:00
|
|
|
private:
|
2017-01-21 01:52:16 +08:00
|
|
|
const R600InstrInfo *TII = nullptr;
|
|
|
|
int Address = 0;
|
2013-04-02 05:47:42 +08:00
|
|
|
|
2016-07-09 03:16:05 +08:00
|
|
|
unsigned OccupiedDwords(MachineInstr &MI) const {
|
|
|
|
switch (MI.getOpcode()) {
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
case R600::INTERP_PAIR_XY:
|
|
|
|
case R600::INTERP_PAIR_ZW:
|
|
|
|
case R600::INTERP_VEC_LOAD:
|
|
|
|
case R600::DOT_4:
|
2013-04-02 05:47:42 +08:00
|
|
|
return 4;
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
case R600::KILL:
|
2013-04-02 05:47:42 +08:00
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-11-15 08:12:45 +08:00
|
|
|
// These will be expanded to two ALU instructions in the
|
|
|
|
// ExpandSpecialInstructions pass.
|
2016-07-09 03:16:05 +08:00
|
|
|
if (TII->isLDSRetInstr(MI.getOpcode()))
|
2013-11-15 08:12:45 +08:00
|
|
|
return 2;
|
|
|
|
|
2016-07-09 03:16:05 +08:00
|
|
|
if (TII->isVector(MI) || TII->isCubeOp(MI.getOpcode()) ||
|
|
|
|
TII->isReductionOp(MI.getOpcode()))
|
2013-04-02 05:47:42 +08:00
|
|
|
return 4;
|
|
|
|
|
|
|
|
unsigned NumLiteral = 0;
|
2016-07-09 03:16:05 +08:00
|
|
|
for (MachineInstr::mop_iterator It = MI.operands_begin(),
|
|
|
|
E = MI.operands_end();
|
|
|
|
It != E; ++It) {
|
2013-04-02 05:47:42 +08:00
|
|
|
MachineOperand &MO = *It;
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
if (MO.isReg() && MO.getReg() == R600::ALU_LITERAL_X)
|
2013-04-02 05:47:42 +08:00
|
|
|
++NumLiteral;
|
|
|
|
}
|
|
|
|
return 1 + NumLiteral;
|
|
|
|
}
|
|
|
|
|
2016-07-09 03:16:05 +08:00
|
|
|
bool isALU(const MachineInstr &MI) const {
|
|
|
|
if (TII->isALUInstr(MI.getOpcode()))
|
2013-04-02 05:47:42 +08:00
|
|
|
return true;
|
2016-07-09 03:16:05 +08:00
|
|
|
if (TII->isVector(MI) || TII->isCubeOp(MI.getOpcode()))
|
2013-04-02 05:47:42 +08:00
|
|
|
return true;
|
2016-07-09 03:16:05 +08:00
|
|
|
switch (MI.getOpcode()) {
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
case R600::PRED_X:
|
|
|
|
case R600::INTERP_PAIR_XY:
|
|
|
|
case R600::INTERP_PAIR_ZW:
|
|
|
|
case R600::INTERP_VEC_LOAD:
|
|
|
|
case R600::COPY:
|
|
|
|
case R600::DOT_4:
|
2013-04-02 05:47:42 +08:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-09 03:16:05 +08:00
|
|
|
bool IsTrivialInst(MachineInstr &MI) const {
|
|
|
|
switch (MI.getOpcode()) {
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
case R600::KILL:
|
|
|
|
case R600::RETURN:
|
|
|
|
case R600::IMPLICIT_DEF:
|
2013-04-02 05:47:42 +08:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<unsigned, unsigned> getAccessedBankLine(unsigned Sel) const {
|
|
|
|
// Sel is (512 + (kc_bank << 12) + ConstIndex) << 2
|
|
|
|
// (See also R600ISelLowering.cpp)
|
|
|
|
// ConstIndex value is in [0, 4095];
|
|
|
|
return std::pair<unsigned, unsigned>(
|
|
|
|
((Sel >> 2) - 512) >> 12, // KC_BANK
|
|
|
|
// Line Number of ConstIndex
|
|
|
|
// A line contains 16 constant registers however KCX bank can lock
|
|
|
|
// two line at the same time ; thus we want to get an even line number.
|
|
|
|
// Line number can be retrieved with (>>4), using (>>5) <<1 generates
|
|
|
|
// an even number.
|
|
|
|
((((Sel >> 2) - 512) & 4095) >> 5) << 1);
|
|
|
|
}
|
|
|
|
|
2016-07-09 03:16:05 +08:00
|
|
|
bool
|
|
|
|
SubstituteKCacheBank(MachineInstr &MI,
|
|
|
|
std::vector<std::pair<unsigned, unsigned>> &CachedConsts,
|
|
|
|
bool UpdateInstr = true) const {
|
2017-01-21 01:52:16 +08:00
|
|
|
std::vector<std::pair<unsigned, unsigned>> UsedKCache;
|
2013-11-15 08:12:45 +08:00
|
|
|
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
if (!TII->isALUInstr(MI.getOpcode()) && MI.getOpcode() != R600::DOT_4)
|
2013-11-15 08:12:45 +08:00
|
|
|
return true;
|
|
|
|
|
2016-06-30 08:01:54 +08:00
|
|
|
const SmallVectorImpl<std::pair<MachineOperand *, int64_t>> &Consts =
|
2016-07-09 03:16:05 +08:00
|
|
|
TII->getSrcs(MI);
|
|
|
|
assert(
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
(TII->isALUInstr(MI.getOpcode()) || MI.getOpcode() == R600::DOT_4) &&
|
2016-07-09 03:16:05 +08:00
|
|
|
"Can't assign Const");
|
2013-04-02 05:47:42 +08:00
|
|
|
for (unsigned i = 0, n = Consts.size(); i < n; ++i) {
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
if (Consts[i].first->getReg() != R600::ALU_CONST)
|
2013-05-18 00:50:02 +08:00
|
|
|
continue;
|
2013-04-02 05:47:42 +08:00
|
|
|
unsigned Sel = Consts[i].second;
|
|
|
|
unsigned Chan = Sel & 3, Index = ((Sel >> 2) - 512) & 31;
|
|
|
|
unsigned KCacheIndex = Index * 4 + Chan;
|
|
|
|
const std::pair<unsigned, unsigned> &BankLine = getAccessedBankLine(Sel);
|
|
|
|
if (CachedConsts.empty()) {
|
|
|
|
CachedConsts.push_back(BankLine);
|
|
|
|
UsedKCache.push_back(std::pair<unsigned, unsigned>(0, KCacheIndex));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (CachedConsts[0] == BankLine) {
|
|
|
|
UsedKCache.push_back(std::pair<unsigned, unsigned>(0, KCacheIndex));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (CachedConsts.size() == 1) {
|
|
|
|
CachedConsts.push_back(BankLine);
|
|
|
|
UsedKCache.push_back(std::pair<unsigned, unsigned>(1, KCacheIndex));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (CachedConsts[1] == BankLine) {
|
|
|
|
UsedKCache.push_back(std::pair<unsigned, unsigned>(1, KCacheIndex));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-15 08:12:45 +08:00
|
|
|
if (!UpdateInstr)
|
|
|
|
return true;
|
|
|
|
|
2013-05-18 00:50:02 +08:00
|
|
|
for (unsigned i = 0, j = 0, n = Consts.size(); i < n; ++i) {
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
if (Consts[i].first->getReg() != R600::ALU_CONST)
|
2013-05-18 00:50:02 +08:00
|
|
|
continue;
|
|
|
|
switch(UsedKCache[j].first) {
|
2013-04-02 05:47:42 +08:00
|
|
|
case 0:
|
2013-05-18 00:50:02 +08:00
|
|
|
Consts[i].first->setReg(
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
R600::R600_KC0RegClass.getRegister(UsedKCache[j].second));
|
2013-04-02 05:47:42 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2013-05-18 00:50:02 +08:00
|
|
|
Consts[i].first->setReg(
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
R600::R600_KC1RegClass.getRegister(UsedKCache[j].second));
|
2013-04-02 05:47:42 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Wrong Cache Line");
|
|
|
|
}
|
2013-05-18 00:50:02 +08:00
|
|
|
j++;
|
2013-04-02 05:47:42 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-15 08:12:45 +08:00
|
|
|
bool canClauseLocalKillFitInClause(
|
|
|
|
unsigned AluInstCount,
|
2017-01-21 01:52:16 +08:00
|
|
|
std::vector<std::pair<unsigned, unsigned>> KCacheBanks,
|
2013-11-15 08:12:45 +08:00
|
|
|
MachineBasicBlock::iterator Def,
|
|
|
|
MachineBasicBlock::iterator BBEnd) {
|
|
|
|
const R600RegisterInfo &TRI = TII->getRegisterInfo();
|
2017-03-07 04:10:05 +08:00
|
|
|
//TODO: change this to defs?
|
2013-11-15 08:12:45 +08:00
|
|
|
for (MachineInstr::const_mop_iterator
|
|
|
|
MOI = Def->operands_begin(),
|
|
|
|
MOE = Def->operands_end(); MOI != MOE; ++MOI) {
|
|
|
|
if (!MOI->isReg() || !MOI->isDef() ||
|
|
|
|
TRI.isPhysRegLiveAcrossClauses(MOI->getReg()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Def defines a clause local register, so check that its use will fit
|
|
|
|
// in the clause.
|
|
|
|
unsigned LastUseCount = 0;
|
|
|
|
for (MachineBasicBlock::iterator UseI = Def; UseI != BBEnd; ++UseI) {
|
2016-07-09 03:16:05 +08:00
|
|
|
AluInstCount += OccupiedDwords(*UseI);
|
2013-11-15 08:12:45 +08:00
|
|
|
// Make sure we won't need to end the clause due to KCache limitations.
|
2016-07-09 03:16:05 +08:00
|
|
|
if (!SubstituteKCacheBank(*UseI, KCacheBanks, false))
|
2013-11-15 08:12:45 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// We have reached the maximum instruction limit before finding the
|
|
|
|
// use that kills this register, so we cannot use this def in the
|
|
|
|
// current clause.
|
|
|
|
if (AluInstCount >= TII->getMaxAlusPerClause())
|
|
|
|
return false;
|
|
|
|
|
2017-03-07 04:10:05 +08:00
|
|
|
// TODO: Is this true? kill flag appears to work OK below
|
2013-11-15 08:12:45 +08:00
|
|
|
// Register kill flags have been cleared by the time we get to this
|
|
|
|
// pass, but it is safe to assume that all uses of this register
|
|
|
|
// occur in the same basic block as its definition, because
|
|
|
|
// it is illegal for the scheduler to schedule them in
|
|
|
|
// different blocks.
|
2017-03-07 04:10:05 +08:00
|
|
|
if (UseI->readsRegister(MOI->getReg()))
|
2013-11-15 08:12:45 +08:00
|
|
|
LastUseCount = AluInstCount;
|
|
|
|
|
2017-03-07 04:10:05 +08:00
|
|
|
// Exit early if the current use kills the register
|
|
|
|
if (UseI != Def && UseI->killsRegister(MOI->getReg()))
|
2013-11-15 08:12:45 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (LastUseCount)
|
|
|
|
return LastUseCount <= TII->getMaxAlusPerClause();
|
|
|
|
llvm_unreachable("Clause local register live at end of clause.");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-02 05:47:42 +08:00
|
|
|
MachineBasicBlock::iterator
|
2013-07-09 23:03:33 +08:00
|
|
|
MakeALUClause(MachineBasicBlock &MBB, MachineBasicBlock::iterator I) {
|
2013-04-02 05:47:42 +08:00
|
|
|
MachineBasicBlock::iterator ClauseHead = I;
|
2017-01-21 01:52:16 +08:00
|
|
|
std::vector<std::pair<unsigned, unsigned>> KCacheBanks;
|
2013-04-02 05:47:42 +08:00
|
|
|
bool PushBeforeModifier = false;
|
|
|
|
unsigned AluInstCount = 0;
|
|
|
|
for (MachineBasicBlock::iterator E = MBB.end(); I != E; ++I) {
|
2016-07-09 03:16:05 +08:00
|
|
|
if (IsTrivialInst(*I))
|
2013-04-02 05:47:42 +08:00
|
|
|
continue;
|
2016-07-09 03:16:05 +08:00
|
|
|
if (!isALU(*I))
|
2013-04-02 05:47:42 +08:00
|
|
|
break;
|
2013-04-04 02:24:47 +08:00
|
|
|
if (AluInstCount > TII->getMaxAlusPerClause())
|
|
|
|
break;
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
if (I->getOpcode() == R600::PRED_X) {
|
2013-10-02 03:32:49 +08:00
|
|
|
// We put PRED_X in its own clause to ensure that ifcvt won't create
|
|
|
|
// clauses with more than 128 insts.
|
|
|
|
// IfCvt is indeed checking that "then" and "else" branches of an if
|
|
|
|
// statement have less than ~60 insts thus converted clauses can't be
|
|
|
|
// bigger than ~121 insts (predicate setter needs to be in the same
|
|
|
|
// clause as predicated alus).
|
|
|
|
if (AluInstCount > 0)
|
|
|
|
break;
|
2016-06-30 08:01:54 +08:00
|
|
|
if (TII->getFlagOp(*I).getImm() & MO_FLAG_PUSH)
|
2013-04-02 05:47:42 +08:00
|
|
|
PushBeforeModifier = true;
|
|
|
|
AluInstCount ++;
|
|
|
|
continue;
|
|
|
|
}
|
2013-06-28 23:46:59 +08:00
|
|
|
// XXX: GROUP_BARRIER instructions cannot be in the same ALU clause as:
|
|
|
|
//
|
|
|
|
// * KILL or INTERP instructions
|
|
|
|
// * Any instruction that sets UPDATE_EXEC_MASK or UPDATE_PRED bits
|
|
|
|
// * Uses waterfalling (i.e. INDEX_MODE = AR.X)
|
|
|
|
//
|
|
|
|
// XXX: These checks have not been implemented yet.
|
|
|
|
if (TII->mustBeLastInClause(I->getOpcode())) {
|
2013-04-04 00:24:04 +08:00
|
|
|
I++;
|
|
|
|
break;
|
|
|
|
}
|
2013-11-15 08:12:45 +08:00
|
|
|
|
|
|
|
// If this instruction defines a clause local register, make sure
|
|
|
|
// its use can fit in this clause.
|
|
|
|
if (!canClauseLocalKillFitInClause(AluInstCount, KCacheBanks, I, E))
|
2013-04-02 05:47:42 +08:00
|
|
|
break;
|
2013-11-15 08:12:45 +08:00
|
|
|
|
2016-07-09 03:16:05 +08:00
|
|
|
if (!SubstituteKCacheBank(*I, KCacheBanks))
|
2013-06-05 07:17:15 +08:00
|
|
|
break;
|
2016-07-09 03:16:05 +08:00
|
|
|
AluInstCount += OccupiedDwords(*I);
|
2013-04-02 05:47:42 +08:00
|
|
|
}
|
|
|
|
unsigned Opcode = PushBeforeModifier ?
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
R600::CF_ALU_PUSH_BEFORE : R600::CF_ALU;
|
2013-04-02 05:47:42 +08:00
|
|
|
BuildMI(MBB, ClauseHead, MBB.findDebugLoc(ClauseHead), TII->get(Opcode))
|
2013-07-09 23:03:33 +08:00
|
|
|
// We don't use the ADDR field until R600ControlFlowFinalizer pass, where
|
|
|
|
// it is safe to assume it is 0. However if we always put 0 here, the ifcvt
|
2016-06-10 10:18:02 +08:00
|
|
|
// pass may assume that identical ALU clause starter at the beginning of a
|
2013-07-09 23:03:33 +08:00
|
|
|
// true and false branch can be factorized which is not the case.
|
|
|
|
.addImm(Address++) // ADDR
|
2013-04-02 05:47:42 +08:00
|
|
|
.addImm(KCacheBanks.empty()?0:KCacheBanks[0].first) // KB0
|
|
|
|
.addImm((KCacheBanks.size() < 2)?0:KCacheBanks[1].first) // KB1
|
|
|
|
.addImm(KCacheBanks.empty()?0:2) // KM0
|
|
|
|
.addImm((KCacheBanks.size() < 2)?0:2) // KM1
|
|
|
|
.addImm(KCacheBanks.empty()?0:KCacheBanks[0].second) // KLINE0
|
|
|
|
.addImm((KCacheBanks.size() < 2)?0:KCacheBanks[1].second) // KLINE1
|
2013-07-09 23:03:33 +08:00
|
|
|
.addImm(AluInstCount) // COUNT
|
|
|
|
.addImm(1); // Enabled
|
2013-04-02 05:47:42 +08:00
|
|
|
return I;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2013-12-12 01:51:41 +08:00
|
|
|
static char ID;
|
|
|
|
|
2017-01-21 01:52:16 +08:00
|
|
|
R600EmitClauseMarkers() : MachineFunctionPass(ID) {
|
2013-12-12 01:51:41 +08:00
|
|
|
initializeR600EmitClauseMarkersPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2013-04-02 05:47:42 +08:00
|
|
|
|
2014-04-29 15:57:24 +08:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override {
|
2016-06-24 14:30:11 +08:00
|
|
|
const R600Subtarget &ST = MF.getSubtarget<R600Subtarget>();
|
|
|
|
TII = ST.getInstrInfo();
|
2013-06-08 04:28:55 +08:00
|
|
|
|
2013-04-02 05:47:42 +08:00
|
|
|
for (MachineFunction::iterator BB = MF.begin(), BB_E = MF.end();
|
|
|
|
BB != BB_E; ++BB) {
|
|
|
|
MachineBasicBlock &MBB = *BB;
|
|
|
|
MachineBasicBlock::iterator I = MBB.begin();
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
if (I != MBB.end() && I->getOpcode() == R600::CF_ALU)
|
2013-04-02 05:47:42 +08:00
|
|
|
continue; // BB was already parsed
|
|
|
|
for (MachineBasicBlock::iterator E = MBB.end(); I != E;) {
|
2017-02-18 12:24:10 +08:00
|
|
|
if (isALU(*I)) {
|
|
|
|
auto next = MakeALUClause(MBB, I);
|
|
|
|
assert(next != I);
|
|
|
|
I = next;
|
|
|
|
} else
|
2013-04-02 05:47:42 +08:00
|
|
|
++I;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-01 10:56:57 +08:00
|
|
|
StringRef getPassName() const override {
|
2013-04-02 05:47:42 +08:00
|
|
|
return "R600 Emit Clause Markers Pass";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-12-12 01:51:41 +08:00
|
|
|
char R600EmitClauseMarkers::ID = 0;
|
2013-04-02 05:47:42 +08:00
|
|
|
|
2013-05-24 01:10:37 +08:00
|
|
|
} // end anonymous namespace
|
2013-04-02 05:47:42 +08:00
|
|
|
|
2013-12-12 01:51:41 +08:00
|
|
|
INITIALIZE_PASS_BEGIN(R600EmitClauseMarkers, "emitclausemarkers",
|
|
|
|
"R600 Emit Clause Markters", false, false)
|
|
|
|
INITIALIZE_PASS_END(R600EmitClauseMarkers, "emitclausemarkers",
|
|
|
|
"R600 Emit Clause Markters", false, false)
|
2013-04-02 05:47:42 +08:00
|
|
|
|
2017-01-21 01:52:16 +08:00
|
|
|
FunctionPass *llvm::createR600EmitClauseMarkers() {
|
2013-12-12 01:51:41 +08:00
|
|
|
return new R600EmitClauseMarkers();
|
2013-04-02 05:47:42 +08:00
|
|
|
}
|