diff options
author | FICTURE7 <FICTURE7@gmail.com> | 2021-09-14 03:23:37 +0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-14 01:23:37 +0200 |
commit | a9343c9364246d3288b4e7f20919ca1ad2e1fd3e (patch) | |
tree | ba8ada2c2f5d2b4b0c92fbc5258bc43ad4809913 /ARMeilleure/CodeGen/X86/CodeGenerator.cs | |
parent | ac4ec1a0151fd958d7ec58146169763b446836fe (diff) |
Refactor `PtcInfo` (#2625)
* Refactor `PtcInfo`
This change reduces the coupling of `PtcInfo` by moving relocation
tracking to the backend. `RelocEntry`s remains as `RelocEntry`s through
out the pipeline until it actually needs to be written to the PTC
streams. Keeping this representation makes inspecting and manipulating
relocations after compilations less painful. This is something I needed
to do to patch relocations to 0 to diff dumps.
Contributes to #1125.
* Turn `Symbol` & `RelocInfo` into readonly structs
* Add documentation to `CompiledFunction`
* Remove `Compiler.Compile<T>`
Remove `Compiler.Compile<T>` and replace it by `Map<T>` of the
`CompiledFunction` returned.
Diffstat (limited to 'ARMeilleure/CodeGen/X86/CodeGenerator.cs')
-rw-r--r-- | ARMeilleure/CodeGen/X86/CodeGenerator.cs | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/ARMeilleure/CodeGen/X86/CodeGenerator.cs b/ARMeilleure/CodeGen/X86/CodeGenerator.cs index 5818eb2e..924c113c 100644 --- a/ARMeilleure/CodeGen/X86/CodeGenerator.cs +++ b/ARMeilleure/CodeGen/X86/CodeGenerator.cs @@ -1,3 +1,4 @@ +using ARMeilleure.CodeGen.Linking; using ARMeilleure.CodeGen.Optimizations; using ARMeilleure.CodeGen.RegisterAllocators; using ARMeilleure.CodeGen.Unwinding; @@ -5,7 +6,6 @@ using ARMeilleure.Common; using ARMeilleure.Diagnostics; using ARMeilleure.IntermediateRepresentation; using ARMeilleure.Translation; -using ARMeilleure.Translation.PTC; using System; using System.Collections.Generic; using System.Diagnostics; @@ -91,7 +91,7 @@ namespace ARMeilleure.CodeGen.X86 _instTable[(int)inst] = func; } - public static CompiledFunction Generate(CompilerContext cctx, PtcInfo ptcInfo = null) + public static CompiledFunction Generate(CompilerContext cctx) { ControlFlowGraph cfg = cctx.Cfg; @@ -149,53 +149,47 @@ namespace ARMeilleure.CodeGen.X86 Logger.StartPass(PassName.CodeGeneration); - using (MemoryStream stream = new MemoryStream()) - { - CodeGenContext context = new CodeGenContext(stream, allocResult, maxCallArgs, cfg.Blocks.Count, ptcInfo); + bool relocatable = (cctx.Options & CompilerOptions.Relocatable) != 0; + + using MemoryStream stream = new(); + + CodeGenContext context = new(stream, allocResult, maxCallArgs, cfg.Blocks.Count, relocatable); - UnwindInfo unwindInfo = WritePrologue(context); + UnwindInfo unwindInfo = WritePrologue(context); - ptcInfo?.WriteUnwindInfo(unwindInfo); + for (BasicBlock block = cfg.Blocks.First; block != null; block = block.ListNext) + { + context.EnterBlock(block); - for (BasicBlock block = cfg.Blocks.First; block != null; block = block.ListNext) + for (Operation node = block.Operations.First; node != default; node = node.ListNext) { - context.EnterBlock(block); + GenerateOperation(context, node); + } - for (Operation node = block.Operations.First; node != default; node = node.ListNext) - { - GenerateOperation(context, node); - } + if (block.SuccessorsCount == 0) + { + // The only blocks which can have 0 successors are exit blocks. + Operation last = block.Operations.Last; - if (block.SuccessorsCount == 0) - { - // The only blocks which can have 0 successors are exit blocks. - Operation last = block.Operations.Last; + Debug.Assert(last.Instruction == Instruction.Tailcall || + last.Instruction == Instruction.Return); + } + else + { + BasicBlock succ = block.GetSuccessor(0); - Debug.Assert(last.Instruction == Instruction.Tailcall || - last.Instruction == Instruction.Return); - } - else + if (succ != block.ListNext) { - BasicBlock succ = block.GetSuccessor(0); - - if (succ != block.ListNext) - { - context.JumpTo(succ); - } + context.JumpTo(succ); } } + } - byte[] code = context.GetCode(); + (byte[] code, RelocInfo relocInfo) = context.GetCode(); - if (ptcInfo != null) - { - ptcInfo.Code = code; - } + Logger.EndPass(PassName.CodeGeneration); - Logger.EndPass(PassName.CodeGeneration); - - return new CompiledFunction(code, unwindInfo); - } + return new CompiledFunction(code, unwindInfo, relocInfo); } private static void GenerateOperation(CodeGenContext context, Operation operation) |