2018-10-30 21:43:02 -04:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace ChocolArm64.Translation
|
|
|
|
{
|
|
|
|
class ILBlock : IILEmit
|
|
|
|
{
|
2019-02-27 21:03:31 -05:00
|
|
|
public long IntInputs { get; private set; }
|
|
|
|
public long IntOutputs { get; private set; }
|
|
|
|
private long _intAwOutputs;
|
2018-10-30 21:43:02 -04:00
|
|
|
|
2019-02-27 21:03:31 -05:00
|
|
|
public long VecInputs { get; private set; }
|
|
|
|
public long VecOutputs { get; private set; }
|
|
|
|
private long _vecAwOutputs;
|
2018-10-30 21:43:02 -04:00
|
|
|
|
|
|
|
public bool HasStateStore { get; private set; }
|
|
|
|
|
2018-12-10 19:58:52 -05:00
|
|
|
private List<IILEmit> _emitters;
|
|
|
|
|
|
|
|
public int Count => _emitters.Count;
|
2018-10-30 21:43:02 -04:00
|
|
|
|
|
|
|
public ILBlock Next { get; set; }
|
|
|
|
public ILBlock Branch { get; set; }
|
|
|
|
|
|
|
|
public ILBlock()
|
|
|
|
{
|
2018-12-10 19:58:52 -05:00
|
|
|
_emitters = new List<IILEmit>();
|
2018-10-30 21:43:02 -04:00
|
|
|
}
|
|
|
|
|
2018-12-10 19:58:52 -05:00
|
|
|
public void Add(IILEmit emitter)
|
2018-10-30 21:43:02 -04:00
|
|
|
{
|
2018-12-10 19:58:52 -05:00
|
|
|
if (emitter is ILBarrier)
|
2018-10-30 21:43:02 -04:00
|
|
|
{
|
|
|
|
//Those barriers are used to separate the groups of CIL
|
|
|
|
//opcodes emitted by each ARM instruction.
|
|
|
|
//We can only consider the new outputs for doing input elimination
|
|
|
|
//after all the CIL opcodes used by the instruction being emitted.
|
2019-02-27 21:03:31 -05:00
|
|
|
_intAwOutputs = IntOutputs;
|
|
|
|
_vecAwOutputs = VecOutputs;
|
2018-10-30 21:43:02 -04:00
|
|
|
}
|
2018-12-10 19:58:52 -05:00
|
|
|
else if (emitter is ILOpCodeLoad ld && ILMethodBuilder.IsRegIndex(ld.Index))
|
2018-10-30 21:43:02 -04:00
|
|
|
{
|
2019-02-27 21:03:31 -05:00
|
|
|
switch (ld.VarType)
|
2018-10-30 21:43:02 -04:00
|
|
|
{
|
2019-02-27 21:03:31 -05:00
|
|
|
case VarType.Flag: IntInputs |= ((1L << ld.Index) << 32) & ~_intAwOutputs; break;
|
|
|
|
case VarType.Int: IntInputs |= (1L << ld.Index) & ~_intAwOutputs; break;
|
|
|
|
case VarType.Vector: VecInputs |= (1L << ld.Index) & ~_vecAwOutputs; break;
|
2018-10-30 21:43:02 -04:00
|
|
|
}
|
|
|
|
}
|
2018-12-10 19:58:52 -05:00
|
|
|
else if (emitter is ILOpCodeStore st && ILMethodBuilder.IsRegIndex(st.Index))
|
2018-10-30 21:43:02 -04:00
|
|
|
{
|
2019-02-27 21:03:31 -05:00
|
|
|
switch (st.VarType)
|
2018-10-30 21:43:02 -04:00
|
|
|
{
|
2019-02-27 21:03:31 -05:00
|
|
|
case VarType.Flag: IntOutputs |= (1L << st.Index) << 32; break;
|
|
|
|
case VarType.Int: IntOutputs |= 1L << st.Index; break;
|
|
|
|
case VarType.Vector: VecOutputs |= 1L << st.Index; break;
|
2018-10-30 21:43:02 -04:00
|
|
|
}
|
|
|
|
}
|
2018-12-10 19:58:52 -05:00
|
|
|
else if (emitter is ILOpCodeStoreState)
|
|
|
|
{
|
|
|
|
HasStateStore = true;
|
|
|
|
}
|
2018-10-30 21:43:02 -04:00
|
|
|
|
2018-12-10 19:58:52 -05:00
|
|
|
_emitters.Add(emitter);
|
2018-10-30 21:43:02 -04:00
|
|
|
}
|
|
|
|
|
2018-12-10 19:58:52 -05:00
|
|
|
public void Emit(ILMethodBuilder context)
|
2018-10-30 21:43:02 -04:00
|
|
|
{
|
2018-12-10 19:58:52 -05:00
|
|
|
foreach (IILEmit ilEmitter in _emitters)
|
2018-10-30 21:43:02 -04:00
|
|
|
{
|
|
|
|
ilEmitter.Emit(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|