-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Verify tmp registers #1010
base: main
Are you sure you want to change the base?
Verify tmp registers #1010
Changes from 20 commits
4d7932a
11f3509
9318029
753c457
abdbf53
3a4c0df
8eba31b
f2a1382
e2ec714
d6879e7
4d12ef0
54ce38f
87e1184
0b1638e
06d93f7
d16e0b2
a5b3a3f
9546bee
82cfbb3
59b6c9f
88838a1
2895ca3
f264fd5
029c548
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,18 +67,53 @@ class VerifyContext { | |
|
||
public function verifyFunctionCode(Module mod, FunctionDefn defn, FunctionCode code) returns Error? { | ||
VerifyContext cx = new(mod, defn); | ||
boolean[] tmpRegisterInitialized = []; | ||
if code.registers.length() > 0 { | ||
tmpRegisterInitialized[code.registers.length() - 1] = false; | ||
} | ||
foreach BasicBlock b in code.blocks { | ||
check verifyBasicBlock(cx, b); | ||
check verifyBasicBlock(cx, b, tmpRegisterInitialized); | ||
} | ||
} | ||
|
||
type IntBinaryInsn IntArithmeticBinaryInsn|IntBitwiseBinaryInsn; | ||
|
||
type Error err:Semantic|err:Internal; | ||
|
||
function verifyBasicBlock(VerifyContext vc, BasicBlock bb) returns Error? { | ||
function verifyBasicBlock(VerifyContext vc, BasicBlock bb, boolean[] tmpRegisterInitialized) returns Error? { | ||
foreach Insn insn in bb.insns { | ||
check verifyInsn(vc, insn); | ||
check verifyTmpRegisters(vc, insn, tmpRegisterInitialized); | ||
} | ||
} | ||
|
||
function verifyTmpRegisters(VerifyContext vc, Insn insn, boolean[] tmpRegisterInitialized) returns Error? { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's call this |
||
if insn is ResultInsnBase { | ||
if tmpRegisterInitialized[insn.result.number] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add |
||
return vc.invalidErr("multiple assignments to a tmp register", insn.pos); | ||
} | ||
else { | ||
tmpRegisterInitialized[insn.result.number] = true; | ||
} | ||
} | ||
|
||
match insn { | ||
var { operand } => { | ||
check verifyTmpOperandInitialized(vc, operand, tmpRegisterInitialized, insn.pos); | ||
} | ||
var { operands } | var { args: operands } => { | ||
// JBUG #35557 can't iterate operands | ||
Operand[] ops = operands; | ||
foreach Operand op in ops { | ||
check verifyTmpOperandInitialized(vc, op, tmpRegisterInitialized, insn.pos); | ||
} | ||
} | ||
} | ||
} | ||
|
||
function verifyTmpOperandInitialized(VerifyContext vc, Operand r, boolean[] tmpRegisterInitialized, Position pos) returns Error? { | ||
if r is TmpRegister && !tmpRegisterInitialized[r.number] { | ||
return vc.invalidErr("tmp register not initialized", pos); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,10 @@ class StmtContext { | |
return bir:createTmpRegister(self.code, t, pos); | ||
} | ||
|
||
function createAssignTmpRegister(bir:SemType t, Position? pos = ()) returns bir:AssignTmpRegister { | ||
return bir:createAssignTmpRegister(self.code, t, pos); | ||
} | ||
|
||
function nextRegisterNumber() returns int { | ||
return self.code.registers.length(); | ||
} | ||
|
@@ -699,6 +703,12 @@ function codeGenMatchStmt(StmtContext cx, bir:BasicBlock startBlock, Environment | |
else { | ||
// Match expression is not a variable: we do not get type narrowing | ||
int patternIndex = 0; | ||
if matched is bir:TmpRegister { | ||
bir:AssignTmpRegister result = cx.createAssignTmpRegister(matched.semType, matched.pos); | ||
bir:AssignInsn insn = { result, operand: matched, pos : stmt.startPos }; | ||
matched = result; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a match we are only reading There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a case like
even though matched is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we'll have to change the definition of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is already the case, the problem is when the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I meant
let me edit. |
||
testBlock.insns.push(insn); | ||
} | ||
foreach var mt in matchTests { | ||
int clauseIndex = mt.clauseIndex; | ||
if clauseIndex == defaultClauseIndex { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaner to do
tmpRegisterIntialized.setLength(code.registers.length());