27#define DEBUG_TYPE "hexagon-cext-opt"
33 int32_t U = (
V & -
A) + O;
34 return U >=
V ? U : U+
A;
39 int32_t U = (
V & -
A) + O;
40 return U <=
V ? U : U-
A;
48 int32_t Min = INT_MIN, Max = INT_MAX;
52 OffsetRange() =
default;
53 OffsetRange(int32_t L, int32_t
H, uint8_t
A, uint8_t O = 0)
54 : Min(
L), Max(
H), Align(
A), Offset(
O) {}
60 if (Offset >=
A.Offset && (Offset -
A.Offset) %
A.Align == 0) {
61 Min =
adjustUp(std::max(Min,
A.Min), Align, Offset);
62 Max =
adjustDown(std::min(Max,
A.Max), Align, Offset);
70 std::tie(Min, Max, Align) = std::make_tuple(0, -1, 1);
73 OffsetRange &shift(int32_t S) {
76 Offset = (Offset+S) % Align;
79 OffsetRange &extendBy(int32_t
D) {
83 Min = (INT_MIN-
D < Min) ? Min+
D : INT_MIN;
85 Max = (INT_MAX-
D > Max) ? Max+
D : INT_MAX;
92 return Min <=
V &&
V <= Max && (
V-Offset) % Align == 0;
95 return Min ==
R.Min && Max ==
R.Max && Align ==
R.Align;
100 bool operator<(
const OffsetRange &R)
const {
101 return std::tie(Min, Max, Align) < std::tie(
R.Min,
R.Max,
R.Align);
103 static OffsetRange
zero() {
return {0, 0, 1}; }
108 Node(
const OffsetRange &R) : MaxEnd(
R.
Max), Range(
R) {}
112 const OffsetRange &Range;
113 Node *Left =
nullptr, *Right =
nullptr;
116 Node *Root =
nullptr;
118 void add(
const OffsetRange &R) {
121 void erase(
const Node *
N) {
125 void order(SmallVectorImpl<Node*> &Seq)
const {
130 nodesWith(Root,
P, CheckAlign, Nodes);
137 for (Node *
N : Nodes)
142 void dump(
const Node *
N)
const;
143 void order(Node *
N, SmallVectorImpl<Node*> &Seq)
const;
144 void nodesWith(Node *
N, int32_t
P,
bool CheckA,
145 SmallVectorImpl<Node*> &Seq)
const;
147 Node *
add(Node *
N,
const OffsetRange &R);
148 Node *
remove(Node *
N,
const Node *
D);
149 Node *rotateLeft(Node *
Lower, Node *Higher);
150 Node *rotateRight(Node *
Lower, Node *Higher);
151 unsigned height(Node *
N) {
152 return N !=
nullptr ?
N->Height : 0;
154 Node *update(Node *
N) {
156 N->Height = 1 + std::max(height(
N->Left), height(
N->Right));
158 N->MaxEnd = std::max(
N->MaxEnd,
N->Left->MaxEnd);
160 N->MaxEnd = std::max(
N->MaxEnd,
N->Right->MaxEnd);
163 Node *rebalance(Node *
N) {
165 int32_t Balance = height(
N->Right) - height(
N->Left);
167 return rotateRight(
N->Left,
N);
169 return rotateLeft(
N->Right,
N);
175 MachineBasicBlock *Block =
nullptr;
180 if (
B->end() == It) {
183 assert(It->getParent() == B);
184 Pos = std::distance(B->begin(), It);
188 if (Block !=
A.Block)
189 return Block->getNumber() <
A.Block->getNumber();
192 return Pos != -1 && Pos <
A.Pos;
200 HexagonConstExtenders() : MachineFunctionPass(ID) {}
202 void getAnalysisUsage(AnalysisUsage &AU)
const override {
208 StringRef getPassName()
const override {
209 return "Hexagon constant-extender optimization";
216 Register(llvm::Register R,
unsigned S) : Reg(
R), Sub(S) {}
219 Register &operator=(
const MachineOperand &
Op) {
222 Sub =
Op.getSubReg();
223 }
else if (
Op.isFI()) {
228 bool isVReg()
const {
229 return Reg != 0 && !Reg.isStack() && Reg.isVirtual();
231 bool isSlot()
const {
return Reg != 0 && Reg.isStack(); }
232 operator MachineOperand()
const {
238 int FI = Reg.stackSlotIndex();
247 return std::tie(Reg, Sub) < std::tie(
R.Reg,
R.Sub);
280 ExtExpr(
Register RS,
bool NG,
unsigned SH) : Rs(
RS), S(SH), Neg(NG) {}
282 bool trivial()
const {
286 return Rs == Ex.Rs && S == Ex.S && Neg == Ex.Neg;
291 bool operator<(
const ExtExpr &Ex)
const {
292 return std::tie(Rs, S, Neg) < std::tie(Ex.Rs, Ex.S, Ex.Neg);
297 MachineInstr *UseMI =
nullptr;
298 unsigned OpNum = -1u;
309 MachineOperand &getOp() {
310 return UseMI->getOperand(OpNum);
312 const MachineOperand &getOp()
const {
313 return UseMI->getOperand(OpNum);
321 const GlobalValue *GV;
329 ExtRoot(
const MachineOperand &
Op);
331 return Kind == ER.Kind && V.ImmVal == ER.V.ImmVal;
339 struct ExtValue :
public ExtRoot {
342 ExtValue(
const MachineOperand &
Op);
343 ExtValue(
const ExtDesc &ED) : ExtValue(ED.getOp()) {}
344 ExtValue(
const ExtRoot &ER, int32_t
Off) : ExtRoot(ER), Offset(
Off) {}
345 bool operator<(
const ExtValue &EV)
const;
347 return ExtRoot(*
this) == ExtRoot(EV) && Offset == EV.Offset;
352 explicit operator MachineOperand()
const;
355 using IndexList = SetVector<unsigned>;
356 using ExtenderInit = std::pair<ExtValue, ExtExpr>;
357 using AssignmentMap = std::map<ExtenderInit, IndexList>;
358 using LocDefList = std::vector<std::pair<Loc, IndexList>>;
360 const HexagonSubtarget *HST =
nullptr;
361 const HexagonInstrInfo *HII =
nullptr;
362 const HexagonRegisterInfo *HRI =
nullptr;
363 MachineDominatorTree *MDT =
nullptr;
364 MachineRegisterInfo *MRI =
nullptr;
365 std::vector<ExtDesc> Extenders;
366 std::vector<unsigned> NewRegs;
368 bool isStoreImmediate(
unsigned Opc)
const;
369 bool isRegOffOpcode(
unsigned ExtOpc)
const ;
370 unsigned getRegOffOpcode(
unsigned ExtOpc)
const;
371 unsigned getDirectRegReplacement(
unsigned ExtOpc)
const;
372 OffsetRange getOffsetRange(Register R,
const MachineInstr &
MI)
const;
373 OffsetRange getOffsetRange(
const ExtDesc &ED)
const;
374 OffsetRange getOffsetRange(Register Rd)
const;
376 void recordExtender(MachineInstr &
MI,
unsigned OpNum);
377 void collectInstr(MachineInstr &
MI);
379 void assignInits(
const ExtRoot &ER,
unsigned Begin,
unsigned End,
380 AssignmentMap &IMap);
381 void calculatePlacement(
const ExtenderInit &ExtI,
const IndexList &Refs,
383 Register insertInitializer(Loc DefL,
const ExtenderInit &ExtI);
384 bool replaceInstrExact(
const ExtDesc &ED, Register ExtR);
385 bool replaceInstrExpr(
const ExtDesc &ED,
const ExtenderInit &ExtI,
386 Register ExtR, int32_t &Diff);
387 bool replaceInstr(
unsigned Idx, Register ExtR,
const ExtenderInit &ExtI);
388 bool replaceExtenders(
const AssignmentMap &IMap);
390 unsigned getOperandIndex(
const MachineInstr &
MI,
391 const MachineOperand &
Op)
const;
392 const MachineOperand &getPredicateOp(
const MachineInstr &
MI)
const;
393 const MachineOperand &getLoadResultOp(
const MachineInstr &
MI)
const;
394 const MachineOperand &getStoredValueOp(
const MachineInstr &
MI)
const;
396 friend struct PrintRegister;
397 friend struct PrintExpr;
398 friend struct PrintInit;
399 friend struct PrintIMap;
400 friend raw_ostream &
operator<< (raw_ostream &OS,
401 const struct PrintRegister &
P);
402 friend raw_ostream &
operator<< (raw_ostream &OS,
const struct PrintExpr &
P);
403 friend raw_ostream &
operator<< (raw_ostream &OS,
const struct PrintInit &
P);
404 friend raw_ostream &
operator<< (raw_ostream &OS,
const ExtDesc &ED);
405 friend raw_ostream &
operator<< (raw_ostream &OS,
const ExtRoot &ER);
406 friend raw_ostream &
operator<< (raw_ostream &OS,
const ExtValue &EV);
407 friend raw_ostream &
operator<< (raw_ostream &OS,
const OffsetRange &OR);
408 friend raw_ostream &
operator<< (raw_ostream &OS,
const struct PrintIMap &
P);
411 using HCE = HexagonConstExtenders;
417 OS <<
'[' <<
OR.Min <<
',' <<
OR.Max <<
"]a" <<
unsigned(
OR.Align)
422 struct PrintRegister {
423 PrintRegister(HCE::Register R,
const HexagonRegisterInfo &
I)
426 const HexagonRegisterInfo &HRI;
439 PrintExpr(
const HCE::ExtExpr &
E,
const HexagonRegisterInfo &
I)
441 const HCE::ExtExpr &Ex;
442 const HexagonRegisterInfo &HRI;
447 OS <<
"## " << (
P.Ex.Neg ?
"- " :
"+ ");
448 if (
P.Ex.Rs.Reg != 0)
452 OS <<
" << " <<
P.Ex.S;
457 PrintInit(
const HCE::ExtenderInit &EI,
const HexagonRegisterInfo &
I)
458 : ExtI(EI), HRI(
I) {}
459 const HCE::ExtenderInit &ExtI;
460 const HexagonRegisterInfo &HRI;
465 OS <<
'[' <<
P.ExtI.first <<
", "
466 << PrintExpr(
P.ExtI.second,
P.HRI) <<
']';
476 OS <<
"bb#" <<
MBB.getNumber() <<
": ";
478 OS <<
printReg(ED.Rd.Reg, &HRI, ED.Rd.Sub);
481 OS <<
" = " << PrintExpr(ED.Expr, HRI);
491 OS <<
"imm:" << ER.V.ImmVal;
494 OS <<
"fpi:" << *ER.V.CFP;
497 OS <<
"sym:" << *ER.V.SymbolName;
500 OS <<
"gad:" << ER.V.GV->getName();
503 OS <<
"blk:" << *ER.V.BA;
506 OS <<
"tgi:" << ER.V.ImmVal;
509 OS <<
"cpi:" << ER.V.ImmVal;
512 OS <<
"jti:" << ER.V.ImmVal;
515 OS <<
"???:" << ER.V.ImmVal;
523 OS << HCE::ExtRoot(EV) <<
" off:" << EV.Offset;
528 PrintIMap(
const HCE::AssignmentMap &M,
const HexagonRegisterInfo &
I)
530 const HCE::AssignmentMap &IMap;
531 const HexagonRegisterInfo &HRI;
537 for (
const std::pair<const HCE::ExtenderInit, HCE::IndexList> &Q :
P.IMap) {
538 OS <<
" " << PrintInit(Q.first,
P.HRI) <<
" -> {";
539 for (
unsigned I : Q.second)
549 "Hexagon constant-extender optimization",
false,
false)
560 dbgs() <<
"Root: " << Root <<
'\n';
566 dbgs() <<
"Node: " <<
N <<
'\n';
567 dbgs() <<
" Height: " <<
N->Height <<
'\n';
568 dbgs() <<
" Count: " <<
N->Count <<
'\n';
569 dbgs() <<
" MaxEnd: " <<
N->MaxEnd <<
'\n';
570 dbgs() <<
" Range: " <<
N->Range <<
'\n';
571 dbgs() <<
" Left: " <<
N->Left <<
'\n';
572 dbgs() <<
" Right: " <<
N->Right <<
"\n\n";
581void RangeTree::order(Node *
N, SmallVectorImpl<Node*> &Seq)
const {
586 order(
N->Right, Seq);
589void RangeTree::nodesWith(Node *
N, int32_t
P,
bool CheckA,
590 SmallVectorImpl<Node*> &Seq)
const {
591 if (
N ==
nullptr ||
N->MaxEnd <
P)
593 nodesWith(
N->Left,
P, CheckA, Seq);
594 if (
N->Range.Min <=
P) {
595 if ((CheckA &&
N->Range.contains(
P)) || (!CheckA &&
P <= N->Range.Max))
597 nodesWith(
N->Right,
P, CheckA, Seq);
601RangeTree::Node *RangeTree::add(Node *
N,
const OffsetRange &R) {
611 N->Left =
add(
N->Left, R);
613 N->Right =
add(
N->Right, R);
614 return rebalance(update(
N));
617RangeTree::Node *RangeTree::remove(Node *
N,
const Node *
D) {
621 assert(
N->Range !=
D->Range &&
"N and D should not be equal");
622 if (
D->Range <
N->Range)
626 return rebalance(update(
N));
631 if (
N->Left ==
nullptr ||
N->Right ==
nullptr)
632 return (
N->Left ==
nullptr) ?
N->Right :
N->Left;
641 return rebalance(update(M));
644RangeTree::Node *RangeTree::rotateLeft(Node *
Lower, Node *Higher) {
649 if (height(
Lower->Left) > height(
Lower->Right))
652 Higher->Right =
Lower->Left;
654 Lower->Left = Higher;
659RangeTree::Node *RangeTree::rotateRight(Node *
Lower, Node *Higher) {
664 if (height(
Lower->Left) < height(
Lower->Right))
667 Higher->Left =
Lower->Right;
669 Lower->Right = Higher;
675HCE::ExtRoot::ExtRoot(
const MachineOperand &
Op) {
680 else if (
Op.isFPImm())
681 V.CFP =
Op.getFPImm();
682 else if (
Op.isSymbol())
683 V.SymbolName =
Op.getSymbolName();
684 else if (
Op.isGlobal())
685 V.GV =
Op.getGlobal();
686 else if (
Op.isBlockAddress())
687 V.BA =
Op.getBlockAddress();
688 else if (
Op.isCPI() ||
Op.isTargetIndex() ||
Op.isJTI())
689 V.ImmVal =
Op.getIndex();
694 TF =
Op.getTargetFlags();
697bool HCE::ExtRoot::operator< (
const HCE::ExtRoot &ER)
const {
699 return Kind < ER.Kind;
705 return V.ImmVal < ER.V.ImmVal;
707 const APFloat &ThisF =
V.CFP->getValueAPF();
708 const APFloat &OtherF = ER.V.CFP->getValueAPF();
712 return StringRef(
V.SymbolName) < StringRef(ER.V.SymbolName);
718 assert(!
V.GV->getName().empty() && !ER.V.GV->getName().empty());
719 return V.GV->getName() < ER.V.GV->getName();
722 const BasicBlock *OtherB = ER.V.BA->getBasicBlock();
729 return V.ImmVal < ER.V.ImmVal;
732HCE::ExtValue::ExtValue(
const MachineOperand &
Op) : ExtRoot(
Op) {
735 else if (
Op.isFPImm() ||
Op.isJTI())
737 else if (
Op.isSymbol() ||
Op.isGlobal() ||
Op.isBlockAddress() ||
738 Op.isCPI() ||
Op.isTargetIndex())
744bool HCE::ExtValue::operator< (
const HCE::ExtValue &EV)
const {
745 const ExtRoot &ER = *
this;
746 if (!(ER == ExtRoot(EV)))
748 return Offset < EV.Offset;
777bool HCE::isStoreImmediate(
unsigned Opc)
const {
779 case Hexagon::S4_storeirbt_io:
780 case Hexagon::S4_storeirbf_io:
781 case Hexagon::S4_storeirht_io:
782 case Hexagon::S4_storeirhf_io:
783 case Hexagon::S4_storeirit_io:
784 case Hexagon::S4_storeirif_io:
785 case Hexagon::S4_storeirb_io:
786 case Hexagon::S4_storeirh_io:
787 case Hexagon::S4_storeiri_io:
795bool HCE::isRegOffOpcode(
unsigned Opc)
const {
797 case Hexagon::L2_loadrub_io:
798 case Hexagon::L2_loadrb_io:
799 case Hexagon::L2_loadruh_io:
800 case Hexagon::L2_loadrh_io:
801 case Hexagon::L2_loadri_io:
802 case Hexagon::L2_loadrd_io:
803 case Hexagon::L2_loadbzw2_io:
804 case Hexagon::L2_loadbzw4_io:
805 case Hexagon::L2_loadbsw2_io:
806 case Hexagon::L2_loadbsw4_io:
807 case Hexagon::L2_loadalignh_io:
808 case Hexagon::L2_loadalignb_io:
809 case Hexagon::L2_ploadrubt_io:
810 case Hexagon::L2_ploadrubf_io:
811 case Hexagon::L2_ploadrbt_io:
812 case Hexagon::L2_ploadrbf_io:
813 case Hexagon::L2_ploadruht_io:
814 case Hexagon::L2_ploadruhf_io:
815 case Hexagon::L2_ploadrht_io:
816 case Hexagon::L2_ploadrhf_io:
817 case Hexagon::L2_ploadrit_io:
818 case Hexagon::L2_ploadrif_io:
819 case Hexagon::L2_ploadrdt_io:
820 case Hexagon::L2_ploadrdf_io:
821 case Hexagon::S2_storerb_io:
822 case Hexagon::S2_storerh_io:
823 case Hexagon::S2_storerf_io:
824 case Hexagon::S2_storeri_io:
825 case Hexagon::S2_storerd_io:
826 case Hexagon::S2_pstorerbt_io:
827 case Hexagon::S2_pstorerbf_io:
828 case Hexagon::S2_pstorerht_io:
829 case Hexagon::S2_pstorerhf_io:
830 case Hexagon::S2_pstorerft_io:
831 case Hexagon::S2_pstorerff_io:
832 case Hexagon::S2_pstorerit_io:
833 case Hexagon::S2_pstorerif_io:
834 case Hexagon::S2_pstorerdt_io:
835 case Hexagon::S2_pstorerdf_io:
836 case Hexagon::A2_addi:
844unsigned HCE::getRegOffOpcode(
unsigned ExtOpc)
const {
849 case A2_tfrsi:
return A2_addi;
854 if (
D.mayLoad() ||
D.mayStore()) {
864 case L4_loadrub_ur:
return L2_loadrub_io;
867 case L4_loadrb_ur:
return L2_loadrb_io;
870 case L4_loadruh_ur:
return L2_loadruh_io;
873 case L4_loadrh_ur:
return L2_loadrh_io;
876 case L4_loadri_ur:
return L2_loadri_io;
879 case L4_loadrd_ur:
return L2_loadrd_io;
881 case L4_loadbzw2_ur:
return L2_loadbzw2_io;
883 case L4_loadbzw4_ur:
return L2_loadbzw4_io;
885 case L4_loadbsw2_ur:
return L2_loadbsw2_io;
887 case L4_loadbsw4_ur:
return L2_loadbsw4_io;
888 case L4_loadalignh_ap:
889 case L4_loadalignh_ur:
return L2_loadalignh_io;
890 case L4_loadalignb_ap:
891 case L4_loadalignb_ur:
return L2_loadalignb_io;
892 case L4_ploadrubt_abs:
return L2_ploadrubt_io;
893 case L4_ploadrubf_abs:
return L2_ploadrubf_io;
894 case L4_ploadrbt_abs:
return L2_ploadrbt_io;
895 case L4_ploadrbf_abs:
return L2_ploadrbf_io;
896 case L4_ploadruht_abs:
return L2_ploadruht_io;
897 case L4_ploadruhf_abs:
return L2_ploadruhf_io;
898 case L4_ploadrht_abs:
return L2_ploadrht_io;
899 case L4_ploadrhf_abs:
return L2_ploadrhf_io;
900 case L4_ploadrit_abs:
return L2_ploadrit_io;
901 case L4_ploadrif_abs:
return L2_ploadrif_io;
902 case L4_ploadrdt_abs:
return L2_ploadrdt_io;
903 case L4_ploadrdf_abs:
return L2_ploadrdf_io;
906 case S4_storerb_ur:
return S2_storerb_io;
909 case S4_storerh_ur:
return S2_storerh_io;
912 case S4_storerf_ur:
return S2_storerf_io;
915 case S4_storeri_ur:
return S2_storeri_io;
918 case S4_storerd_ur:
return S2_storerd_io;
919 case S4_pstorerbt_abs:
return S2_pstorerbt_io;
920 case S4_pstorerbf_abs:
return S2_pstorerbf_io;
921 case S4_pstorerht_abs:
return S2_pstorerht_io;
922 case S4_pstorerhf_abs:
return S2_pstorerhf_io;
923 case S4_pstorerft_abs:
return S2_pstorerft_io;
924 case S4_pstorerff_abs:
return S2_pstorerff_io;
925 case S4_pstorerit_abs:
return S2_pstorerit_io;
926 case S4_pstorerif_abs:
return S2_pstorerif_io;
927 case S4_pstorerdt_abs:
return S2_pstorerdt_io;
928 case S4_pstorerdf_abs:
return S2_pstorerdf_io;
934 if (!isStoreImmediate(ExtOpc))
944unsigned HCE::getDirectRegReplacement(
unsigned ExtOpc)
const {
946 case Hexagon::A2_addi:
return Hexagon::A2_add;
947 case Hexagon::A2_andir:
return Hexagon::A2_and;
948 case Hexagon::A2_combineii:
return Hexagon::A4_combineri;
949 case Hexagon::A2_orir:
return Hexagon::A2_or;
950 case Hexagon::A2_paddif:
return Hexagon::A2_paddf;
951 case Hexagon::A2_paddit:
return Hexagon::A2_paddt;
952 case Hexagon::A2_subri:
return Hexagon::A2_sub;
953 case Hexagon::A2_tfrsi:
return TargetOpcode::COPY;
954 case Hexagon::A4_cmpbeqi:
return Hexagon::A4_cmpbeq;
955 case Hexagon::A4_cmpbgti:
return Hexagon::A4_cmpbgt;
956 case Hexagon::A4_cmpbgtui:
return Hexagon::A4_cmpbgtu;
957 case Hexagon::A4_cmpheqi:
return Hexagon::A4_cmpheq;
958 case Hexagon::A4_cmphgti:
return Hexagon::A4_cmphgt;
959 case Hexagon::A4_cmphgtui:
return Hexagon::A4_cmphgtu;
960 case Hexagon::A4_combineii:
return Hexagon::A4_combineir;
961 case Hexagon::A4_combineir:
return TargetOpcode::REG_SEQUENCE;
962 case Hexagon::A4_combineri:
return TargetOpcode::REG_SEQUENCE;
963 case Hexagon::A4_rcmpeqi:
return Hexagon::A4_rcmpeq;
964 case Hexagon::A4_rcmpneqi:
return Hexagon::A4_rcmpneq;
965 case Hexagon::C2_cmoveif:
966 return Hexagon::A2_tfrf;
967 case Hexagon::C2_cmoveit:
968 return Hexagon::A2_tfrt;
969 case Hexagon::C2_cmpeqi:
return Hexagon::C2_cmpeq;
970 case Hexagon::C2_cmpgti:
return Hexagon::C2_cmpgt;
971 case Hexagon::C2_cmpgtui:
return Hexagon::C2_cmpgtu;
972 case Hexagon::C2_muxii:
return Hexagon::C2_muxir;
973 case Hexagon::C2_muxir:
return Hexagon::C2_mux;
974 case Hexagon::C2_muxri:
return Hexagon::C2_mux;
975 case Hexagon::C4_cmpltei:
return Hexagon::C4_cmplte;
976 case Hexagon::C4_cmplteui:
return Hexagon::C4_cmplteu;
977 case Hexagon::C4_cmpneqi:
return Hexagon::C4_cmpneq;
978 case Hexagon::M2_accii:
return Hexagon::M2_acci;
980 case Hexagon::M2_macsip:
return Hexagon::M2_maci;
981 case Hexagon::M2_mpysin:
return Hexagon::M2_mpyi;
982 case Hexagon::M2_mpysip:
return Hexagon::M2_mpyi;
983 case Hexagon::M2_mpysmi:
return Hexagon::M2_mpyi;
984 case Hexagon::M2_naccii:
return Hexagon::M2_nacci;
985 case Hexagon::M4_mpyri_addi:
return Hexagon::M4_mpyri_addr;
986 case Hexagon::M4_mpyri_addr:
return Hexagon::M4_mpyrr_addr;
987 case Hexagon::M4_mpyrr_addi:
return Hexagon::M4_mpyrr_addr;
988 case Hexagon::S4_addaddi:
return Hexagon::M2_acci;
989 case Hexagon::S4_addi_asl_ri:
return Hexagon::S2_asl_i_r_acc;
990 case Hexagon::S4_addi_lsr_ri:
return Hexagon::S2_lsr_i_r_acc;
991 case Hexagon::S4_andi_asl_ri:
return Hexagon::S2_asl_i_r_and;
992 case Hexagon::S4_andi_lsr_ri:
return Hexagon::S2_lsr_i_r_and;
993 case Hexagon::S4_ori_asl_ri:
return Hexagon::S2_asl_i_r_or;
994 case Hexagon::S4_ori_lsr_ri:
return Hexagon::S2_lsr_i_r_or;
995 case Hexagon::S4_subaddi:
return Hexagon::M2_subacc;
996 case Hexagon::S4_subi_asl_ri:
return Hexagon::S2_asl_i_r_nac;
997 case Hexagon::S4_subi_lsr_ri:
return Hexagon::S2_lsr_i_r_nac;
1000 case Hexagon::S4_storeirbf_io:
return Hexagon::S2_pstorerbf_io;
1001 case Hexagon::S4_storeirb_io:
return Hexagon::S2_storerb_io;
1002 case Hexagon::S4_storeirbt_io:
return Hexagon::S2_pstorerbt_io;
1003 case Hexagon::S4_storeirhf_io:
return Hexagon::S2_pstorerhf_io;
1004 case Hexagon::S4_storeirh_io:
return Hexagon::S2_storerh_io;
1005 case Hexagon::S4_storeirht_io:
return Hexagon::S2_pstorerht_io;
1006 case Hexagon::S4_storeirif_io:
return Hexagon::S2_pstorerif_io;
1007 case Hexagon::S4_storeiri_io:
return Hexagon::S2_storeri_io;
1008 case Hexagon::S4_storeirit_io:
return Hexagon::S2_pstorerit_io;
1030 unsigned Opc =
MI.getOpcode();
1033 if (!isRegOffOpcode(
Opc) || HII->isConstExtended(
MI))
1034 return OffsetRange::zero();
1036 if (
Opc == Hexagon::A2_addi) {
1038 if (Rb !=
Register(Op1) || !Op2.isImm())
1039 return OffsetRange::zero();
1040 OffsetRange
R = { -(1<<15)+1, (1<<15)-1, 1 };
1041 return R.shift(Op2.getImm());
1045 if (HII->isPostIncrement(
MI))
1046 return OffsetRange::zero();
1049 assert(
D.mayLoad() ||
D.mayStore());
1051 unsigned BaseP, OffP;
1052 if (!HII->getBaseAndOffsetPosition(
MI, BaseP, OffP) ||
1054 !
MI.getOperand(OffP).isImm())
1055 return OffsetRange::zero();
1066 int32_t
Off =
MI.getOperand(OffP).getImm();
1069 OffsetRange
R = { Min,
Max,
A };
1070 return R.shift(
Off);
1080OffsetRange HCE::getOffsetRange(
const ExtDesc &ED)
const {
1084 unsigned IdxOpc = getRegOffOpcode(ED.UseMI->getOpcode());
1087 return OffsetRange::zero();
1088 case Hexagon::A2_addi:
1089 return { -32767, 32767, 1 };
1090 case Hexagon::A2_subri:
1091 return { -511, 511, 1 };
1094 if (!ED.UseMI->mayLoad() && !ED.UseMI->mayStore())
1095 return OffsetRange::zero();
1104 return { Min,
Max,
A };
1109OffsetRange HCE::getOffsetRange(
Register Rd)
const {
1116 return OffsetRange::zero();
1117 Range.intersect(getOffsetRange(Rd, *
Op.getParent()));
1123 unsigned Opc =
MI.getOpcode();
1127 bool IsLoad =
MI.mayLoad();
1128 bool IsStore =
MI.mayStore();
1134 if (
Op.isFI() &&
Op.getIndex() < 0)
1137 if (IsLoad || IsStore) {
1138 unsigned AM = HII->getAddrMode(
MI);
1144 ED.Rd =
MI.getOperand(OpNum-1);
1151 if (!isStoreImmediate(
Opc))
1152 ED.Expr.Rs =
MI.getOperand(OpNum-1);
1155 ED.Expr.Rs =
MI.getOperand(OpNum-2);
1156 ED.Expr.S =
MI.getOperand(OpNum-1).getImm();
1163 case Hexagon::A2_tfrsi:
1164 ED.Rd =
MI.getOperand(0);
1167 case Hexagon::A2_combineii:
1168 case Hexagon::A4_combineir:
1169 ED.Rd = {
MI.getOperand(0).getReg(), Hexagon::isub_hi };
1172 case Hexagon::A4_combineri:
1173 ED.Rd = {
MI.getOperand(0).getReg(), Hexagon::isub_lo };
1176 case Hexagon::A2_addi:
1177 ED.Rd =
MI.getOperand(0);
1178 ED.Expr.Rs =
MI.getOperand(OpNum-1);
1180 case Hexagon::M2_accii:
1181 case Hexagon::M2_naccii:
1182 case Hexagon::S4_addaddi:
1183 ED.Expr.Rs =
MI.getOperand(OpNum-1);
1185 case Hexagon::A2_subri:
1186 ED.Rd =
MI.getOperand(0);
1187 ED.Expr.Rs =
MI.getOperand(OpNum+1);
1190 case Hexagon::S4_subaddi:
1191 ED.Expr.Rs =
MI.getOperand(OpNum+1);
1202 ExtRoot ER(ED.getOp());
1204 if (ER.V.GV->getName().empty())
1208 if (ER.V.BA->getFunction() != &(
MI.getMF()->getFunction()))
1210 Extenders.push_back(ED);
1214 if (!HII->isConstExtended(
MI))
1218 unsigned Opc =
MI.getOpcode();
1220 case Hexagon::M2_macsin:
1221 case Hexagon::C4_addipc:
1222 case Hexagon::S4_or_andi:
1223 case Hexagon::S4_or_andix:
1224 case Hexagon::S4_or_ori:
1227 recordExtender(
MI, HII->getCExtOpNum(
MI));
1234 if (
MBB.getNumber() == -1)
1241void HCE::assignInits(
const ExtRoot &ER,
unsigned Begin,
unsigned End,
1242 AssignmentMap &IMap) {
1245 for (
unsigned I = Begin;
I !=
End; ++
I)
1246 assert(ER == ExtRoot(Extenders[
I].getOp()));
1252 std::vector<OffsetRange>
Ranges(
End-Begin);
1258 for (
unsigned I = Begin;
I !=
End; ++
I) {
1259 const ExtDesc &ED = Extenders[
I];
1265 Ranges[
I-Begin] = getOffsetRange(ED.Rd).shift(EV.Offset);
1270 if (ED.UseMI->getOpcode() == Hexagon::A2_tfrsi) {
1272 Ranges[
I-Begin].extendBy(-
D).extendBy(
D);
1278 for (
unsigned I = Begin;
I !=
End; ++
I) {
1279 const ExtDesc &ED = Extenders[
I];
1284 OffsetRange Dev = getOffsetRange(ED);
1285 Ranges[
I-Begin].intersect(Dev.shift(EV.Offset));
1291 std::map<OffsetRange, IndexList> RangeMap;
1292 for (
unsigned I = Begin;
I !=
End; ++
I)
1293 RangeMap[Ranges[
I-Begin]].insert(
I);
1296 dbgs() <<
"Ranges\n";
1297 for (
unsigned I = Begin;
I !=
End; ++
I)
1299 dbgs() <<
"RangeMap\n";
1300 for (
auto &
P : RangeMap) {
1301 dbgs() <<
" " <<
P.first <<
" ->";
1302 for (
unsigned I :
P.second)
1312 for (
const OffsetRange &R : Ranges)
1319 for (RangeTree::Node *
N : Nodes) {
1334 std::set<int32_t> CandSet;
1335 for (RangeTree::Node *
N : Nodes) {
1336 const OffsetRange &
R =
N->Range;
1337 auto P0 = MaxAlign(
Tree.nodesWith(
R.Min,
false),
R.Align,
R.Offset);
1338 CandSet.insert(
R.Min);
1339 if (
R.Align <
P0.first)
1341 auto P1 = MaxAlign(
Tree.nodesWith(
R.Max,
false),
R.Align,
R.Offset);
1342 CandSet.insert(
R.Max);
1343 if (
R.Align <
P1.first)
1353 using CMap = std::map<int32_t,unsigned>;
1355 for (
auto It = CandSet.begin(), Et = CandSet.end(); It != Et; ) {
1356 auto &&
V =
Tree.nodesWith(*It);
1357 unsigned N = std::accumulate(
V.begin(),
V.end(), 0u,
1358 [](
unsigned Acc,
const RangeTree::Node *
N) {
1359 return Acc + N->Count;
1362 Counts.insert({*It,
N});
1363 It = (
N != 0) ? std::next(It) : CandSet.erase(It);
1370 Counts, [](
const CMap::value_type &
A,
const CMap::value_type &
B) {
1371 return A.second <
B.second || (
A.second ==
B.second &&
A <
B);
1373 int32_t Best = BestIt->first;
1374 ExtValue BestV(ER, Best);
1375 for (RangeTree::Node *
N :
Tree.nodesWith(Best)) {
1376 for (
unsigned I : RangeMap[
N->Range])
1377 IMap[{BestV,Extenders[
I].Expr}].insert(
I);
1382 LLVM_DEBUG(
dbgs() <<
"IMap (before fixup) = " << PrintIMap(IMap, *HRI));
1391 for (std::pair<const ExtenderInit,IndexList> &
P : IMap) {
1393 if (
P.first.second.trivial())
1397 const ExtValue &EV =
P.first.first;
1398 AssignmentMap::iterator
F = IMap.find({EV, ExtExpr()});
1399 if (
F == IMap.end())
1438 bool IsStack =
any_of(
F->second, [
this](
unsigned I) {
1439 return Extenders[I].Expr.Rs.isSlot();
1441 auto SameValue = [&EV,
this,IsStack](
unsigned I) {
1442 const ExtDesc &ED = Extenders[
I];
1443 return ED.Expr.Rs.isSlot() == IsStack &&
1444 ExtValue(ED).Offset == EV.Offset;
1446 if (
all_of(
P.second, SameValue)) {
1447 F->second.insert_range(
P.second);
1452 LLVM_DEBUG(
dbgs() <<
"IMap (after fixup) = " << PrintIMap(IMap, *HRI));
1455void HCE::calculatePlacement(
const ExtenderInit &ExtI,
const IndexList &Refs,
1467 const ExtDesc &ED0 = Extenders[Refs[0]];
1469 RefMIs.
insert(ED0.UseMI);
1471 for (
unsigned i = 1, e = Refs.size(); i != e; ++i) {
1472 const ExtDesc &ED = Extenders[Refs[i]];
1475 DomB = MDT->findNearestCommonDominator(DomB,
MBB);
1483 const MachineInstr *DefI = Rs.isVReg() ?
MRI->getVRegDef(Rs.Reg) :
nullptr;
1491 if (Blocks.
count(DomB)) {
1494 for (It = DomB->
begin(); It !=
End; ++It)
1495 if (RefMIs.
count(&*It))
1497 assert(It !=
End &&
"Should have found a ref in DomB");
1502 Loc DefLoc(DomB, It);
1503 Defs.emplace_back(DefLoc, Refs);
1506HCE::Register HCE::insertInitializer(
Loc DefL,
const ExtenderInit &ExtI) {
1511 const ExtValue &EV = ExtI.first;
1514 const ExtExpr &Ex = ExtI.second;
1517 if (Ex.Rs.isSlot()) {
1518 assert(Ex.S == 0 &&
"Cannot have a shift of a stack slot");
1519 assert(!Ex.Neg &&
"Cannot subtract a stack slot");
1521 InitI =
BuildMI(
MBB, At, dl, HII->get(Hexagon::PS_fi), DefR)
1525 assert((Ex.Rs.Reg == 0 || Ex.Rs.isVReg()) &&
"Expecting virtual register");
1528 InitI =
BuildMI(
MBB, At, dl, HII->get(Hexagon::A2_tfrsi), DefR)
1530 }
else if (Ex.S == 0) {
1533 InitI =
BuildMI(
MBB, At, dl, HII->get(Hexagon::A2_subri), DefR)
1538 InitI =
BuildMI(
MBB, At, dl, HII->get(Hexagon::A2_addi), DefR)
1543 if (HST->useCompound()) {
1544 unsigned NewOpc = Ex.Neg ? Hexagon::S4_subi_asl_ri
1545 : Hexagon::S4_addi_asl_ri;
1547 InitI =
BuildMI(
MBB, At, dl, HII->get(NewOpc), DefR)
1556 BuildMI(
MBB, At, dl, HII->get(Hexagon::S2_asl_i_r), TmpR)
1560 InitI =
BuildMI(
MBB, At, dl, HII->get(Hexagon::A2_subri), DefR)
1564 InitI =
BuildMI(
MBB, At, dl, HII->get(Hexagon::A2_addi), DefR)
1574 <<
" for initializer: " << PrintInit(ExtI, *HRI) <<
"\n "
1580bool HCE::replaceInstrExact(
const ExtDesc &ED,
Register ExtR) {
1585 unsigned ExtOpc =
MI.getOpcode();
1590 unsigned RegOpc = getDirectRegReplacement(ExtOpc);
1592 if (RegOpc == TargetOpcode::REG_SEQUENCE) {
1593 if (ExtOpc == Hexagon::A4_combineri)
1595 .
add(
MI.getOperand(0))
1596 .
add(
MI.getOperand(1))
1597 .
addImm(Hexagon::isub_hi)
1599 .
addImm(Hexagon::isub_lo);
1600 else if (ExtOpc == Hexagon::A4_combineir)
1602 .
add(
MI.getOperand(0))
1604 .
addImm(Hexagon::isub_hi)
1605 .
add(
MI.getOperand(2))
1606 .
addImm(Hexagon::isub_lo);
1612 if (ExtOpc == Hexagon::C2_cmpgei || ExtOpc == Hexagon::C2_cmpgeui) {
1613 unsigned NewOpc = ExtOpc == Hexagon::C2_cmpgei ? Hexagon::C2_cmplt
1614 : Hexagon::C2_cmpltu;
1616 .
add(
MI.getOperand(0))
1618 .
add(
MI.getOperand(1));
1625 unsigned RegN = ED.OpNum;
1627 for (
unsigned i = 0, e =
MI.getNumOperands(); i != e; ++i) {
1629 MIB.
add(
MI.getOperand(i));
1638 if (
MI.mayLoadOrStore() && !isStoreImmediate(ExtOpc)) {
1646 unsigned RegOpc, Shift;
1647 unsigned AM = HII->getAddrMode(
MI);
1649 RegOpc = HII->changeAddrMode_io_rr(ExtOpc);
1654 RegOpc = HII->changeAddrMode_ur_rr(ExtOpc);
1655 Shift =
MI.getOperand(
MI.mayLoad() ? 2 : 1).getImm();
1660 if (RegOpc == -1u) {
1661 dbgs() <<
"\nExtOpc: " << HII->getName(ExtOpc) <<
" has no rr version\n";
1666 unsigned BaseP, OffP;
1667 HII->getBaseAndOffsetPosition(
MI, BaseP, OffP);
1673 MIB.
add(getLoadResultOp(
MI));
1675 if (HII->isPredicated(
MI))
1676 MIB.
add(getPredicateOp(
MI));
1679 MIB.
add(
MI.getOperand(BaseP));
1683 MIB.
add(getStoredValueOp(
MI));
1697bool HCE::replaceInstrExpr(
const ExtDesc &ED,
const ExtenderInit &ExtI,
1703 unsigned ExtOpc =
MI.getOpcode();
1705 if (ExtOpc == Hexagon::A2_tfrsi) {
1714 unsigned IdxOpc = getRegOffOpcode(ExtOpc);
1715 assert(IdxOpc == Hexagon::A2_addi);
1718 int32_t
D =
isInt<16>(Diff) ? Diff : (Diff > 0 ? 32767 : -32768);
1724 OffsetRange
R = getOffsetRange(
MI.getOperand(0));
1729 .
add(
MI.getOperand(0))
1737 OffsetRange
Uses = getOffsetRange(
MI.getOperand(0));
1738 if (!
Uses.contains(-Diff))
1739 dbgs() <<
"Diff: " << -Diff <<
" out of range " <<
Uses
1747 const ExtValue &EV = ExtI.first; (void)EV;
1748 const ExtExpr &Ex = ExtI.second; (void)Ex;
1750 if (ExtOpc == Hexagon::A2_addi || ExtOpc == Hexagon::A2_subri) {
1755 bool IsAddi = ExtOpc == Hexagon::A2_addi;
1758 assert(Ex.Rs == RegOp && EV == ImmOp && Ex.Neg != IsAddi &&
1759 "Initializer mismatch");
1761 BuildMI(
MBB, At, dl, HII->get(TargetOpcode::COPY))
1762 .
add(
MI.getOperand(0))
1768 if (ExtOpc == Hexagon::M2_accii || ExtOpc == Hexagon::M2_naccii ||
1769 ExtOpc == Hexagon::S4_addaddi || ExtOpc == Hexagon::S4_subaddi) {
1778 bool IsSub = ExtOpc == Hexagon::S4_subaddi;
1780 ExtValue
V =
MI.getOperand(IsSub ? 2 : 3);
1781 assert(EV ==
V && Rs == Ex.Rs && IsSub == Ex.Neg &&
"Initializer mismatch");
1783 unsigned NewOpc = ExtOpc == Hexagon::M2_naccii ? Hexagon::A2_sub
1786 .
add(
MI.getOperand(0))
1787 .
add(
MI.getOperand(1))
1793 if (
MI.mayLoadOrStore()) {
1794 unsigned IdxOpc = getRegOffOpcode(ExtOpc);
1795 assert(IdxOpc &&
"Expecting indexed opcode");
1800 MIB.
add(getLoadResultOp(
MI));
1802 if (HII->isPredicated(
MI))
1803 MIB.
add(getPredicateOp(
MI));
1809 MIB.
add(getStoredValueOp(
MI));
1816 dbgs() <<
'\n' << PrintInit(ExtI, *HRI) <<
" " <<
MI;
1822bool HCE::replaceInstr(
unsigned Idx,
Register ExtR,
const ExtenderInit &ExtI) {
1823 if (HST->getCLOpts().cext_limit) {
1828 const ExtDesc &ED = Extenders[
Idx];
1829 assert((!ED.IsDef || ED.Rd.Reg != 0) &&
"Missing Rd for def");
1830 const ExtValue &DefV = ExtI.first;
1831 assert(ExtRoot(ExtValue(ED)) == ExtRoot(DefV) &&
"Extender root mismatch");
1832 const ExtExpr &DefEx = ExtI.second;
1835 int32_t Diff = EV.Offset - DefV.Offset;
1838 << PrintRegister(ExtR, *HRI) <<
" Diff:" << Diff <<
'\n');
1842 bool IsAbs =
false, IsAbsSet =
false;
1843 if (
MI.mayLoadOrStore()) {
1844 unsigned AM = HII->getAddrMode(
MI);
1853 std::vector<std::pair<MachineInstr*,unsigned>> RegOps;
1854 if (ED.IsDef && Diff != 0) {
1857 RegOps.push_back({&UI, getOperandIndex(UI,
Op)});
1862 bool Replaced =
false;
1863 if (Diff == 0 && DefEx.trivial() && !IsAbs && !IsAbsSet)
1864 Replaced = replaceInstrExact(ED, ExtR);
1866 Replaced = replaceInstrExpr(ED, ExtI, ExtR, Diff);
1868 if (Diff != 0 && Replaced && ED.IsDef) {
1870 for (std::pair<MachineInstr*,unsigned>
P : RegOps) {
1871 unsigned J =
P.second;
1872 assert(
P.first->getNumOperands() > J+1 &&
1873 P.first->getOperand(J+1).isImm());
1882 assert(ED.Rd.Sub == 0 && ExtR.Sub == 0);
1883 MRI->replaceRegWith(ED.Rd.Reg, ExtR.Reg);
1890bool HCE::replaceExtenders(
const AssignmentMap &IMap) {
1894 for (
const std::pair<const ExtenderInit, IndexList> &
P : IMap) {
1895 const IndexList &Idxs =
P.second;
1896 if (Idxs.size() < HST->getCLOpts().cext_threshold)
1900 calculatePlacement(
P.first, Idxs, Defs);
1901 for (
const std::pair<Loc,IndexList> &Q : Defs) {
1902 Register DefR = insertInitializer(Q.first,
P.first);
1903 NewRegs.push_back(DefR.Reg);
1904 for (
unsigned I : Q.second)
1905 Changed |= replaceInstr(
I, DefR,
P.first);
1913 for (
unsigned i = 0, n =
MI.getNumOperands(); i != n; ++i)
1914 if (&
MI.getOperand(i) == &
Op)
1922 if (!
Op.isReg() || !
Op.isUse() ||
1923 MRI->getRegClass(
Op.getReg()) != &Hexagon::PredRegsRegClass)
1925 assert(
Op.getSubReg() == 0 &&
"Predicate register with a subregister");
1933 return MI.getOperand(0);
1938 return MI.getOperand(
MI.getNumExplicitOperands()-1);
1946 <<
" due to exception handling\n");
1954 MDT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
1959 llvm::sort(Extenders, [
this](
const ExtDesc &
A,
const ExtDesc &
B) {
1960 ExtValue VA(
A), VB(
B);
1967 return A.OpNum <
B.OpNum;
1975 return MDT->dominates(MA, MB);
1979 LLVM_DEBUG(
dbgs() <<
"Collected " << Extenders.size() <<
" extenders\n");
1980 for (
unsigned I = 0,
E = Extenders.size();
I !=
E; ) {
1982 const ExtRoot &
T = Extenders[
B].getOp();
1983 while (
I !=
E && ExtRoot(Extenders[
I].getOp()) ==
T)
1987 assignInits(
T,
B,
I, IMap);
1988 Changed |= replaceExtenders(IMap);
1993 MF.
print(
dbgs() <<
"After " << getPassName() <<
'\n',
nullptr);
1995 dbgs() <<
"No changes\n";
2001 return new HexagonConstExtenders();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
bpf unwind BPF Unwind Lower
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
hexagon cext Hexagon constant extender static false unsigned ReplaceCounter
static int32_t adjustUp(int32_t V, uint8_t A, uint8_t O)
static int32_t adjustDown(int32_t V, uint8_t A, uint8_t O)
static Interval intersect(const Interval &I1, const Interval &I2)
Promote Memory to Register
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
MachineRegisterInfo & MRI
Remove Loads Into Fake Uses
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallVector class.
APInt bitcastToAPInt() const
bool ult(const APInt &RHS) const
Unsigned less than comparison.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
const Function * getParent() const
Return the enclosing method, or null if none.
Implements a dense probed hash-table based set.
FunctionPass class - This class is used to implement most global optimizations.
bool hasPersonalityFn() const
Check whether this function has a personality function.
const HexagonRegisterInfo & getRegisterInfo() const
const HexagonInstrInfo * getInstrInfo() const override
Describe properties that are true of each instruction in the target description file.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
LLVM_ABI DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any debug instructions.
MachineInstrBundleIterator< MachineInstr > iterator
Analysis pass which computes a MachineDominatorTree.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
void print(raw_ostream &OS, const SlotIndexes *=nullptr) const
print - Print out the MachineFunction in a format suitable for debugging to the specified stream.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
Representation of each machine instruction.
const MachineBasicBlock * getParent() const
MachineOperand class - Representation of each machine instruction operand.
static MachineOperand CreateES(const char *SymName, unsigned TargetFlags=0)
static MachineOperand CreateFPImm(const ConstantFP *CFP)
void setImm(int64_t immVal)
static MachineOperand CreateImm(int64_t Val)
static MachineOperand CreateJTI(unsigned Idx, unsigned TargetFlags=0)
static MachineOperand CreateGA(const GlobalValue *GV, int64_t Offset, unsigned TargetFlags=0)
static MachineOperand CreateBA(const BlockAddress *BA, int64_t Offset, unsigned TargetFlags=0)
static MachineOperand CreateCPI(unsigned Idx, int Offset, unsigned TargetFlags=0)
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_GlobalAddress
Address of a global value.
@ MO_BlockAddress
Address of a basic block.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
@ MO_TargetIndex
Target-dependent index+offset operand.
@ MO_FPImmediate
Floating-point immediate operand.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
static MachineOperand CreateTargetIndex(unsigned Idx, int64_t Offset, unsigned TargetFlags=0)
static MachineOperand CreateFI(int Idx)
Wrapper class representing virtual and physical registers.
static Register index2StackSlot(int FI)
Convert a frame index to a stack slot register value.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
std::pair< iterator, bool > insert(const ValueT &V)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
self_iterator getIterator()
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
static unsigned getMemAccessSizeInBytes(MemAccessSize S)
@ BasicBlock
Various leaf nodes.
NodeAddr< NodeBase * > Node
LLVM_ABI std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
bool operator<(int64_t V1, const APSInt &V2)
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
bool operator!=(uint64_t V1, const APInt &V2)
constexpr T alignDown(U Value, V Align, W Skew=0)
Returns the largest unsigned integer less than or equal to Value and is Skew mod Align.
FunctionPass * createHexagonConstExtenders()
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
@ Off
Use window algorithm after SMS algorithm fails.
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
DWARFExpression::Operation Op
auto max_element(R &&Range)
Provide wrappers to std::max_element which take ranges instead of having to pass begin/end explicitly...
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
@ End
Run the machine verifier once, at the end of the pipeline.
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.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This struct is a compact representation of a valid (non-zero power of two) alignment.