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 19 matching lines...) Expand all Loading... |
30 | 30 |
31 #include "v8.h" | 31 #include "v8.h" |
32 | 32 |
33 namespace v8 { | 33 namespace v8 { |
34 namespace internal { | 34 namespace internal { |
35 | 35 |
36 // ------------------------------------------------------------------------- | 36 // ------------------------------------------------------------------------- |
37 // RegisterAllocator implementation. | 37 // RegisterAllocator implementation. |
38 | 38 |
39 bool RegisterAllocator::IsReserved(Register reg) { | 39 bool RegisterAllocator::IsReserved(Register reg) { |
40 return reg.is(rsp) || reg.is(rbp) || reg.is(rsi) || reg.is(r10); | 40 return reg.is(rsp) || reg.is(rbp) || reg.is(rsi) || |
| 41 reg.is(kScratchRegister); |
41 } | 42 } |
42 | 43 |
43 | 44 |
44 // The register allocator uses small integers to represent the | 45 // The register allocator uses small integers to represent the |
45 // non-reserved assembler registers. | 46 // non-reserved assembler registers. |
46 | |
47 int RegisterAllocator::ToNumber(Register reg) { | 47 int RegisterAllocator::ToNumber(Register reg) { |
48 ASSERT(reg.is_valid() && !IsReserved(reg)); | 48 ASSERT(reg.is_valid() && !IsReserved(reg)); |
49 return reg.code(); | 49 static const int numbers[] = { |
| 50 0, // rax |
| 51 2, // rcx |
| 52 3, // rdx |
| 53 1, // rbx |
| 54 -1, // rsp |
| 55 -1, // rbp |
| 56 -1, // rsi |
| 57 4, // rdi |
| 58 5, // r8 |
| 59 6, // r9 |
| 60 -1, // r10 |
| 61 7, // r11 |
| 62 11, // r12 |
| 63 10, // r13 |
| 64 8, // r14 |
| 65 9 // r15 |
| 66 }; |
| 67 return numbers[reg.code()]; |
50 } | 68 } |
51 | 69 |
52 | 70 |
53 Register RegisterAllocator::ToRegister(int num) { | 71 Register RegisterAllocator::ToRegister(int num) { |
54 ASSERT(num >= 0 && num < kNumRegisters); | 72 ASSERT(num >= 0 && num < kNumRegisters); |
55 Register result = {num}; | 73 static Register registers[] = |
56 return result; | 74 { rax, rbx, rcx, rdx, rdi, r8, r9, r11, r14, r15, r13, r12 }; |
| 75 return registers[num]; |
57 } | 76 } |
58 | 77 |
59 | 78 |
60 void RegisterAllocator::Initialize() { | 79 void RegisterAllocator::Initialize() { |
61 // TODO(X64): Implement. | 80 Reset(); |
| 81 // The non-reserved rdi register is live on JS function entry. |
| 82 Use(rdi); // JS function. |
62 } | 83 } |
63 | |
64 | |
65 } } // namespace v8::internal | 84 } } // namespace v8::internal |
66 | 85 |
67 #endif // V8_X64_REGISTER_ALLOCATOR_X64_INL_H_ | 86 #endif // V8_X64_REGISTER_ALLOCATOR_X64_INL_H_ |
OLD | NEW |