| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 #include "v8.h" |
| 29 |
| 30 #include "lithium-codegen.h" |
| 31 |
| 32 #if V8_TARGET_ARCH_IA32 |
| 33 #include "ia32/lithium-ia32.h" |
| 34 #include "ia32/lithium-codegen-ia32.h" |
| 35 #elif V8_TARGET_ARCH_X64 |
| 36 #include "x64/lithium-x64.h" |
| 37 #include "x64/lithium-codegen-x64.h" |
| 38 #elif V8_TARGET_ARCH_ARM |
| 39 #include "arm/lithium-arm.h" |
| 40 #include "arm/lithium-codegen-arm.h" |
| 41 #elif V8_TARGET_ARCH_A64 |
| 42 #include "a64/lithium-a64.h" |
| 43 #include "a64/lithium-codegen-a64.h" |
| 44 #elif V8_TARGET_ARCH_MIPS |
| 45 #include "mips/lithium-mips.h" |
| 46 #include "mips/lithium-codegen-mips.h" |
| 47 #else |
| 48 #error Unsupported target architecture. |
| 49 #endif |
| 50 |
| 51 namespace v8 { |
| 52 namespace internal { |
| 53 |
| 54 |
| 55 HGraph* LCodeGenBase::graph() const { |
| 56 return chunk()->graph(); |
| 57 } |
| 58 |
| 59 |
| 60 LCodeGenBase::LCodeGenBase(LChunk* chunk, |
| 61 MacroAssembler* assembler, |
| 62 CompilationInfo* info) |
| 63 : chunk_(static_cast<LPlatformChunk*>(chunk)), |
| 64 masm_(assembler), |
| 65 info_(info), |
| 66 zone_(info->zone()), |
| 67 status_(UNUSED), |
| 68 current_block_(-1), |
| 69 current_instruction_(-1), |
| 70 instructions_(chunk->instructions()), |
| 71 last_lazy_deopt_pc_(0) { |
| 72 } |
| 73 |
| 74 |
| 75 bool LCodeGenBase::GenerateBody() { |
| 76 ASSERT(is_generating()); |
| 77 bool emit_instructions = true; |
| 78 LCodeGen* codegen = static_cast<LCodeGen*>(this); |
| 79 for (current_instruction_ = 0; |
| 80 !is_aborted() && current_instruction_ < instructions_->length(); |
| 81 current_instruction_++) { |
| 82 LInstruction* instr = instructions_->at(current_instruction_); |
| 83 |
| 84 // Don't emit code for basic blocks with a replacement. |
| 85 if (instr->IsLabel()) { |
| 86 emit_instructions = !LLabel::cast(instr)->HasReplacement() && |
| 87 (!FLAG_unreachable_code_elimination || |
| 88 instr->hydrogen_value()->block()->IsReachable()); |
| 89 if (FLAG_code_comments && !emit_instructions) { |
| 90 Comment( |
| 91 ";;; <@%d,#%d> -------------------- B%d (unreachable/replaced) " |
| 92 "--------------------", |
| 93 current_instruction_, |
| 94 instr->hydrogen_value()->id(), |
| 95 instr->hydrogen_value()->block()->block_id()); |
| 96 } |
| 97 } |
| 98 if (!emit_instructions) continue; |
| 99 |
| 100 if (FLAG_code_comments && instr->HasInterestingComment(codegen)) { |
| 101 Comment(";;; <@%d,#%d> %s", |
| 102 current_instruction_, |
| 103 instr->hydrogen_value()->id(), |
| 104 instr->Mnemonic()); |
| 105 } |
| 106 |
| 107 GenerateBodyInstructionPre(instr); |
| 108 |
| 109 RecordAndUpdatePosition(instr->position()); |
| 110 |
| 111 instr->CompileToNative(codegen); |
| 112 |
| 113 GenerateBodyInstructionPost(instr); |
| 114 } |
| 115 EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
| 116 last_lazy_deopt_pc_ = masm()->pc_offset(); |
| 117 return !is_aborted(); |
| 118 } |
| 119 |
| 120 |
| 121 void LCodeGenBase::Comment(const char* format, ...) { |
| 122 if (!FLAG_code_comments) return; |
| 123 char buffer[4 * KB]; |
| 124 StringBuilder builder(buffer, ARRAY_SIZE(buffer)); |
| 125 va_list arguments; |
| 126 va_start(arguments, format); |
| 127 builder.AddFormattedList(format, arguments); |
| 128 va_end(arguments); |
| 129 |
| 130 // Copy the string before recording it in the assembler to avoid |
| 131 // issues when the stack allocated buffer goes out of scope. |
| 132 size_t length = builder.position(); |
| 133 Vector<char> copy = Vector<char>::New(static_cast<int>(length) + 1); |
| 134 OS::MemCopy(copy.start(), builder.Finalize(), copy.length()); |
| 135 masm()->RecordComment(copy.start()); |
| 136 } |
| 137 |
| 138 |
| 139 int LCodeGenBase::GetNextEmittedBlock() const { |
| 140 for (int i = current_block_ + 1; i < graph()->blocks()->length(); ++i) { |
| 141 if (!chunk_->GetLabel(i)->HasReplacement()) return i; |
| 142 } |
| 143 return -1; |
| 144 } |
| 145 |
| 146 |
| 147 } } // namespace v8::internal |
| OLD | NEW |