llvm.org GIT mirror llvm / 9bd2215
[globalisel] Add GISelChangeObserver::changingInstr() Summary: In addition to knowing that an instruction is changed. It's also useful to know when it's about to change. For example, it might print the instruction so you can track the changes in a debug log, it might remove it from some queue while it's being worked on, or it might want to change several instructions as a single transaction and act on all the changes at once. Added changingInstr() to all existing uses of changedInstr() Reviewers: aditya_nandakumar Reviewed By: aditya_nandakumar Subscribers: rovka, kristof.beyls, llvm-commits Differential Revision: https://reviews.llvm.org/D55623 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348992 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Sanders 1 year, 10 months ago
5 changed file(s) with 40 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
2929 virtual void erasingInstr(MachineInstr &MI) = 0;
3030 /// An instruction was created and inserted into the function.
3131 virtual void createdInstr(MachineInstr &MI) = 0;
32 /// This instruction is about to be mutated in some way.
33 virtual void changingInstr(MachineInstr &MI) = 0;
3234 /// This instruction was mutated in some way.
3335 virtual void changedInstr(MachineInstr &MI) = 0;
3436 };
4343 virtual ~WorkListMaintainer() {}
4444
4545 void erasingInstr(MachineInstr &MI) override {
46 LLVM_DEBUG(dbgs() << "Erased: "; MI.print(dbgs()); dbgs() << "\n");
46 LLVM_DEBUG(dbgs() << "Erased: " << MI << "\n");
4747 WorkList.remove(&MI);
4848 }
4949 void createdInstr(MachineInstr &MI) override {
50 LLVM_DEBUG(dbgs() << "Created: "; MI.print(dbgs()); dbgs() << "\n");
50 LLVM_DEBUG(dbgs() << "Created: " << MI << "\n");
5151 WorkList.insert(&MI);
52 }
53 void changingInstr(MachineInstr &MI) override {
54 LLVM_DEBUG(dbgs() << "Changing: " << MI << "\n");
55 WorkList.remove(&MI);
5256 }
5357 // Currently changed conservatively assumes erased.
5458 void changedInstr(MachineInstr &MI) override {
55 LLVM_DEBUG(dbgs() << "Changed: "; MI.print(dbgs()); dbgs() << "\n");
59 LLVM_DEBUG(dbgs() << "Changed: " << MI << "\n");
5660 WorkList.remove(&MI);
5761 }
5862 };
9090 else
9191 InstList.insert(&MI);
9292 }
93 LLVM_DEBUG(dbgs() << ".. .. New MI: " << MI;);
93 LLVM_DEBUG(dbgs() << ".. .. New MI: " << MI);
9494 }
9595
9696 void erasingInstr(MachineInstr &MI) override {
97 LLVM_DEBUG(dbgs() << ".. .. Erasing: " << MI;);
97 LLVM_DEBUG(dbgs() << ".. .. Erasing: " << MI);
9898 InstList.remove(&MI);
9999 ArtifactList.remove(&MI);
100 }
101
102 void changingInstr(MachineInstr &MI) override {
103 LLVM_DEBUG(dbgs() << ".. .. Changing MI: " << MI);
100104 }
101105
102106 void changedInstr(MachineInstr &MI) override {
103107 // When insts change, we want to revisit them to legalize them again.
104108 // We'll consider them the same as created.
105 LLVM_DEBUG(dbgs() << ".. .. Changed MI: " << MI;);
109 LLVM_DEBUG(dbgs() << ".. .. Changed MI: " << MI);
106110 createdInstr(MI);
107111 }
108112 };
710710 }
711711 auto &TII = *MI.getMF()->getSubtarget().getInstrInfo();
712712 // Make the original instruction a trunc now, and update its source.
713 Observer.changingInstr(MI);
713714 MI.setDesc(TII.get(TargetOpcode::G_TRUNC));
714715 MI.getOperand(1).setReg(MIBNewOp->getOperand(0).getReg());
715716 Observer.changedInstr(MI);
725726 // Perform operation at larger width (any extension is fine here, high bits
726727 // don't affect the result) and then truncate the result back to the
727728 // original type.
729 Observer.changingInstr(MI);
728730 widenScalarSrc(MI, WideTy, 1, TargetOpcode::G_ANYEXT);
729731 widenScalarSrc(MI, WideTy, 2, TargetOpcode::G_ANYEXT);
730732 widenScalarDst(MI, WideTy);
732734 return Legalized;
733735
734736 case TargetOpcode::G_SHL:
737 Observer.changingInstr(MI);
735738 widenScalarSrc(MI, WideTy, 1, TargetOpcode::G_ANYEXT);
736739 // The "number of bits to shift" operand must preserve its value as an
737740 // unsigned integer:
742745
743746 case TargetOpcode::G_SDIV:
744747 case TargetOpcode::G_SREM:
748 Observer.changingInstr(MI);
745749 widenScalarSrc(MI, WideTy, 1, TargetOpcode::G_SEXT);
746750 widenScalarSrc(MI, WideTy, 2, TargetOpcode::G_SEXT);
747751 widenScalarDst(MI, WideTy);
749753 return Legalized;
750754
751755 case TargetOpcode::G_ASHR:
756 Observer.changingInstr(MI);
752757 widenScalarSrc(MI, WideTy, 1, TargetOpcode::G_SEXT);
753758 // The "number of bits to shift" operand must preserve its value as an
754759 // unsigned integer:
760765 case TargetOpcode::G_UDIV:
761766 case TargetOpcode::G_UREM:
762767 case TargetOpcode::G_LSHR:
768 Observer.changingInstr(MI);
763769 widenScalarSrc(MI, WideTy, 1, TargetOpcode::G_ZEXT);
764770 widenScalarSrc(MI, WideTy, 2, TargetOpcode::G_ZEXT);
765771 widenScalarDst(MI, WideTy);
772778 // Perform operation at larger width (any extension is fine here, high bits
773779 // don't affect the result) and then truncate the result back to the
774780 // original type.
781 Observer.changingInstr(MI);
775782 widenScalarSrc(MI, WideTy, 2, TargetOpcode::G_ANYEXT);
776783 widenScalarSrc(MI, WideTy, 3, TargetOpcode::G_ANYEXT);
777784 widenScalarDst(MI, WideTy);
782789 case TargetOpcode::G_FPTOUI:
783790 if (TypeIdx != 0)
784791 return UnableToLegalize;
792 Observer.changingInstr(MI);
785793 widenScalarDst(MI, WideTy);
786794 Observer.changedInstr(MI);
787795 return Legalized;
789797 case TargetOpcode::G_SITOFP:
790798 if (TypeIdx != 1)
791799 return UnableToLegalize;
800 Observer.changingInstr(MI);
792801 widenScalarSrc(MI, WideTy, 1, TargetOpcode::G_SEXT);
793802 Observer.changedInstr(MI);
794803 return Legalized;
796805 case TargetOpcode::G_UITOFP:
797806 if (TypeIdx != 1)
798807 return UnableToLegalize;
808 Observer.changingInstr(MI);
799809 widenScalarSrc(MI, WideTy, 1, TargetOpcode::G_ZEXT);
800810 Observer.changedInstr(MI);
801811 return Legalized;
803813 case TargetOpcode::G_INSERT:
804814 if (TypeIdx != 0)
805815 return UnableToLegalize;
816 Observer.changingInstr(MI);
806817 widenScalarSrc(MI, WideTy, 1, TargetOpcode::G_ANYEXT);
807818 widenScalarDst(MI, WideTy);
808819 Observer.changedInstr(MI);
818829 LLVM_FALLTHROUGH;
819830 case TargetOpcode::G_SEXTLOAD:
820831 case TargetOpcode::G_ZEXTLOAD:
832 Observer.changingInstr(MI);
821833 widenScalarDst(MI, WideTy);
822834 Observer.changedInstr(MI);
823835 return Legalized;
827839 WideTy != LLT::scalar(8))
828840 return UnableToLegalize;
829841
842 Observer.changingInstr(MI);
830843 widenScalarSrc(MI, WideTy, 0, TargetOpcode::G_ZEXT);
831844 Observer.changedInstr(MI);
832845 return Legalized;
835848 MachineOperand &SrcMO = MI.getOperand(1);
836849 LLVMContext &Ctx = MIRBuilder.getMF().getFunction().getContext();
837850 const APInt &Val = SrcMO.getCImm()->getValue().sext(WideTy.getSizeInBits());
851 Observer.changingInstr(MI);
838852 SrcMO.setCImm(ConstantInt::get(Ctx, Val));
839853
840854 widenScalarDst(MI, WideTy);
856870 default:
857871 llvm_unreachable("Unhandled fp widen type");
858872 }
873 Observer.changingInstr(MI);
859874 SrcMO.setFPImm(ConstantFP::get(Ctx, Val));
860875
861876 widenScalarDst(MI, WideTy, 0, TargetOpcode::G_FPTRUNC);
863878 return Legalized;
864879 }
865880 case TargetOpcode::G_BRCOND:
881 Observer.changingInstr(MI);
866882 widenScalarSrc(MI, WideTy, 0, TargetOpcode::G_ANYEXT);
867883 Observer.changedInstr(MI);
868884 return Legalized;
869885
870886 case TargetOpcode::G_FCMP:
887 Observer.changingInstr(MI);
871888 if (TypeIdx == 0)
872889 widenScalarDst(MI, WideTy);
873890 else {
878895 return Legalized;
879896
880897 case TargetOpcode::G_ICMP:
898 Observer.changingInstr(MI);
881899 if (TypeIdx == 0)
882900 widenScalarDst(MI, WideTy);
883901 else {
893911
894912 case TargetOpcode::G_GEP:
895913 assert(TypeIdx == 1 && "unable to legalize pointer of GEP");
914 Observer.changingInstr(MI);
896915 widenScalarSrc(MI, WideTy, 2, TargetOpcode::G_SEXT);
897916 Observer.changedInstr(MI);
898917 return Legalized;
900919 case TargetOpcode::G_PHI: {
901920 assert(TypeIdx == 0 && "Expecting only Idx 0");
902921
922 Observer.changingInstr(MI);
903923 for (unsigned I = 1; I < MI.getNumOperands(); I += 2) {
904924 MachineBasicBlock &OpMBB = *MI.getOperand(I + 1).getMBB();
905925 MIRBuilder.setInsertPt(OpMBB, OpMBB.getFirstTerminator());
915935 case TargetOpcode::G_EXTRACT_VECTOR_ELT:
916936 if (TypeIdx != 2)
917937 return UnableToLegalize;
938 Observer.changingInstr(MI);
918939 widenScalarSrc(MI, WideTy, 2, TargetOpcode::G_SEXT);
919940 Observer.changedInstr(MI);
920941 return Legalized;
11511172 return UnableToLegalize;
11521173 case TargetOpcode::G_CTLZ_ZERO_UNDEF: {
11531174 // This trivially expands to CTLZ.
1175 Observer.changingInstr(MI);
11541176 MI.setDesc(TII.get(TargetOpcode::G_CTLZ));
11551177 Observer.changedInstr(MI);
11561178 return Legalized;
12001222 }
12011223 case TargetOpcode::G_CTTZ_ZERO_UNDEF: {
12021224 // This trivially expands to CTTZ.
1225 Observer.changingInstr(MI);
12031226 MI.setDesc(TII.get(TargetOpcode::G_CTTZ));
12041227 Observer.changedInstr(MI);
12051228 return Legalized;
1212
1313 class DummyGISelObserver : public GISelChangeObserver {
1414 public:
15 void changingInstr(MachineInstr &MI) override {}
1516 void changedInstr(MachineInstr &MI) override {}
1617 void createdInstr(MachineInstr &MI) override {}
1718 void erasingInstr(MachineInstr &MI) override {}