blob: e7e9f4746adf43ca45b3b1726724abd0138aa675 [file] [log] [blame]
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "nodes.h"
18#include "utils/growable_array.h"
19
20namespace art {
21
22void HGraph::AddBlock(HBasicBlock* block) {
23 block->set_block_id(blocks_.Size());
24 blocks_.Add(block);
25}
26
27void HBasicBlock::AddInstruction(HInstruction* instruction) {
28 if (first_instruction_ == nullptr) {
29 DCHECK(last_instruction_ == nullptr);
30 first_instruction_ = last_instruction_ = instruction;
31 } else {
32 last_instruction_->next_ = instruction;
33 instruction->previous_ = last_instruction_;
34 last_instruction_ = instruction;
35 }
36}
37
38#define DEFINE_ACCEPT(name) \
39void H##name::Accept(HGraphVisitor* visitor) { \
40 visitor->Visit##name(this); \
41}
42
43FOR_EACH_INSTRUCTION(DEFINE_ACCEPT)
44
45#undef DEFINE_ACCEPT
46
47void HGraphVisitor::VisitInsertionOrder() {
48 const GrowableArray<HBasicBlock*>* blocks = graph_->blocks();
49 for (size_t i = 0 ; i < blocks->Size(); i++) {
50 VisitBasicBlock(blocks->Get(i));
51 }
52}
53
54void HGraphVisitor::VisitBasicBlock(HBasicBlock* block) {
55 for (HInstructionIterator it(block); !it.Done(); it.Advance()) {
56 it.Current()->Accept(this);
57 }
58}
59
60} // namespace art