Package com.aparapi.internal.instruction
Class ExpressionList
- java.lang.Object
-
- com.aparapi.internal.instruction.ExpressionList
-
public class ExpressionList extends java.lang.Object
Essentially a glorified linked list of Instructions plus some additional state to allow us to transform sequences. ExpressionLists do have the notion of a parent which allows us to clone an existing parent, allow transformations and then possibly commit or abort the transformations at will.
-
-
Field Summary
Fields Modifier and Type Field Description private Instruction
head
private Instruction
instruction
private static java.util.logging.Logger
logger
private MethodModel
methodModel
private ExpressionList
parent
private Instruction
tail
-
Constructor Summary
Constructors Modifier Constructor Description ExpressionList(MethodModel _methodModel)
private
ExpressionList(MethodModel _methodModel, ExpressionList _parent, Instruction _instruction)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Instruction
add(Instruction _instruction)
Add this instruction to the end of the list.private void
addAsComposites(InstructionSet.ByteCode _byteCode, Instruction _start, BranchSet _branchSet)
Instruction
createList(Instruction _newTail)
[1] [2] [3] [4] Note that passing null here essentially deletes the existing expression list and returns the expressionboolean
doesNotContainCompositeOrBranch(Instruction _start, Instruction _exclusiveEnd)
boolean
doesNotContainContinueOrBreak(Instruction _start, Instruction _extent)
Determine whether the sequence of instructions from _start to _extent is free of branches which extend beyond _extent.java.lang.String
dumpDiagram(Instruction _instruction)
Aids debugging.boolean
foldComposite(Instruction _instruction)
Fold headTail.tail into valid compositesInstruction
getHead()
Instruction
getTail()
void
insertBetween(Instruction _prev, Instruction _next, Instruction _newOne)
Insert the given instruction (_newone) between the existing entries (_prev and _next).void
replaceInclusive(Instruction _head, Instruction _tail, Instruction _newOne)
Inclusive replace between _head and _tail with _newOne.void
unwind()
-
-
-
Field Detail
-
logger
private static java.util.logging.Logger logger
-
methodModel
private final MethodModel methodModel
-
parent
private final ExpressionList parent
-
head
private Instruction head
-
tail
private Instruction tail
-
instruction
private final Instruction instruction
-
-
Constructor Detail
-
ExpressionList
private ExpressionList(MethodModel _methodModel, ExpressionList _parent, Instruction _instruction)
-
ExpressionList
public ExpressionList(MethodModel _methodModel)
-
-
Method Detail
-
doesNotContainContinueOrBreak
public boolean doesNotContainContinueOrBreak(Instruction _start, Instruction _extent)
Determine whether the sequence of instructions from _start to _extent is free of branches which extend beyond _extent. As a side effect, if we find a possible branch it is likely a break or continue so we mark the conditional as such.- Parameters:
_start
-_extent
-- Returns:
-
doesNotContainCompositeOrBranch
public boolean doesNotContainCompositeOrBranch(Instruction _start, Instruction _exclusiveEnd)
-
unwind
public void unwind()
-
createList
public Instruction createList(Instruction _newTail)
[1] [2] [3] [4] Note that passing null here essentially deletes the existing expression list and returns the expression- Parameters:
_newTail
-- Returns:
-
add
public Instruction add(Instruction _instruction)
Add this instruction to the end of the list.- Parameters:
_instruction
-- Returns:
- The instruction we added
-
insertBetween
public void insertBetween(Instruction _prev, Instruction _next, Instruction _newOne)
Insert the given instruction (_newone) between the existing entries (_prev and _next).- Parameters:
_prev
-_next
-_newOne
-
-
replaceInclusive
public void replaceInclusive(Instruction _head, Instruction _tail, Instruction _newOne)
Inclusive replace between _head and _tail with _newOne.| | --> | | ---> ... ---> | | ---> | | | prev | | _head | | _tail | | next | | | <-- | | <--- ... <----| | <--- | |
To| | --> | | ---> | | | prev | | _newOne | | next | | | <-- | | <--- | |
-
foldComposite
public boolean foldComposite(Instruction _instruction) throws ClassParseException
Fold headTail.tail into valid compositesif(??){then}... ?? ?> [THEN] ... --------> if (??){THEN}else{ELSE}... ?? ?> [THEN] >> [ELSE] ... ------------> --------> sun for (INIT,??,DELTA){BODY} ... [INIT] ?? ?> [BODY] [DELTA] << ... ------------------> <------------------- sun for (,??,DELTA){BODY} ... ?? ?> [BODY] [DELTA] << ... ------------------> <------------------- sun while (?){l} ... ?? ?> [BODY] << ... -----------> <------------ eclipse for (INIT,??,DELTA){BODY} ... [INIT] >> [BODY] [DELTA] ?? ?< ... ----------------> <----------------- eclipse for (,??,DELTA){BODY} ... >> [BODY] [DELTA] ?? ?< ... ---------------> <----------------- eclipse while (??){BODY} ... >> [BODY] ?? ?< ... --------> <---------- eclipe if (?1) { while (?2) {BODY} } else {ELSE} ... ?1 ?> >> [BODY] ?2 ?< >> [ELSE] ... ---------> <--------- ---------------------> --------> sun for (,?1,DELTA){ if (?2) { THEN break; } BODY} ... ?1 ?> ?2 ?> [THEN] >> [BODY] [DELTA] << ... -----------> ----------------------------------> ------------------> <------------------------------------ sun for (,?1,DELTA){ if (?2) { THEN continue; } BODY} ... ?1 ?> ?2 ?> THEN >> [BODY] [DELTA] << ... ---------> --------> --------------------------------> <---------------------------------- Some exceptions based on sun javac optimizations if (?1){ if (?2){THEN} }else{ ELSE } ... One might expect ?1 ?> ?2 ?> [THEN] >> [ELSE] ... -----------------> -------->! -------------> However the conditional branch to the unconditional (!) is optimized away and instead the unconditional inverted and extended ?1 ?> ?2 ?> [THEN] >> [ELSE] ... -----------------> --------*---------> sun if (?1) { while (?2) {l} } else {e} ... One might expect ?1 ?> ?2 ?> [BODY] << >> [ELSE] ... -------------------> ----------->! <---------- --------> However as above the conditional branch to the unconditional (!) can be optimized away and the conditional inverted and extended ?1 ?> ?2 ?> [BODY] << >> [ELSE] ... --------------------> -----------*---------> <----------- However we can also now remove the forward unconditional completely as it is unreachable ?1 ?> ?2 ?> [BODY] << [ELSE] ... -----------------> ------------------> <----------- sun while(?1){if (?2) {THEN} else {ELSE} } ... One might expect ?1 ?> ?2 ?> [BODY] >> [ELSE] << ... --------------------------> <--------------------- ----------> ------->! However the unconditional branch to the unconditional backbranch (!) can be optimized away and the unconditional wrapped back directly to the loop control head ?1 ?> ?2 ?> [BODY] << [ELSE] << ... --------------------------> <--------------------- ----------> <-----------
- Parameters:
_instruction
-- Throws:
ClassParseException
-
addAsComposites
private void addAsComposites(InstructionSet.ByteCode _byteCode, Instruction _start, BranchSet _branchSet)
-
dumpDiagram
public java.lang.String dumpDiagram(Instruction _instruction)
Aids debugging. Creates a diagrammatic form of the roots (+ tail instruction) so that we can analyze control flow.I I I C C I U I U[I]I |---------->1 |---->1 |------>2 |-->2
- Parameters:
_instruction
- The instruction we are considering adding (may be null)- Returns:
-
getTail
public Instruction getTail()
-
getHead
public Instruction getHead()
-
-