summaryrefslogtreecommitdiff
path: root/source/slang/ir-insts.h
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-02-13 10:22:54 -0800
committerGitHub <noreply@github.com>2018-02-13 10:22:54 -0800
commit32549707cc9aa67dbc19cbdc0490ffebc8ec253c (patch)
tree4a8d50d9e42d73e045cd6cddf5e5879a43ce7f6b /source/slang/ir-insts.h
parent214a1fced7c53b81c00bec67fa2b91a357d5ece4 (diff)
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<T>` 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.
Diffstat (limited to 'source/slang/ir-insts.h')
-rw-r--r--source/slang/ir-insts.h36
1 files changed, 18 insertions, 18 deletions
diff --git a/source/slang/ir-insts.h b/source/slang/ir-insts.h
index eec42d59a..f53004ae4 100644
--- a/source/slang/ir-insts.h
+++ b/source/slang/ir-insts.h
@@ -124,8 +124,8 @@ struct IRFieldExtract : IRInst
IRUse base;
IRUse field;
- IRValue* getBase() { return base.usedValue; }
- IRValue* getField() { return field.usedValue; }
+ IRValue* getBase() { return base.get(); }
+ IRValue* getField() { return field.get(); }
};
struct IRFieldAddress : IRInst
@@ -133,8 +133,8 @@ struct IRFieldAddress : IRInst
IRUse base;
IRUse field;
- IRValue* getBase() { return base.usedValue; }
- IRValue* getField() { return field.usedValue; }
+ IRValue* getBase() { return base.get(); }
+ IRValue* getField() { return field.get(); }
};
// Terminators
@@ -146,7 +146,7 @@ struct IRReturnVal : IRReturn
{
IRUse val;
- IRValue* getVal() { return val.usedValue; }
+ IRValue* getVal() { return val.get(); }
};
struct IRReturnVoid : IRReturn
@@ -168,7 +168,7 @@ struct IRUnconditionalBranch : IRTerminatorInst
{
IRUse block;
- IRBlock* getTargetBlock() { return (IRBlock*)block.usedValue; }
+ IRBlock* getTargetBlock() { return (IRBlock*)block.get(); }
};
// Special cases of unconditional branch, to handle
@@ -191,8 +191,8 @@ struct IRLoop : IRUnconditionalBranch
// on a `continue`.
IRUse continueBlock;
- IRBlock* getBreakBlock() { return (IRBlock*)breakBlock.usedValue; }
- IRBlock* getContinueBlock() { return (IRBlock*)continueBlock.usedValue; }
+ IRBlock* getBreakBlock() { return (IRBlock*)breakBlock.get(); }
+ IRBlock* getContinueBlock() { return (IRBlock*)continueBlock.get(); }
};
struct IRConditionalBranch : IRTerminatorInst
@@ -201,9 +201,9 @@ struct IRConditionalBranch : IRTerminatorInst
IRUse trueBlock;
IRUse falseBlock;
- IRValue* getCondition() { return condition.usedValue; }
- IRBlock* getTrueBlock() { return (IRBlock*)trueBlock.usedValue; }
- IRBlock* getFalseBlock() { return (IRBlock*)falseBlock.usedValue; }
+ IRValue* getCondition() { return condition.get(); }
+ IRBlock* getTrueBlock() { return (IRBlock*)trueBlock.get(); }
+ IRBlock* getFalseBlock() { return (IRBlock*)falseBlock.get(); }
};
// A conditional branch that represent the test inside a loop
@@ -230,7 +230,7 @@ struct IRIfElse : IRConditionalBranch
{
IRUse afterBlock;
- IRBlock* getAfterBlock() { return (IRBlock*)afterBlock.usedValue; }
+ IRBlock* getAfterBlock() { return (IRBlock*)afterBlock.get(); }
};
// A multi-way branch that represents a source-level `switch`
@@ -240,9 +240,9 @@ struct IRSwitch : IRTerminatorInst
IRUse breakLabel;
IRUse defaultLabel;
- IRValue* getCondition() { return condition.usedValue; }
- IRBlock* getBreakLabel() { return (IRBlock*) breakLabel.usedValue; }
- IRBlock* getDefaultLabel() { return (IRBlock*) defaultLabel.usedValue; }
+ IRValue* getCondition() { return condition.get(); }
+ IRBlock* getBreakLabel() { return (IRBlock*) breakLabel.get(); }
+ IRBlock* getDefaultLabel() { return (IRBlock*) defaultLabel.get(); }
// remaining args are: caseVal, caseLabel, ...
@@ -255,7 +255,7 @@ struct IRSwizzle : IRReturn
{
IRUse base;
- IRValue* getBase() { return base.usedValue; }
+ IRValue* getBase() { return base.get(); }
UInt getElementCount()
{
return getArgCount() - 1;
@@ -271,8 +271,8 @@ struct IRSwizzleSet : IRReturn
IRUse base;
IRUse source;
- IRValue* getBase() { return base.usedValue; }
- IRValue* getSource() { return source.usedValue; }
+ IRValue* getBase() { return base.get(); }
+ IRValue* getSource() { return source.get(); }
UInt getElementCount()
{
return getArgCount() - 2;