B3ValueKey.cpp
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 #include "config.h" 27 #include "B3ValueKey.h" 28 29 #if ENABLE(B3_JIT) 30 31 #include "B3ArgumentRegValue.h" 32 #include "B3ProcedureInlines.h" 33 #include "B3SlotBaseValue.h" 34 #include "B3ValueInlines.h" 35 #include "B3ValueKeyInlines.h" 36 37 namespace JSC { namespace B3 { 38 39 ValueKey ValueKey::intConstant(Type type, int64_t value) 40 { 41 switch (type.kind()) { 42 case Int32: 43 return ValueKey(Const32, Int32, value); 44 case Int64: 45 return ValueKey(Const64, Int64, value); 46 default: 47 RELEASE_ASSERT_NOT_REACHED(); 48 return ValueKey(); 49 } 50 } 51 52 void ValueKey::dump(PrintStream& out) const 53 { 54 out.print(m_type, " ", m_kind, "(", u.indices[0], ", ", u.indices[1], ", ", u.indices[2], ")"); 55 } 56 57 Value* ValueKey::materialize(Procedure& proc, Origin origin) const 58 { 59 // NOTE: We sometimes cannot return a Value* for some key, like for Check and friends. That's because 60 // though those nodes have side exit effects. It would be weird to materialize anything that has a side 61 // exit. We can't possibly know enough about a side exit to know where it would be safe to emit one. 62 switch (opcode()) { 63 case FramePointer: 64 return proc.add<Value>(kind(), type(), origin); 65 case Identity: 66 case Opaque: 67 case Abs: 68 case Floor: 69 case Ceil: 70 case Sqrt: 71 case Neg: 72 case Depend: 73 case SExt8: 74 case SExt16: 75 case SExt32: 76 case ZExt32: 77 case Clz: 78 case Trunc: 79 case IToD: 80 case IToF: 81 case FloatToDouble: 82 case DoubleToFloat: 83 return proc.add<Value>(kind(), type(), origin, child(proc, 0)); 84 case Add: 85 case Sub: 86 case Mul: 87 case Div: 88 case UDiv: 89 case Mod: 90 case UMod: 91 case BitAnd: 92 case BitOr: 93 case BitXor: 94 case Shl: 95 case SShr: 96 case ZShr: 97 case RotR: 98 case RotL: 99 case Equal: 100 case NotEqual: 101 case LessThan: 102 case GreaterThan: 103 case Above: 104 case Below: 105 case AboveEqual: 106 case BelowEqual: 107 case EqualOrUnordered: 108 return proc.add<Value>(kind(), type(), origin, child(proc, 0), child(proc, 1)); 109 case Select: 110 return proc.add<Value>(kind(), type(), origin, child(proc, 0), child(proc, 1), child(proc, 2)); 111 case Const32: 112 return proc.add<Const32Value>(origin, static_cast<int32_t>(value())); 113 case Const64: 114 return proc.add<Const64Value>(origin, value()); 115 case ConstDouble: 116 return proc.add<ConstDoubleValue>(origin, doubleValue()); 117 case ConstFloat: 118 return proc.add<ConstFloatValue>(origin, floatValue()); 119 case BottomTuple: 120 return proc.add<BottomTupleValue>(origin, type()); 121 case ArgumentReg: 122 return proc.add<ArgumentRegValue>(origin, Reg::fromIndex(static_cast<unsigned>(value()))); 123 case SlotBase: 124 return proc.add<SlotBaseValue>(origin, proc.stackSlots()[value()]); 125 default: 126 return nullptr; 127 } 128 } 129 130 } } // namespace JSC::B3 131 132 #endif // ENABLE(B3_JIT) 133