@@ -655,10 +655,12 @@ static std::vector<MatchedEntry> getMatchedEntries(InstructionMapper &Mapper) {
655
655
continue ;
656
656
657
657
const MachineInstr &MI = *InstrList[I];
658
- stable_hash StableHashI = stableHashValue (MI);
659
- if (!StableHashI)
658
+ // We optimistically skip Debug instructions and CFI instructions.
659
+ // Debug instructions will be deleted in the outlined function.
660
+ // CFI instructions are adapted to the outlined function.
661
+ if (MI.isDebugInstr () || MI.isCFIInstruction ())
660
662
continue ;
661
-
663
+ stable_hash StableHashI = stableHashValue (MI);
662
664
Sequence.clear ();
663
665
Sequence.push_back (StableHashI);
664
666
@@ -673,11 +675,10 @@ static std::vector<MatchedEntry> getMatchedEntries(InstructionMapper &Mapper) {
673
675
break ;
674
676
675
677
const MachineInstr &MJ = *InstrList[J];
676
- stable_hash StableHashJ = stableHashValue (MJ);
677
- // Break on invalid stable hash
678
- if (!StableHashJ)
679
- break ;
678
+ if (MJ.isDebugInstr () || MJ.isCFIInstruction ())
679
+ continue ;
680
680
681
+ stable_hash StableHashJ = stableHashValue (MJ);
681
682
LastNode = followHashNode (StableHashJ, LastNode);
682
683
if (!LastNode)
683
684
break ;
@@ -694,31 +695,6 @@ static std::vector<MatchedEntry> getMatchedEntries(InstructionMapper &Mapper) {
694
695
return MatchedEntries;
695
696
}
696
697
697
- static std::vector<stable_hash>
698
- stableHashMachineInstrs (const MachineBasicBlock::iterator &Begin,
699
- const MachineBasicBlock::iterator &End) {
700
- std::vector<stable_hash> Sequence;
701
- for (auto I = Begin; I != End; I++) {
702
- const MachineInstr &MI = *I;
703
- if (MI.isDebugInstr ())
704
- continue ;
705
- stable_hash Hash = stableHashValue (MI);
706
- // if (!Hash)
707
- // continue;
708
- Sequence.push_back (Hash);
709
- }
710
- return Sequence;
711
- }
712
-
713
- // Save hash sequence of candidates for global function outlining.
714
- static void
715
- saveHashSequence (std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList) {
716
- for (auto &OF : FunctionList) {
717
- auto &C = OF->Candidates .front ();
718
- OF->OutlinedHashSequence = stableHashMachineInstrs (C.begin (), C.end ());
719
- }
720
- }
721
-
722
698
void MachineOutliner::findGlobalCandidates (
723
699
InstructionMapper &Mapper,
724
700
std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList) {
@@ -746,8 +722,6 @@ void MachineOutliner::findGlobalCandidates(
746
722
FunctionList.push_back (
747
723
std::make_unique<GlobalOutlinedFunction>(*OF, ME.Count ));
748
724
}
749
- assert (OutlinerMode == CGDataMode::Read);
750
- saveHashSequence (FunctionList);
751
725
}
752
726
753
727
void MachineOutliner::findCandidates (
@@ -854,9 +828,6 @@ void MachineOutliner::findCandidates(
854
828
855
829
FunctionList.push_back (std::make_unique<OutlinedFunction>(*OF));
856
830
}
857
- assert (OutlinerMode != CGDataMode::Read);
858
- if (OutlinerMode == CGDataMode::Write)
859
- saveHashSequence (FunctionList);
860
831
}
861
832
862
833
MachineFunction *MachineOutliner::createOutlinedFunction (
@@ -916,6 +887,7 @@ MachineFunction *MachineOutliner::createOutlinedFunction(
916
887
MachineFunction *OriginalMF = FirstCand.front ().getMF ();
917
888
const std::vector<MCCFIInstruction> &Instrs =
918
889
OriginalMF->getFrameInstructions ();
890
+ std::vector<stable_hash> OutlinedHashSequence;
919
891
for (auto &MI : FirstCand) {
920
892
if (MI.isDebugInstr ())
921
893
continue ;
@@ -932,9 +904,23 @@ MachineFunction *MachineOutliner::createOutlinedFunction(
932
904
NewMI->dropMemRefs (MF);
933
905
NewMI->setDebugLoc (DL);
934
906
MBB.insert (MBB.end (), NewMI);
907
+ // For non-debug and non-cfi instructions, compute stable hash sequence.
908
+ if (OutlinerMode != CGDataMode::None) {
909
+ stable_hash Hash = stableHashValue (MI);
910
+ OutlinedHashSequence.push_back (Hash);
911
+ }
935
912
}
936
913
}
937
914
915
+ // TODO: Update function name based on the hash sequence.
916
+
917
+ // Publish the hash sequence to the local hash tree.
918
+ if (OutlinerMode == CGDataMode::Write) {
919
+ assert (!OutlinedHashSequence.empty ());
920
+ unsigned Count = OF.Candidates .size ();
921
+ LocalHashTree->insert ({OutlinedHashSequence, Count});
922
+ }
923
+
938
924
// Set normal properties for a late MachineFunction.
939
925
MF.getProperties ().reset (MachineFunctionProperties::Property::IsSSA);
940
926
MF.getProperties ().set (MachineFunctionProperties::Property::NoPHIs);
@@ -1154,10 +1140,6 @@ bool MachineOutliner::outline(
1154
1140
// Statistics.
1155
1141
NumOutlined++;
1156
1142
}
1157
- if (OutlinerMode == CGDataMode::Write) {
1158
- unsigned Count = OF->Candidates .size ();
1159
- LocalHashTree->insert ({OF->OutlinedHashSequence , Count});
1160
- }
1161
1143
}
1162
1144
1163
1145
LLVM_DEBUG (dbgs () << " OutlinedSomething = " << OutlinedSomething << " \n " ;);
0 commit comments