Commit Graph

15 Commits

Author SHA1 Message Date
Mikhail Glukhikh febf336d23 IrConstTransformer: transform constants also inside call children 2021-12-13 16:24:59 +03:00
Mads Ager 05ff2b1292 [JVM_IR] Extend when to switch translation to deal with nested ors.
FIR translates:

```
when (x) {
  1, 2, 3 -> action
  else -> other_action
}
```

to an IR structure with nested ors:

```
if ((x == 1 || x == 2) || (x == 3)) action
else other_action
```

This change allows that to turn into switch instructions in the
JVM backend.
2021-02-16 03:20:07 -08:00
Mark Punzalan 238cc7c257 [FIR] Enable BytecodeText tests for FIR.
143 out of 767 tests (18.6%) are currently failing.
2020-09-29 10:21:21 +03:00
Alexander Udalov c706673de9 Minor, refactor bytecode text tests on when-over-string optimization
- Merge `duplicatingItemsSameHashCode.kt` and
  `duplicatingItemsSameHashCode2.kt` into one test enabled on both
  backends, and rename it to
  `duplicatingItemsSameHashCodeFewBranches.kt`.
- Rename `duplicatingItemsSameHashCode3.kt` to
  `duplicatingItemsSameHashCodeMoreBranches.kt`, and also enable it for
  both backends.
- Use JVM_TEMPLATES/JVM_IR_TEMPLATES to check backend-specific behavior:
    1) JVM IR does not optimize less than 2 branches by design
    2) JVM IR does not generate duplicate branches, also by design

Related to KT-36846.
2020-08-31 16:47:11 +02:00
Dmitry Petrov 81b30b7399 Update bytecode text tests for JVM_IR 2020-02-20 14:20:21 +03:00
Steven Schäfer 0b76f60b63 JVM IR: Handle NonInlinedConst 2019-10-05 10:52:59 +02:00
pyos 5b595b58b2 JVM_IR: fold constant string concatenations 2019-04-23 16:20:43 +02:00
Ting-Yuan Huang f6cf434650 when: emit switch for String if possible
Effectively, the following when structure:

  when (s) {
    s1, s2 -> e1,
    s3 -> e2,
    s4 -> e3,
    ...
    else -> e
  }

is implemented as:

  when (s.hashCode()) {
    h1 -> {
      if (s == s1)
        e1
      else if (s == s2)
        e1
      else if (s == s3)
        e2
      else
        e
    }
    h2 -> if (s == s3) e2 else e,
    ...
    else -> e
  }

where s1.hashCode() == s2.hashCode() == s3.hashCode() == h1,
      s4.hashCode() == h2.

A tableswitch or lookupswitch is used for the hash code lookup.

Change-Id: I087bf623dbb4a41d3cc64399a1b42342a50757a6
2019-03-20 09:13:51 +01:00
Mads Ager 3a11322506 Enable bytecode text tests for the JVM_IR backend. 2018-12-21 16:20:45 +01:00
Alexander Udalov 5b58eb8491 Remove LANGUAGE_VERSION from non-coroutine codegen tests
Most of these tests used this directive as a way to opt in to a new
language feature, and most of those features are already stable for a
long time, so no opt-in is needed. Some other tests used the directive
to opt out from a language feature, replace those by the `LANGUAGE`
directive. One test used the directive to test behavior that actually
depended on the API version; use `API_VERSION` directive there instead.
2018-12-20 12:53:23 +01:00
Mikhail Zarechenskiy 0134b8819b Optimize const vals by inlining them at use sites
#KT-11734 Fixed
 #KT-13570 Fixed
2016-12-05 22:11:33 +03:00
Michael Bogdanov 8835b0599a Inline preevaluated string and primitive only constants in compilation time, don't inline const references in non-annotation context, fix for KT-11025: Don't inline const val in compare instuctions
#KT-11025 Fixed
2016-02-17 16:53:18 +03:00
Denis Zharkov 0efe28a12a Do not inline non-const vals
#KT-10425 Fixed
2016-02-05 17:43:55 +03:00
Denis Zharkov 8d8c3d2b9e When2Switch: generate ifnonnull check for nullable values before *switch-opcode 2014-07-21 17:13:56 +04:00
Denis Zharkov d4cb822ee8 When by String constants:
Generate TABLESWITCH/LOOKUPSWITCH bytecode operation for when operator by String constants
2014-07-21 17:13:56 +04:00