protected void AnalyzeBlock(BasicBlock block) { if (analyzed.Get(block.Sequence)) return; //Debug.WriteLine(String.Format("Analyzing Block #{0} - Label L_{1:X4}", block.Index, block.Label)); traversed.Set(block.Sequence, true); // Analysis all child blocks first foreach (BasicBlock nextBlock in block.NextBlocks) { if (!traversed.Get(nextBlock.Sequence)) AnalyzeBlock(nextBlock); } //Debug.WriteLine(String.Format("Working Block #{0} - Label L_{1:X4}", block.Index, block.Label)); RegisterBitmap used = new RegisterBitmap(); if (block.NextBlocks.Count == 0) { if (block.Label == Int32.MaxValue) { used.Set(architecture.StackFrameRegister); used.Set(architecture.StackPointerRegister); used.Set(architecture.CallingConvention.GetReturnRegisters(methodCompiler.Method.Signature.ReturnType.Type)); used.Set(architecture.CallingConvention.CalleeSavedRegisters); } } else { foreach (BasicBlock nextBlock in block.NextBlocks) used.Or(top[nextBlock.Sequence]); } bottom[block.Sequence] = used; var ctx = new Context(instructionSet, block); ctx.GotoLast(); for (; ; ctx.GotoPrevious()) { if (ctx.Ignore || ctx.Instruction == null) if (ctx.IsFirstInstruction) break; else continue; RegisterBitmap inputRegisters = new RegisterBitmap(); RegisterBitmap outputRegisters = new RegisterBitmap(); GetRegisterUsage(ctx, ref inputRegisters, ref outputRegisters); RegisterBitmap assignment = inputRegisters; assignment.Xor(outputRegisters); assignment.Not(); used.And(assignment); used.Or(inputRegisters); usage[ctx.Index] = used; if (ctx.IsFirstInstruction) break; } top[block.Sequence] = used; analyzed.Set(block.Sequence, true); }
/// <summary> /// Gets the input registers. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public virtual RegisterBitmap GetInputRegisters(Context context) { RegisterBitmap registers = new RegisterBitmap(); registers.Set(GetRegister(context.Operand1, true)); registers.Set(GetRegister(context.Operand2, true)); registers.Set(GetRegister(context.Operand3, true)); registers.Set(GetRegister(context.Result, ResultIsInput)); registers.Or(AdditionalInputRegisters); return registers; }
/// <summary> /// Gets the output registers. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public virtual RegisterBitmap GetOutputRegisters(Context context) { RegisterBitmap registers = new RegisterBitmap(); if (context.Result.IsRegister) registers.Set(context.Result.Register); registers.Or(AdditionalOutputRegisters); return registers; }
/// <summary> /// Gets the output registers. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public virtual RegisterBitmap GetOutputRegisters(Context context) { RegisterBitmap registers = new RegisterBitmap(); RegisterOperand regOperand = context.Result as RegisterOperand; if (regOperand != null) registers.Set(regOperand.Register); registers.Or(AdditionalOutputRegisters); return registers; }