34 : MachineEvaluator(tri, mri), MF(mf), MFI(mf.getFrameInfo()),
TII(tii) {
51 unsigned InVirtReg, InPhysReg = 0;
54 Type *ATy = Arg.getType();
62 if (Width == 0 || Width > 64)
64 if (Arg.hasAttribute(Attribute::ByVal))
66 InPhysReg = getNextPhysReg(InPhysReg, Width);
69 InVirtReg = getVirtRegFor(InPhysReg);
72 if (Arg.hasAttribute(Attribute::SExt))
73 VRX.
insert(std::make_pair(InVirtReg, ExtType(ExtType::SExt, Width)));
74 else if (Arg.hasAttribute(Attribute::ZExt))
75 VRX.
insert(std::make_pair(InVirtReg, ExtType(ExtType::ZExt, Width)));
81 return MachineEvaluator::mask(Reg, 0);
88 case Hexagon::DoubleRegsRegClassID:
89 case Hexagon::DoubleRegs_with_isub_hi_in_IntRegsLow8RegClassID:
90 case Hexagon::HvxWRRegClassID:
91 case Hexagon::HvxVQRRegClassID:
105 using namespace Hexagon;
107 if (HST.useHVXOps()) {
108 for (
auto &RC : {HvxVRRegClass, HvxWRRegClass, HvxQRRegClass,
110 if (RC.contains(Reg))
118 (
Twine(
"Unhandled physical register") +
TRI.
getName(Reg)).str().c_str());
130 assert(IsSubLo != IsSubHi &&
"Must refer to either low or high subreg");
133 switch (RC.
getID()) {
134 case Hexagon::DoubleRegsRegClassID:
135 case Hexagon::DoubleRegs_with_isub_hi_in_IntRegsLow8RegClassID:
136 return Hexagon::IntRegsRegClass;
137 case Hexagon::HvxWRRegClassID:
138 return Hexagon::HvxVRRegClass;
139 case Hexagon::HvxVQRRegClassID:
140 return Hexagon::HvxWRRegClass;
145 dbgs() <<
"Reg class id: " << RC.
getID() <<
" idx: " <<
Idx <<
'\n';
153 std::vector<BT::RegisterRef>
Vector;
157 for (
unsigned i = 0, n =
Vector.size(); i < n; ++i) {
180 using namespace Hexagon;
182 unsigned NumDefs = 0;
186 if (!MO.isReg() || !MO.isDef())
189 assert(MO.getSubReg() == 0);
195 unsigned Opc =
MI.getOpcode();
205 return evaluateLoad(
MI, Inputs, Outputs);
224 if (evaluateFormalCopy(
MI, Inputs, Outputs))
235 if (MO.isGlobal() || MO.isBlockAddress() || MO.isSymbol() || MO.isJTI() ||
240 RegisterRefs Reg(
MI);
241#define op(i) MI.getOperand(i)
242#define rc(i) RegisterCell::ref(getCell(Reg[i], Inputs))
243#define im(i) MI.getOperand(i).getImm()
256 auto cop = [
this, &Reg, &
MI, &Inputs](
unsigned N,
260 return eIMM(
Op.getImm(), W);
270 return eXTR(RC, 0, RW);
277 return eXTR(RC, W-RW, W);
283 return eXTR(RC,
N*16,
N*16+16);
306 unsigned Reg0 = Reg[0].Reg;
315 return rr0(
eIMM(
im(1), W0), Outputs);
321 int FI =
op(1).getIndex();
322 int Off =
op(2).getImm();
326 RC.
fill(0, L, BT::BitValue::Zero);
327 return rr0(RC, Outputs);
335 return rr0(
rc(1), Outputs);
342 RC.
fill(PW, RW, BT::BitValue::Zero);
343 return rr0(RC, Outputs);
349 RC.
fill(PW, RW, BT::BitValue::Zero);
350 return rr0(
eINS(RC,
eXTR(
rc(1), 0, PW), 0), Outputs);
362 assert(W0 == 64 && W1 == 32);
365 return rr0(RC, Outputs);
369 return rr0(
eADD(
rc(1),
rc(2)), Outputs);
372 case S4_addi_asl_ri: {
374 return rr0(RC, Outputs);
376 case S4_addi_lsr_ri: {
378 return rr0(RC, Outputs);
382 return rr0(RC, Outputs);
384 case M4_mpyri_addi: {
387 return rr0(RC, Outputs);
389 case M4_mpyrr_addi: {
392 return rr0(RC, Outputs);
394 case M4_mpyri_addr_u2: {
397 return rr0(RC, Outputs);
399 case M4_mpyri_addr: {
402 return rr0(RC, Outputs);
404 case M4_mpyrr_addr: {
407 return rr0(RC, Outputs);
411 return rr0(RC, Outputs);
415 return rr0(RC, Outputs);
419 return rr0(RC, Outputs);
423 return rr0(RC, Outputs);
425 case S2_addasl_rrri: {
427 return rr0(RC, Outputs);
431 RPC.
fill(0, 2, BT::BitValue::Zero);
432 return rr0(
eADD(RPC,
eIMM(
im(2), W0)), Outputs);
436 return rr0(
eSUB(
rc(1),
rc(2)), Outputs);
439 case S4_subi_asl_ri: {
441 return rr0(RC, Outputs);
443 case S4_subi_lsr_ri: {
445 return rr0(RC, Outputs);
449 return rr0(RC, Outputs);
453 return rr0(RC, Outputs);
457 return rr0(
eSUB(
eIMM(0, W0),
rc(1)), Outputs);
461 return rr0(hi(M, W0), Outputs);
464 return rr0(
eMLS(
rc(1),
rc(2)), Outputs);
465 case M2_dpmpyss_acc_s0:
467 case M2_dpmpyss_nac_s0:
471 return rr0(lo(M, W0), Outputs);
476 return rr0(RC, Outputs);
481 return rr0(RC, Outputs);
486 return rr0(RC, Outputs);
491 return rr0(RC, Outputs);
495 return rr0(lo(M, 32), Outputs);
499 return rr0(lo(M, 32), Outputs);
503 return rr0(lo(M, 32), Outputs);
507 return rr0(hi(M, W0), Outputs);
510 return rr0(
eMLU(
rc(1),
rc(2)), Outputs);
511 case M2_dpmpyuu_acc_s0:
513 case M2_dpmpyuu_nac_s0:
523 return rr0(
eAND(
rc(1),
rc(2)), Outputs);
527 case S4_andi_asl_ri: {
529 return rr0(RC, Outputs);
531 case S4_andi_lsr_ri: {
533 return rr0(RC, Outputs);
547 return rr0(
eORL(
rc(1),
rc(2)), Outputs);
551 case S4_ori_asl_ri: {
553 return rr0(RC, Outputs);
555 case S4_ori_lsr_ri: {
557 return rr0(RC, Outputs);
566 return rr0(RC, Outputs);
570 return rr0(RC, Outputs);
578 return rr0(
eXOR(
rc(1),
rc(2)), Outputs);
589 return rr0(
eNOT(
rc(1)), Outputs);
593 return rr0(
eASL(
rc(1),
im(2)), Outputs);
595 return rr0(
eASL(
rc(1), 16), Outputs);
608 case S2_asl_i_r_xacc:
609 case S2_asl_i_p_xacc:
618 return rr0(
eASR(
rc(1),
im(2)), Outputs);
620 return rr0(
eASR(
rc(1), 16), Outputs);
633 case S2_asr_i_r_rnd: {
639 return rr0(
eXTR(RC, 0, W0), Outputs);
641 case S2_asr_i_r_rnd_goodsyntax: {
644 return rr0(
rc(1), Outputs);
648 return rr0(
eXTR(RC, 0, W0), Outputs);
652 case S2_asr_i_svw_trun:
658 return rr0(
eLSR(
rc(1),
im(2)), Outputs);
671 case S2_lsr_i_r_xacc:
672 case S2_lsr_i_p_xacc:
677 RC[
im(2)] = BT::BitValue::Zero;
678 return rr0(RC, Outputs);
682 RC[
im(2)] = BT::BitValue::One;
683 return rr0(RC, Outputs);
685 case S2_togglebit_i: {
688 RC[BX] = RC[BX].is(0) ? BT::BitValue::One
689 : RC[BX].is(1) ? BT::BitValue::Zero
690 : BT::BitValue::self();
691 return rr0(RC, Outputs);
700 .
fill(W1+(W1-BX), W0, Zero);
703 return rr0(RC, Outputs);
712 return rr0(
eIMM(0, W0), Outputs);
719 if (
Opc == S2_extractu ||
Opc == S2_extractup)
720 return rr0(
eZXT(RC,
Wd), Outputs);
721 return rr0(
eSXT(RC,
Wd), Outputs);
731 return rr0(
rc(1), Outputs);
744 return rr0(cop(2, W0/2).cat(cop(1, W0/2)), Outputs);
748 case A2_combine_hh: {
752 unsigned LoH = !(
Opc == A2_combine_ll ||
Opc == A2_combine_hl);
754 unsigned HiH = !(
Opc == A2_combine_ll ||
Opc == A2_combine_lh);
758 return rr0(RC, Outputs);
767 return rr0(RC, Outputs);
771 return rr0(RC, Outputs);
775 return rr0(RC, Outputs);
779 return rr0(RC, Outputs);
783 return rr0(RC, Outputs);
788 assert(WR == 64 && WP == 8);
793 BT::BitValue F = (V.is(0) || V.is(1)) ? V : BT::BitValue::self();
794 RC.
fill(i*8, i*8+8,
F);
796 return rr0(RC, Outputs);
808 if (PC0.
is(0) || PC0.
is(1))
810 R2.meet(R3, Reg[0].Reg);
811 return rr0(
R2, Outputs);
820 return rr0(
eSXT(
rc(1), 8), Outputs);
822 return rr0(
eSXT(
rc(1), 16), Outputs);
825 assert(W0 == 64 && W1 == 32);
827 return rr0(RC, Outputs);
830 return rr0(
eZXT(
rc(1), 8), Outputs);
832 return rr0(
eZXT(
rc(1), 16), Outputs);
850 return rr0(
eCLB(
rc(1),
false, 32), Outputs);
853 return rr0(
eCLB(
rc(1),
true, 32), Outputs);
859 if (TV.
is(0) || TV.
is(1))
860 return rr0(
eCLB(R1, TV, 32), Outputs);
865 return rr0(
eCTB(
rc(1),
false, 32), Outputs);
868 return rr0(
eCTB(
rc(1),
true, 32), Outputs);
875 bool Has0 =
false, All1 =
true;
887 RC.
fill(0, W0, (All1 ? BT::BitValue::One : BT::BitValue::Zero));
888 return rr0(RC, Outputs);
892 bool Has1 =
false, All0 =
true;
904 RC.
fill(0, W0, (Has1 ? BT::BitValue::One : BT::BitValue::Zero));
905 return rr0(RC, Outputs);
908 return rr0(
eAND(
rc(1),
rc(2)), Outputs);
912 return rr0(
eNOT(
rc(1)), Outputs);
914 return rr0(
eORL(
rc(1),
rc(2)), Outputs);
918 return rr0(
eXOR(
rc(1),
rc(2)), Outputs);
946 if (V.is(0) || V.is(1)) {
948 bool TV = (
Opc == S2_tstbit_i);
949 BT::BitValue F = V.is(TV) ? BT::BitValue::One : BT::BitValue::Zero;
958 if (
unsigned DefR = getUniqueDefVReg(
MI)) {
964 RC.
fill(PW, RW, BT::BitValue::Zero);
969 return MachineEvaluator::evaluate(
MI, Inputs, Outputs);
980 bool &FallsThru)
const {
984 bool SimpleBranch =
false;
985 bool Negated =
false;
987 case Hexagon::J2_jumpf:
988 case Hexagon::J2_jumpfpt:
989 case Hexagon::J2_jumpfnew:
990 case Hexagon::J2_jumpfnewpt:
993 case Hexagon::J2_jumpt:
994 case Hexagon::J2_jumptpt:
995 case Hexagon::J2_jumptnew:
996 case Hexagon::J2_jumptnewpt:
1001 case Hexagon::J2_jump:
1024 if (!
Test.is(!Negated)) {
1035unsigned HexagonEvaluator::getUniqueDefVReg(
const MachineInstr &
MI)
const {
1036 unsigned DefReg = 0;
1038 if (!
Op.isReg() || !
Op.isDef())
1051 const CellMapType &Inputs,
1052 CellMapType &Outputs)
const {
1053 using namespace Hexagon;
1057 assert(
MI.mayLoad() &&
"A load that mayn't?");
1058 unsigned Opc =
MI.getOpcode();
1069 case L2_loadalignb_pbr:
1070 case L2_loadalignb_pcr:
1071 case L2_loadalignb_pi:
1073 case L2_loadalignh_pbr:
1074 case L2_loadalignh_pcr:
1075 case L2_loadalignh_pi:
1077 case L2_loadbsw2_pbr:
1078 case L2_loadbsw2_pci:
1079 case L2_loadbsw2_pcr:
1080 case L2_loadbsw2_pi:
1081 case L2_loadbsw4_pbr:
1082 case L2_loadbsw4_pci:
1083 case L2_loadbsw4_pcr:
1084 case L2_loadbsw4_pi:
1086 case L2_loadbzw2_pbr:
1087 case L2_loadbzw2_pci:
1088 case L2_loadbzw2_pcr:
1089 case L2_loadbzw2_pi:
1090 case L2_loadbzw4_pbr:
1091 case L2_loadbzw4_pci:
1092 case L2_loadbzw4_pcr:
1093 case L2_loadbzw4_pi:
1112 case L2_loadrub_pbr:
1113 case L2_loadrub_pci:
1114 case L2_loadrub_pcr:
1140 case L2_loadruh_pbr:
1141 case L2_loadruh_pci:
1142 case L2_loadruh_pcr:
1158 case L2_loadw_locked:
1174 case L4_loadd_locked:
1189 assert(W >= BitNum && BitNum > 0);
1192 for (
uint16_t i = 0; i < BitNum; ++i)
1193 Res[i] = BT::BitValue::self(
BT::BitRef(RD.Reg, i));
1198 Res[i] = BT::BitValue::ref(Sign);
1201 Res[i] = BT::BitValue::Zero;
1209 const CellMapType &Inputs,
1210 CellMapType &Outputs)
const {
1218 if (!RS.Reg.isPhysical())
1233 if (
F->second.Type == ExtType::SExt)
1235 else if (
F->second.Type == ExtType::ZExt)
1242unsigned HexagonEvaluator::getNextPhysReg(
unsigned PReg,
unsigned Width)
const {
1243 using namespace Hexagon;
1245 bool Is64 = DoubleRegsRegClass.contains(PReg);
1246 assert(PReg == 0 || Is64 || IntRegsRegClass.contains(PReg));
1248 static const unsigned Phys32[] = { R0, R1,
R2, R3,
R4, R5 };
1249 static const unsigned Phys64[] = { D0, D1, D2 };
1250 const unsigned Num32 =
sizeof(Phys32)/
sizeof(
unsigned);
1251 const unsigned Num64 =
sizeof(Phys64)/
sizeof(
unsigned);
1255 return (Width <= 32) ? Phys32[0] : Phys64[0];
1259 unsigned Idx32 = 0, Idx64 = 0;
1261 while (Idx32 < Num32) {
1262 if (Phys32[Idx32] == PReg)
1268 while (Idx64 < Num64) {
1269 if (Phys64[Idx64] == PReg)
1277 return (Idx32+1 < Num32) ? Phys32[Idx32+1] : 0;
1278 return (Idx64+1 < Num64) ? Phys64[Idx64+1] : 0;
1281unsigned HexagonEvaluator::getVirtRegFor(
unsigned PReg)
const {
1282 for (std::pair<MCRegister, Register>
P :
MRI.
liveins())
1283 if (
P.first == PReg)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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
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.
bool isPointerTy() const
True if this is an instance of PointerType.
bool isIntegerTy() const
True if this is an instance of IntegerType.
LLVM_ABI unsigned getIntegerBitWidth() const
#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.
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
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.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
@ Sub
Subtraction of integers.
LLVM_ABI 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