Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1014 PostorderProcessor* child_; | 1014 PostorderProcessor* child_; |
| 1015 HLoopInformation* loop_; | 1015 HLoopInformation* loop_; |
| 1016 HBasicBlock* block_; | 1016 HBasicBlock* block_; |
| 1017 HBasicBlock* loop_header_; | 1017 HBasicBlock* loop_header_; |
| 1018 int loop_index; | 1018 int loop_index; |
| 1019 int loop_length; | 1019 int loop_length; |
| 1020 HSuccessorIterator successor_iterator; | 1020 HSuccessorIterator successor_iterator; |
| 1021 }; | 1021 }; |
| 1022 | 1022 |
| 1023 | 1023 |
| 1024 bool HGraph::TryRotateLeft(HInstruction* instr) { | |
| 1025 HInstruction* current = instr; | |
| 1026 ASSERT(current->IsBitwise()); | |
| 1027 HBitwise* bor = HBitwise::cast(current); | |
| 1028 HShl* shl; | |
| 1029 HShr* shr; | |
| 1030 if (bor->left()->IsShl() && bor->right()->IsShr()) { | |
| 1031 shl = HShl::cast(bor->left()); | |
| 1032 shr = HShr::cast(bor->right()); | |
| 1033 } else if (bor->left()->IsShr() && bor->right()->IsShl()) { | |
| 1034 shl = HShl::cast(bor->right()); | |
| 1035 shr = HShr::cast(bor->left()); | |
| 1036 } else { | |
| 1037 return false; | |
| 1038 } | |
| 1039 | |
| 1040 | |
| 1041 if (shl->UseCount()>1 || shr->UseCount()>1) return false; | |
|
ulan
2012/09/27 14:55:30
Please add space before and after each ">" operato
| |
| 1042 if (!shr->representation().IsInteger32() || | |
| 1043 !shl->representation().IsInteger32()) | |
|
Erik Corry
2012/09/27 14:45:44
Missing {}
| |
| 1044 return false; | |
| 1045 if (shl->left() != shr->left()) return false; | |
| 1046 | |
| 1047 if (!shr->right()->representation().IsInteger32() || | |
| 1048 !shl->right()->representation().IsInteger32() || | |
| 1049 !shl->left()->representation().IsInteger32()) | |
| 1050 return false; | |
| 1051 | |
| 1052 if (!shr->right()->IsSub()) return false; | |
|
Erik Corry
2012/09/27 14:45:44
This function needs a comment explaining what it i
| |
| 1053 HSub* sub = HSub::cast(shr->right()); | |
| 1054 if (!sub->left()->IsConstant() || | |
| 1055 !sub->left()->representation().IsInteger32() || | |
| 1056 !sub->right()->representation().IsInteger32()) | |
| 1057 return false; | |
| 1058 | |
| 1059 if (HConstant::cast(sub->left())->Integer32Value() != 32) return false; | |
| 1060 | |
| 1061 if (sub->right()->IsChange() && shl->right()->IsChange()) { | |
| 1062 if (sub->right()->OperandAt(0) != shl->right()->OperandAt(0)) | |
|
Erik Corry
2012/09/27 14:45:44
Missing {}
| |
| 1063 return false; | |
| 1064 } else if (sub->right() != shl->right()) { | |
| 1065 return false; | |
| 1066 } | |
| 1067 | |
| 1068 // start replacement | |
| 1069 HValue* left = shr->left(); | |
| 1070 HValue* right = shr->right(); | |
| 1071 HValue* context = shr->context(); | |
| 1072 HInstruction* ror = new(zone()) HRor(context, left, right); | |
| 1073 ror->InsertAfter(bor); | |
| 1074 bor->DeleteAndReplaceWith(ror); | |
| 1075 shl->DeleteAndReplaceWith(NULL); | |
| 1076 shr->DeleteAndReplaceWith(NULL); | |
| 1077 | |
| 1078 return true; | |
| 1079 } | |
| 1080 | |
| 1081 | |
| 1082 | |
| 1083 bool HGraph::TryRotateRight(HInstruction* instr) { | |
|
Erik Corry
2012/09/27 14:45:44
There is a lot of copied code here - can they be c
| |
| 1084 HInstruction* current = instr; | |
| 1085 ASSERT(current->IsBitwise()); | |
| 1086 HBitwise* bor = HBitwise::cast(current); | |
| 1087 HShl* shl; | |
| 1088 HShr* shr; | |
| 1089 if (bor->left()->IsShl() && bor->right()->IsShr()) { | |
|
ulan
2012/09/27 14:55:30
Please add space before and after each ">" operato
| |
| 1090 shl = HShl::cast(bor->left()); | |
| 1091 shr = HShr::cast(bor->right()); | |
| 1092 } else if (bor->left()->IsShr() && bor->right()->IsShl()) { | |
| 1093 shl = HShl::cast(bor->right()); | |
| 1094 shr = HShr::cast(bor->left()); | |
| 1095 } else { | |
| 1096 return false; | |
| 1097 } | |
| 1098 if (shl->UseCount()>1 || shr->UseCount()>1) return false; | |
| 1099 if (!shr->representation().IsInteger32() || | |
| 1100 !shl->representation().IsInteger32()) | |
| 1101 return false; | |
| 1102 if (shl->left() != shr->left()) return false; | |
| 1103 if (!shr->right()->representation().IsInteger32() || | |
| 1104 !shl->right()->representation().IsInteger32() || | |
| 1105 !shl->left()->representation().IsInteger32()) | |
| 1106 return false; | |
| 1107 if (!shl->right()->IsSub()) return false; | |
| 1108 HSub* sub = HSub::cast(shl->right()); | |
| 1109 if (!sub->left()->IsConstant() || | |
| 1110 !sub->left()->representation().IsInteger32() || | |
| 1111 !sub->right()->representation().IsInteger32()) | |
| 1112 return false; | |
| 1113 HConstant* constant = HConstant::cast(sub->left()); | |
| 1114 if (constant->Integer32Value() != 32) return false; | |
| 1115 | |
| 1116 if (sub->right()->IsChange() && shl->right()->IsChange()) { | |
| 1117 if (sub->right()->OperandAt(0) != shl->right()->OperandAt(0)) | |
| 1118 return false; | |
| 1119 } else if (sub->right() != shl->right()) { | |
| 1120 return false; | |
| 1121 } | |
| 1122 | |
| 1123 // start replacement | |
| 1124 HValue* left = shr->left(); | |
| 1125 HValue* right = shr->right(); | |
| 1126 HValue* context = shr->context(); | |
| 1127 HInstruction* ror = new(zone()) HRor(context, left, right); | |
| 1128 ror->InsertAfter(bor); | |
| 1129 bor->DeleteAndReplaceWith(ror); | |
| 1130 shl->DeleteAndReplaceWith(NULL); | |
| 1131 shr->DeleteAndReplaceWith(NULL); | |
| 1132 if (sub->HasNoUses()) sub->DeleteAndReplaceWith(NULL); | |
| 1133 if (constant->HasNoUses()) constant->DeleteAndReplaceWith(NULL); | |
| 1134 | |
| 1135 return true; | |
| 1136 } | |
| 1137 | |
| 1138 | |
| 1139 | |
| 1140 void HGraph::ReplaceWithRor() { | |
| 1141 if (!FLAG_use_replace_with_ror) return; | |
| 1142 HPhase phase("H_ReplaceWithRor", this); | |
| 1143 for (int i = 0; i < blocks()->length(); ++i) { | |
| 1144 HInstruction* instr = blocks()->at(i)->first(); | |
| 1145 while (instr != NULL) { | |
| 1146 if (instr->IsBitwise() && | |
| 1147 HBitwise::cast(instr)->op() == Token::BIT_OR) { | |
| 1148 if (!TryRotateLeft(instr)) { | |
| 1149 TryRotateRight(instr); | |
| 1150 } | |
| 1151 } | |
| 1152 instr = instr->next(); | |
| 1153 } | |
| 1154 } | |
| 1155 } | |
| 1156 | |
| 1157 | |
| 1024 void HGraph::OrderBlocks() { | 1158 void HGraph::OrderBlocks() { |
| 1025 HPhase phase("H_Block ordering"); | 1159 HPhase phase("H_Block ordering"); |
| 1026 BitVector visited(blocks_.length(), zone()); | 1160 BitVector visited(blocks_.length(), zone()); |
| 1027 | 1161 |
| 1028 ZoneList<HBasicBlock*> reverse_result(8, zone()); | 1162 ZoneList<HBasicBlock*> reverse_result(8, zone()); |
| 1029 HBasicBlock* start = blocks_[0]; | 1163 HBasicBlock* start = blocks_[0]; |
| 1030 PostorderProcessor* postorder = | 1164 PostorderProcessor* postorder = |
| 1031 PostorderProcessor::CreateEntryProcessor(zone(), start, &visited); | 1165 PostorderProcessor::CreateEntryProcessor(zone(), start, &visited); |
| 1032 while (postorder != NULL) { | 1166 while (postorder != NULL) { |
| 1033 postorder = postorder->PerformStep(zone(), &visited, &reverse_result); | 1167 postorder = postorder->PerformStep(zone(), &visited, &reverse_result); |
| (...skipping 2361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3395 if (FLAG_use_range) { | 3529 if (FLAG_use_range) { |
| 3396 HRangeAnalysis rangeAnalysis(this); | 3530 HRangeAnalysis rangeAnalysis(this); |
| 3397 rangeAnalysis.Analyze(); | 3531 rangeAnalysis.Analyze(); |
| 3398 } | 3532 } |
| 3399 ComputeMinusZeroChecks(); | 3533 ComputeMinusZeroChecks(); |
| 3400 | 3534 |
| 3401 // Eliminate redundant stack checks on backwards branches. | 3535 // Eliminate redundant stack checks on backwards branches. |
| 3402 HStackCheckEliminator sce(this); | 3536 HStackCheckEliminator sce(this); |
| 3403 sce.Process(); | 3537 sce.Process(); |
| 3404 | 3538 |
| 3539 #if defined(V8_TARGET_ARCH_ARM) | |
|
ulan
2012/09/27 15:30:10
I am concerned with this ifdef. Hydrogen should co
| |
| 3540 ReplaceWithRor(); | |
| 3541 #endif | |
| 3542 | |
| 3405 EliminateRedundantBoundsChecks(); | 3543 EliminateRedundantBoundsChecks(); |
| 3406 DehoistSimpleArrayIndexComputations(); | 3544 DehoistSimpleArrayIndexComputations(); |
| 3407 | 3545 |
| 3408 return true; | 3546 return true; |
| 3409 } | 3547 } |
| 3410 | 3548 |
| 3411 | 3549 |
| 3412 // We try to "factor up" HBoundsCheck instructions towards the root of the | 3550 // We try to "factor up" HBoundsCheck instructions towards the root of the |
| 3413 // dominator tree. | 3551 // dominator tree. |
| 3414 // For now we handle checks where the index is like "exp + int32value". | 3552 // For now we handle checks where the index is like "exp + int32value". |
| (...skipping 6568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9983 } | 10121 } |
| 9984 } | 10122 } |
| 9985 | 10123 |
| 9986 #ifdef DEBUG | 10124 #ifdef DEBUG |
| 9987 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 10125 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
| 9988 if (allocator_ != NULL) allocator_->Verify(); | 10126 if (allocator_ != NULL) allocator_->Verify(); |
| 9989 #endif | 10127 #endif |
| 9990 } | 10128 } |
| 9991 | 10129 |
| 9992 } } // namespace v8::internal | 10130 } } // namespace v8::internal |
| OLD | NEW |