seafoam 0.7 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a17a259b362af5eef7c3c874e6d796f647c6017d413cba708ac0a27e18043681
4
- data.tar.gz: 39eba465ba4ed92b3085a276d541072ccff48d62fdd00a317961c7401bcb0ee0
3
+ metadata.gz: 6f5cdd6b29d9c25bc7db525b2f49d6937fb996bc108a7bf18ddf0364575e6999
4
+ data.tar.gz: 510608b5d784ef4c58768aafb42372bdd33aad226a6123e9ad72ea77845a8050
5
5
  SHA512:
6
- metadata.gz: e55cdfa1eea817f24bbaa22ef80916923441393529351df21c258987354cafe98d07ed4bff2fd3e6fc5ab5656ea7f85b938d7a906ee511cd9f06fa19c335431f
7
- data.tar.gz: '070468e7e9c1fd55b6429c07d8c226e1c0c0e4225a0f9a90bd577e7b57bb8320bcd0a59e1da223632986245f6eb5482a1320b11e6b786f41f456187766664b9b'
6
+ metadata.gz: 125d9c14699c1a9a72bc1311b2673cf24d725af3c4da38eac1c2c89ebce4d6157c3e08ad7cc7b8769f8c755227cd04da4b9a6f53ae30f0f3ce38e7a1cf12d4b2
7
+ data.tar.gz: 2430c0b5f04378767c5bbbb51274900deae22291fd905831f4a5d5847edd5e7497e3df94a434ab803689ee4f9b3f6cd5d6740bdc28dbf96d7da329c8610ac6e5
@@ -6,13 +6,14 @@ jobs:
6
6
  steps:
7
7
  - uses: actions/checkout@v2
8
8
  - uses: ruby/setup-ruby@v1
9
+ - run: gem install bundler:1.17.2
9
10
  - run: bundle install
10
11
  - run: bundle exec rubocop
11
12
  specs:
12
13
  strategy:
13
14
  matrix:
14
15
  os: [ubuntu, macos]
15
- ruby: [2.5, 2.6, 2.7]
16
+ ruby: [2.5, 2.6, 2.7, 3.0]
16
17
  runs-on: ${{ matrix.os }}-latest
17
18
  steps:
18
19
  - uses: actions/checkout@v2
@@ -27,7 +28,7 @@ jobs:
27
28
  strategy:
28
29
  matrix:
29
30
  os: [ubuntu, macos]
30
- ruby: [2.5, 2.6, 2.7]
31
+ ruby: [2.5, 2.6, 2.7, 3.0]
31
32
  runs-on: ${{ matrix.os }}-latest
32
33
  steps:
33
34
  - uses: actions/checkout@v2
data/.gitignore CHANGED
@@ -4,4 +4,3 @@
4
4
  *.svg
5
5
  *.class
6
6
  /.idea
7
- /Gemfile.lock
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.8
1
+ 2.5.9
data/Gemfile.lock ADDED
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ seafoam (0.7)
5
+ crabstone (~> 4.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ benchmark-ips (2.8.4)
12
+ crabstone (4.0.3)
13
+ ffi
14
+ diff-lcs (1.4.4)
15
+ ffi (1.15.0)
16
+ parallel (1.20.1)
17
+ parser (3.0.1.1)
18
+ ast (~> 2.4.1)
19
+ rainbow (3.0.0)
20
+ regexp_parser (2.1.1)
21
+ rexml (3.2.5)
22
+ rspec (3.10.0)
23
+ rspec-core (~> 3.10.0)
24
+ rspec-expectations (~> 3.10.0)
25
+ rspec-mocks (~> 3.10.0)
26
+ rspec-core (3.10.1)
27
+ rspec-support (~> 3.10.0)
28
+ rspec-expectations (3.10.1)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.10.0)
31
+ rspec-mocks (3.10.2)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.10.0)
34
+ rspec-support (3.10.2)
35
+ rubocop (0.93.1)
36
+ parallel (~> 1.10)
37
+ parser (>= 2.7.1.5)
38
+ rainbow (>= 2.2.2, < 4.0)
39
+ regexp_parser (>= 1.8)
40
+ rexml
41
+ rubocop-ast (>= 0.6.0)
42
+ ruby-progressbar (~> 1.7)
43
+ unicode-display_width (>= 1.4.0, < 2.0)
44
+ rubocop-ast (1.5.0)
45
+ parser (>= 3.0.1.1)
46
+ ruby-progressbar (1.11.0)
47
+ unicode-display_width (1.7.0)
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ benchmark-ips (~> 2.7)
54
+ rspec (~> 3.8)
55
+ rubocop (~> 0.74)
56
+ seafoam!
57
+
58
+ BUNDLED WITH
59
+ 1.17.2
data/README.md CHANGED
@@ -26,7 +26,6 @@ Admittedly, Seafoam does not yet have:
26
26
 
27
27
  * an interactive user interface
28
28
  * diffing of graphs
29
- * visualization of basic blocks
30
29
  * breaking of edges for very congested graphs
31
30
  * the same speed in rendering big graphs - Seafoam is best suited for looking at graphs before lowering, which is what language developers are usually doing, or use spotlight
32
31
 
@@ -305,6 +304,7 @@ graph0 = # 2:Fib.fib(int)/After phase org.graalvm.compiler.java.GraphBuilderPhas
305
304
  * `--show-frame-state` shows frame state nodes, which are hidden by default
306
305
  * `--hide-floating` hides nodes that aren't fixed by control flow
307
306
  * `--no-reduce-edges` turns off the option to reduce the number of edges by inlining simple nodes above their users
307
+ * `--draw-blocks` to draw basic block information if available
308
308
 
309
309
  ## Configuration
310
310
 
data/docs/bgv.md CHANGED
@@ -57,7 +57,8 @@ GraphBody {
57
57
  Props props
58
58
  sint32 nodes_count
59
59
  Node[nodes_count] nodes
60
- Blocks blocks
60
+ sint32 blocks_count
61
+ Blocks[blocks_count] blocks
61
62
  }
62
63
 
63
64
  Node {
@@ -54,6 +54,10 @@ easier to understand.
54
54
 
55
55
  You may need to use `--experimental-options`.
56
56
 
57
+ ## Getting basic blocks
58
+
59
+ To get the graph when scheduled, so that you can see basic blocks, use `-Dgraal.PrintGraphWithSchedule=true`. Truffle graphs beyond the initial stages have scheduling information by default.
60
+
57
61
  ## Getting CFG files
58
62
 
59
63
  To also get CFG files, add `-Dgraal.PrintBackendCFG=true`, or `--vm.Dgraal.PrintBackendCFG=true` for Truffle.
data/examples/Fib.java CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * % javac Fib.java
3
- * % java -XX:CompileOnly=::fib -Dgraal.Dump=:2 Fib 14
3
+ * % java -XX:CompileOnly=::fib -Dgraal.Dump=:2 -Dgraal.PrintGraphWithSchedule=true Fib 14
4
4
  */
5
5
 
6
6
  class Fib {
Binary file
@@ -127,13 +127,21 @@ module Seafoam
127
127
  end
128
128
  end
129
129
  end
130
- skip_blocks
130
+
131
+ # Read block information.
132
+ @reader.read_sint32.times do
133
+ block_id = @reader.read_sint32
134
+ block_nodes = @reader.read_sint32.times.map { @reader.read_sint32 }
135
+ # Followers aren't used but could be.
136
+ @reader.read_sint32.times.map { @reader.read_sint32 }
137
+ graph.create_block block_id, block_nodes
138
+ end
131
139
  graph
132
140
  end
133
141
 
134
142
  # Skip over a graph, having read or skipped its headers.
135
143
  def skip_graph
136
- # Already read BEGIN_GRAPH, id, format, args, and props
144
+ # Already read BEGIN_GRAPH, id, format, args, and props.
137
145
  @reader.read_sint32.times do
138
146
  @reader.skip_int32
139
147
  node_class = read_pool_object
@@ -30,6 +30,7 @@ module Seafoam
30
30
  @out.puts ' --show-frame-state'
31
31
  @out.puts ' --hide-floating'
32
32
  @out.puts ' --no-reduce-edges'
33
+ @out.puts ' --draw-blocks'
33
34
  @out.puts ' --option key value'
34
35
  @out.puts ' --help'
35
36
  @out.puts ' --version'
@@ -406,6 +407,7 @@ module Seafoam
406
407
  args = args.dup
407
408
  out_file = nil
408
409
  explicit_out_file = false
410
+ draw_blocks = false
409
411
  until args.empty?
410
412
  arg = args.shift
411
413
  case arg
@@ -424,6 +426,8 @@ module Seafoam
424
426
  annotator_options[:hide_floating] = true
425
427
  when '--no-reduce-edges'
426
428
  annotator_options[:reduce_edges] = false
429
+ when '--draw-blocks'
430
+ draw_blocks = true
427
431
  when '--option'
428
432
  key = args.shift
429
433
  raise ArgumentError, 'no key for --option' unless key
@@ -469,14 +473,14 @@ module Seafoam
469
473
  if out_format == :dot
470
474
  File.open(out_file, 'w') do |stream|
471
475
  writer = GraphvizWriter.new(stream)
472
- writer.write_graph graph
476
+ writer.write_graph graph, false, draw_blocks
473
477
  end
474
478
  else
475
479
  begin
476
480
  IO.popen(['dot', "-T#{out_format}", '-o', out_file], 'w') do |stream|
477
481
  writer = GraphvizWriter.new(stream)
478
482
  hidpi = out_format == :png
479
- writer.write_graph graph, hidpi
483
+ writer.write_graph graph, hidpi, draw_blocks
480
484
  end
481
485
  rescue Errno::ENOENT
482
486
  raise 'Could not run Graphviz - is it installed?'
data/lib/seafoam/graph.rb CHANGED
@@ -2,12 +2,13 @@ module Seafoam
2
2
  # A graph, with properties, nodes, and edges. We don't encapsulate the graph
3
3
  # too much - be careful.
4
4
  class Graph
5
- attr_reader :props, :nodes, :edges
5
+ attr_reader :props, :nodes, :edges, :blocks
6
6
 
7
7
  def initialize(props = nil)
8
8
  @props = props || {}
9
9
  @nodes = {}
10
10
  @edges = []
11
+ @blocks = []
11
12
  end
12
13
 
13
14
  # Create a node.
@@ -27,6 +28,14 @@ module Seafoam
27
28
  to.inputs.push edge
28
29
  edge
29
30
  end
31
+
32
+ # Add a new basic block with given id and node id list.
33
+ def create_block(id, node_ids)
34
+ nodes = node_ids.select { |n| @nodes.key? n }.map { |n| @nodes[n] }
35
+ block = Block.new(id, nodes)
36
+ @blocks.push block
37
+ block
38
+ end
30
39
  end
31
40
 
32
41
  # A node, with properties, input edges, and output edges.
@@ -88,4 +97,19 @@ module Seafoam
88
97
  "<Edge #{from.id} -> #{to.id}>"
89
98
  end
90
99
  end
100
+
101
+ # A control-flow basic block
102
+ class Block
103
+ attr_reader :id, :nodes
104
+
105
+ def initialize(id, nodes)
106
+ @id = id
107
+ @nodes = nodes
108
+ end
109
+
110
+ # Inspect.
111
+ def inspect
112
+ "<Block #{id}>"
113
+ end
114
+ end
91
115
  end
@@ -7,15 +7,16 @@ module Seafoam
7
7
  end
8
8
 
9
9
  # Write a graph.
10
- def write_graph(graph, hidpi = false)
10
+ def write_graph(graph, hidpi = false, draw_blocks = false)
11
11
  inline_attrs = {}
12
12
  attrs = {}
13
13
  attrs[:dpi] = 200 if hidpi
14
- attrs[:bgcolor] = 'transparent'
14
+ attrs[:bgcolor] = 'white'
15
15
  @stream.puts 'digraph G {'
16
16
  @stream.puts " graph #{write_attrs(attrs)};"
17
17
  write_nodes inline_attrs, graph
18
18
  write_edges inline_attrs, graph
19
+ write_blocks graph if draw_blocks
19
20
  @stream.puts '}'
20
21
  end
21
22
 
@@ -166,6 +167,24 @@ module Seafoam
166
167
  end
167
168
  end
168
169
 
170
+ # Write basic block outlines.
171
+ def write_blocks(graph)
172
+ graph.blocks.each do |block|
173
+ @stream.puts " subgraph cluster_block#{block.id} {"
174
+ @stream.puts ' fontname = "Arial";'
175
+ @stream.puts " label = \"B#{block.id}\";"
176
+ @stream.puts ' style=dotted;'
177
+
178
+ block.nodes.each do |node|
179
+ next if node.props[:hidden] || node.props[:inlined]
180
+
181
+ @stream.puts " node#{node.id};"
182
+ end
183
+
184
+ @stream.puts ' }'
185
+ end
186
+ end
187
+
169
188
  # Return attributes for a node or edge modified to 'shade' them in terms
170
189
  # the spotlight functionality - so basically make them light grey.
171
190
  def shade(attrs)
@@ -1,5 +1,5 @@
1
1
  module Seafoam
2
2
  MAJOR_VERSION = 0
3
- MINOR_VERSION = 7
3
+ MINOR_VERSION = 8
4
4
  VERSION = "#{MAJOR_VERSION}.#{MINOR_VERSION}"
5
5
  end
@@ -52,6 +52,16 @@ describe Seafoam::BGV::BGVParser do
52
52
  end
53
53
  end
54
54
 
55
+ it 'can read basic blocks' do
56
+ parser = Seafoam::BGV::BGVParser.new(File.expand_path('../../../examples/fib-java.bgv', __dir__))
57
+ parser.read_file_header
58
+ parser.skip_document_props
59
+ parser.read_graph_preheader
60
+ parser.skip_graph_header
61
+ graph = parser.read_graph
62
+ expect(graph.blocks.size).to eq 3
63
+ end
64
+
55
65
  it 'can alternate skipping and reading full files' do
56
66
  Seafoam::SpecHelpers::SAMPLE_BGV.each do |file|
57
67
  parser = Seafoam::BGV::BGVParser.new(file)
@@ -108,7 +118,7 @@ describe Seafoam::BGV::BGVParser do
108
118
  parser = Seafoam::BGV::BGVParser.new(@fib_java_bgv)
109
119
  parser.read_file_header
110
120
  parser.skip_document_props
111
- 54.times do
121
+ 56.times do
112
122
  expect(parser.read_graph_preheader).to_not be_nil
113
123
  parser.skip_graph_header
114
124
  parser.skip_graph
@@ -150,7 +160,7 @@ describe Seafoam::BGV::BGVParser do
150
160
  parser.read_graph_preheader
151
161
  parser.read_graph_header
152
162
  graph = parser.read_graph
153
- expect(graph.nodes.size).to eq 22
163
+ expect(graph.nodes.size).to eq 21
154
164
  expect(graph.edges.size).to eq 30
155
165
  end
156
166
  end
@@ -33,18 +33,18 @@ describe Seafoam::Commands do
33
33
  @commands.send :list, @fib_java
34
34
  lines = @out.string.lines.map(&:rstrip)
35
35
  expect(lines.take(5)).to eq [
36
- "#{@fib_java}:0 2:Fib.fib(int)/After phase org.graalvm.compiler.java.GraphBuilderPhase",
37
- "#{@fib_java}:1 2:Fib.fib(int)/After phase org.graalvm.compiler.phases.PhaseSuite",
38
- "#{@fib_java}:2 2:Fib.fib(int)/After phase org.graalvm.compiler.phases.common.DeadCodeEliminationPhase",
39
- "#{@fib_java}:3 2:Fib.fib(int)/After parsing",
40
- "#{@fib_java}:4 2:Fib.fib(int)/After phase org.graalvm.compiler.phases.common.CanonicalizerPhase"
36
+ "#{@fib_java}:0 17:Fib.fib(int)/After phase org.graalvm.compiler.java.GraphBuilderPhase",
37
+ "#{@fib_java}:1 17:Fib.fib(int)/After phase org.graalvm.compiler.phases.PhaseSuite",
38
+ "#{@fib_java}:2 17:Fib.fib(int)/After phase org.graalvm.compiler.phases.common.DeadCodeEliminationPhase",
39
+ "#{@fib_java}:3 17:Fib.fib(int)/After parsing",
40
+ "#{@fib_java}:4 17:Fib.fib(int)/After phase org.graalvm.compiler.phases.common.CanonicalizerPhase"
41
41
  ]
42
42
  expect(lines.drop(lines.length - 5)).to eq [
43
- "#{@fib_java}:49 2:Fib.fib(int)/After phase org.graalvm.compiler.phases.common.DeadCodeEliminationPhase",
44
- "#{@fib_java}:50 2:Fib.fib(int)/After phase org.graalvm.compiler.phases.common.PropagateDeoptimizeProbabilityPhase",
45
- "#{@fib_java}:51 2:Fib.fib(int)/After phase org.graalvm.compiler.phases.schedule.SchedulePhase",
46
- "#{@fib_java}:52 2:Fib.fib(int)/After phase org.graalvm.compiler.core.phases.LowTier",
47
- "#{@fib_java}:53 2:Fib.fib(int)/After low tier"
43
+ "#{@fib_java}:51 17:Fib.fib(int)/After phase org.graalvm.compiler.phases.common.DeadCodeEliminationPhase",
44
+ "#{@fib_java}:52 17:Fib.fib(int)/After phase org.graalvm.compiler.phases.common.PropagateDeoptimizeProbabilityPhase",
45
+ "#{@fib_java}:53 17:Fib.fib(int)/After phase org.graalvm.compiler.phases.schedule.SchedulePhase",
46
+ "#{@fib_java}:54 17:Fib.fib(int)/After phase org.graalvm.compiler.core.phases.LowTier",
47
+ "#{@fib_java}:55 17:Fib.fib(int)/After low tier"
48
48
  ]
49
49
  end
50
50
 
@@ -96,7 +96,7 @@ describe Seafoam::Commands do
96
96
  it 'prints the number of edges and nodes for a graph' do
97
97
  @commands.send :edges, "#{@fib_java}:0"
98
98
  lines = @out.string.lines.map(&:rstrip)
99
- expect(lines.first).to eq '22 nodes, 30 edges'
99
+ expect(lines.first).to eq '21 nodes, 30 edges'
100
100
  end
101
101
 
102
102
  it 'prints the edges for a node' do
@@ -129,19 +129,17 @@ describe Seafoam::Commands do
129
129
  describe '#props' do
130
130
  it 'prints properties for a file' do
131
131
  @commands.send :props, @fib_java
132
- expect(@out.string.gsub(/\n\n/, "\n")).to eq "{\n \"vm.uuid\": \"28729\"\n}\n"
132
+ expect(@out.string.gsub(/\n\n/, "\n")).to eq "{\n \"vm.uuid\": \"94468\"\n}\n"
133
133
  end
134
134
 
135
135
  it 'prints properties for a graph' do
136
136
  @commands.send :props, "#{@fib_java}:0"
137
- lines = @out.string.lines.map(&:rstrip)
138
- expect(lines[3]).to include '"name": "2:Fib.fib(int)"'
137
+ expect(@out.string).to include '"scope": "main.Compiling.GraalCompiler.FrontEnd.PhaseSuite.GraphBuilderPhase"'
139
138
  end
140
139
 
141
140
  it 'prints properties for a node' do
142
141
  @commands.send :props, "#{@fib_java}:0:13"
143
- lines = @out.string.lines.map(&:rstrip)
144
- expect(lines[3]).to include '"declaring_class": "Fib"'
142
+ expect(@out.string).to include '"declaring_class": "Fib"'
145
143
  end
146
144
 
147
145
  it 'prints properties for an edge' do
@@ -33,6 +33,6 @@ describe Seafoam::Spotlight do
33
33
  spotlight.shade
34
34
  expect(@graph.nodes.values
35
35
  .select { |n| n.props[:hidden] }
36
- .map(&:id).sort).to eq [0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 15, 16, 17, 21]
36
+ .map(&:id).sort).to eq [0, 1, 2, 4, 5, 7, 8, 9, 10, 11, 15, 16, 17, 21]
37
37
  end
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seafoam
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.7'
4
+ version: '0.8'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Seaton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-05 00:00:00.000000000 Z
11
+ date: 2021-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: crabstone
@@ -85,6 +85,7 @@ files:
85
85
  - CODE_OF_CONDUCT.md
86
86
  - CONTRIBUTING.md
87
87
  - Gemfile
88
+ - Gemfile.lock
88
89
  - LICENSE.md
89
90
  - README.md
90
91
  - bin/bgv2isabelle
@@ -167,7 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
168
  - !ruby/object:Gem::Version
168
169
  version: '0'
169
170
  requirements: []
170
- rubygems_version: 3.1.4
171
+ rubyforge_project:
172
+ rubygems_version: 2.7.6.3
171
173
  signing_key:
172
174
  specification_version: 4
173
175
  summary: A tool for working with compiler graphs