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 20 matching lines...) Expand all Loading... |
31 #include "register-allocator-inl.h" | 31 #include "register-allocator-inl.h" |
32 | 32 |
33 namespace v8 { | 33 namespace v8 { |
34 namespace internal { | 34 namespace internal { |
35 | 35 |
36 // ------------------------------------------------------------------------- | 36 // ------------------------------------------------------------------------- |
37 // Result implementation. | 37 // Result implementation. |
38 | 38 |
39 | 39 |
40 Result::Result(Register reg) { | 40 Result::Result(Register reg) { |
41 ASSERT(reg.is_valid()); | 41 ASSERT(reg.is_valid() && !RegisterAllocator::IsReserved(reg)); |
42 CodeGeneratorScope::Current()->allocator()->Use(reg); | 42 CodeGeneratorScope::Current()->allocator()->Use(reg); |
43 value_ = StaticTypeField::encode(StaticType::UNKNOWN_TYPE) | 43 value_ = StaticTypeField::encode(StaticType::UNKNOWN_TYPE) |
44 | TypeField::encode(REGISTER) | 44 | TypeField::encode(REGISTER) |
45 | DataField::encode(reg.code_); | 45 | DataField::encode(reg.code_); |
46 } | 46 } |
47 | 47 |
48 | 48 |
49 Result::Result(Register reg, StaticType type) { | 49 Result::Result(Register reg, StaticType type) { |
50 ASSERT(reg.is_valid()); | 50 ASSERT(reg.is_valid() && !RegisterAllocator::IsReserved(reg)); |
51 CodeGeneratorScope::Current()->allocator()->Use(reg); | 51 CodeGeneratorScope::Current()->allocator()->Use(reg); |
52 value_ = StaticTypeField::encode(type.static_type_) | 52 value_ = StaticTypeField::encode(type.static_type_) |
53 | TypeField::encode(REGISTER) | 53 | TypeField::encode(REGISTER) |
54 | DataField::encode(reg.code_); | 54 | DataField::encode(reg.code_); |
55 } | 55 } |
56 | 56 |
57 | 57 |
58 // ------------------------------------------------------------------------- | 58 // ------------------------------------------------------------------------- |
59 // RegisterAllocator implementation. | 59 // RegisterAllocator implementation. |
60 | 60 |
61 | 61 |
62 Result RegisterAllocator::AllocateWithoutSpilling() { | 62 Result RegisterAllocator::AllocateWithoutSpilling() { |
63 // Return the first free register, if any. | 63 // Return the first free register, if any. |
64 int free_reg = registers_.ScanForFreeRegister(); | 64 int num = registers_.ScanForFreeRegister(); |
65 if (free_reg < kNumRegisters) { | 65 if (num == RegisterAllocator::kInvalidRegister) { |
66 Register free_result = { free_reg }; | 66 return Result(); |
67 return Result(free_result); | |
68 } | 67 } |
69 return Result(); | 68 return Result(RegisterAllocator::ToRegister(num)); |
70 } | 69 } |
71 | 70 |
72 | 71 |
73 Result RegisterAllocator::Allocate() { | 72 Result RegisterAllocator::Allocate() { |
74 Result result = AllocateWithoutSpilling(); | 73 Result result = AllocateWithoutSpilling(); |
75 if (!result.is_valid()) { | 74 if (!result.is_valid()) { |
76 // Ask the current frame to spill a register. | 75 // Ask the current frame to spill a register. |
77 ASSERT(cgen_->has_valid_frame()); | 76 ASSERT(cgen_->has_valid_frame()); |
78 Register free_reg = cgen_->frame()->SpillAnyRegister(); | 77 Register free_reg = cgen_->frame()->SpillAnyRegister(); |
79 if (free_reg.is_valid()) { | 78 if (free_reg.is_valid()) { |
(...skipping 17 matching lines...) Expand all Loading... |
97 cgen_->frame()->Spill(target); | 96 cgen_->frame()->Spill(target); |
98 ASSERT(!is_used(target)); | 97 ASSERT(!is_used(target)); |
99 return Result(target); | 98 return Result(target); |
100 } | 99 } |
101 // Otherwise (if it's referenced outside the frame) we cannot allocate it. | 100 // Otherwise (if it's referenced outside the frame) we cannot allocate it. |
102 return Result(); | 101 return Result(); |
103 } | 102 } |
104 | 103 |
105 | 104 |
106 } } // namespace v8::internal | 105 } } // namespace v8::internal |
OLD | NEW |