Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
//===- AMDGPULegalizerInfo.cpp -----------------------------------*- C++ -*-==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
/// This file implements the targeting of the Machinelegalizer class for
|
|
|
|
/// AMDGPU.
|
|
|
|
/// \todo This should be generated by TableGen.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-03-24 07:58:31 +08:00
|
|
|
#include "AMDGPU.h"
|
2018-03-30 01:21:10 +08:00
|
|
|
#include "AMDGPULegalizerInfo.h"
|
2018-03-17 23:17:41 +08:00
|
|
|
#include "AMDGPUTargetMachine.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetOpcodes.h"
|
2018-03-30 01:21:10 +08:00
|
|
|
#include "llvm/CodeGen/ValueTypes.h"
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/IR/Type.h"
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
2018-01-30 01:37:29 +08:00
|
|
|
using namespace LegalizeActions;
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
|
2018-03-09 00:24:16 +08:00
|
|
|
AMDGPULegalizerInfo::AMDGPULegalizerInfo(const SISubtarget &ST,
|
|
|
|
const GCNTargetMachine &TM) {
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
using namespace TargetOpcode;
|
|
|
|
|
2018-03-17 23:17:41 +08:00
|
|
|
auto GetAddrSpacePtr = [&TM](unsigned AS) {
|
|
|
|
return LLT::pointer(AS, TM.getPointerSizeInBits(AS));
|
|
|
|
};
|
|
|
|
|
2018-03-17 23:17:45 +08:00
|
|
|
auto AMDGPUAS = ST.getAMDGPUAS();
|
|
|
|
|
2018-03-17 23:17:41 +08:00
|
|
|
const LLT S1 = LLT::scalar(1);
|
AMDGPU/GlobalISel: Mark G_BITCAST s32 <--> <2 x s16> legal
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, igorb, dstuttard, tpr, t-tye, llvm-commits
Differential Revision: https://reviews.llvm.org/D34129
llvm-svn: 305692
2017-06-19 21:15:45 +08:00
|
|
|
const LLT V2S16 = LLT::vector(2, 16);
|
2018-03-17 23:17:41 +08:00
|
|
|
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
const LLT S64 = LLT::scalar(64);
|
2018-03-17 23:17:41 +08:00
|
|
|
|
|
|
|
const LLT GlobalPtr = GetAddrSpacePtr(AMDGPUAS::GLOBAL_ADDRESS);
|
|
|
|
const LLT ConstantPtr = GetAddrSpacePtr(AMDGPUAS::CONSTANT_ADDRESS);
|
2018-03-17 23:17:45 +08:00
|
|
|
const LLT LocalPtr = GetAddrSpacePtr(AMDGPUAS::LOCAL_ADDRESS);
|
|
|
|
const LLT FlatPtr = GetAddrSpacePtr(AMDGPUAS.FLAT_ADDRESS);
|
|
|
|
const LLT PrivatePtr = GetAddrSpacePtr(AMDGPUAS.PRIVATE_ADDRESS);
|
|
|
|
|
|
|
|
const LLT AddrSpaces[] = {
|
|
|
|
GlobalPtr,
|
|
|
|
ConstantPtr,
|
|
|
|
LocalPtr,
|
|
|
|
FlatPtr,
|
|
|
|
PrivatePtr
|
|
|
|
};
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
|
AMDGPU/GlobalISel: Mark 32-bit G_ADD as legal
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, igorb, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D33992
llvm-svn: 305232
2017-06-13 04:54:56 +08:00
|
|
|
setAction({G_ADD, S32}, Legal);
|
2018-03-19 22:07:23 +08:00
|
|
|
setAction({G_SUB, S32}, Legal);
|
2018-03-02 03:22:05 +08:00
|
|
|
setAction({G_MUL, S32}, Legal);
|
AMDGPU/GlobalISel: Mark 32-bit G_AND as legal
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, igorb, dstuttard, tpr, t-tye, llvm-commits
Differential Revision: https://reviews.llvm.org/D34349
llvm-svn: 306112
2017-06-23 23:17:17 +08:00
|
|
|
setAction({G_AND, S32}, Legal);
|
2018-03-02 03:09:21 +08:00
|
|
|
setAction({G_OR, S32}, Legal);
|
|
|
|
setAction({G_XOR, S32}, Legal);
|
AMDGPU/GlobalISel: Mark 32-bit G_ADD as legal
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, igorb, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D33992
llvm-svn: 305232
2017-06-13 04:54:56 +08:00
|
|
|
|
AMDGPU/GlobalISel: Mark G_BITCAST s32 <--> <2 x s16> legal
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, igorb, dstuttard, tpr, t-tye, llvm-commits
Differential Revision: https://reviews.llvm.org/D34129
llvm-svn: 305692
2017-06-19 21:15:45 +08:00
|
|
|
setAction({G_BITCAST, V2S16}, Legal);
|
|
|
|
setAction({G_BITCAST, 1, S32}, Legal);
|
|
|
|
|
|
|
|
setAction({G_BITCAST, S32}, Legal);
|
|
|
|
setAction({G_BITCAST, 1, V2S16}, Legal);
|
|
|
|
|
2018-03-17 23:17:48 +08:00
|
|
|
getActionDefinitionsBuilder(G_FCONSTANT)
|
|
|
|
.legalFor({S32, S64});
|
|
|
|
getActionDefinitionsBuilder({G_IMPLICIT_DEF, G_CONSTANT})
|
|
|
|
.legalFor({S1, S32, S64});
|
|
|
|
|
AMDGPU/GlobalISel: Mark 1-bit integer constants as legal
Summary:
These are mostly legal, but will probably need special lowering for some
cases.
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, igorb, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D33791
llvm-svn: 304628
2017-06-03 09:13:33 +08:00
|
|
|
// FIXME: i1 operands to intrinsics should always be legal, but other i1
|
|
|
|
// values may not be legal. We need to figure out how to distinguish
|
|
|
|
// between these two scenarios.
|
|
|
|
setAction({G_CONSTANT, S1}, Legal);
|
2018-03-02 03:16:52 +08:00
|
|
|
|
AMDGPU/GlobalISel: Mark 32-bit G_FADD as legal
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, igorb, dstuttard, tpr, t-tye, llvm-commits
Differential Revision: https://reviews.llvm.org/D38439
llvm-svn: 316815
2017-10-28 07:57:41 +08:00
|
|
|
setAction({G_FADD, S32}, Legal);
|
|
|
|
|
2018-03-02 03:09:16 +08:00
|
|
|
setAction({G_FCMP, S1}, Legal);
|
|
|
|
setAction({G_FCMP, 1, S32}, Legal);
|
|
|
|
setAction({G_FCMP, 1, S64}, Legal);
|
|
|
|
|
AMDGPU/GlobalISel: Mark 32-bit G_FMUL as legal
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, igorb, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D36218
llvm-svn: 309898
2017-08-03 06:56:30 +08:00
|
|
|
setAction({G_FMUL, S32}, Legal);
|
|
|
|
|
2018-03-02 04:56:21 +08:00
|
|
|
setAction({G_ZEXT, S64}, Legal);
|
|
|
|
setAction({G_ZEXT, 1, S32}, Legal);
|
|
|
|
|
2018-03-02 03:04:25 +08:00
|
|
|
setAction({G_FPTOSI, S32}, Legal);
|
|
|
|
setAction({G_FPTOSI, 1, S32}, Legal);
|
|
|
|
|
2018-02-07 12:47:59 +08:00
|
|
|
setAction({G_FPTOUI, S32}, Legal);
|
|
|
|
setAction({G_FPTOUI, 1, S32}, Legal);
|
|
|
|
|
2018-03-17 23:17:45 +08:00
|
|
|
for (LLT PtrTy : AddrSpaces) {
|
|
|
|
LLT IdxTy = LLT::scalar(PtrTy.getSizeInBits());
|
|
|
|
setAction({G_GEP, PtrTy}, Legal);
|
|
|
|
setAction({G_GEP, 1, IdxTy}, Legal);
|
|
|
|
}
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
|
AMDGPU/GlobalISel: Mark 32-bit G_ICMP as legal
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, igorb, dstuttard, tpr, t-tye, llvm-commits
Differential Revision: https://reviews.llvm.org/D33890
llvm-svn: 304797
2017-06-06 22:16:50 +08:00
|
|
|
setAction({G_ICMP, S1}, Legal);
|
|
|
|
setAction({G_ICMP, 1, S32}, Legal);
|
|
|
|
|
2018-03-17 23:17:41 +08:00
|
|
|
|
|
|
|
getActionDefinitionsBuilder({G_LOAD, G_STORE})
|
|
|
|
.legalIf([=, &ST](const LegalityQuery &Query) {
|
|
|
|
const LLT &Ty0 = Query.Types[0];
|
|
|
|
|
|
|
|
// TODO: Decompose private loads into 4-byte components.
|
|
|
|
// TODO: Illegal flat loads on SI
|
|
|
|
switch (Ty0.getSizeInBits()) {
|
|
|
|
case 32:
|
|
|
|
case 64:
|
|
|
|
case 128:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case 96:
|
|
|
|
// XXX hasLoadX3
|
|
|
|
return (ST.getGeneration() >= AMDGPUSubtarget::SEA_ISLANDS);
|
|
|
|
|
|
|
|
case 256:
|
|
|
|
case 512:
|
|
|
|
// TODO: constant loads
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
|
AMDGPU/GlobalISel: Mark 32-bit G_SELECT as legal
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, igorb, dstuttard, tpr, t-tye, llvm-commits
Differential Revision: https://reviews.llvm.org/D33949
llvm-svn: 304910
2017-06-07 21:54:51 +08:00
|
|
|
setAction({G_SELECT, S32}, Legal);
|
|
|
|
setAction({G_SELECT, 1, S1}, Legal);
|
|
|
|
|
AMDGPU/GlobalISel: Mark 32-bit G_SHL as legal
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, igorb, dstuttard, tpr, t-tye, llvm-commits
Differential Revision: https://reviews.llvm.org/D34589
llvm-svn: 306298
2017-06-26 23:56:52 +08:00
|
|
|
setAction({G_SHL, S32}, Legal);
|
|
|
|
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
|
|
|
|
// FIXME: When RegBankSelect inserts copies, it will only create new
|
|
|
|
// registers with scalar types. This means we can end up with
|
|
|
|
// G_LOAD/G_STORE/G_GEP instruction with scalar types for their pointer
|
|
|
|
// operands. In assert builds, the instruction selector will assert
|
|
|
|
// if it sees a generic instruction which isn't legal, so we need to
|
|
|
|
// tell it that scalar types are legal for pointer operands
|
|
|
|
setAction({G_GEP, S64}, Legal);
|
|
|
|
|
2018-03-12 21:35:53 +08:00
|
|
|
for (unsigned Op : {G_EXTRACT_VECTOR_ELT, G_INSERT_VECTOR_ELT}) {
|
|
|
|
getActionDefinitionsBuilder(Op)
|
|
|
|
.legalIf([=](const LegalityQuery &Query) {
|
|
|
|
const LLT &VecTy = Query.Types[1];
|
|
|
|
const LLT &IdxTy = Query.Types[2];
|
|
|
|
return VecTy.getSizeInBits() % 32 == 0 &&
|
|
|
|
VecTy.getSizeInBits() <= 512 &&
|
|
|
|
IdxTy.getSizeInBits() == 32;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-06 00:25:15 +08:00
|
|
|
// FIXME: Doesn't handle extract of illegal sizes.
|
|
|
|
getActionDefinitionsBuilder(G_EXTRACT)
|
|
|
|
.unsupportedIf([=](const LegalityQuery &Query) {
|
|
|
|
return Query.Types[0].getSizeInBits() >= Query.Types[1].getSizeInBits();
|
|
|
|
})
|
|
|
|
.legalIf([=](const LegalityQuery &Query) {
|
|
|
|
const LLT &Ty0 = Query.Types[0];
|
|
|
|
const LLT &Ty1 = Query.Types[1];
|
|
|
|
return (Ty0.getSizeInBits() % 32 == 0) &&
|
|
|
|
(Ty1.getSizeInBits() % 32 == 0);
|
|
|
|
});
|
|
|
|
|
2018-03-12 21:35:43 +08:00
|
|
|
// Merge/Unmerge
|
|
|
|
for (unsigned Op : {G_MERGE_VALUES, G_UNMERGE_VALUES}) {
|
|
|
|
unsigned BigTyIdx = Op == G_MERGE_VALUES ? 0 : 1;
|
|
|
|
unsigned LitTyIdx = Op == G_MERGE_VALUES ? 1 : 0;
|
|
|
|
|
|
|
|
getActionDefinitionsBuilder(Op)
|
|
|
|
.legalIf([=](const LegalityQuery &Query) {
|
|
|
|
const LLT &BigTy = Query.Types[BigTyIdx];
|
|
|
|
const LLT &LitTy = Query.Types[LitTyIdx];
|
|
|
|
return BigTy.getSizeInBits() % 32 == 0 &&
|
|
|
|
LitTy.getSizeInBits() % 32 == 0 &&
|
|
|
|
BigTy.getSizeInBits() <= 512;
|
|
|
|
})
|
|
|
|
// Any vectors left are the wrong size. Scalarize them.
|
|
|
|
.fewerElementsIf([](const LegalityQuery &Query) { return true; },
|
|
|
|
[](const LegalityQuery &Query) {
|
|
|
|
return std::make_pair(
|
|
|
|
0, Query.Types[0].getElementType());
|
|
|
|
})
|
|
|
|
.fewerElementsIf([](const LegalityQuery &Query) { return true; },
|
|
|
|
[](const LegalityQuery &Query) {
|
|
|
|
return std::make_pair(
|
|
|
|
1, Query.Types[1].getElementType());
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
computeTables();
|
|
|
|
}
|