|
|||||||||
上一个类 下一个类 | 框架 无框架 | ||||||||
摘要: 嵌套 | 字段 | 构造函数 | 方法 | 详细信息: 字段 | 构造函数 | 方法 |
java.lang.Objectedu.ustc.cs.compile.arch.x86.regalloc.RegAllocator
public class RegAllocator
This class implements a simple X86 register allocator.we use a greedy-like local algorithm to
allocate registers. There are no basic block breaking down,
no data flow analysis. Given a String as an variable name,
this allocator returns an available register. Meanwhile it may spill
registers.
This register allocator asserts that:
1. at one time there is no more than one value stored in a register:
for example: a = b;
in some register allocator, variable a and b shares the same
register. However, to keep the allocator simple, in this allocate we do not put them together.
2. we do not increment esp pointer so that in this version of regAllocator it is very simple.
The following are some of the register allocator's usage:
1. To get a free register, use getReg(java.lang.String)
.
2. if getReg(java.lang.String)
returns null, it implies that all
the registers in the register pool are occupied. We have to spill out a
register so that we can use the present one by asking selectReg()
to
select one for us, let's say it is %eax.
3. Now we have to spill %eax: call spill(edu.ustc.cs.compile.arch.x86.X86Register)
with argument
X86Register.EAX
, and we can get a sequence of spilling code. After we add the spilling code
to our assembly statement sequence, %eax is now free.
字段摘要 | |
---|---|
private java.util.LinkedList<java.lang.Integer> |
availableMemSlot
|
private java.util.LinkedList<X86Register> |
lruList
|
private java.util.HashMap<java.lang.String,java.lang.Integer> |
name2place
|
private int |
numOfMemAlloc
|
private java.util.HashMap<X86Register,java.lang.String> |
reg2name
|
构造函数摘要 | |
---|---|
RegAllocator()
|
方法摘要 | |
---|---|
X86Register |
getAFreeRegister()
Uses LRU to determine a free register and returns it. |
AssemblySequence |
getMem2Reg(java.lang.String valName,
X86Register reg)
Generates a chain of instructions the fetches a variable from the memory to a register. if in stack we do not have the record of the variable, it returns null. |
Instruct.Operand |
getPositionInMem(java.lang.String name)
Returns the stack address corresponding to a variable register. |
Instruct.Operand |
getPositionInMem(X86Register reg)
Returns the stack address corresponding to a variable or a register. |
X86Register |
getReg(java.lang.String valName)
Returns a register that is free to store the variable, or null if there are no available allocator. |
boolean |
hasFreeReg()
Returns a free register that is free or null if there are no available register. |
boolean |
isFree(X86Register reg)
Tests if a register is free for use. |
X86Register |
selectReg()
Selects a register by LRU algorithm. |
AssemblySequence |
spill(X86Register reg)
Spills a register to memory. |
private void |
useReg(X86Register reg_)
|
从类 java.lang.Object 继承的方法 |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
字段详细信息 |
---|
private java.util.HashMap<java.lang.String,java.lang.Integer> name2place
private java.util.HashMap<X86Register,java.lang.String> reg2name
private java.util.LinkedList<X86Register> lruList
private java.util.LinkedList<java.lang.Integer> availableMemSlot
private int numOfMemAlloc
构造函数详细信息 |
---|
public RegAllocator()
方法详细信息 |
---|
public X86Register getReg(java.lang.String valName)
valName
- The name of the variable which needs a register to allocate.
X86Register
public boolean hasFreeReg()
public AssemblySequence spill(X86Register reg)
reg
- The register name that shall be spilled out.
public AssemblySequence getMem2Reg(java.lang.String valName, X86Register reg)
valName
- the variable name that shall be restored to a register.reg
- the to-be-used register's name.
public boolean isFree(X86Register reg)
reg
- the register's name.
public X86Register getAFreeRegister()
public Instruct.Operand getPositionInMem(java.lang.String name)
Instruct.Operand
name
- name of the variable
public Instruct.Operand getPositionInMem(X86Register reg)
Instruct.Operand
reg
- name of the register
public X86Register selectReg()
private void useReg(X86Register reg_)
|
|||||||||
上一个类 下一个类 | 框架 无框架 | ||||||||
摘要: 嵌套 | 字段 | 构造函数 | 方法 | 详细信息: 字段 | 构造函数 | 方法 |