@@ -3843,21 +3843,17 @@ void MachineVerifier::verifyLiveInterval(const LiveInterval &LI) {
3843
3843
3844
3844
namespace {
3845
3845
3846
- // FrameSetup and FrameDestroy can have zero adjustment, so using a single
3847
- // integer, we can't tell whether it is a FrameSetup or FrameDestroy if the
3848
- // value is zero.
3849
- // We use a bool plus an integer to capture the stack state.
3846
+ // / Store for each MachineBasicBlock the call frame size at its entry and its
3847
+ // / exit. No value means that no call frame is open, zero means that a
3848
+ // / zero-sized call frame is open.
3850
3849
struct StackStateOfBB {
3851
3850
StackStateOfBB () = default ;
3852
- StackStateOfBB (int EntryVal, int ExitVal, bool EntrySetup, bool ExitSetup)
3853
- : EntryValue(EntryVal), ExitValue(ExitVal), EntryIsSetup(EntrySetup),
3854
- ExitIsSetup (ExitSetup) {}
3855
-
3856
- // Can be negative, which means we are setting up a frame.
3857
- int EntryValue = 0 ;
3858
- int ExitValue = 0 ;
3859
- bool EntryIsSetup = false ;
3860
- bool ExitIsSetup = false ;
3851
+ StackStateOfBB (std::optional<unsigned > EntryVal,
3852
+ std::optional<unsigned > ExitVal)
3853
+ : Entry(EntryVal), Exit(ExitVal) {}
3854
+
3855
+ std::optional<unsigned > Entry;
3856
+ std::optional<unsigned > Exit;
3861
3857
};
3862
3858
3863
3859
} // end anonymous namespace
@@ -3866,19 +3862,20 @@ struct StackStateOfBB {
3866
3862
// / by a FrameDestroy <n>, stack adjustments are identical on all
3867
3863
// / CFG edges to a merge point, and frame is destroyed at end of a return block.
3868
3864
void MachineVerifier::verifyStackFrame () {
3869
- unsigned FrameSetupOpcode = TII->getCallFrameSetupOpcode ();
3865
+ unsigned FrameSetupOpcode = TII->getCallFrameSetupOpcode ();
3870
3866
unsigned FrameDestroyOpcode = TII->getCallFrameDestroyOpcode ();
3871
3867
if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u )
3872
3868
return ;
3873
3869
3874
3870
SmallVector<StackStateOfBB, 8 > SPState;
3875
3871
SPState.resize (MF->getNumBlockIDs ());
3876
- df_iterator_default_set<const MachineBasicBlock*> Reachable;
3872
+ df_iterator_default_set<const MachineBasicBlock *> Reachable;
3877
3873
3878
3874
// Visit the MBBs in DFS order.
3879
3875
for (df_ext_iterator<const MachineFunction *,
3880
3876
df_iterator_default_set<const MachineBasicBlock *>>
3881
- DFI = df_ext_begin (MF, Reachable), DFE = df_ext_end (MF, Reachable);
3877
+ DFI = df_ext_begin (MF, Reachable),
3878
+ DFE = df_ext_end (MF, Reachable);
3882
3879
DFI != DFE; ++DFI) {
3883
3880
const MachineBasicBlock *MBB = *DFI;
3884
3881
@@ -3888,49 +3885,45 @@ void MachineVerifier::verifyStackFrame() {
3888
3885
const MachineBasicBlock *StackPred = DFI.getPath (DFI.getPathLength () - 2 );
3889
3886
assert (Reachable.count (StackPred) &&
3890
3887
" DFS stack predecessor is already visited.\n " );
3891
- BBState.EntryValue = SPState[StackPred->getNumber ()].ExitValue ;
3892
- BBState.EntryIsSetup = SPState[StackPred->getNumber ()].ExitIsSetup ;
3893
- BBState.ExitValue = BBState.EntryValue ;
3894
- BBState.ExitIsSetup = BBState.EntryIsSetup ;
3888
+ BBState.Entry = SPState[StackPred->getNumber ()].Exit ;
3889
+ BBState.Exit = BBState.Entry ;
3895
3890
}
3896
3891
3897
- if (( int ) MBB->getCallFrameSizeOrZero () != - BBState.EntryValue ) {
3892
+ if (MBB->getCallFrameSize () != BBState.Entry ) {
3898
3893
report (" Call frame size on entry does not match value computed from "
3899
3894
" predecessor" ,
3900
3895
MBB);
3901
- OS << " Call frame size on entry " << MBB->getCallFrameSizeOrZero ()
3902
- << " does not match value computed from predecessor "
3903
- << -BBState. EntryValue << ' \n ' ;
3896
+ OS << " Call frame size on entry " << MBB->getCallFrameSize ()
3897
+ << " does not match value computed from predecessor " << BBState. Entry
3898
+ << ' \n ' ;
3904
3899
}
3905
3900
3906
3901
// Update stack state by checking contents of MBB.
3907
3902
for (const auto &I : *MBB) {
3908
3903
if (I.getOpcode () == FrameSetupOpcode) {
3909
- if (BBState.ExitIsSetup )
3904
+ if (BBState.Exit . has_value () )
3910
3905
report (" FrameSetup is after another FrameSetup" , &I);
3911
3906
if (!MRI->isSSA () && !MF->getFrameInfo ().adjustsStack ())
3912
3907
report (" AdjustsStack not set in presence of a frame pseudo "
3913
- " instruction." , &I);
3914
- BBState. ExitValue -= TII-> getFrameTotalSize ( I);
3915
- BBState.ExitIsSetup = true ;
3908
+ " instruction." ,
3909
+ & I);
3910
+ BBState.Exit = TII-> getFrameTotalSize (I) ;
3916
3911
}
3917
3912
3918
3913
if (I.getOpcode () == FrameDestroyOpcode) {
3919
- int Size = TII->getFrameTotalSize (I);
3920
- if (!BBState.ExitIsSetup )
3914
+ int64_t Size = TII->getFrameTotalSize (I);
3915
+ if (!BBState.Exit . has_value () )
3921
3916
report (" FrameDestroy is not after a FrameSetup" , &I);
3922
- int AbsSPAdj = BBState.ExitValue < 0 ? -BBState.ExitValue :
3923
- BBState.ExitValue ;
3924
- if (BBState.ExitIsSetup && AbsSPAdj != Size) {
3917
+ else if ((int64_t )BBState.Exit .value () != Size) {
3925
3918
report (" FrameDestroy <n> is after FrameSetup <m>" , &I);
3926
3919
OS << " FrameDestroy <" << Size << " > is after FrameSetup <"
3927
- << AbsSPAdj << " >.\n " ;
3920
+ << BBState. Exit . value () << " >.\n " ;
3928
3921
}
3929
3922
if (!MRI->isSSA () && !MF->getFrameInfo ().adjustsStack ())
3930
3923
report (" AdjustsStack not set in presence of a frame pseudo "
3931
- " instruction." , &I);
3932
- BBState. ExitValue += Size ;
3933
- BBState.ExitIsSetup = false ;
3924
+ " instruction." ,
3925
+ &I) ;
3926
+ BBState.Exit . reset () ;
3934
3927
}
3935
3928
}
3936
3929
SPState[MBB->getNumber ()] = BBState;
@@ -3939,38 +3932,32 @@ void MachineVerifier::verifyStackFrame() {
3939
3932
// state.
3940
3933
for (const MachineBasicBlock *Pred : MBB->predecessors ()) {
3941
3934
if (Reachable.count (Pred) &&
3942
- (SPState[Pred->getNumber ()].ExitValue != BBState.EntryValue ||
3943
- SPState[Pred->getNumber ()].ExitIsSetup != BBState.EntryIsSetup )) {
3935
+ SPState[Pred->getNumber ()].Exit != BBState.Entry ) {
3944
3936
report (" The exit stack state of a predecessor is inconsistent." , MBB);
3945
- OS << " Predecessor " << printMBBReference (*Pred) << " has exit state ("
3946
- << SPState[Pred->getNumber ()].ExitValue << " , "
3947
- << SPState[Pred->getNumber ()].ExitIsSetup << " ), while "
3948
- << printMBBReference (*MBB) << " has entry state ("
3949
- << BBState.EntryValue << " , " << BBState.EntryIsSetup << " ).\n " ;
3937
+ OS << " Predecessor " << printMBBReference (*Pred) << " has exit state "
3938
+ << SPState[Pred->getNumber ()].Exit << " , while "
3939
+ << printMBBReference (*MBB) << " has entry state " << BBState.Entry
3940
+ << " .\n " ;
3950
3941
}
3951
3942
}
3952
3943
3953
3944
// Make sure the entry state of any successor is consistent with the exit
3954
3945
// state.
3955
3946
for (const MachineBasicBlock *Succ : MBB->successors ()) {
3956
3947
if (Reachable.count (Succ) &&
3957
- (SPState[Succ->getNumber ()].EntryValue != BBState.ExitValue ||
3958
- SPState[Succ->getNumber ()].EntryIsSetup != BBState.ExitIsSetup )) {
3948
+ SPState[Succ->getNumber ()].Entry != BBState.Exit ) {
3959
3949
report (" The entry stack state of a successor is inconsistent." , MBB);
3960
- OS << " Successor " << printMBBReference (*Succ) << " has entry state ("
3961
- << SPState[Succ->getNumber ()].EntryValue << " , "
3962
- << SPState[Succ->getNumber ()].EntryIsSetup << " ), while "
3963
- << printMBBReference (*MBB) << " has exit state ("
3964
- << BBState.ExitValue << " , " << BBState.ExitIsSetup << " ).\n " ;
3950
+ OS << " Successor " << printMBBReference (*Succ) << " has entry state "
3951
+ << SPState[Succ->getNumber ()].Entry << " , while "
3952
+ << printMBBReference (*MBB) << " has exit state " << BBState.Exit
3953
+ << " .\n " ;
3965
3954
}
3966
3955
}
3967
3956
3968
3957
// Make sure a basic block with return ends with zero stack adjustment.
3969
3958
if (!MBB->empty () && MBB->back ().isReturn ()) {
3970
- if (BBState.ExitIsSetup )
3959
+ if (BBState.Exit . has_value () )
3971
3960
report (" A return block ends with a FrameSetup." , MBB);
3972
- if (BBState.ExitValue )
3973
- report (" A return block ends with a nonzero stack adjustment." , MBB);
3974
3961
}
3975
3962
}
3976
3963
}
0 commit comments