some opt
This commit is contained in:
@@ -35,6 +35,27 @@ public class IrBasicBlock extends IrValue {
|
||||
instr.setBBlock(this);
|
||||
}
|
||||
|
||||
public void addInstr(IrInstr instr, int index) {
|
||||
instrs.add(index, instr);
|
||||
instr.setBBlock(this);
|
||||
}
|
||||
|
||||
public void deleteInstr(IrInstr instr) {
|
||||
instrs.remove(instr);
|
||||
instr.setBBlock(null);
|
||||
instr.clearUses();
|
||||
instr.clearUsers();
|
||||
}
|
||||
|
||||
public void clearAllInstrs() {
|
||||
for (IrInstr instr : instrs) {
|
||||
instr.setBBlock(null);
|
||||
instr.clearUses();
|
||||
instr.clearUsers();
|
||||
}
|
||||
instrs.clear();
|
||||
}
|
||||
|
||||
public IrFuncValue getFunc() {
|
||||
return func;
|
||||
}
|
||||
@@ -87,6 +108,20 @@ public class IrBasicBlock extends IrValue {
|
||||
return instrs;
|
||||
}
|
||||
|
||||
public IrInstr getFirstInstr() {
|
||||
if (instrs.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return instrs.get(0);
|
||||
}
|
||||
|
||||
public IrInstr getLastInstr() {
|
||||
if (instrs.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return instrs.get(instrs.size() - 1);
|
||||
}
|
||||
|
||||
public void addPred(IrBasicBlock bb) {
|
||||
this.preds.add(bb);
|
||||
}
|
||||
@@ -119,6 +154,14 @@ public class IrBasicBlock extends IrValue {
|
||||
return this.directDomi;
|
||||
}
|
||||
|
||||
public HashSet<IrBasicBlock> getDirectDomies() {
|
||||
return directDomies;
|
||||
}
|
||||
|
||||
public HashSet<IrBasicBlock> getDomiFrontier() {
|
||||
return domiFrontier;
|
||||
}
|
||||
|
||||
public void toMips() {
|
||||
new MipsLabel(getMipsLabel());
|
||||
for (IrInstr instr : instrs) {
|
||||
|
||||
@@ -45,6 +45,27 @@ public class IrFuncValue extends IrValue {
|
||||
bblocks.add(bblock);
|
||||
}
|
||||
|
||||
public void deleteBBlock(IrBasicBlock bblock) {
|
||||
bblocks.remove(bblock);
|
||||
bblock.clearAllInstrs();
|
||||
}
|
||||
|
||||
public void deleteDeadBlock() {
|
||||
ArrayList<IrBasicBlock> liveBlocks = new ArrayList<>();
|
||||
ArrayList<IrBasicBlock> deadBlocks = new ArrayList<>();
|
||||
for (IrBasicBlock bb : bblocks) {
|
||||
if (!bb.getPreds().isEmpty() || bb.isEntry()) {
|
||||
liveBlocks.add(bb);
|
||||
} else {
|
||||
deadBlocks.add(bb);
|
||||
}
|
||||
}
|
||||
bblocks = liveBlocks;
|
||||
for (IrBasicBlock bb : deadBlocks) {
|
||||
bb.clearAllInstrs();
|
||||
}
|
||||
}
|
||||
|
||||
public Register getRegister(IrValue value) {
|
||||
return valueRegisterMap.get(value);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,28 @@ public class IrValue {
|
||||
users.add(user);
|
||||
}
|
||||
|
||||
public void deleteUser(IrUser user) {
|
||||
users.remove(user);
|
||||
}
|
||||
|
||||
public void clearUsers() {
|
||||
ArrayList<IrUser> usersCopy = new ArrayList<>(users);
|
||||
for (IrUser user : usersCopy) {
|
||||
user.deleteUse(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void replaceUserToAnother(IrValue newValue) {
|
||||
ArrayList<IrUser> usersCopy = new ArrayList<>(users);
|
||||
for (IrUser user : usersCopy) {
|
||||
for (int i = 0; i < user.getUses().size(); i++) {
|
||||
if (user.getUse(i) == this) {
|
||||
user.setUse(i, newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return type.toString() + " " + name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user