42 : MachineEvaluator(tri, mri), MF(mf), MFI(mf.getFrameInfo()),
TII(tii) {
59 unsigned InVirtReg, InPhysReg = 0;
62 Type *ATy = Arg.getType();
70 if (Width == 0 || Width > 64)
72 if (Arg.hasAttribute(Attribute::ByVal))
74 InPhysReg = getNextPhysReg(InPhysReg, Width);
77 InVirtReg = getVirtRegFor(InPhysReg);
80 if (Arg.hasAttribute(Attribute::SExt))
81 VRX.
insert(std::make_pair(InVirtReg, ExtType(ExtType::SExt, Width)));
82 else if (Arg.hasAttribute(Attribute::ZExt))
83 VRX.
insert(std::make_pair(InVirtReg, ExtType(ExtType::ZExt, Width)));
89 return MachineEvaluator::mask(Reg, 0);
96 case Hexagon::DoubleRegsRegClassID:
97 case Hexagon::HvxWRRegClassID:
98 case Hexagon::HvxVQRRegClassID:
112 using namespace Hexagon;
114 if (HST.useHVXOps()) {
115 for (
auto &RC : {HvxVRRegClass, HvxWRRegClass, HvxQRRegClass,
117 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;
145 case Hexagon::HvxVQRRegClassID:
146 return Hexagon::HvxWRRegClass;
151 dbgs() <<
"Reg class id: " << RC.
getID() <<
" idx: " <<
Idx <<
'\n';
159 std::vector<BT::RegisterRef>
Vector;
163 for (
unsigned i = 0, n =
Vector.size(); i < n; ++i) {
186 using namespace Hexagon;
188 unsigned NumDefs = 0;
192 if (!MO.isReg() || !MO.isDef())
195 assert(MO.getSubReg() == 0);
201 unsigned Opc =
MI.getOpcode();
211 return evaluateLoad(
MI, Inputs, Outputs);
230 if (evaluateFormalCopy(
MI, Inputs, Outputs))
241 if (MO.isGlobal() || MO.isBlockAddress() || MO.isSymbol() || MO.isJTI() ||
246 RegisterRefs Reg(
MI);
247#define op(i) MI.getOperand(i)
248#define rc(i) RegisterCell::ref(getCell(Reg[i], Inputs))
249#define im(i) MI.getOperand(i).getImm()
262 auto cop = [
this, &Reg, &
MI, &Inputs](
unsigned N,
266 return eIMM(
Op.getImm(), W);
276 return eXTR(RC, 0, RW);
283 return eXTR(RC, W-RW, W);
289 return eXTR(RC,
N*16,
N*16+16);
312 unsigned Reg0 = Reg[0].Reg;
321 return rr0(
eIMM(
im(1), W0), Outputs);
323 return rr0(
RegisterCell(W0).fill(0, W0, BT::BitValue::Zero), Outputs);
325 return rr0(
RegisterCell(W0).fill(0, W0, BT::BitValue::One), Outputs);
327 int FI =
op(1).getIndex();
328 int Off =
op(2).getImm();
332 RC.
fill(0, L, BT::BitValue::Zero);
333 return rr0(RC, Outputs);
341 return rr0(
rc(1), Outputs);
348 RC.
fill(PW, RW, BT::BitValue::Zero);
349 return rr0(RC, Outputs);
355 RC.
fill(PW, RW, BT::BitValue::Zero);
356 return rr0(
eINS(RC,
eXTR(
rc(1), 0, PW), 0), Outputs);
368 assert(W0 == 64 && W1 == 32);
371 return rr0(RC, Outputs);
375 return rr0(
eADD(
rc(1),
rc(2)), Outputs);
378 case S4_addi_asl_ri: {
380 return rr0(RC, Outputs);
382 case S4_addi_lsr_ri: {
384 return rr0(RC, Outputs);
388 return rr0(RC, Outputs);
390 case M4_mpyri_addi: {
393 return rr0(RC, Outputs);
395 case M4_mpyrr_addi: {
398 return rr0(RC, Outputs);
400 case M4_mpyri_addr_u2: {
403 return rr0(RC, Outputs);
405 case M4_mpyri_addr: {
408 return rr0(RC, Outputs);
410 case M4_mpyrr_addr: {
413 return rr0(RC, Outputs);
417 return rr0(RC, Outputs);
421 return rr0(RC, Outputs);
425 return rr0(RC, Outputs);
429 return rr0(RC, Outputs);
431 case S2_addasl_rrri: {
433 return rr0(RC, Outputs);
437 RPC.
fill(0, 2, BT::BitValue::Zero);
438 return rr0(
eADD(RPC,
eIMM(
im(2), W0)), Outputs);
442 return rr0(
eSUB(
rc(1),
rc(2)), Outputs);
445 case S4_subi_asl_ri: {
447 return rr0(RC, Outputs);
449 case S4_subi_lsr_ri: {
451 return rr0(RC, Outputs);
455 return rr0(RC, Outputs);
459 return rr0(RC, Outputs);
463 return rr0(
eSUB(
eIMM(0, W0),
rc(1)), Outputs);
467 return rr0(hi(M, W0), Outputs);
470 return rr0(
eMLS(
rc(1),
rc(2)), Outputs);
471 case M2_dpmpyss_acc_s0:
473 case M2_dpmpyss_nac_s0:
477 return rr0(lo(M, W0), Outputs);
482 return rr0(RC, Outputs);
487 return rr0(RC, Outputs);
492 return rr0(RC, Outputs);
497 return rr0(RC, Outputs);
501 return rr0(lo(M, 32), Outputs);
505 return rr0(lo(M, 32), Outputs);
509 return rr0(lo(M, 32), Outputs);
513 return rr0(hi(M, W0), Outputs);
516 return rr0(
eMLU(
rc(1),
rc(2)), Outputs);
517 case M2_dpmpyuu_acc_s0:
519 case M2_dpmpyuu_nac_s0:
529 return rr0(
eAND(
rc(1),
rc(2)), Outputs);
533 case S4_andi_asl_ri: {
535 return rr0(RC, Outputs);
537 case S4_andi_lsr_ri: {
539 return rr0(RC, Outputs);
553 return rr0(
eORL(
rc(1),
rc(2)), Outputs);
557 case S4_ori_asl_ri: {
559 return rr0(RC, Outputs);
561 case S4_ori_lsr_ri: {
563 return rr0(RC, Outputs);
572 return rr0(RC, Outputs);
576 return rr0(RC, Outputs);
584 return rr0(
eXOR(
rc(1),
rc(2)), Outputs);
595 return rr0(
eNOT(
rc(1)), Outputs);
599 return rr0(
eASL(
rc(1),
im(2)), Outputs);
601 return rr0(
eASL(
rc(1), 16), Outputs);
614 case S2_asl_i_r_xacc:
615 case S2_asl_i_p_xacc:
624 return rr0(
eASR(
rc(1),
im(2)), Outputs);
626 return rr0(
eASR(
rc(1), 16), Outputs);
639 case S2_asr_i_r_rnd: {
645 return rr0(
eXTR(RC, 0, W0), Outputs);
647 case S2_asr_i_r_rnd_goodsyntax: {
650 return rr0(
rc(1), Outputs);
654 return rr0(
eXTR(RC, 0, W0), Outputs);
658 case S2_asr_i_svw_trun:
664 return rr0(
eLSR(
rc(1),
im(2)), Outputs);
677 case S2_lsr_i_r_xacc:
678 case S2_lsr_i_p_xacc:
683 RC[
im(2)] = BT::BitValue::Zero;
684 return rr0(RC, Outputs);
688 RC[
im(2)] = BT::BitValue::One;
689 return rr0(RC, Outputs);
691 case S2_togglebit_i: {
694 RC[BX] = RC[BX].is(0) ? BT::BitValue::One
695 : RC[BX].is(1) ? BT::BitValue::Zero
696 : BT::BitValue::self();
697 return rr0(RC, Outputs);
706 .
fill(W1+(W1-BX), W0, Zero);
709 return rr0(RC, Outputs);
718 return rr0(
eIMM(0, W0), Outputs);
725 if (Opc == S2_extractu || Opc == S2_extractup)
726 return rr0(
eZXT(RC,
Wd), Outputs);
727 return rr0(
eSXT(RC,
Wd), Outputs);
737 return rr0(
rc(1), Outputs);
750 return rr0(cop(2, W0/2).cat(cop(1, W0/2)), Outputs);
754 case A2_combine_hh: {
758 unsigned LoH = !(Opc == A2_combine_ll || Opc == A2_combine_hl);
760 unsigned HiH = !(Opc == A2_combine_ll || Opc == A2_combine_lh);
764 return rr0(RC, Outputs);
773 return rr0(RC, Outputs);
777 return rr0(RC, Outputs);
781 return rr0(RC, Outputs);
785 return rr0(RC, Outputs);
789 return rr0(RC, Outputs);
794 assert(WR == 64 && WP == 8);
799 BT::BitValue F = (V.is(0) || V.is(1)) ? V : BT::BitValue::self();
800 RC.
fill(i*8, i*8+8,
F);
802 return rr0(RC, Outputs);
814 if (PC0.
is(0) || PC0.
is(1))
816 R2.meet(R3, Reg[0].Reg);
817 return rr0(
R2, Outputs);
826 return rr0(
eSXT(
rc(1), 8), Outputs);
828 return rr0(
eSXT(
rc(1), 16), Outputs);
831 assert(W0 == 64 && W1 == 32);
833 return rr0(RC, Outputs);
836 return rr0(
eZXT(
rc(1), 8), Outputs);
838 return rr0(
eZXT(
rc(1), 16), Outputs);
856 return rr0(
eCLB(
rc(1),
false, 32), Outputs);
859 return rr0(
eCLB(
rc(1),
true, 32), Outputs);
865 if (TV.
is(0) || TV.
is(1))
866 return rr0(
eCLB(R1, TV, 32), Outputs);
871 return rr0(
eCTB(
rc(1),
false, 32), Outputs);
874 return rr0(
eCTB(
rc(1),
true, 32), Outputs);
881 bool Has0 =
false, All1 =
true;
893 RC.
fill(0, W0, (All1 ? BT::BitValue::One : BT::BitValue::Zero));
894 return rr0(RC, Outputs);
898 bool Has1 =
false, All0 =
true;
910 RC.
fill(0, W0, (Has1 ? BT::BitValue::One : BT::BitValue::Zero));
911 return rr0(RC, Outputs);
914 return rr0(
eAND(
rc(1),
rc(2)), Outputs);
918 return rr0(
eNOT(
rc(1)), Outputs);
920 return rr0(
eORL(
rc(1),
rc(2)), Outputs);
924 return rr0(
eXOR(
rc(1),
rc(2)), Outputs);
952 if (V.is(0) || V.is(1)) {
954 bool TV = (Opc == S2_tstbit_i);
955 BT::BitValue F = V.is(TV) ? BT::BitValue::One : BT::BitValue::Zero;
964 if (
unsigned DefR = getUniqueDefVReg(
MI)) {
970 RC.
fill(PW, RW, BT::BitValue::Zero);
975 return MachineEvaluator::evaluate(
MI, Inputs, Outputs);
986 bool &FallsThru)
const {
990 bool SimpleBranch =
false;
991 bool Negated =
false;
993 case Hexagon::J2_jumpf:
994 case Hexagon::J2_jumpfpt:
995 case Hexagon::J2_jumpfnew:
996 case Hexagon::J2_jumpfnewpt:
999 case Hexagon::J2_jumpt:
1000 case Hexagon::J2_jumptpt:
1001 case Hexagon::J2_jumptnew:
1002 case Hexagon::J2_jumptnewpt:
1005 SimpleBranch =
true;
1007 case Hexagon::J2_jump:
1030 if (!
Test.is(!Negated)) {
1041unsigned HexagonEvaluator::getUniqueDefVReg(
const MachineInstr &
MI)
const {
1042 unsigned DefReg = 0;
1044 if (!
Op.isReg() || !
Op.isDef())
1057 const CellMapType &Inputs,
1058 CellMapType &Outputs)
const {
1059 using namespace Hexagon;
1063 assert(
MI.mayLoad() &&
"A load that mayn't?");
1064 unsigned Opc =
MI.getOpcode();
1075 case L2_loadalignb_pbr:
1076 case L2_loadalignb_pcr:
1077 case L2_loadalignb_pi:
1079 case L2_loadalignh_pbr:
1080 case L2_loadalignh_pcr:
1081 case L2_loadalignh_pi:
1083 case L2_loadbsw2_pbr:
1084 case L2_loadbsw2_pci:
1085 case L2_loadbsw2_pcr:
1086 case L2_loadbsw2_pi:
1087 case L2_loadbsw4_pbr:
1088 case L2_loadbsw4_pci:
1089 case L2_loadbsw4_pcr:
1090 case L2_loadbsw4_pi:
1092 case L2_loadbzw2_pbr:
1093 case L2_loadbzw2_pci:
1094 case L2_loadbzw2_pcr:
1095 case L2_loadbzw2_pi:
1096 case L2_loadbzw4_pbr:
1097 case L2_loadbzw4_pci:
1098 case L2_loadbzw4_pcr:
1099 case L2_loadbzw4_pi:
1118 case L2_loadrub_pbr:
1119 case L2_loadrub_pci:
1120 case L2_loadrub_pcr:
1146 case L2_loadruh_pbr:
1147 case L2_loadruh_pci:
1148 case L2_loadruh_pcr:
1164 case L2_loadw_locked:
1180 case L4_loadd_locked:
1195 assert(W >= BitNum && BitNum > 0);
1198 for (
uint16_t i = 0; i < BitNum; ++i)
1199 Res[i] = BT::BitValue::self(
BT::BitRef(RD.Reg, i));
1204 Res[i] = BT::BitValue::ref(Sign);
1207 Res[i] = BT::BitValue::Zero;
1215 const CellMapType &Inputs,
1216 CellMapType &Outputs)
const {
1224 if (!RS.Reg.isPhysical())
1239 if (
F->second.Type == ExtType::SExt)
1241 else if (
F->second.Type == ExtType::ZExt)
1248unsigned HexagonEvaluator::getNextPhysReg(
unsigned PReg,
unsigned Width)
const {
1249 using namespace Hexagon;
1251 bool Is64 = DoubleRegsRegClass.contains(PReg);
1252 assert(PReg == 0 || Is64 || IntRegsRegClass.contains(PReg));
1254 static const unsigned Phys32[] = { R0, R1,
R2, R3,
R4, R5 };
1255 static const unsigned Phys64[] = { D0, D1, D2 };
1256 const unsigned Num32 =
sizeof(Phys32)/
sizeof(
unsigned);
1257 const unsigned Num64 =
sizeof(Phys64)/
sizeof(
unsigned);
1261 return (Width <= 32) ? Phys32[0] : Phys64[0];
1265 unsigned Idx32 = 0, Idx64 = 0;
1267 while (Idx32 < Num32) {
1268 if (Phys32[Idx32] == PReg)
1274 while (Idx64 < Num64) {
1275 if (Phys64[Idx64] == PReg)
1283 return (Idx32+1 < Num32) ? Phys32[Idx32+1] : 0;
1284 return (Idx64+1 < Num64) ? Phys64[Idx64+1] : 0;
1287unsigned HexagonEvaluator::getVirtRegFor(
unsigned PReg)
const {
1288 for (std::pair<MCRegister, Register>
P :
MRI.
liveins())
1289 if (
P.first == PReg)
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
const HexagonInstrInfo * TII
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
support::ulittle32_t & Wd
This class represents an incoming formal argument to a Function.
This class represents an Operation in the Expression.
iterator find(const_arg_type_t< KeyT > Val)
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
iterator_range< arg_iterator > args()
bool isPredicated(const MachineInstr &MI) const override
Returns true if the instruction is already predicated.
const char * getName(MCRegister RegNo) const
Return the human-readable symbolic target-specific name for the specified physical register.
Wrapper class representing physical registers. Should be passed by value.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
ArrayRef< std::pair< MCRegister, Register > > liveins() const
Wrapper class representing virtual and physical registers.
A vector that has set insertion semantics.
bool insert(const value_type &X)
Insert a new element into the SetVector.
unsigned getID() const
Return the register class ID number.
const TargetRegisterClass * getMinimalPhysRegClass(MCRegister Reg, MVT VT=MVT::Other) const
Returns the Register Class of a physical register of the given type, picking the most sub register cl...
TypeSize getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
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...
The instances of the Type class are immutable: once they are created, they are never changed.
unsigned getIntegerBitWidth() const
bool isPointerTy() const
True if this is an instance of PointerType.
bool isIntegerTy() const
True if this is an instance of IntegerType.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
void shuffle(Iterator first, Iterator last, RNG &&g)
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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.
uint64_t value() const
This is a hole in the type system and should not be abused.
bool is(unsigned T) const
RegisterCell eXOR(const RegisterCell &A1, const RegisterCell &A2) const
const TargetRegisterInfo & TRI
RegisterCell eNOT(const RegisterCell &A1) const
RegisterCell eIMM(int64_t V, uint16_t W) const
RegisterCell eLSR(const RegisterCell &A1, uint16_t Sh) const
RegisterCell eMLU(const RegisterCell &A1, const RegisterCell &A2) const
RegisterCell eZXT(const RegisterCell &A1, uint16_t FromN) const
RegisterCell eMLS(const RegisterCell &A1, const RegisterCell &A2) const
uint16_t getRegBitWidth(const RegisterRef &RR) const
RegisterCell eCLB(const RegisterCell &A1, bool B, uint16_t W) const
MachineRegisterInfo & MRI
RegisterCell eASR(const RegisterCell &A1, uint16_t Sh) const
RegisterCell eASL(const RegisterCell &A1, uint16_t Sh) const
void putCell(const RegisterRef &RR, RegisterCell RC, CellMapType &M) const
RegisterCell eCTB(const RegisterCell &A1, bool B, uint16_t W) const
RegisterCell getCell(const RegisterRef &RR, const CellMapType &M) const
RegisterCell eAND(const RegisterCell &A1, const RegisterCell &A2) const
RegisterCell eORL(const RegisterCell &A1, const RegisterCell &A2) const
RegisterCell eSXT(const RegisterCell &A1, uint16_t FromN) const
RegisterCell eINS(const RegisterCell &A1, const RegisterCell &A2, uint16_t AtN) const
RegisterCell eADD(const RegisterCell &A1, const RegisterCell &A2) const
RegisterCell eSUB(const RegisterCell &A1, const RegisterCell &A2) const
RegisterCell eXTR(const RegisterCell &A1, uint16_t B, uint16_t E) const
RegisterCell & cat(const RegisterCell &RC)
static RegisterCell self(unsigned Reg, uint16_t Width)
static RegisterCell ref(const RegisterCell &C)
RegisterCell & fill(uint16_t B, uint16_t E, const BitValue &V)
RegisterCell & insert(const RegisterCell &RC, const BitMask &M)
BitTracker::BitMask mask(Register Reg, unsigned Sub) const override
uint16_t getPhysRegBitWidth(MCRegister Reg) const override
bool evaluate(const MachineInstr &MI, const CellMapType &Inputs, CellMapType &Outputs) const override
HexagonEvaluator(const HexagonRegisterInfo &tri, MachineRegisterInfo &mri, const HexagonInstrInfo &tii, MachineFunction &mf)
BitTracker::RegisterCell RegisterCell
const HexagonInstrInfo & TII
const TargetRegisterClass & composeWithSubRegIndex(const TargetRegisterClass &RC, unsigned Idx) const override
BitTracker::CellMapType CellMapType
BitTracker::RegisterRef RegisterRef