Skip to content

Commit 49bf60d

Browse files
scottp101igcbot
authored andcommitted
Move "Defer" to helper.h
Move "Defer" to helper.h
1 parent a9a5d48 commit 49bf60d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

IGC/Compiler/CISACodeGen/helper.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,4 +536,20 @@ namespace IGC
536536
std::pair<llvm::Value*, unsigned int> GetURBBaseAndOffset(llvm::Value* pUrbOffset);
537537

538538
std::vector<std::pair<unsigned int, std::string>> GetPrintfStrings(llvm::Module &M);
539+
540+
template<typename Fn>
541+
struct Defer
542+
{
543+
Defer(Fn F) : F(F) {}
544+
~Defer() {
545+
if (Do) F();
546+
}
547+
void operator()() {
548+
if (Do) F();
549+
Do = false;
550+
}
551+
private:
552+
bool Do = true;
553+
Fn F;
554+
};
539555
} // namespace IGC

0 commit comments

Comments
 (0)