@@ -3786,42 +3786,39 @@ void MachineVerifier::verifyLiveInterval(const LiveInterval &LI) {
3786
3786
3787
3787
namespace {
3788
3788
3789
- // FrameSetup and FrameDestroy can have zero adjustment, so using a single
3790
- // integer, we can't tell whether it is a FrameSetup or FrameDestroy if the
3791
- // value is zero.
3792
- // We use a bool plus an integer to capture the stack state.
3793
- struct StackStateOfBB {
3794
- StackStateOfBB () = default ;
3795
- StackStateOfBB (int EntryVal, int ExitVal, bool EntrySetup, bool ExitSetup) :
3796
- EntryValue (EntryVal), ExitValue(ExitVal), EntryIsSetup(EntrySetup),
3797
- ExitIsSetup (ExitSetup) {}
3798
-
3799
- // Can be negative, which means we are setting up a frame.
3800
- int EntryValue = 0 ;
3801
- int ExitValue = 0 ;
3802
- bool EntryIsSetup = false ;
3803
- bool ExitIsSetup = false ;
3804
- };
3789
+ // / Store for each MachineBasicBlock the call frame size at its entry and its
3790
+ // / exit. No value means that no call frame is open, zero means that a
3791
+ // / zero-sized call frame is open.
3792
+ struct StackStateOfBB {
3793
+ StackStateOfBB () = default ;
3794
+ StackStateOfBB (std::optional<unsigned > EntryVal,
3795
+ std::optional<unsigned > ExitVal)
3796
+ : Entry(EntryVal), Exit(ExitVal) {}
3797
+
3798
+ std::optional<unsigned > Entry;
3799
+ std::optional<unsigned > Exit;
3800
+ };
3805
3801
3806
3802
} // end anonymous namespace
3807
3803
3808
3804
// / Make sure on every path through the CFG, a FrameSetup <n> is always followed
3809
3805
// / by a FrameDestroy <n>, stack adjustments are identical on all
3810
3806
// / CFG edges to a merge point, and frame is destroyed at end of a return block.
3811
3807
void MachineVerifier::verifyStackFrame () {
3812
- unsigned FrameSetupOpcode = TII->getCallFrameSetupOpcode ();
3808
+ unsigned FrameSetupOpcode = TII->getCallFrameSetupOpcode ();
3813
3809
unsigned FrameDestroyOpcode = TII->getCallFrameDestroyOpcode ();
3814
3810
if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u )
3815
3811
return ;
3816
3812
3817
3813
SmallVector<StackStateOfBB, 8 > SPState;
3818
3814
SPState.resize (MF->getNumBlockIDs ());
3819
- df_iterator_default_set<const MachineBasicBlock*> Reachable;
3815
+ df_iterator_default_set<const MachineBasicBlock *> Reachable;
3820
3816
3821
3817
// Visit the MBBs in DFS order.
3822
3818
for (df_ext_iterator<const MachineFunction *,
3823
3819
df_iterator_default_set<const MachineBasicBlock *>>
3824
- DFI = df_ext_begin (MF, Reachable), DFE = df_ext_end (MF, Reachable);
3820
+ DFI = df_ext_begin (MF, Reachable),
3821
+ DFE = df_ext_end (MF, Reachable);
3825
3822
DFI != DFE; ++DFI) {
3826
3823
const MachineBasicBlock *MBB = *DFI;
3827
3824
@@ -3831,49 +3828,45 @@ void MachineVerifier::verifyStackFrame() {
3831
3828
const MachineBasicBlock *StackPred = DFI.getPath (DFI.getPathLength () - 2 );
3832
3829
assert (Reachable.count (StackPred) &&
3833
3830
" DFS stack predecessor is already visited.\n " );
3834
- BBState.EntryValue = SPState[StackPred->getNumber ()].ExitValue ;
3835
- BBState.EntryIsSetup = SPState[StackPred->getNumber ()].ExitIsSetup ;
3836
- BBState.ExitValue = BBState.EntryValue ;
3837
- BBState.ExitIsSetup = BBState.EntryIsSetup ;
3831
+ BBState.Entry = SPState[StackPred->getNumber ()].Exit ;
3832
+ BBState.Exit = BBState.Entry ;
3838
3833
}
3839
3834
3840
- if (( int ) MBB->getCallFrameSizeOrZero () != - BBState.EntryValue ) {
3835
+ if (MBB->getCallFrameSize () != BBState.Entry ) {
3841
3836
report (" Call frame size on entry does not match value computed from "
3842
3837
" predecessor" ,
3843
3838
MBB);
3844
- errs () << " Call frame size on entry " << MBB->getCallFrameSizeOrZero ()
3839
+ errs () << " Call frame size on entry " << MBB->getCallFrameSize ()
3845
3840
<< " does not match value computed from predecessor "
3846
- << - BBState.EntryValue << ' \n ' ;
3841
+ << BBState.Entry << ' \n ' ;
3847
3842
}
3848
3843
3849
3844
// Update stack state by checking contents of MBB.
3850
3845
for (const auto &I : *MBB) {
3851
3846
if (I.getOpcode () == FrameSetupOpcode) {
3852
- if (BBState.ExitIsSetup )
3847
+ if (BBState.Exit . has_value () )
3853
3848
report (" FrameSetup is after another FrameSetup" , &I);
3854
3849
if (!MRI->isSSA () && !MF->getFrameInfo ().adjustsStack ())
3855
3850
report (" AdjustsStack not set in presence of a frame pseudo "
3856
- " instruction." , &I);
3857
- BBState. ExitValue -= TII-> getFrameTotalSize ( I);
3858
- BBState.ExitIsSetup = true ;
3851
+ " instruction." ,
3852
+ & I);
3853
+ BBState.Exit = TII-> getFrameTotalSize (I) ;
3859
3854
}
3860
3855
3861
3856
if (I.getOpcode () == FrameDestroyOpcode) {
3862
- int Size = TII->getFrameTotalSize (I);
3863
- if (!BBState.ExitIsSetup )
3857
+ int64_t Size = TII->getFrameTotalSize (I);
3858
+ if (!BBState.Exit . has_value () )
3864
3859
report (" FrameDestroy is not after a FrameSetup" , &I);
3865
- int AbsSPAdj = BBState.ExitValue < 0 ? -BBState.ExitValue :
3866
- BBState.ExitValue ;
3867
- if (BBState.ExitIsSetup && AbsSPAdj != Size) {
3860
+ else if ((int64_t )BBState.Exit .value () != Size) {
3868
3861
report (" FrameDestroy <n> is after FrameSetup <m>" , &I);
3869
3862
errs () << " FrameDestroy <" << Size << " > is after FrameSetup <"
3870
- << AbsSPAdj << " >.\n " ;
3863
+ << BBState. Exit . value () << " >.\n " ;
3871
3864
}
3872
3865
if (!MRI->isSSA () && !MF->getFrameInfo ().adjustsStack ())
3873
3866
report (" AdjustsStack not set in presence of a frame pseudo "
3874
- " instruction." , &I);
3875
- BBState. ExitValue += Size ;
3876
- BBState.ExitIsSetup = false ;
3867
+ " instruction." ,
3868
+ &I) ;
3869
+ BBState.Exit . reset () ;
3877
3870
}
3878
3871
}
3879
3872
SPState[MBB->getNumber ()] = BBState;
@@ -3882,38 +3875,32 @@ void MachineVerifier::verifyStackFrame() {
3882
3875
// state.
3883
3876
for (const MachineBasicBlock *Pred : MBB->predecessors ()) {
3884
3877
if (Reachable.count (Pred) &&
3885
- (SPState[Pred->getNumber ()].ExitValue != BBState.EntryValue ||
3886
- SPState[Pred->getNumber ()].ExitIsSetup != BBState.EntryIsSetup )) {
3878
+ SPState[Pred->getNumber ()].Exit != BBState.Entry ) {
3887
3879
report (" The exit stack state of a predecessor is inconsistent." , MBB);
3888
3880
errs () << " Predecessor " << printMBBReference (*Pred)
3889
- << " has exit state (" << SPState[Pred->getNumber ()].ExitValue
3890
- << " , " << SPState[Pred->getNumber ()].ExitIsSetup << " ), while "
3891
- << printMBBReference (*MBB) << " has entry state ("
3892
- << BBState.EntryValue << " , " << BBState.EntryIsSetup << " ).\n " ;
3881
+ << " has exit state " << SPState[Pred->getNumber ()].Exit
3882
+ << " , while " << printMBBReference (*MBB) << " has entry state "
3883
+ << BBState.Entry << " .\n " ;
3893
3884
}
3894
3885
}
3895
3886
3896
3887
// Make sure the entry state of any successor is consistent with the exit
3897
3888
// state.
3898
3889
for (const MachineBasicBlock *Succ : MBB->successors ()) {
3899
3890
if (Reachable.count (Succ) &&
3900
- (SPState[Succ->getNumber ()].EntryValue != BBState.ExitValue ||
3901
- SPState[Succ->getNumber ()].EntryIsSetup != BBState.ExitIsSetup )) {
3891
+ SPState[Succ->getNumber ()].Entry != BBState.Exit ) {
3902
3892
report (" The entry stack state of a successor is inconsistent." , MBB);
3903
3893
errs () << " Successor " << printMBBReference (*Succ)
3904
- << " has entry state (" << SPState[Succ->getNumber ()].EntryValue
3905
- << " , " << SPState[Succ->getNumber ()].EntryIsSetup << " ), while "
3906
- << printMBBReference (*MBB) << " has exit state ("
3907
- << BBState.ExitValue << " , " << BBState.ExitIsSetup << " ).\n " ;
3894
+ << " has entry state " << SPState[Succ->getNumber ()].Entry
3895
+ << " , while " << printMBBReference (*MBB) << " has exit state "
3896
+ << BBState.Exit << " .\n " ;
3908
3897
}
3909
3898
}
3910
3899
3911
3900
// Make sure a basic block with return ends with zero stack adjustment.
3912
3901
if (!MBB->empty () && MBB->back ().isReturn ()) {
3913
- if (BBState.ExitIsSetup )
3902
+ if (BBState.Exit . has_value () )
3914
3903
report (" A return block ends with a FrameSetup." , MBB);
3915
- if (BBState.ExitValue )
3916
- report (" A return block ends with a nonzero stack adjustment." , MBB);
3917
3904
}
3918
3905
}
3919
3906
}
0 commit comments