summaryrefslogtreecommitdiff
path: root/chapter24/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'chapter24/src/main')
-rw-r--r--chapter24/src/main/java/com/seaofnodes/simple/Parser.java8
-rw-r--r--chapter24/src/main/java/com/seaofnodes/simple/node/CallEndNode.java3
-rw-r--r--chapter24/src/main/java/com/seaofnodes/simple/node/RegionNode.java6
-rw-r--r--chapter24/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java52
4 files changed, 39 insertions, 30 deletions
diff --git a/chapter24/src/main/java/com/seaofnodes/simple/Parser.java b/chapter24/src/main/java/com/seaofnodes/simple/Parser.java
index 43908685..65c4abf7 100644
--- a/chapter24/src/main/java/com/seaofnodes/simple/Parser.java
+++ b/chapter24/src/main/java/com/seaofnodes/simple/Parser.java
@@ -1055,7 +1055,9 @@ public class Parser {
boolean eq = false;
if( match("==") ) eq = true;
else if( !match("!=") ) break;
- lhs = peep(new BoolNode.EQ(lhs,parseComparison()));
+ lhs.keep();
+ Node rhs = parseComparison();
+ lhs = peep(new BoolNode.EQ(lhs.unkeep(),rhs));
if( !eq ) lhs = peep(new NotNode(lhs));
}
return lhs;
@@ -1082,14 +1084,14 @@ public class Parser {
else if( match("<" ) ) dir0 = 1;
else if( match(">" ) ) dir0 = 2;
else break;
+ lhs.keep();
// Check and record direction
if( dir==0 ) {
dir = Math.abs(dir0);
Node rhs = parseShift();
- lhs = makeCompBool(dir0,lhs,rhs); // Convert to a bool
+ lhs = makeCompBool(dir0,lhs.unkeep(),rhs); // Convert to a bool
} else if( dir == Math.abs(dir0) ) {
// e0 < lhs < ???
- lhs.keep();
Node ifNode = new IfNode(ctrl(), lhs).peephole();
Node ifT = new CProjNode(ifNode. keep(), 0, "True" ).peephole();
Node ifF = new CProjNode(ifNode.unkeep(), 1, "False").peephole();
diff --git a/chapter24/src/main/java/com/seaofnodes/simple/node/CallEndNode.java b/chapter24/src/main/java/com/seaofnodes/simple/node/CallEndNode.java
index d95af697..8c25c158 100644
--- a/chapter24/src/main/java/com/seaofnodes/simple/node/CallEndNode.java
+++ b/chapter24/src/main/java/com/seaofnodes/simple/node/CallEndNode.java
@@ -76,8 +76,9 @@ public class CallEndNode extends CFGNode implements MultiNode {
CFGNode idom = call;
while( !(idom instanceof FunNode) && idom!=null )
idom = idom.idom();
+ if( idom!=null ) addDep(idom);
// Inline?
- if( idom != fun && idom != null ) {
+ if( idom != fun && idom != null && !((FunNode)idom)._folding ) {
// Trivial inline: rewrite
_folding = true;
// Rewrite Fun so the normal RegionNode ideal collapses
diff --git a/chapter24/src/main/java/com/seaofnodes/simple/node/RegionNode.java b/chapter24/src/main/java/com/seaofnodes/simple/node/RegionNode.java
index f6d96410..8f0bddb6 100644
--- a/chapter24/src/main/java/com/seaofnodes/simple/node/RegionNode.java
+++ b/chapter24/src/main/java/com/seaofnodes/simple/node/RegionNode.java
@@ -101,8 +101,10 @@ public class RegionNode extends CFGNode {
while( nouts != nOuts() ) {
nouts = nOuts();
for( int i=0; i<nOuts(); i++ )
- if( out(i) instanceof PhiNode phi && phi.nIns()==nIns() )
+ if( out(i) instanceof PhiNode phi && phi.nIns()==nIns() ) {
+ CodeGen.CODE.addAll(phi.in(path)._outputs);
CodeGen.CODE.addAll(phi.delDef(path)._outputs);
+ }
}
return isDead() ? Parser.XCTRL : delDef(path);
}
@@ -165,4 +167,4 @@ public class RegionNode extends CFGNode {
// Never equal if inProgress
@Override public boolean eq( Node n ) { return !inProgress(); }
-} \ No newline at end of file
+}
diff --git a/chapter24/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java b/chapter24/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java
index 1c61bb37..a5dac751 100644
--- a/chapter24/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java
+++ b/chapter24/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java
@@ -216,7 +216,9 @@ public class arm extends Machine {
assert 0 <= rm && rm < 32;
assert 0 <= rn && rn < 32;
assert 0 <= rd && rd < 32;
- return (opcode << 21) | (rm << 16) | (cond.ordinal() << 12) | (0b01 << 10) | (rn << 5) | rd;
+ // Is one of the standard conditions, excluding AL and NV, encoded in the "cond" field with its least significant bit inverted.
+ int actualCond = cond.ordinal() ^ 1;
+ return (opcode << 21) | (rm << 16) | (actualCond << 12) | (0b01 << 10) | (rn << 5) | rd;
}
static public int cset(int opcode, COND cond, int rn, int rd) {
@@ -563,29 +565,6 @@ public class arm extends Machine {
return (opcode << 26) | delta;
}
- @Override public RegMask callArgMask(TypeFunPtr tfp, int idx, int maxArgSlot ) { return callInMask(tfp,idx,maxArgSlot); }
- static RegMask callInMask(TypeFunPtr tfp, int idx, int maxArgSlot ) {
- if( idx==0 ) return CodeGen.CODE._rpcMask;
- if( idx==1 ) return null;
- // Count floats in signature up to index
- if( idx-2 >= tfp.nargs() ) return null; // Anti-dependence
- // Count floats in signature up to index
- int fcnt=0;
- for( int i=2; i<idx; i++ )
- if( tfp.arg(i-2) instanceof TypeFloat)
- fcnt++;
- // Floats up to XMMS in XMM registers
- if( tfp.arg(idx-2) instanceof TypeFloat ) {
- if( fcnt < XMMS.length )
- return XMMS[fcnt];
- } else {
- RegMask[] cargs = CALLINMASK;
- if( idx-2-fcnt < cargs.length )
- return cargs[idx-2-fcnt];
- }
- throw Utils.TODO(); // Pass on stack slot
- }
-
public static long decodeImm12(int imm12) {
int immr = (imm12 >> 6) & 0x3F;
int imms = imm12 & 0x3F;
@@ -609,6 +588,31 @@ public class arm extends Machine {
return val;
}
+ @Override public RegMask callArgMask(TypeFunPtr tfp, int idx, int maxArgSlot ) { return callInMask(tfp,idx,maxArgSlot); }
+ static RegMask callInMask(TypeFunPtr tfp, int idx, int maxArgSlot ) {
+ if( idx==0 ) return CodeGen.CODE._rpcMask;
+ if( idx==1 ) return null;
+ // Count floats in signature up to index
+ if( idx-2 >= tfp.nargs() ) return null; // Anti-dependence
+ // Count floats in signature up to index
+ int fcnt=0;
+ for( int i=2; i<idx; i++ )
+ if( tfp.arg(i-2) instanceof TypeFloat)
+ fcnt++;
+ // Floats up to XMMS in XMM registers
+ if( tfp.arg(idx-2) instanceof TypeFloat ) {
+ if( fcnt < XMMS.length )
+ return XMMS[fcnt];
+ } else {
+ RegMask[] cargs = CALLINMASK;
+ if( idx-2-fcnt < cargs.length )
+ return cargs[idx-2-fcnt];
+ }
+ // Pass on stack slot (8 and higher)
+ if( maxArgSlot>0 ) throw Utils.TODO();
+ return new RegMask(MAX_REG + 1 + (idx - 2));
+ }
+
// Return the max stack slot used by this signature, or 0
@Override public short maxArgSlot( TypeFunPtr tfp ) {
int icnt=0, fcnt=0; // Count of ints, floats