From 684c23f1c5257886a219d540ac4ec0e574b7e49b Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Tue, 29 Sep 2026 16:16:13 -0700 Subject: Bring forward the lazy mem alias Integrate with ch15 NewNode creating aliases --- chapter13/README.md | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'chapter13/README.md') diff --git a/chapter13/README.md b/chapter13/README.md index c54bfa70..1c492468 100644 --- a/chapter13/README.md +++ b/chapter13/README.md @@ -1,5 +1,10 @@ # Chapter 13: References +Memory retains one `$mem` binding and lazy partitions. Typed initialization +stores now include each field's declared type and initialization flag, while +`MemMerge` preserves the other fields. Start and Return keep control in slot 0 +and memory in slot 1. + # Table of Contents 1. [References](#references) @@ -64,21 +69,23 @@ p.tree.la = null; // Accessing unknown field 'la' from 'null' It turns out `p.tree` is `null`, so we can't access the field `la` from it. ```java // name = "tree" -// memAlias(alias) = StoreNode +// mem() is the current aggregate; its tree alias selects the initializing Store. // in(3) = {ConstantNode@1651} "null" -return parsePostfix(new LoadNode(name, alias, declaredType.glb(), memAlias(alias), expr).peephole()); +return parsePostfix(new LoadNode(name, alias, declaredType.glb(), mem(), expr).peephole()); ``` `LoadNode::idealize` -In LoadNode idealize we return st.val(). +LoadNode first selects its alias through any MemMerge, then returns `st.val()` +when it finds a matching Store to the same object. ```java // Simple Load-after-Store on same address. if( mem() instanceof StoreNode st && - ptr() == st.ptr() ) { // Must check same object + ptr() == st.ptr() && _alias == st._alias ) { // Same object and field assert _name.equals(st._name); // Equiv class aliasing is perfect return st.val(); // // <<-- {ConstantNode@1651} "null" } ``` -`mem(): ` refers to `memAlias(alias)`. Therefore, in the next iteration, we will end up with: +After alias selection, the Load's `mem()` refers to that initializing Store. +In the next iteration, we will end up with: ```java ... @@ -98,9 +105,9 @@ When we are creating the struct, we set up the initial value to Null: ```java private Node newStruct(TypeStruct obj) { Node n = new NewNode(TypeMemPtr.make(obj), ctrl()).peephole().keep(); - int alias = START._aliasStarts.get(obj._name); + int alias = _aliases.get(obj._name); for( Field field : obj._fields ) { - memAlias(alias, new StoreNode(field._fname, alias, field._type, ctrl(), memAlias(alias), n, new ConstantNode(field._type.makeInit()).peephole(),true).peephole()); + store(field._fname,alias,field._type,n,new ConstantNode(field._type.makeInit()).peephole(),true); alias++; } return n.unkeep(); @@ -114,7 +121,7 @@ for( Field field : obj._fields ) { // field._type = *FamilyTree? // REMEMBER: // @Override public TypeMemPtr makeInit() { return NULLPTR; } - memAlias(..., new ConstantNode(field._type.makeInit()).peephole(),true).peephole()); + store(field._fname,alias,field._type,n,new ConstantNode(field._type.makeInit()).peephole(),true); alias++; } ``` @@ -256,4 +263,4 @@ for( ; lca != early.idom(); lca = lca.idom() ) if( better(lca,best) ) best = lca; assert !(best instanceof IfNode); -``` \ No newline at end of file +``` -- cgit v1.2.3