From 32549707cc9aa67dbc19cbdc0490ffebc8ec253c Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Tue, 13 Feb 2018 10:22:54 -0800 Subject: Fix a bug in IR use-def information (#406) The basic problem here is that when unlinking an `IRUse` from the linked list of uses, there were several cases where I was failing to set the `prevLink` field of the next node to match the `prevLink` field of the node being removed. That doesn't show up when walking the linked list of uses forward, but it breaks it whenever you have subsequent unlinking operations. This change fixes the bugs of that kind I could find, and also adds a debug validation method to try to avoid breaking it again. I also made more access to `IRUse` go through accessor methods rather than using fields directly, to try to avoid this kind of error. I stopped short of making anything `private`, because I tend to find that it creates more hassles than it avoids. A few other fixes along the way: - Made the `List` type default-initialize elements when you resize it. I hadn't realized we weren't doing that. - Add a standalone `dumpIR(IRGlobalValue*)` so help when debugging issues. --- source/slang/ir.h | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'source/slang/ir.h') diff --git a/source/slang/ir.h b/source/slang/ir.h index 028468308..407506116 100644 --- a/source/slang/ir.h +++ b/source/slang/ir.h @@ -82,22 +82,27 @@ IROpInfo getIROpInfo(IROp op); // A use of another value/inst within an IR operation struct IRUse { + IRValue* get() { return usedValue; } + IRUser* getUser() { return user; } + + void init(IRUser* user, IRValue* usedValue); + void set(IRValue* usedValue); + void clear(); + // The value that is being used - IRValue* usedValue; + IRValue* usedValue = nullptr; // The value that is doing the using. - IRUser* user; + IRUser* user = nullptr; // The next use of the same value - IRUse* nextUse; + IRUse* nextUse = nullptr; // A "link" back to where this use is referenced, // so that we can simplify updates. - IRUse** prevLink; + IRUse** prevLink = nullptr; - void init(IRUser* user, IRValue* usedValue); - void set(IRValue* usedValue); - void clear(); + void debugValidate(); }; enum IRDecorationOp : uint16_t @@ -262,7 +267,7 @@ struct IRUser : IRChildValue IRValue* getArg(UInt index) { - return getArgs()[index].usedValue; + return getArgs()[index].get(); } void setArg(UInt index, IRValue* value) @@ -542,6 +547,8 @@ void printSlangIRAssembly(StringBuilder& builder, IRModule* module); String getSlangIRAssembly(IRModule* module); void dumpIR(IRModule* module); +void dumpIR(IRGlobalValue* globalVal); + String dumpIRFunc(IRFunc* func); } -- cgit v1.2.3