1 | /* |
2 | * Copyright (C) 2015-2017 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(B3_JIT) |
29 | |
30 | #include "AirOpcode.h" |
31 | |
32 | namespace JSC::B3::Air { |
33 | |
34 | inline Air::Opcode moveForType(Type type) |
35 | { |
36 | switch (type.kind()) { |
37 | case Int32: |
38 | return Move32; |
39 | case Int64: |
40 | RELEASE_ASSERT(is64Bit()); |
41 | return Move; |
42 | case Float: |
43 | return MoveFloat; |
44 | case Double: |
45 | return MoveDouble; |
46 | case Void: |
47 | case Tuple: |
48 | break; |
49 | } |
50 | RELEASE_ASSERT_NOT_REACHED(); |
51 | return Air::Oops; |
52 | } |
53 | |
54 | inline Air::Opcode relaxedMoveForType(Type type) |
55 | { |
56 | switch (type.kind()) { |
57 | case Int32: |
58 | case Int64: |
59 | // For Int32, we could return Move or Move32. It's a trade-off. |
60 | // |
61 | // Move32: Using Move32 guarantees that we use the narrower move, but in cases where the |
62 | // register allocator can't prove that the variables involved are 32-bit, this will |
63 | // disable coalescing. |
64 | // |
65 | // Move: Using Move guarantees that the register allocator can coalesce normally, but in |
66 | // cases where it can't prove that the variables are 32-bit and it doesn't coalesce, |
67 | // this will force us to use a full 64-bit Move instead of the slightly cheaper |
68 | // 32-bit Move32. |
69 | // |
70 | // Coalescing is a lot more profitable than turning Move into Move32. So, it's better to |
71 | // use Move here because in cases where the register allocator cannot prove that |
72 | // everything is 32-bit, we still get coalescing. |
73 | return Move; |
74 | case Float: |
75 | // MoveFloat is always coalescable and we never convert MoveDouble to MoveFloat, so we |
76 | // should use MoveFloat when we know that the temporaries involved are 32-bit. |
77 | return MoveFloat; |
78 | case Double: |
79 | return MoveDouble; |
80 | case Void: |
81 | case Tuple: |
82 | break; |
83 | } |
84 | RELEASE_ASSERT_NOT_REACHED(); |
85 | return Air::Oops; |
86 | } |
87 | |
88 | } // namespace JSC::B3::Air |
89 | |
90 | #endif // ENABLE(B3_JIT) |
91 | |