Skip to content

Commit f17d0a8

Browse files
Add GetPrevLabelInstr and GetBlockStartInstr
1 parent 86715b3 commit f17d0a8

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

lib/Backend/IR.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,6 +2851,42 @@ Instr::GetPrevRealInstrOrLabel() const
28512851
return instr;
28522852
}
28532853

2854+
///----------------------------------------------------------------------------
2855+
///
2856+
/// Instr::GetPrevLabelInstr
2857+
///
2858+
///----------------------------------------------------------------------------
2859+
IR::LabelInstr *
2860+
Instr::GetPrevLabelInstr() const
2861+
{
2862+
IR::Instr *instr = this->m_prev;
2863+
2864+
while (!instr->IsLabelInstr())
2865+
{
2866+
instr = instr->m_prev;
2867+
AssertMsg(instr, "GetPrevLabelInstr() failed...");
2868+
}
2869+
return instr->AsLabelInstr();
2870+
}
2871+
2872+
///----------------------------------------------------------------------------
2873+
///
2874+
/// Instr::GetPrevLabelInstr
2875+
///
2876+
///----------------------------------------------------------------------------
2877+
IR::Instr *
2878+
Instr::GetBlockStartInstr() const
2879+
{
2880+
IR::Instr *instr = this->m_prev;
2881+
2882+
while (!instr->StartsBasicBlock())
2883+
{
2884+
instr = instr->m_prev;
2885+
AssertMsg(instr, "GetBlockStartInstr() failed...");
2886+
}
2887+
return instr;
2888+
}
2889+
28542890
///----------------------------------------------------------------------------
28552891
///
28562892
/// Instr::GetInsertBeforeByteCodeUsesInstr

lib/Backend/IR.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ class Instr
295295
IR::Instr * GetNextBranchOrLabel() const;
296296
IR::Instr * GetPrevRealInstr() const;
297297
IR::Instr * GetPrevRealInstrOrLabel() const;
298+
IR::LabelInstr *GetPrevLabelInstr() const;
299+
IR::Instr * GetBlockStartInstr() const;
298300
IR::Instr * GetInsertBeforeByteCodeUsesInstr();
299301
IR::ByteCodeUsesInstr * GetFirstByteCodeUsesInstrBackward();
300302
bool IsByteCodeUsesInstrFor(IR::Instr * instr) const;

0 commit comments

Comments
 (0)