OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 Result VirtualFrame::RawCallCodeObject(Handle<Code> code, | 888 Result VirtualFrame::RawCallCodeObject(Handle<Code> code, |
889 RelocInfo::Mode rmode) { | 889 RelocInfo::Mode rmode) { |
890 ASSERT(cgen()->HasValidEntryRegisters()); | 890 ASSERT(cgen()->HasValidEntryRegisters()); |
891 __ call(code, rmode); | 891 __ call(code, rmode); |
892 Result result = cgen()->allocator()->Allocate(eax); | 892 Result result = cgen()->allocator()->Allocate(eax); |
893 ASSERT(result.is_valid()); | 893 ASSERT(result.is_valid()); |
894 return result; | 894 return result; |
895 } | 895 } |
896 | 896 |
897 | 897 |
| 898 // This function assumes that the only results that could be in a_reg or b_reg |
| 899 // are a and b. Other results can be live, but must not be in a_reg or b_reg. |
| 900 void VirtualFrame::MoveResultsToRegisters(Result* a, |
| 901 Result* b, |
| 902 Register a_reg, |
| 903 Register b_reg) { |
| 904 if (a->is_register() && a->reg().is(a_reg)) { |
| 905 b->ToRegister(b_reg); |
| 906 } else if (!cgen()->allocator()->is_used(a_reg)) { |
| 907 a->ToRegister(a_reg); |
| 908 b->ToRegister(b_reg); |
| 909 } else if (cgen()->allocator()->is_used(b_reg)) { |
| 910 // a must be in b_reg, b in a_reg. |
| 911 __ xchg(a_reg, b_reg); |
| 912 // Results a and b will be invalidated, so it is ok if they are switched. |
| 913 } else { |
| 914 b->ToRegister(b_reg); |
| 915 a->ToRegister(a_reg); |
| 916 } |
| 917 a->Unuse(); |
| 918 b->Unuse(); |
| 919 } |
| 920 |
| 921 |
898 Result VirtualFrame::CallLoadIC(RelocInfo::Mode mode) { | 922 Result VirtualFrame::CallLoadIC(RelocInfo::Mode mode) { |
899 // Name and receiver are on the top of the frame. The IC expects | 923 // Name and receiver are on the top of the frame. The IC expects |
900 // name in ecx and receiver in eax. | 924 // name in ecx and receiver in eax. |
901 Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); | |
902 Result name = Pop(); | 925 Result name = Pop(); |
903 Result receiver = Pop(); | 926 Result receiver = Pop(); |
904 PrepareForCall(0, 0); // No stack arguments. | 927 PrepareForCall(0, 0); // No stack arguments. |
905 // Move results to the right registers: | 928 MoveResultsToRegisters(&name, &receiver, ecx, eax); |
906 if (name.is_register() && name.reg().is(eax)) { | 929 |
907 if (receiver.is_register() && receiver.reg().is(ecx)) { | 930 Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
908 // Wrong registers. | |
909 __ xchg(eax, ecx); | |
910 } else { | |
911 // Register ecx is free for name, which frees eax for receiver. | |
912 name.ToRegister(ecx); | |
913 receiver.ToRegister(eax); | |
914 } | |
915 } else { | |
916 // Register eax is free for receiver, which frees ecx for name. | |
917 receiver.ToRegister(eax); | |
918 name.ToRegister(ecx); | |
919 } | |
920 name.Unuse(); | |
921 receiver.Unuse(); | |
922 return RawCallCodeObject(ic, mode); | 931 return RawCallCodeObject(ic, mode); |
923 } | 932 } |
924 | 933 |
925 | 934 |
926 Result VirtualFrame::CallKeyedLoadIC(RelocInfo::Mode mode) { | 935 Result VirtualFrame::CallKeyedLoadIC(RelocInfo::Mode mode) { |
927 // Key and receiver are on top of the frame. Put them in eax and edx. | 936 // Key and receiver are on top of the frame. Put them in eax and edx. |
928 Result key = Pop(); | 937 Result key = Pop(); |
929 Result receiver = Pop(); | 938 Result receiver = Pop(); |
930 PrepareForCall(0, 0); | 939 PrepareForCall(0, 0); |
931 | 940 MoveResultsToRegisters(&key, &receiver, eax, edx); |
932 if (!key.is_register() || !key.reg().is(edx)) { | |
933 // Register edx is available for receiver. | |
934 receiver.ToRegister(edx); | |
935 key.ToRegister(eax); | |
936 } else if (!receiver.is_register() || !receiver.reg().is(eax)) { | |
937 // Register eax is available for key. | |
938 key.ToRegister(eax); | |
939 receiver.ToRegister(edx); | |
940 } else { | |
941 __ xchg(edx, eax); | |
942 } | |
943 key.Unuse(); | |
944 receiver.Unuse(); | |
945 | 941 |
946 Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); | 942 Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); |
947 return RawCallCodeObject(ic, mode); | 943 return RawCallCodeObject(ic, mode); |
948 } | 944 } |
949 | 945 |
950 | 946 |
951 Result VirtualFrame::CallStoreIC(Handle<String> name, bool is_contextual) { | 947 Result VirtualFrame::CallStoreIC(Handle<String> name, bool is_contextual) { |
952 // Value and (if not contextual) receiver are on top of the frame. | 948 // Value and (if not contextual) receiver are on top of the frame. |
953 // The IC expects name in ecx, value in eax, and receiver in edx. | 949 // The IC expects name in ecx, value in eax, and receiver in edx. |
954 Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); | 950 Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
955 Result value = Pop(); | 951 Result value = Pop(); |
956 if (is_contextual) { | 952 if (is_contextual) { |
957 PrepareForCall(0, 0); | 953 PrepareForCall(0, 0); |
958 value.ToRegister(eax); | 954 value.ToRegister(eax); |
959 __ mov(edx, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); | 955 __ mov(edx, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
960 __ mov(ecx, name); | 956 __ mov(ecx, name); |
| 957 value.Unuse(); |
961 } else { | 958 } else { |
962 Result receiver = Pop(); | 959 Result receiver = Pop(); |
963 PrepareForCall(0, 0); | 960 PrepareForCall(0, 0); |
964 | 961 MoveResultsToRegisters(&value, &receiver, eax, edx); |
965 if (value.is_register() && value.reg().is(edx)) { | |
966 if (receiver.is_register() && receiver.reg().is(eax)) { | |
967 // Wrong registers. | |
968 __ xchg(eax, edx); | |
969 } else { | |
970 // Register eax is free for value, which frees edx for receiver. | |
971 value.ToRegister(eax); | |
972 receiver.ToRegister(edx); | |
973 } | |
974 } else { | |
975 // Register edx is free for receiver, which guarantees eax is free for | |
976 // value. | |
977 receiver.ToRegister(edx); | |
978 value.ToRegister(eax); | |
979 } | |
980 } | 962 } |
981 __ mov(ecx, name); | 963 __ mov(ecx, name); |
982 value.Unuse(); | |
983 return RawCallCodeObject(ic, RelocInfo::CODE_TARGET); | 964 return RawCallCodeObject(ic, RelocInfo::CODE_TARGET); |
984 } | 965 } |
985 | 966 |
986 | 967 |
987 Result VirtualFrame::CallKeyedStoreIC() { | 968 Result VirtualFrame::CallKeyedStoreIC() { |
988 // Value, key, and receiver are on the top of the frame. The IC | 969 // Value, key, and receiver are on the top of the frame. The IC |
989 // expects value in eax and key and receiver on the stack. It does | 970 // expects value in eax, key in ecx, and receiver in edx. |
990 // not drop the key and receiver. | 971 Result value = Pop(); |
| 972 Result key = Pop(); |
| 973 Result receiver = Pop(); |
| 974 PrepareForCall(0, 0); |
| 975 if (!cgen()->allocator()->is_used(eax) || |
| 976 (value.is_register() && value.reg().is(eax))) { |
| 977 value.ToRegister(eax); // No effect if value is in eax already. |
| 978 MoveResultsToRegisters(&key, &receiver, ecx, edx); |
| 979 value.Unuse(); |
| 980 } else if (!cgen()->allocator()->is_used(ecx) || |
| 981 (key.is_register() && key.reg().is(ecx))) { |
| 982 // Receiver and/or key are in eax. |
| 983 key.ToRegister(ecx); |
| 984 MoveResultsToRegisters(&value, &receiver, eax, edx); |
| 985 key.Unuse(); |
| 986 } else if (!cgen()->allocator()->is_used(edx) || |
| 987 (receiver.is_register() && receiver.reg().is(edx))) { |
| 988 receiver.ToRegister(edx); |
| 989 MoveResultsToRegisters(&key, &value, ecx, eax); |
| 990 receiver.Unuse(); |
| 991 } else { |
| 992 // All three registers are used, and no value is in the correct place. |
| 993 // We have one of the two circular permutations of eax, ecx, edx. |
| 994 ASSERT(value.is_register()); |
| 995 if (value.reg().is(ecx)) { |
| 996 __ xchg(eax, edx); |
| 997 __ xchg(eax, ecx); |
| 998 } else { |
| 999 __ xchg(eax, ecx); |
| 1000 __ xchg(eax, edx); |
| 1001 } |
| 1002 value.Unuse(); |
| 1003 key.Unuse(); |
| 1004 receiver.Unuse(); |
| 1005 } |
| 1006 |
991 Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); | 1007 Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
992 Result value = Pop(); | |
993 PrepareForCall(2, 0); // Two stack args, neither callee-dropped. | |
994 value.ToRegister(eax); | |
995 value.Unuse(); | |
996 return RawCallCodeObject(ic, RelocInfo::CODE_TARGET); | 1008 return RawCallCodeObject(ic, RelocInfo::CODE_TARGET); |
997 } | 1009 } |
998 | 1010 |
999 | 1011 |
1000 Result VirtualFrame::CallCallIC(RelocInfo::Mode mode, | 1012 Result VirtualFrame::CallCallIC(RelocInfo::Mode mode, |
1001 int arg_count, | 1013 int arg_count, |
1002 int loop_nesting) { | 1014 int loop_nesting) { |
1003 // Function name, arguments, and receiver are on top of the frame. | 1015 // Function name, arguments, and receiver are on top of the frame. |
1004 // The IC expects the name in ecx and the rest on the stack and | 1016 // The IC expects the name in ecx and the rest on the stack and |
1005 // drops them all. | 1017 // drops them all. |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 return; | 1193 return; |
1182 } | 1194 } |
1183 | 1195 |
1184 UNREACHABLE(); | 1196 UNREACHABLE(); |
1185 } | 1197 } |
1186 | 1198 |
1187 | 1199 |
1188 #undef __ | 1200 #undef __ |
1189 | 1201 |
1190 } } // namespace v8::internal | 1202 } } // namespace v8::internal |
OLD | NEW |