44 : MachineEvaluator(tri, mri), MF(mf), MFI(mf.getFrameInfo()),
TII(tii) {
61 unsigned InVirtReg, InPhysReg = 0;
72 if (Width == 0 || Width > 64)
74 if (
Arg.hasAttribute(Attribute::ByVal))
76 InPhysReg = getNextPhysReg(InPhysReg, Width);
79 InVirtReg = getVirtRegFor(InPhysReg);
82 if (
Arg.hasAttribute(Attribute::SExt))
83 VRX.
insert(std::make_pair(InVirtReg,
ExtType(ExtType::SExt, Width)));
84 else if (
Arg.hasAttribute(Attribute::ZExt))
85 VRX.
insert(std::make_pair(InVirtReg,
ExtType(ExtType::ZExt, Width)));
91 return MachineEvaluator::mask(Reg, 0);
98 case Hexagon::DoubleRegsRegClassID:
99 case Hexagon::HvxWRRegClassID:
100 case Hexagon::HvxVQRRegClassID:
102 : BT::BitMask(RW, 2*RW-1);
116 using namespace Hexagon;
118 if (HST.useHVXOps()) {
119 for (
auto &RC : {HvxVRRegClass, HvxWRRegClass, HvxQRRegClass,
121 if (RC.contains(Reg))
129 (
Twine(
"Unhandled physical register") +
TRI.
getName(Reg)).str().c_str());
141 assert(IsSubLo != IsSubHi &&
"Must refer to either low or high subreg");
144 switch (RC.
getID()) {
145 case Hexagon::DoubleRegsRegClassID:
146 return Hexagon::IntRegsRegClass;
147 case Hexagon::HvxWRRegClassID:
148 return Hexagon::HvxVRRegClass;
149 case Hexagon::HvxVQRRegClassID:
150 return Hexagon::HvxWRRegClass;
155 dbgs() <<
"Reg class id: " << RC.
getID() <<
" idx: " << Idx <<
'\n';
163 std::vector<BT::RegisterRef>
Vector;
167 for (
unsigned i = 0, n = Vector.size(); i < n; ++i) {
176 size_t size()
const {
return Vector.size(); }
180 assert(n < Vector.size());
190 using namespace Hexagon;
192 unsigned NumDefs = 0;
196 if (!MO.isReg() || !MO.isDef())
199 assert(MO.getSubReg() == 0);
215 return evaluateLoad(MI, Inputs, Outputs);
234 if (evaluateFormalCopy(MI, Inputs, Outputs))
245 if (MO.isGlobal() || MO.isBlockAddress() || MO.isSymbol() || MO.isJTI() ||
250 RegisterRefs
Reg(MI);
251 #define op(i) MI.getOperand(i) 252 #define rc(i) RegisterCell::ref(getCell(Reg[i], Inputs)) 253 #define im(i) MI.getOperand(i).getImm() 266 auto cop = [
this, &
Reg, &
MI, &Inputs](
unsigned N,
280 return eXTR(RC, 0, RW);
287 return eXTR(RC, W-RW, W);
293 return eXTR(RC, N*16, N*16+16);
303 RC.cat(
eXTR(Rt, I*BW, I*BW+BW)).cat(
eXTR(Rs, I*BW, I*BW+BW));
316 unsigned Reg0 = Reg[0].Reg;
325 return rr0(
eIMM(
im(1), W0), Outputs);
331 int FI =
op(1).getIndex();
332 int Off =
op(2).getImm();
337 return rr0(RC, Outputs);
345 return rr0(
rc(1), Outputs);
353 return rr0(RC, Outputs);
360 return rr0(
eINS(RC,
eXTR(
rc(1), 0, PW), 0), Outputs);
372 assert(W0 == 64 && W1 == 32);
375 return rr0(RC, Outputs);
379 return rr0(
eADD(
rc(1),
rc(2)), Outputs);
382 case S4_addi_asl_ri: {
384 return rr0(RC, Outputs);
386 case S4_addi_lsr_ri: {
388 return rr0(RC, Outputs);
392 return rr0(RC, Outputs);
394 case M4_mpyri_addi: {
397 return rr0(RC, Outputs);
399 case M4_mpyrr_addi: {
402 return rr0(RC, Outputs);
404 case M4_mpyri_addr_u2: {
407 return rr0(RC, Outputs);
409 case M4_mpyri_addr: {
412 return rr0(RC, Outputs);
414 case M4_mpyrr_addr: {
417 return rr0(RC, Outputs);
421 return rr0(RC, Outputs);
425 return rr0(RC, Outputs);
429 return rr0(RC, Outputs);
433 return rr0(RC, Outputs);
435 case S2_addasl_rrri: {
437 return rr0(RC, Outputs);
442 return rr0(
eADD(RPC,
eIMM(
im(2), W0)), Outputs);
446 return rr0(
eSUB(
rc(1),
rc(2)), Outputs);
449 case S4_subi_asl_ri: {
451 return rr0(RC, Outputs);
453 case S4_subi_lsr_ri: {
455 return rr0(RC, Outputs);
459 return rr0(RC, Outputs);
463 return rr0(RC, Outputs);
467 return rr0(
eSUB(
eIMM(0, W0),
rc(1)), Outputs);
471 return rr0(hi(M, W0), Outputs);
474 return rr0(
eMLS(
rc(1),
rc(2)), Outputs);
475 case M2_dpmpyss_acc_s0:
477 case M2_dpmpyss_nac_s0:
481 return rr0(lo(M, W0), Outputs);
486 return rr0(RC, Outputs);
491 return rr0(RC, Outputs);
496 return rr0(RC, Outputs);
500 return rr0(lo(M, 32), Outputs);
504 return rr0(lo(M, 32), Outputs);
508 return rr0(lo(M, 32), Outputs);
512 return rr0(hi(M, W0), Outputs);
515 return rr0(
eMLU(
rc(1),
rc(2)), Outputs);
516 case M2_dpmpyuu_acc_s0:
518 case M2_dpmpyuu_nac_s0:
528 return rr0(
eAND(
rc(1),
rc(2)), Outputs);
532 case S4_andi_asl_ri: {
534 return rr0(RC, Outputs);
536 case S4_andi_lsr_ri: {
538 return rr0(RC, Outputs);
552 return rr0(
eORL(
rc(1),
rc(2)), Outputs);
556 case S4_ori_asl_ri: {
558 return rr0(RC, Outputs);
560 case S4_ori_lsr_ri: {
562 return rr0(RC, Outputs);
571 return rr0(RC, Outputs);
575 return rr0(RC, Outputs);
583 return rr0(
eXOR(
rc(1),
rc(2)), Outputs);
594 return rr0(
eNOT(
rc(1)), Outputs);
598 return rr0(
eASL(
rc(1),
im(2)), Outputs);
600 return rr0(
eASL(
rc(1), 16), Outputs);
613 case S2_asl_i_r_xacc:
614 case S2_asl_i_p_xacc:
623 return rr0(
eASR(
rc(1),
im(2)), Outputs);
625 return rr0(
eASR(
rc(1), 16), Outputs);
638 case S2_asr_i_r_rnd: {
644 return rr0(
eXTR(RC, 0, W0), Outputs);
646 case S2_asr_i_r_rnd_goodsyntax: {
649 return rr0(
rc(1), Outputs);
653 return rr0(
eXTR(RC, 0, W0), Outputs);
657 case S2_asr_i_svw_trun:
663 return rr0(
eLSR(
rc(1),
im(2)), Outputs);
676 case S2_lsr_i_r_xacc:
677 case S2_lsr_i_p_xacc:
683 return rr0(RC, Outputs);
688 return rr0(RC, Outputs);
690 case S2_togglebit_i: {
696 return rr0(RC, Outputs);
705 .
fill(W1+(W1-BX), W0, Zero);
708 return rr0(RC, Outputs);
717 return rr0(
eIMM(0, W0), Outputs);
724 if (Opc == S2_extractu || Opc == S2_extractup)
725 return rr0(
eZXT(RC, Wd), Outputs);
726 return rr0(
eSXT(RC, Wd), Outputs);
731 assert(Wd < W0 && Of < W0);
736 return rr0(
rc(1), Outputs);
737 return rr0(
eINS(
rc(1),
eXTR(
rc(2), 0, Wd), Of), Outputs);
749 return rr0(cop(2, W0/2).cat(cop(1, W0/2)), Outputs);
753 case A2_combine_hh: {
757 unsigned LoH = !(Opc == A2_combine_ll || Opc == A2_combine_hl);
759 unsigned HiH = !(Opc == A2_combine_ll || Opc == A2_combine_lh);
763 return rr0(RC, Outputs);
772 return rr0(RC, Outputs);
776 return rr0(RC, Outputs);
780 return rr0(RC, Outputs);
784 return rr0(RC, Outputs);
788 return rr0(RC, Outputs);
793 assert(WR == 64 && WP == 8);
799 RC.
fill(i*8, i*8+8, F);
801 return rr0(RC, Outputs);
813 if (PC0.
is(0) || PC0.
is(1))
815 R2.
meet(R3, Reg[0].Reg);
816 return rr0(R2, Outputs);
825 return rr0(
eSXT(
rc(1), 8), Outputs);
827 return rr0(
eSXT(
rc(1), 16), Outputs);
830 assert(W0 == 64 && W1 == 32);
832 return rr0(RC, Outputs);
835 return rr0(
eZXT(
rc(1), 8), Outputs);
837 return rr0(
eZXT(
rc(1), 16), Outputs);
855 return rr0(
eCLB(
rc(1),
false, 32), Outputs);
858 return rr0(
eCLB(
rc(1),
true, 32), Outputs);
864 if (TV.
is(0) || TV.
is(1))
865 return rr0(
eCLB(R1, TV, 32), Outputs);
870 return rr0(
eCTB(
rc(1),
false, 32), Outputs);
873 return rr0(
eCTB(
rc(1),
true, 32), Outputs);
880 bool Has0 =
false, All1 =
true;
893 return rr0(RC, Outputs);
897 bool Has1 =
false, All0 =
true;
910 return rr0(RC, Outputs);
913 return rr0(
eAND(
rc(1),
rc(2)), Outputs);
917 return rr0(
eNOT(
rc(1)), Outputs);
919 return rr0(
eORL(
rc(1),
rc(2)), Outputs);
923 return rr0(
eXOR(
rc(1),
rc(2)), Outputs);
951 if (V.
is(0) || V.
is(1)) {
953 bool TV = (Opc == S2_tstbit_i);
963 if (
unsigned DefR = getUniqueDefVReg(MI)) {
974 return MachineEvaluator::evaluate(MI, Inputs, Outputs);
985 bool &FallsThru)
const {
989 bool SimpleBranch =
false;
990 bool Negated =
false;
992 case Hexagon::J2_jumpf:
993 case Hexagon::J2_jumpfpt:
994 case Hexagon::J2_jumpfnew:
995 case Hexagon::J2_jumpfnewpt:
998 case Hexagon::J2_jumpt:
999 case Hexagon::J2_jumptpt:
1000 case Hexagon::J2_jumptnew:
1001 case Hexagon::J2_jumptnewpt:
1004 SimpleBranch =
true;
1006 case Hexagon::J2_jump:
1025 if (!Test.
is(0) && !Test.
is(1))
1029 if (!Test.
is(!Negated)) {
1040 unsigned HexagonEvaluator::getUniqueDefVReg(
const MachineInstr &
MI)
const {
1041 unsigned DefReg = 0;
1043 if (!
Op.isReg() || !
Op.isDef())
1055 bool HexagonEvaluator::evaluateLoad(
const MachineInstr &MI,
1058 using namespace Hexagon;
1074 case L2_loadalignb_pbr:
1075 case L2_loadalignb_pcr:
1076 case L2_loadalignb_pi:
1078 case L2_loadalignh_pbr:
1079 case L2_loadalignh_pcr:
1080 case L2_loadalignh_pi:
1082 case L2_loadbsw2_pbr:
1083 case L2_loadbsw2_pci:
1084 case L2_loadbsw2_pcr:
1085 case L2_loadbsw2_pi:
1086 case L2_loadbsw4_pbr:
1087 case L2_loadbsw4_pci:
1088 case L2_loadbsw4_pcr:
1089 case L2_loadbsw4_pi:
1091 case L2_loadbzw2_pbr:
1092 case L2_loadbzw2_pci:
1093 case L2_loadbzw2_pcr:
1094 case L2_loadbzw2_pi:
1095 case L2_loadbzw4_pbr:
1096 case L2_loadbzw4_pci:
1097 case L2_loadbzw4_pcr:
1098 case L2_loadbzw4_pi:
1117 case L2_loadrub_pbr:
1118 case L2_loadrub_pci:
1119 case L2_loadrub_pcr:
1145 case L2_loadruh_pbr:
1146 case L2_loadruh_pci:
1147 case L2_loadruh_pcr:
1163 case L2_loadw_locked:
1179 case L4_loadd_locked:
1194 assert(W >= BitNum && BitNum > 0);
1197 for (
uint16_t i = 0; i < BitNum; ++i)
1213 bool HexagonEvaluator::evaluateFormalCopy(
const MachineInstr &MI,
1238 if (F->second.Type == ExtType::SExt)
1240 else if (F->second.Type == ExtType::ZExt)
1247 unsigned HexagonEvaluator::getNextPhysReg(
unsigned PReg,
unsigned Width)
const {
1248 using namespace Hexagon;
1250 bool Is64 = DoubleRegsRegClass.contains(PReg);
1251 assert(PReg == 0 || Is64 || IntRegsRegClass.contains(PReg));
1253 static const unsigned Phys32[] = { R0, R1,
R2, R3,
R4, R5 };
1254 static const unsigned Phys64[] = { D0, D1, D2 };
1255 const unsigned Num32 =
sizeof(Phys32)/
sizeof(
unsigned);
1256 const unsigned Num64 =
sizeof(Phys64)/
sizeof(
unsigned);
1260 return (Width <= 32) ? Phys32[0] : Phys64[0];
1264 unsigned Idx32 = 0, Idx64 = 0;
1266 while (Idx32 < Num32) {
1267 if (Phys32[Idx32] == PReg)
1273 while (Idx64 < Num64) {
1274 if (Phys64[Idx64] == PReg)
1282 return (Idx32+1 < Num32) ? Phys32[Idx32+1] : 0;
1283 return (Idx64+1 < Num64) ? Phys64[Idx64+1] : 0;
1286 unsigned HexagonEvaluator::getVirtRegFor(
unsigned PReg)
const {
1287 for (std::pair<unsigned,unsigned>
P :
MRI.
liveins())
1288 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
RegisterCell & fill(uint16_t B, uint16_t E, const BitValue &V)
This class represents lattice values for constants.
RegisterCell eASR(const RegisterCell &A1, uint16_t Sh) const
BitTracker::RegisterRef RegisterRef
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical 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
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
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
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
unsigned 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...
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
Retuns the total number of operands.
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.
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
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
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
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
const char * getName(MCRegister RegNo) const
Return the human-readable symbolic target-specific name for the specified physical register...
ArrayRef< std::pair< unsigned, unsigned > > liveins() const
RegisterCell & insert(const RegisterCell &RC, const BitMask &M)
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.
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.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
RegisterCell eZXT(const RegisterCell &A1, uint16_t FromN) const
bool meet(const RegisterCell &RC, unsigned SelfR)
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()
Wrapper class representing virtual and physical registers.
static BitValue ref(const BitValue &V)