OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1656 PrintF("L%d: Exit\n\n", number()); | 1656 PrintF("L%d: Exit\n\n", number()); |
1657 } | 1657 } |
1658 | 1658 |
1659 | 1659 |
1660 void BlockNode::PrintText() { | 1660 void BlockNode::PrintText() { |
1661 PrintReachingDefinitions(); | 1661 PrintReachingDefinitions(); |
1662 // Print the instructions in the block. | 1662 // Print the instructions in the block. |
1663 PrintF("L%d: Block\n", number()); | 1663 PrintF("L%d: Block\n", number()); |
1664 TextInstructionPrinter printer; | 1664 TextInstructionPrinter printer; |
1665 for (int i = 0, len = instructions_.length(); i < len; i++) { | 1665 for (int i = 0, len = instructions_.length(); i < len; i++) { |
| 1666 AstNode* instr = instructions_[i]; |
| 1667 // Print a star next to dead instructions. |
| 1668 if (instr->AsExpression() != NULL && instr->AsExpression()->is_live()) { |
| 1669 PrintF(" "); |
| 1670 } else { |
| 1671 PrintF("* "); |
| 1672 } |
1666 PrintF("%d ", printer.NextNumber()); | 1673 PrintF("%d ", printer.NextNumber()); |
1667 printer.Visit(instructions_[i]); | 1674 printer.Visit(instr); |
1668 printer.AssignNumber(instructions_[i]); | 1675 printer.AssignNumber(instr); |
1669 PrintF("\n"); | 1676 PrintF("\n"); |
1670 } | 1677 } |
1671 PrintF("goto L%d\n\n", successor_->number()); | 1678 PrintF("goto L%d\n\n", successor_->number()); |
1672 } | 1679 } |
1673 | 1680 |
1674 | 1681 |
1675 void BranchNode::PrintText() { | 1682 void BranchNode::PrintText() { |
1676 PrintReachingDefinitions(); | 1683 PrintReachingDefinitions(); |
1677 PrintF("L%d: Branch\n", number()); | 1684 PrintF("L%d: Branch\n", number()); |
1678 PrintF("goto (L%d, L%d)\n\n", successor0_->number(), successor1_->number()); | 1685 PrintF("goto (L%d, L%d)\n\n", successor0_->number(), successor1_->number()); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1746 rd_.Initialize(definition_count); | 1753 rd_.Initialize(definition_count); |
1747 // The RD_in set for the entry node has a definition for each parameter | 1754 // The RD_in set for the entry node has a definition for each parameter |
1748 // and local. | 1755 // and local. |
1749 if (predecessor_ == NULL) { | 1756 if (predecessor_ == NULL) { |
1750 for (int i = 0; i < variable_count; i++) rd_.rd_in()->Add(i); | 1757 for (int i = 0; i < variable_count; i++) rd_.rd_in()->Add(i); |
1751 } | 1758 } |
1752 | 1759 |
1753 for (int i = 0; i < instruction_count; i++) { | 1760 for (int i = 0; i < instruction_count; i++) { |
1754 Expression* expr = instructions_[i]->AsExpression(); | 1761 Expression* expr = instructions_[i]->AsExpression(); |
1755 if (expr == NULL) continue; | 1762 if (expr == NULL) continue; |
1756 Variable* var = expr->AssignedVar(); | 1763 Variable* var = expr->AssignedVariable(); |
1757 if (var == NULL || !var->IsStackAllocated()) continue; | 1764 if (var == NULL || !var->IsStackAllocated()) continue; |
1758 | 1765 |
1759 // All definitions of this variable are killed. | 1766 // All definitions of this variable are killed. |
1760 BitVector* def_set = | 1767 BitVector* def_set = |
1761 variables->at(ReachingDefinitions::IndexFor(var, variable_count)); | 1768 variables->at(ReachingDefinitions::IndexFor(var, variable_count)); |
1762 rd_.kill()->Union(*def_set); | 1769 rd_.kill()->Union(*def_set); |
1763 | 1770 |
1764 // All previously generated definitions are not generated. | 1771 // All previously generated definitions are not generated. |
1765 rd_.gen()->Subtract(*def_set); | 1772 rd_.gen()->Subtract(*def_set); |
1766 | 1773 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1923 variable_count)); | 1930 variable_count)); |
1924 BitVector* reaching_definitions = new BitVector(*definitions); | 1931 BitVector* reaching_definitions = new BitVector(*definitions); |
1925 // Intersected with all definitions (of any variable) reaching this | 1932 // Intersected with all definitions (of any variable) reaching this |
1926 // instruction. | 1933 // instruction. |
1927 reaching_definitions->Intersect(rd); | 1934 reaching_definitions->Intersect(rd); |
1928 proxy->set_reaching_definitions(reaching_definitions); | 1935 proxy->set_reaching_definitions(reaching_definitions); |
1929 } | 1936 } |
1930 | 1937 |
1931 // It may instead (or also) be a definition. If so update the running | 1938 // It may instead (or also) be a definition. If so update the running |
1932 // value of reaching definitions for the block. | 1939 // value of reaching definitions for the block. |
1933 Variable* var = expr->AssignedVar(); | 1940 Variable* var = expr->AssignedVariable(); |
1934 if (var == NULL || !var->IsStackAllocated()) continue; | 1941 if (var == NULL || !var->IsStackAllocated()) continue; |
1935 | 1942 |
1936 // All definitions of this variable are killed. | 1943 // All definitions of this variable are killed. |
1937 BitVector* def_set = | 1944 BitVector* def_set = |
1938 variables->at(ReachingDefinitions::IndexFor(var, variable_count)); | 1945 variables->at(ReachingDefinitions::IndexFor(var, variable_count)); |
1939 rd.Subtract(*def_set); | 1946 rd.Subtract(*def_set); |
1940 // This definition is generated. | 1947 // This definition is generated. |
1941 rd.Add(expr->num()); | 1948 rd.Add(expr->num()); |
1942 } | 1949 } |
1943 } | 1950 } |
(...skipping 10 matching lines...) Expand all Loading... |
1954 List<BitVector*> variables; | 1961 List<BitVector*> variables; |
1955 for (int i = 0; i < variable_count_; i++) { | 1962 for (int i = 0; i < variable_count_; i++) { |
1956 // Add the initial definition for each variable. | 1963 // Add the initial definition for each variable. |
1957 BitVector* initial = new BitVector(definition_count); | 1964 BitVector* initial = new BitVector(definition_count); |
1958 initial->Add(i); | 1965 initial->Add(i); |
1959 variables.Add(initial); | 1966 variables.Add(initial); |
1960 } | 1967 } |
1961 for (int i = 0, len = body_definitions_->length(); i < len; i++) { | 1968 for (int i = 0, len = body_definitions_->length(); i < len; i++) { |
1962 // Account for each definition in the body as a definition of the | 1969 // Account for each definition in the body as a definition of the |
1963 // defined variable. | 1970 // defined variable. |
1964 Variable* var = body_definitions_->at(i)->AssignedVar(); | 1971 Variable* var = body_definitions_->at(i)->AssignedVariable(); |
1965 variables[IndexFor(var, variable_count_)]->Add(i + variable_count_); | 1972 variables[IndexFor(var, variable_count_)]->Add(i + variable_count_); |
1966 } | 1973 } |
1967 | 1974 |
1968 // Step 2: Compute KILL and GEN for each block node, initialize RD_in for | 1975 // Step 2: Compute KILL and GEN for each block node, initialize RD_in for |
1969 // all nodes, and mark and add all nodes to the worklist in reverse | 1976 // all nodes, and mark and add all nodes to the worklist in reverse |
1970 // postorder. All nodes should currently have the same mark. | 1977 // postorder. All nodes should currently have the same mark. |
1971 bool mark = postorder_->at(0)->IsMarkedWith(false); // Negation of current. | 1978 bool mark = postorder_->at(0)->IsMarkedWith(false); // Negation of current. |
1972 WorkList<Node> worklist(node_count); | 1979 WorkList<Node> worklist(node_count); |
1973 for (int i = node_count - 1; i >= 0; i--) { | 1980 for (int i = node_count - 1; i >= 0; i--) { |
1974 postorder_->at(i)->InitializeReachingDefinitions(definition_count, | 1981 postorder_->at(i)->InitializeReachingDefinitions(definition_count, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2039 } | 2046 } |
2040 } | 2047 } |
2041 } | 2048 } |
2042 } | 2049 } |
2043 } | 2050 } |
2044 } | 2051 } |
2045 } while (changed); | 2052 } while (changed); |
2046 } | 2053 } |
2047 | 2054 |
2048 | 2055 |
| 2056 void Node::MarkCriticalInstructions( |
| 2057 List<AstNode*>* stack, |
| 2058 ZoneList<Expression*>* body_definitions, |
| 2059 int variable_count) { |
| 2060 } |
| 2061 |
| 2062 |
| 2063 void BlockNode::MarkCriticalInstructions( |
| 2064 List<AstNode*>* stack, |
| 2065 ZoneList<Expression*>* body_definitions, |
| 2066 int variable_count) { |
| 2067 for (int i = instructions_.length() - 1; i >= 0; i--) { |
| 2068 // Only expressions can appear in the flow graph for now. |
| 2069 Expression* expr = instructions_[i]->AsExpression(); |
| 2070 if (expr != NULL && !expr->is_live() && |
| 2071 (expr->is_loop_condition() || expr->IsCritical())) { |
| 2072 expr->mark_as_live(); |
| 2073 expr->ProcessNonLiveChildren(stack, body_definitions, variable_count); |
| 2074 } |
| 2075 } |
| 2076 } |
| 2077 |
| 2078 |
| 2079 void MarkLiveCode(ZoneList<Node*>* nodes, |
| 2080 ZoneList<Expression*>* body_definitions, |
| 2081 int variable_count) { |
| 2082 List<AstNode*> stack(20); |
| 2083 |
| 2084 // Mark the critical AST nodes as live; mark their dependencies and |
| 2085 // add them to the marking stack. |
| 2086 for (int i = nodes->length() - 1; i >= 0; i--) { |
| 2087 nodes->at(i)->MarkCriticalInstructions(&stack, body_definitions, |
| 2088 variable_count); |
| 2089 } |
| 2090 |
| 2091 // Continue marking dependencies until no more. |
| 2092 while (!stack.is_empty()) { |
| 2093 // Only expressions can appear in the flow graph for now. |
| 2094 Expression* expr = stack.RemoveLast()->AsExpression(); |
| 2095 if (expr != NULL) { |
| 2096 expr->ProcessNonLiveChildren(&stack, body_definitions, variable_count); |
| 2097 } |
| 2098 } |
| 2099 } |
| 2100 |
| 2101 |
2049 } } // namespace v8::internal | 2102 } } // namespace v8::internal |
OLD | NEW |