Example #1
0
 def transform_graph_to_jitcode(self, graph, jitcode, verbose):
     """Transform a graph into a JitCode containing the same bytecode
     in a different format.
     """
     portal_jd = self.callcontrol.jitdriver_sd_from_portal_graph(graph)
     graph = copygraph(graph, shallowvars=True)
     #
     # step 1: mangle the graph so that it contains the final instructions
     # that we want in the JitCode, but still as a control flow graph
     transform_graph(graph, self.cpu, self.callcontrol, portal_jd)
     #
     # step 2: perform register allocation on it
     regallocs = {}
     for kind in KINDS:
         regallocs[kind] = perform_register_allocation(graph, kind)
     #
     # step 3: flatten the graph to produce human-readable "assembler",
     # which means mostly producing a linear list of operations and
     # inserting jumps or conditional jumps.  This is a list of tuples
     # of the shape ("opname", arg1, ..., argN) or (Label(...),).
     ssarepr = flatten_graph(graph, regallocs)
     #
     # step 3b: compute the liveness around certain operations
     compute_liveness(ssarepr)
     #
     # step 4: "assemble" it into a JitCode, which contains a sequence
     # of bytes and lists of constants.  It's during this step that
     # constants are cast to their normalized type (Signed, GCREF or
     # Float).
     self.assembler.assemble(ssarepr, jitcode)
     #
     # print the resulting assembler
     if self.debug:
         self.print_ssa_repr(ssarepr, portal_jd, verbose)
Example #2
0
 def transform_graph_to_jitcode(self, graph, jitcode, verbose, index):
     """Transform a graph into a JitCode containing the same bytecode
     in a different format.
     """
     portal_jd = self.callcontrol.jitdriver_sd_from_portal_graph(graph)
     graph = copygraph(graph, shallowvars=True)
     #
     # step 1: mangle the graph so that it contains the final instructions
     # that we want in the JitCode, but still as a control flow graph
     transform_graph(graph, self.cpu, self.callcontrol, portal_jd)
     #
     # step 2: perform register allocation on it
     regallocs = {}
     for kind in KINDS:
         regallocs[kind] = perform_register_allocation(graph, kind)
     #
     # step 3: flatten the graph to produce human-readable "assembler",
     # which means mostly producing a linear list of operations and
     # inserting jumps or conditional jumps.  This is a list of tuples
     # of the shape ("opname", arg1, ..., argN) or (Label(...),).
     ssarepr = flatten_graph(graph, regallocs, cpu=self.callcontrol.cpu)
     #
     # step 3b: compute the liveness around certain operations
     compute_liveness(ssarepr)
     #
     # step 4: "assemble" it into a JitCode, which contains a sequence
     # of bytes and lists of constants.  It's during this step that
     # constants are cast to their normalized type (Signed, GCREF or
     # Float).
     self.assembler.assemble(ssarepr, jitcode)
     jitcode.index = index
     #
     # print the resulting assembler
     if self.debug:
         self.print_ssa_repr(ssarepr, portal_jd, verbose)
Example #3
0
 def check_assembler(self, graph, expected, transform=False,
                     callcontrol=None):
     # 'transform' can be False only for simple graphs.  More complex
     # graphs must first be transformed by jtransform.py before they can be
     # subjected to register allocation and flattening.
     if transform:
         from rpython.jit.codewriter.jtransform import transform_graph
         transform_graph(graph, callcontrol=callcontrol)
     regalloc = perform_register_allocation(graph, 'int')
     regalloc2 = perform_register_allocation(graph, 'ref')
     ssarepr = flatten_graph(graph, {'int': regalloc,
                                     'ref': regalloc2})
     assert_format(ssarepr, expected)
Example #4
0
 def encoding_test(self, func, args, expected,
                   transform=False, liveness=False, cc=None, jd=None):
     graphs = self.make_graphs(func, args)
     #graphs[0].show()
     if transform:
         from rpython.jit.codewriter.jtransform import transform_graph
         cc = cc or FakeCallControl()
         transform_graph(graphs[0], FakeCPU(self.rtyper), cc, jd)
     ssarepr = flatten_graph(graphs[0], fake_regallocs(),
                             _include_all_exc_links=not transform)
     if liveness:
         from rpython.jit.codewriter.liveness import compute_liveness
         compute_liveness(ssarepr)
     if expected is not None:
         assert_format(ssarepr, expected)
Example #5
0
 def encoding_test(self, func, args, expected,
                   transform=False, liveness=False, cc=None, jd=None):
     graphs = self.make_graphs(func, args)
     #graphs[0].show()
     if transform:
         from rpython.jit.codewriter.jtransform import transform_graph
         cc = cc or FakeCallControl()
         transform_graph(graphs[0], FakeCPU(self.rtyper), cc, jd)
     ssarepr = flatten_graph(graphs[0], fake_regallocs(),
                             _include_all_exc_links=not transform)
     if liveness:
         from rpython.jit.codewriter.liveness import compute_liveness
         compute_liveness(ssarepr)
     if expected is not None:
         assert_format(ssarepr, expected)