public class BasicBlock
extends java.lang.Object
Constructor and Description |
---|
BasicBlock(int startLineNum,
int loopCnt,
int ifCnt)
BasicBlock constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addComment(java.lang.String comment)
Add a comment to basic block (for debugging)
(this can be called multiple times for multi-line comments)
|
void |
addInEdge(BasicBlock b)
Add an incoming edge from another control flow block
Also adds outgoing edge from parameter to this block
|
void |
addInst(TACInst inst)
Append instruction into basic block
Throws exception if attempting to place an instruction after
an IF (which should terminate block)
|
void |
addInst(TACInst inst,
int n)
Add instruction into specified place in the basic block
Shifts instructions at specified position to the right one
Throws exception if n is greater than the size or attempt
to place an instruction after an IF (which should terminate block)
|
void |
addInstAfter(TACInst ins_inst,
TACInst after_inst)
Adds inst1 after inst2.
|
void |
addInstAtEndBeforeIf(TACInst inst1)
Inserts given instruction at end of block, before any if-instruction.
|
void |
addInstBefore(TACInst inst1,
TACInst inst2)
Adds inst1 before inst2.
|
void |
addOutEdge(BasicBlock b)
Add an outgoing edge to another control flow block
Also adds incoming edge from this block to parameter
|
void |
check()
Check block for errors
throws an exception if block is malformed
|
boolean |
containsInEdge(BasicBlock bb)
Does this block contain another block as an in edge?
|
boolean |
containsOutEdge(BasicBlock bb)
Does this block contain another block as an out edge?
|
java.util.Set<java.lang.String> |
getAvailableAnalyses()
Returns a set of names of available dataflow analyses results.
|
static BasicBlock |
getBlock(int id)
Returns basic block by ID.
|
java.lang.String |
getComments()
Get comments for instruction
|
java.util.Set<BasicBlock> |
getDominanceFrontier()
Returns the set of BasicBlocks in the dominance frontier.
|
java.util.Set<?> |
getEntrySet(java.lang.String analysis)
Returns the block entry set for the given analysis.
|
java.util.Set<?> |
getExitSet(java.lang.String analysis)
Returns the block exit set for the given analysis.
|
java.lang.String |
getFullString()
Returns string representation of entire basic block
|
int |
getID()
Get the identifier of this basic block
|
int |
getIfCnt()
Get the if count for this block,
i.e., number of if statements this block is contained in
(note: predicate considered part of the if statement)
|
BasicBlock |
getImmediateDominator()
Returns the immediate dominator of the block.
|
int |
getIndexOf(TACInst inst)
Returns the index of inst in block, or -1 if not found.
|
java.util.List<TACInst> |
getInstructions()
Returns a collection with the instructions in this block.
|
int |
getLoopCnt()
Get the loop count for this block,
i.e., number of loops this block is contained in
(note: predicate considered part of the loop)
|
BasicBlock |
getNthInEdge(int n)
Get nth incoming edge (basic block)
|
TACInst |
getNthInst(int n)
Get the nth instruction
Note: throws an exception if there aren't at least n+1 instructions
|
BasicBlock |
getNthOutEdge(int n)
Get nth outgoing edge (basic block)
|
int |
getNumInEdges()
Get number of incoming edges
|
int |
getNumInsn()
Get the number of instructions at this basic block
|
int |
getNumOutEdges()
Get number of outgoing edges
|
int |
getStartLineNum()
Get the starting source line number of this basic block
|
int |
indexOf(TACInst inst)
Get the index of some instruction
|
void |
print()
Prints basic block -- for debugging
|
void |
printAll()
Prints basic block and all connected basic blocks -- for debugging
Must be called using entrance block as reference object
|
void |
removeAllInEdges()
Remove all incoming edges from other control flow blocks
Also removes outgoing edges from source basic blocks
|
void |
removeAllOutEdges()
Remove all outgoing edges to other control flow blocks
Also removes incoming edges in source basic blocks
|
void |
removeComments()
Remove comments from an instruction
|
void |
removeInEdge(BasicBlock b)
Remove an incoming edge to another control flow block
Also removes outgoing edge from parameter to this block
|
void |
removeInst(TACInst inst)
Removes given instruction from block (if found).
|
void |
removeNthInst(int n)
Remove the nth instruction
Note: throws an exception if there aren't at least n+1 instructions
|
void |
removeOutEdge(BasicBlock b)
Remove an outgoing edge to another control flow block
Also removes incoming edge from parameter to this block
|
void |
replaceInEdge(BasicBlock remove,
BasicBlock add)
Replaces the incoming edge with an edge to the new control flock block.
|
void |
replaceOutEdge(BasicBlock remove,
BasicBlock add)
Replaces the outgoing edge with an edge to the new control flock block.
|
void |
setDominanceFrontier(java.util.Set<BasicBlock> df)
Sets the set of BasicBlocks in the dominance frontier.
|
void |
setEntrySet(java.lang.String analysis,
java.util.Set<?> data)
Sets the block entry result sets for given analysis.
|
void |
setExitSet(java.lang.String analysis,
java.util.Set<?> data)
Sets the block exit result sets for given analysis.
|
void |
setIfCnt(int ifCnt)
Set the if count for this block,
i.e., number of if statements this block is contained in
(note: predicate considered part of the if)
|
void |
setImmediateDominator(BasicBlock idom)
Sets the immediate dominator of the block.
|
void |
setLoopCnt(int loopCnt)
Set the loop count for this block,
i.e., number of loops this block is contained in
(note: predicate considered part of the loop)
|
void |
setNthInst(int n,
TACInst inst)
Set the nth instruction -- replaces the previous nth instruction
with the specified instruction
Note: throws an exception if there aren't at least n+1 instructions
|
java.lang.String |
toString()
Returns string identifier for basic block
|
int |
whichPred(BasicBlock pred)
Returns the number of the incoming edge connecting block to this block,
or -1 if this block is not connected to pred.
|
public BasicBlock(int startLineNum, int loopCnt, int ifCnt)
startLineNum
- starting source line number of this block
(for debugging -- does not have to be exact)loopCnt
- loop count (# loops block is contained in --
note: predicate considered part of loop)ifCnt
- if count (# if statements block is contained in --
note: predicate considered part of if statement)public static BasicBlock getBlock(int id)
id
- public int getID()
public int getStartLineNum()
public void addInst(TACInst inst)
inst
- three-address code (TAC) instructionpublic void addInst(TACInst inst, int n)
inst
- three-address code (TAC) instructionn
- position to placepublic void addInstBefore(TACInst inst1, TACInst inst2)
inst1
- inst2
- public void addInstAtEndBeforeIf(TACInst inst1)
inst1
- instruction to insert.public void addInstAfter(TACInst ins_inst, TACInst after_inst)
ins_inst
- after_inst
- public int getIndexOf(TACInst inst)
inst
- public int getNumInsn()
public java.util.List<TACInst> getInstructions()
public int indexOf(TACInst inst)
inst
- instruction to find the index ofpublic TACInst getNthInst(int n)
n
- index of instruction to getpublic void setNthInst(int n, TACInst inst)
n
- index of instruction to getinst
- replacement instructionpublic void removeNthInst(int n)
n
- index of instruction to removepublic void removeInst(TACInst inst)
inst
- TACInst to removepublic void addInEdge(BasicBlock b)
b
- incoming basic blockpublic void addOutEdge(BasicBlock b)
b
- outgoing basic blockpublic void removeInEdge(BasicBlock b)
b
- incoming basic blockpublic void removeOutEdge(BasicBlock b)
b
- outgoing basic blockpublic void removeAllInEdges()
public void removeAllOutEdges()
public void replaceInEdge(BasicBlock remove, BasicBlock add)
remove
- the edge to removeadd
- the edge to addpublic void replaceOutEdge(BasicBlock remove, BasicBlock add)
remove
- the edge to removeadd
- the edge to addpublic BasicBlock getNthInEdge(int n)
n
- index of incoming edge to getpublic BasicBlock getNthOutEdge(int n)
n
- index of outgoing edge to getpublic int getNumInEdges()
public int getNumOutEdges()
public boolean containsInEdge(BasicBlock bb)
bb
- block to check if containspublic boolean containsOutEdge(BasicBlock bb)
bb
- block to check if containspublic int getLoopCnt()
public void setLoopCnt(int loopCnt)
loopCnt
- new loop countpublic int getIfCnt()
public void setIfCnt(int ifCnt)
ifCnt
- new if countpublic void check()
public java.lang.String getComments()
public void addComment(java.lang.String comment)
comment
- comment to addpublic void removeComments()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getFullString()
public void print()
public void printAll()
public int whichPred(BasicBlock pred)
pred
- predecessor to look forpublic BasicBlock getImmediateDominator()
public void setImmediateDominator(BasicBlock idom)
idom
- BasicBlockpublic java.util.Set<java.lang.String> getAvailableAnalyses()
public java.util.Set<?> getEntrySet(java.lang.String analysis)
analysis
- name of the analysis.public void setEntrySet(java.lang.String analysis, java.util.Set<?> data)
analysis
- name of the analysis.data
- block entry result sets.public java.util.Set<?> getExitSet(java.lang.String analysis)
analysis
- name of the analysis.public void setExitSet(java.lang.String analysis, java.util.Set<?> data)
analysis
- name of the analysis.data
- block exit result sets.public java.util.Set<BasicBlock> getDominanceFrontier()
public void setDominanceFrontier(java.util.Set<BasicBlock> df)
df
- Set of BasicBlock