Skip to content

Commit 74b8d8a

Browse files
committed
[MachineOutliner] CFI clean up. Will be folded into the prior commit
1 parent 80df5a2 commit 74b8d8a

File tree

2 files changed

+23
-44
lines changed

2 files changed

+23
-44
lines changed

llvm/include/llvm/CodeGen/MachineOutliner.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,6 @@ struct OutlinedFunction {
234234
/// Target-defined identifier for constructing a frame for this function.
235235
unsigned FrameConstructionID = 0;
236236

237-
/// The sequence of stable_hash'es of instructions.
238-
std::vector<stable_hash> OutlinedHashSequence;
239-
240237
/// Return the number of candidates for this \p OutlinedFunction.
241238
virtual unsigned getOccurrenceCount() const { return Candidates.size(); }
242239

llvm/lib/CodeGen/MachineOutliner.cpp

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -655,10 +655,12 @@ static std::vector<MatchedEntry> getMatchedEntries(InstructionMapper &Mapper) {
655655
continue;
656656

657657
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())
660662
continue;
661-
663+
stable_hash StableHashI = stableHashValue(MI);
662664
Sequence.clear();
663665
Sequence.push_back(StableHashI);
664666

@@ -673,11 +675,10 @@ static std::vector<MatchedEntry> getMatchedEntries(InstructionMapper &Mapper) {
673675
break;
674676

675677
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;
680680

681+
stable_hash StableHashJ = stableHashValue(MJ);
681682
LastNode = followHashNode(StableHashJ, LastNode);
682683
if (!LastNode)
683684
break;
@@ -694,31 +695,6 @@ static std::vector<MatchedEntry> getMatchedEntries(InstructionMapper &Mapper) {
694695
return MatchedEntries;
695696
}
696697

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-
722698
void MachineOutliner::findGlobalCandidates(
723699
InstructionMapper &Mapper,
724700
std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList) {
@@ -746,8 +722,6 @@ void MachineOutliner::findGlobalCandidates(
746722
FunctionList.push_back(
747723
std::make_unique<GlobalOutlinedFunction>(*OF, ME.Count));
748724
}
749-
assert(OutlinerMode == CGDataMode::Read);
750-
saveHashSequence(FunctionList);
751725
}
752726

753727
void MachineOutliner::findCandidates(
@@ -854,9 +828,6 @@ void MachineOutliner::findCandidates(
854828

855829
FunctionList.push_back(std::make_unique<OutlinedFunction>(*OF));
856830
}
857-
assert(OutlinerMode != CGDataMode::Read);
858-
if (OutlinerMode == CGDataMode::Write)
859-
saveHashSequence(FunctionList);
860831
}
861832

862833
MachineFunction *MachineOutliner::createOutlinedFunction(
@@ -916,6 +887,7 @@ MachineFunction *MachineOutliner::createOutlinedFunction(
916887
MachineFunction *OriginalMF = FirstCand.front().getMF();
917888
const std::vector<MCCFIInstruction> &Instrs =
918889
OriginalMF->getFrameInstructions();
890+
std::vector<stable_hash> OutlinedHashSequence;
919891
for (auto &MI : FirstCand) {
920892
if (MI.isDebugInstr())
921893
continue;
@@ -932,9 +904,23 @@ MachineFunction *MachineOutliner::createOutlinedFunction(
932904
NewMI->dropMemRefs(MF);
933905
NewMI->setDebugLoc(DL);
934906
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+
}
935912
}
936913
}
937914

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+
938924
// Set normal properties for a late MachineFunction.
939925
MF.getProperties().reset(MachineFunctionProperties::Property::IsSSA);
940926
MF.getProperties().set(MachineFunctionProperties::Property::NoPHIs);
@@ -1154,10 +1140,6 @@ bool MachineOutliner::outline(
11541140
// Statistics.
11551141
NumOutlined++;
11561142
}
1157-
if (OutlinerMode == CGDataMode::Write) {
1158-
unsigned Count = OF->Candidates.size();
1159-
LocalHashTree->insert({OF->OutlinedHashSequence, Count});
1160-
}
11611143
}
11621144

11631145
LLVM_DEBUG(dbgs() << "OutlinedSomething = " << OutlinedSomething << "\n";);

0 commit comments

Comments
 (0)