Bug 18884 - const-folded literals get unnecessary tmp storage
Summary: const-folded literals get unnecessary tmp storage
Status: RESOLVED FIXED
Alias: None
Product: systemtap
Classification: Unclassified
Component: translator (show other bugs)
Version: unspecified
: P2 minor
Target Milestone: ---
Assignee: Unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-28 18:57 UTC by Josh Stone
Modified: 2015-11-25 05:26 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Josh Stone 2015-08-28 18:57:44 UTC
Thanks to the const-folding pass, trivial numeric and string operations are reduced in pass-2.  You can see this in -vp2 of the following probes:

  probe oneshot { println("foobar") }
  probe oneshot { println("foo" . "bar") }

The second one becomes just like the first, as println("foobar").

In the translator pass, we also try to avoid tmp copies of literal values, and instead just emit the values directly into their expressions.  However, this is compared on the tok->type rather than checking if the expression itself is a literal.  The pattern in translate.cxx looks like this:

  if (val->tok->type == tok_number || val->tok->type == tok_string)
    tmpval.override(c_expression(val))

This is basically everywhere c_expression is called, and c_expression itself also asserts the tok->type.

But in the case of "foo"."bar", const_folder::visit_concatenation points the new literal_string's tok at the original "." operator, which is not a tok_string.  That's useful for accurate error reporting, but it means the translator shouldn't rely on tok->type being accurate.

The difference is visible in pass-3:

$ stap -p3 -e 'probe oneshot { println("foobar") }' | grep -c tmp
0
$ stap -p3 -e 'probe oneshot { println("foo"."bar") }' | grep -c tmp
4

This might also occur in other places where we synthesize code with literals, tied back to original tokens, like saved $var in .return probes, but I haven't checked for sure.
Comment 1 Josh Stone 2015-11-25 05:26:14 UTC
commit b2d74f03a0c5536dcc2c7b6af262cfdc5459e947