45 : MachineEvaluator(tri, mri), MF(mf), MFI(mf.getFrameInfo()),
TII(tii) {
62 unsigned InVirtReg, InPhysReg = 0;
73 if (Width == 0 || Width > 64)
75 if (
Arg.hasAttribute(Attribute::ByVal))
77 InPhysReg = getNextPhysReg(InPhysReg, Width);
80 InVirtReg = getVirtRegFor(InPhysReg);
83 if (
Arg.hasAttribute(Attribute::SExt))
84 VRX.
insert(std::make_pair(InVirtReg,
ExtType(ExtType::SExt, Width)));
85 else if (
Arg.hasAttribute(Attribute::ZExt))
86 VRX.
insert(std::make_pair(InVirtReg,
ExtType(ExtType::ZExt, Width)));
92 return MachineEvaluator::mask(Reg, 0);
99 case Hexagon::DoubleRegsRegClassID:
100 case Hexagon::HvxWRRegClassID:
102 : BT::BitMask(RW, 2*RW-1);
116 using namespace Hexagon;
117 for (
auto &RC : {HvxVRRegClass, HvxWRRegClass, HvxQRRegClass})
118 if (RC.contains(Reg))
125 (
Twine(
"Unhandled physical register") +
TRI.
getName(Reg)).str().c_str());
137 assert(IsSubLo != IsSubHi &&
"Must refer to either low or high subreg");
140 switch (RC.
getID()) {
141 case Hexagon::DoubleRegsRegClassID:
142 return Hexagon::IntRegsRegClass;
143 case Hexagon::HvxWRRegClassID:
144 return Hexagon::HvxVRRegClass;
149 dbgs() <<
"Reg class id: " << RC.
getID() <<
" idx: " << Idx <<
'\n';
157 std::vector<BT::RegisterRef> Vector;
161 for (
unsigned i = 0, n = Vector.size(); i < n; ++i) {
170 size_t size()
const {
return Vector.size(); }
174 assert(n < Vector.size());
184 using namespace Hexagon;
186 unsigned NumDefs = 0;
190 if (!MO.isReg() || !MO.isDef())
193 assert(MO.getSubReg() == 0);
209 return evaluateLoad(MI, Inputs, Outputs);
228 if (evaluateFormalCopy(MI, Inputs, Outputs))
239 if (MO.isGlobal() || MO.isBlockAddress() || MO.isSymbol() || MO.isJTI() ||
244 RegisterRefs
Reg(MI);
245 #define op(i) MI.getOperand(i) 246 #define rc(i) RegisterCell::ref(getCell(Reg[i], Inputs)) 247 #define im(i) MI.getOperand(i).getImm() 260 auto cop = [
this, &
Reg, &
MI, &Inputs](
unsigned N,
274 return eXTR(RC, 0, RW);
281 return eXTR(RC, W-RW, W);
287 return eXTR(RC, N*16, N*16+16);
292 uint16_t
I = Odd, Ws = Rs.
width();
310 unsigned Reg0 = Reg[0].Reg;
319 return rr0(
eIMM(
im(1), W0), Outputs);
325 int FI =
op(1).getIndex();
326 int Off =
op(2).getImm();
331 return rr0(RC, Outputs);
339 return rr0(
rc(1), Outputs);
347 return rr0(RC, Outputs);
354 return rr0(
eINS(RC,
eXTR(
rc(1), 0, PW), 0), Outputs);
366 assert(W0 == 64 && W1 == 32);
369 return rr0(RC, Outputs);
373 return rr0(
eADD(
rc(1),
rc(2)), Outputs);
376 case S4_addi_asl_ri: {
378 return rr0(RC, Outputs);
380 case S4_addi_lsr_ri: {
382 return rr0(RC, Outputs);
386 return rr0(RC, Outputs);
388 case M4_mpyri_addi: {
391 return rr0(RC, Outputs);
393 case M4_mpyrr_addi: {
396 return rr0(RC, Outputs);
398 case M4_mpyri_addr_u2: {
401 return rr0(RC, Outputs);
403 case M4_mpyri_addr: {
406 return rr0(RC, Outputs);
408 case M4_mpyrr_addr: {
411 return rr0(RC, Outputs);
415 return rr0(RC, Outputs);
419 return rr0(RC, Outputs);
423 return rr0(RC, Outputs);
427 return rr0(RC, Outputs);
429 case S2_addasl_rrri: {
431 return rr0(RC, Outputs);
436 return rr0(
eADD(RPC,
eIMM(
im(2), W0)), Outputs);
440 return rr0(
eSUB(
rc(1),
rc(2)), Outputs);
443 case S4_subi_asl_ri: {
445 return rr0(RC, Outputs);
447 case S4_subi_lsr_ri: {
449 return rr0(RC, Outputs);
453 return rr0(RC, Outputs);
457 return rr0(RC, Outputs);
461 return rr0(
eSUB(
eIMM(0, W0),
rc(1)), Outputs);
465 return rr0(hi(M, W0), Outputs);
468 return rr0(
eMLS(
rc(1),
rc(2)), Outputs);
469 case M2_dpmpyss_acc_s0:
471 case M2_dpmpyss_nac_s0:
475 return rr0(lo(M, W0), Outputs);
480 return rr0(RC, Outputs);
485 return rr0(RC, Outputs);
490 return rr0(RC, Outputs);
494 return rr0(lo(M, 32), Outputs);
498 return rr0(lo(M, 32), Outputs);
502 return rr0(lo(M, 32), Outputs);
506 return rr0(hi(M, W0), Outputs);
509 return rr0(
eMLU(
rc(1),
rc(2)), Outputs);
510 case M2_dpmpyuu_acc_s0:
512 case M2_dpmpyuu_nac_s0:
522 return rr0(
eAND(
rc(1),
rc(2)), Outputs);
526 case S4_andi_asl_ri: {
528 return rr0(RC, Outputs);
530 case S4_andi_lsr_ri: {
532 return rr0(RC, Outputs);
546 return rr0(
eORL(
rc(1),
rc(2)), Outputs);
550 case S4_ori_asl_ri: {
552 return rr0(RC, Outputs);
554 case S4_ori_lsr_ri: {
556 return rr0(RC, Outputs);
565 return rr0(RC, Outputs);
569 return rr0(RC, Outputs);
577 return rr0(
eXOR(
rc(1),
rc(2)), Outputs);
588 return rr0(
eNOT(
rc(1)), Outputs);
592 return rr0(
eASL(
rc(1),
im(2)), Outputs);
594 return rr0(
eASL(
rc(1), 16), Outputs);
607 case S2_asl_i_r_xacc:
608 case S2_asl_i_p_xacc:
617 return rr0(
eASR(
rc(1),
im(2)), Outputs);
619 return rr0(
eASR(
rc(1), 16), Outputs);
632 case S2_asr_i_r_rnd: {
638 return rr0(
eXTR(RC, 0, W0), Outputs);
640 case S2_asr_i_r_rnd_goodsyntax: {
643 return rr0(
rc(1), Outputs);
647 return rr0(
eXTR(RC, 0, W0), Outputs);
651 case S2_asr_i_svw_trun:
657 return rr0(
eLSR(
rc(1),
im(2)), Outputs);
670 case S2_lsr_i_r_xacc:
671 case S2_lsr_i_p_xacc:
677 return rr0(RC, Outputs);
682 return rr0(RC, Outputs);
684 case S2_togglebit_i: {
690 return rr0(RC, Outputs);
699 .
fill(W1+(W1-BX), W0, Zero);
702 return rr0(RC, Outputs);
708 uint16_t Wd =
im(2), Of =
im(3);
711 return rr0(
eIMM(0, W0), Outputs);
718 if (Opc == S2_extractu || Opc == S2_extractup)
719 return rr0(
eZXT(RC, Wd), Outputs);
720 return rr0(
eSXT(RC, Wd), Outputs);
724 uint16_t Wd =
im(3), Of =
im(4);
725 assert(Wd < W0 && Of < W0);
730 return rr0(
rc(1), Outputs);
731 return rr0(
eINS(
rc(1),
eXTR(
rc(2), 0, Wd), Of), Outputs);
743 return rr0(cop(2, W0/2).cat(cop(1, W0/2)), Outputs);
747 case A2_combine_hh: {
751 unsigned LoH = !(Opc == A2_combine_ll || Opc == A2_combine_hl);
753 unsigned HiH = !(Opc == A2_combine_ll || Opc == A2_combine_lh);
757 return rr0(RC, Outputs);
766 return rr0(RC, Outputs);
770 return rr0(RC, Outputs);
774 return rr0(RC, Outputs);
778 return rr0(RC, Outputs);
782 return rr0(RC, Outputs);
787 assert(WR == 64 && WP == 8);
790 for (uint16_t i = 0; i < WP; ++i) {
793 RC.
fill(i*8, i*8+8, F);
795 return rr0(RC, Outputs);
807 if (PC0.
is(0) || PC0.
is(1))
809 R2.
meet(R3, Reg[0].Reg);
810 return rr0(R2, Outputs);
819 return rr0(
eSXT(
rc(1), 8), Outputs);
821 return rr0(
eSXT(
rc(1), 16), Outputs);
824 assert(W0 == 64 && W1 == 32);
826 return rr0(RC, Outputs);
829 return rr0(
eZXT(
rc(1), 8), Outputs);
831 return rr0(
eZXT(
rc(1), 16), Outputs);
849 return rr0(
eCLB(
rc(1),
false, 32), Outputs);
852 return rr0(
eCLB(
rc(1),
true, 32), Outputs);
858 if (TV.
is(0) || TV.
is(1))
859 return rr0(
eCLB(R1, TV, 32), Outputs);
864 return rr0(
eCTB(
rc(1),
false, 32), Outputs);
867 return rr0(
eCTB(
rc(1),
true, 32), Outputs);
874 bool Has0 =
false, All1 =
true;
875 for (uint16_t i = 0; i < 8; ++i) {
887 return rr0(RC, Outputs);
891 bool Has1 =
false, All0 =
true;
892 for (uint16_t i = 0; i < 8; ++i) {
904 return rr0(RC, Outputs);
907 return rr0(
eAND(
rc(1),
rc(2)), Outputs);
911 return rr0(
eNOT(
rc(1)), Outputs);
913 return rr0(
eORL(
rc(1),
rc(2)), Outputs);
917 return rr0(
eXOR(
rc(1),
rc(2)), Outputs);
945 if (V.
is(0) || V.
is(1)) {
947 bool TV = (Opc == S2_tstbit_i);
957 if (
unsigned DefR = getUniqueDefVReg(MI)) {
968 return MachineEvaluator::evaluate(MI, Inputs, Outputs);
979 bool &FallsThru)
const {
983 bool SimpleBranch =
false;
984 bool Negated =
false;
986 case Hexagon::J2_jumpf:
987 case Hexagon::J2_jumpfpt:
988 case Hexagon::J2_jumpfnew:
989 case Hexagon::J2_jumpfnewpt:
992 case Hexagon::J2_jumpt:
993 case Hexagon::J2_jumptpt:
994 case Hexagon::J2_jumptnew:
995 case Hexagon::J2_jumptnewpt:
1000 case Hexagon::J2_jump:
1019 if (!Test.
is(0) && !Test.
is(1))
1023 if (!Test.
is(!Negated)) {
1034 unsigned HexagonEvaluator::getUniqueDefVReg(
const MachineInstr &
MI)
const {
1035 unsigned DefReg = 0;
1037 if (!
Op.isReg() || !
Op.isDef())
1039 unsigned R =
Op.getReg();
1049 bool HexagonEvaluator::evaluateLoad(
const MachineInstr &MI,
1052 using namespace Hexagon;
1068 case L2_loadalignb_pbr:
1069 case L2_loadalignb_pcr:
1070 case L2_loadalignb_pi:
1072 case L2_loadalignh_pbr:
1073 case L2_loadalignh_pcr:
1074 case L2_loadalignh_pi:
1076 case L2_loadbsw2_pbr:
1077 case L2_loadbsw2_pci:
1078 case L2_loadbsw2_pcr:
1079 case L2_loadbsw2_pi:
1080 case L2_loadbsw4_pbr:
1081 case L2_loadbsw4_pci:
1082 case L2_loadbsw4_pcr:
1083 case L2_loadbsw4_pi:
1085 case L2_loadbzw2_pbr:
1086 case L2_loadbzw2_pci:
1087 case L2_loadbzw2_pcr:
1088 case L2_loadbzw2_pi:
1089 case L2_loadbzw4_pbr:
1090 case L2_loadbzw4_pci:
1091 case L2_loadbzw4_pcr:
1092 case L2_loadbzw4_pi:
1111 case L2_loadrub_pbr:
1112 case L2_loadrub_pci:
1113 case L2_loadrub_pcr:
1139 case L2_loadruh_pbr:
1140 case L2_loadruh_pci:
1141 case L2_loadruh_pcr:
1157 case L2_loadw_locked:
1173 case L4_loadd_locked:
1188 assert(W >= BitNum && BitNum > 0);
1191 for (uint16_t i = 0; i < BitNum; ++i)
1196 for (uint16_t i = BitNum; i <
W; ++i)
1199 for (uint16_t i = BitNum; i <
W; ++i)
1207 bool HexagonEvaluator::evaluateFormalCopy(
const MachineInstr &MI,
1223 uint16_t EW = F->second.Width;
1232 if (F->second.Type == ExtType::SExt)
1234 else if (F->second.Type == ExtType::ZExt)
1241 unsigned HexagonEvaluator::getNextPhysReg(
unsigned PReg,
unsigned Width)
const {
1242 using namespace Hexagon;
1244 bool Is64 = DoubleRegsRegClass.contains(PReg);
1245 assert(PReg == 0 || Is64 || IntRegsRegClass.contains(PReg));
1247 static const unsigned Phys32[] = { R0, R1,
R2, R3,
R4, R5 };
1248 static const unsigned Phys64[] = { D0, D1, D2 };
1249 const unsigned Num32 =
sizeof(Phys32)/
sizeof(
unsigned);
1250 const unsigned Num64 =
sizeof(Phys64)/
sizeof(
unsigned);
1254 return (Width <= 32) ? Phys32[0] : Phys64[0];
1258 unsigned Idx32 = 0, Idx64 = 0;
1260 while (Idx32 < Num32) {
1261 if (Phys32[Idx32] == PReg)
1267 while (Idx64 < Num64) {
1268 if (Phys64[Idx64] == PReg)
1276 return (Idx32+1 < Num32) ? Phys32[Idx32+1] : 0;
1277 return (Idx64+1 < Num64) ? Phys64[Idx64+1] : 0;
1280 unsigned HexagonEvaluator::getVirtRegFor(
unsigned PReg)
const {
1281 for (std::pair<unsigned,unsigned>
P :
MRI.
liveins())
1282 if (
P.first == PReg)
RegisterCell eASL(const RegisterCell &A1, uint16_t Sh) const
This class represents an incoming formal argument to a Function.
const TargetRegisterInfo & TRI
MachineBasicBlock * getMBB() const
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
RegisterCell & fill(uint16_t B, uint16_t E, const BitValue &V)
Compute iterated dominance frontiers using a linear time algorithm.
RegisterCell eASR(const RegisterCell &A1, uint16_t Sh) const
BitTracker::RegisterRef RegisterRef
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
void putCell(const RegisterRef &RR, RegisterCell RC, CellMapType &M) const
static RegisterCell self(unsigned Reg, uint16_t Width)
BitTracker::BitMask mask(unsigned Reg, unsigned Sub) const override
const HexagonInstrInfo & TII
iterator_range< mop_iterator > operands()
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
RegisterCell eORL(const RegisterCell &A1, const RegisterCell &A2) const
HexagonEvaluator(const HexagonRegisterInfo &tri, MachineRegisterInfo &mri, const HexagonInstrInfo &tii, MachineFunction &mf)
bool evaluate(const MachineInstr &MI, const CellMapType &Inputs, CellMapType &Outputs) const override
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
const char * getRegClassName(const TargetRegisterClass *Class) const
Returns the name of the register class.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
const HexagonInstrInfo * TII
unsigned getNumOperands() const
Access to explicit operands of the instruction.
Printable printReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
BitTracker::CellMapType CellMapType
bool isIntegerTy() const
True if this is an instance of IntegerType.
This file contains the simple types necessary to represent the attributes associated with functions a...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
RegisterCell eLSR(const RegisterCell &A1, uint16_t Sh) const
unsigned getID() const
Return the register class ID number.
Type * getType() const
All values are typed, get the type of this value.
bool insert(const value_type &X)
Insert a new element into the SetVector.
RegisterCell eADD(const RegisterCell &A1, const RegisterCell &A2) const
const TargetRegisterClass & composeWithSubRegIndex(const TargetRegisterClass &RC, unsigned Idx) const override
RegisterCell eCLB(const RegisterCell &A1, bool B, uint16_t W) const
const char * getName(unsigned RegNo) const
Return the human-readable symbolic target-specific name for the specified physical register...
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
RegisterCell eSUB(const RegisterCell &A1, const RegisterCell &A2) const
RegisterCell eIMM(int64_t V, uint16_t W) const
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
The instances of the Type class are immutable: once they are created, they are never changed...
RegisterCell eNOT(const RegisterCell &A1) const
uint16_t getPhysRegBitWidth(unsigned Reg) const override
bool isPointerTy() const
True if this is an instance of PointerType.
RegisterCell eAND(const RegisterCell &A1, const RegisterCell &A2) const
RegisterCell eINS(const RegisterCell &A1, const RegisterCell &A2, uint16_t AtN) const
BitTracker::RegisterCell RegisterCell
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isPredicated(const MachineInstr &MI) const override
Returns true if the instruction is already predicated.
RegisterCell eMLS(const RegisterCell &A1, const RegisterCell &A2) const
uint16_t getRegBitWidth(const RegisterRef &RR) const
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
static BitValue self(const BitRef &Self=BitRef())
MachineOperand class - Representation of each machine instruction operand.
RegisterCell eXOR(const RegisterCell &A1, const RegisterCell &A2) const
RegisterCell eCTB(const RegisterCell &A1, bool B, uint16_t W) const
bool is(unsigned T) const
MachineRegisterInfo & MRI
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
RegisterCell getCell(const RegisterRef &RR, const CellMapType &M) const
ArrayRef< std::pair< unsigned, unsigned > > liveins() const
RegisterCell & insert(const RegisterCell &RC, const BitMask &M)
amdgpu Simplify well known AMD library false Value Value * Arg
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
RegisterCell & cat(const RegisterCell &RC)
unsigned getIntegerBitWidth() const
APFloat abs(APFloat X)
Returns the absolute value of the argument.
const TargetRegisterClass * getMinimalPhysRegClass(unsigned Reg, MVT VT=MVT::Other) const
Returns the Register Class of a physical register of the given type, picking the most sub register cl...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
RegisterCell eXTR(const RegisterCell &A1, uint16_t B, uint16_t E) const
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
RegisterCell eSXT(const RegisterCell &A1, uint16_t FromN) const
RegisterCell eMLU(const RegisterCell &A1, const RegisterCell &A2) const
A vector that has set insertion semantics.
RegisterCell eZXT(const RegisterCell &A1, uint16_t FromN) const
bool meet(const RegisterCell &RC, unsigned SelfR)
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
unsigned getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
static RegisterCell ref(const RegisterCell &C)
const MachineOperand & getOperand(unsigned i) const
iterator_range< arg_iterator > args()
static BitValue ref(const BitValue &V)