nodes.h revision 633021e6ff6b9a57a374a994e74cfd69275ce100
1/*
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#ifndef ART_COMPILER_OPTIMIZING_NODES_H_
18#define ART_COMPILER_OPTIMIZING_NODES_H_
19
20#include "locations.h"
21#include "offsets.h"
22#include "primitive.h"
23#include "utils/arena_object.h"
24#include "utils/arena_bit_vector.h"
25#include "utils/growable_array.h"
26
27namespace art {
28
29class HBasicBlock;
30class HEnvironment;
31class HInstruction;
32class HIntConstant;
33class HGraphVisitor;
34class HPhi;
35class HSuspendCheck;
36class LiveInterval;
37class LocationSummary;
38
39static const int kDefaultNumberOfBlocks = 8;
40static const int kDefaultNumberOfSuccessors = 2;
41static const int kDefaultNumberOfPredecessors = 2;
42static const int kDefaultNumberOfDominatedBlocks = 1;
43static const int kDefaultNumberOfBackEdges = 1;
44
45enum IfCondition {
46  kCondEQ,
47  kCondNE,
48  kCondLT,
49  kCondLE,
50  kCondGT,
51  kCondGE,
52};
53
54class HInstructionList {
55 public:
56  HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {}
57
58  void AddInstruction(HInstruction* instruction);
59  void RemoveInstruction(HInstruction* instruction);
60
61  // Return true if this list contains `instruction`.
62  bool Contains(HInstruction* instruction) const;
63
64  // Return true if `instruction1` is found before `instruction2` in
65  // this instruction list and false otherwise.  Abort if none
66  // of these instructions is found.
67  bool FoundBefore(const HInstruction* instruction1,
68                   const HInstruction* instruction2) const;
69
70 private:
71  HInstruction* first_instruction_;
72  HInstruction* last_instruction_;
73
74  friend class HBasicBlock;
75  friend class HInstructionIterator;
76  friend class HBackwardInstructionIterator;
77
78  DISALLOW_COPY_AND_ASSIGN(HInstructionList);
79};
80
81// Control-flow graph of a method. Contains a list of basic blocks.
82class HGraph : public ArenaObject {
83 public:
84  explicit HGraph(ArenaAllocator* arena)
85      : arena_(arena),
86        blocks_(arena, kDefaultNumberOfBlocks),
87        reverse_post_order_(arena, kDefaultNumberOfBlocks),
88        maximum_number_of_out_vregs_(0),
89        number_of_vregs_(0),
90        number_of_in_vregs_(0),
91        number_of_temporaries_(0),
92        current_instruction_id_(0) {}
93
94  ArenaAllocator* GetArena() const { return arena_; }
95  const GrowableArray<HBasicBlock*>& GetBlocks() const { return blocks_; }
96  HBasicBlock* GetBlock(size_t id) const { return blocks_.Get(id); }
97
98  HBasicBlock* GetEntryBlock() const { return entry_block_; }
99  HBasicBlock* GetExitBlock() const { return exit_block_; }
100
101  void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; }
102  void SetExitBlock(HBasicBlock* block) { exit_block_ = block; }
103
104  void AddBlock(HBasicBlock* block);
105
106  void BuildDominatorTree();
107  void TransformToSSA();
108  void SimplifyCFG();
109
110  // Find all natural loops in this graph. Aborts computation and returns false
111  // if one loop is not natural, that is the header does not dominate the back
112  // edge.
113  bool FindNaturalLoops() const;
114
115  void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor);
116  void SimplifyLoop(HBasicBlock* header);
117
118  int GetNextInstructionId() {
119    return current_instruction_id_++;
120  }
121
122  uint16_t GetMaximumNumberOfOutVRegs() const {
123    return maximum_number_of_out_vregs_;
124  }
125
126  void UpdateMaximumNumberOfOutVRegs(uint16_t new_value) {
127    maximum_number_of_out_vregs_ = std::max(new_value, maximum_number_of_out_vregs_);
128  }
129
130  void UpdateNumberOfTemporaries(size_t count) {
131    number_of_temporaries_ = std::max(count, number_of_temporaries_);
132  }
133
134  size_t GetNumberOfTemporaries() const {
135    return number_of_temporaries_;
136  }
137
138  void SetNumberOfVRegs(uint16_t number_of_vregs) {
139    number_of_vregs_ = number_of_vregs;
140  }
141
142  uint16_t GetNumberOfVRegs() const {
143    return number_of_vregs_;
144  }
145
146  void SetNumberOfInVRegs(uint16_t value) {
147    number_of_in_vregs_ = value;
148  }
149
150  uint16_t GetNumberOfInVRegs() const {
151    return number_of_in_vregs_;
152  }
153
154  uint16_t GetNumberOfLocalVRegs() const {
155    return number_of_vregs_ - number_of_in_vregs_;
156  }
157
158  const GrowableArray<HBasicBlock*>& GetReversePostOrder() const {
159    return reverse_post_order_;
160  }
161
162 private:
163  HBasicBlock* FindCommonDominator(HBasicBlock* first, HBasicBlock* second) const;
164  void VisitBlockForDominatorTree(HBasicBlock* block,
165                                  HBasicBlock* predecessor,
166                                  GrowableArray<size_t>* visits);
167  void FindBackEdges(ArenaBitVector* visited);
168  void VisitBlockForBackEdges(HBasicBlock* block,
169                              ArenaBitVector* visited,
170                              ArenaBitVector* visiting);
171  void RemoveDeadBlocks(const ArenaBitVector& visited) const;
172
173  ArenaAllocator* const arena_;
174
175  // List of blocks in insertion order.
176  GrowableArray<HBasicBlock*> blocks_;
177
178  // List of blocks to perform a reverse post order tree traversal.
179  GrowableArray<HBasicBlock*> reverse_post_order_;
180
181  HBasicBlock* entry_block_;
182  HBasicBlock* exit_block_;
183
184  // The maximum number of virtual registers arguments passed to a HInvoke in this graph.
185  uint16_t maximum_number_of_out_vregs_;
186
187  // The number of virtual registers in this method. Contains the parameters.
188  uint16_t number_of_vregs_;
189
190  // The number of virtual registers used by parameters of this method.
191  uint16_t number_of_in_vregs_;
192
193  // The number of temporaries that will be needed for the baseline compiler.
194  size_t number_of_temporaries_;
195
196  // The current id to assign to a newly added instruction. See HInstruction.id_.
197  int current_instruction_id_;
198
199  DISALLOW_COPY_AND_ASSIGN(HGraph);
200};
201
202class HLoopInformation : public ArenaObject {
203 public:
204  HLoopInformation(HBasicBlock* header, HGraph* graph)
205      : header_(header),
206        suspend_check_(nullptr),
207        back_edges_(graph->GetArena(), kDefaultNumberOfBackEdges),
208        // Make bit vector growable, as the number of blocks may change.
209        blocks_(graph->GetArena(), graph->GetBlocks().Size(), true) {}
210
211  HBasicBlock* GetHeader() const {
212    return header_;
213  }
214
215  HSuspendCheck* GetSuspendCheck() const { return suspend_check_; }
216  void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; }
217  bool HasSuspendCheck() const { return suspend_check_ != nullptr; }
218
219  void AddBackEdge(HBasicBlock* back_edge) {
220    back_edges_.Add(back_edge);
221  }
222
223  void RemoveBackEdge(HBasicBlock* back_edge) {
224    back_edges_.Delete(back_edge);
225  }
226
227  bool IsBackEdge(HBasicBlock* block) {
228    for (size_t i = 0, e = back_edges_.Size(); i < e; ++i) {
229      if (back_edges_.Get(i) == block) return true;
230    }
231    return false;
232  }
233
234  int NumberOfBackEdges() const {
235    return back_edges_.Size();
236  }
237
238  HBasicBlock* GetPreHeader() const;
239
240  const GrowableArray<HBasicBlock*>& GetBackEdges() const {
241    return back_edges_;
242  }
243
244  void ClearBackEdges() {
245    back_edges_.Reset();
246  }
247
248  // Find blocks that are part of this loop. Returns whether the loop is a natural loop,
249  // that is the header dominates the back edge.
250  bool Populate();
251
252  // Returns whether this loop information contains `block`.
253  // Note that this loop information *must* be populated before entering this function.
254  bool Contains(const HBasicBlock& block) const;
255
256  // Returns whether this loop information is an inner loop of `other`.
257  // Note that `other` *must* be populated before entering this function.
258  bool IsIn(const HLoopInformation& other) const;
259
260  const ArenaBitVector& GetBlocks() const { return blocks_; }
261
262 private:
263  // Internal recursive implementation of `Populate`.
264  void PopulateRecursive(HBasicBlock* block);
265
266  HBasicBlock* header_;
267  HSuspendCheck* suspend_check_;
268  GrowableArray<HBasicBlock*> back_edges_;
269  ArenaBitVector blocks_;
270
271  DISALLOW_COPY_AND_ASSIGN(HLoopInformation);
272};
273
274static constexpr size_t kNoLifetime = -1;
275static constexpr uint32_t kNoDexPc = -1;
276
277// A block in a method. Contains the list of instructions represented
278// as a double linked list. Each block knows its predecessors and
279// successors.
280
281class HBasicBlock : public ArenaObject {
282 public:
283  explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc)
284      : graph_(graph),
285        predecessors_(graph->GetArena(), kDefaultNumberOfPredecessors),
286        successors_(graph->GetArena(), kDefaultNumberOfSuccessors),
287        loop_information_(nullptr),
288        dominator_(nullptr),
289        dominated_blocks_(graph->GetArena(), kDefaultNumberOfDominatedBlocks),
290        block_id_(-1),
291        dex_pc_(dex_pc),
292        lifetime_start_(kNoLifetime),
293        lifetime_end_(kNoLifetime) {}
294
295  const GrowableArray<HBasicBlock*>& GetPredecessors() const {
296    return predecessors_;
297  }
298
299  const GrowableArray<HBasicBlock*>& GetSuccessors() const {
300    return successors_;
301  }
302
303  const GrowableArray<HBasicBlock*>& GetDominatedBlocks() const {
304    return dominated_blocks_;
305  }
306
307  bool IsEntryBlock() const {
308    return graph_->GetEntryBlock() == this;
309  }
310
311  bool IsExitBlock() const {
312    return graph_->GetExitBlock() == this;
313  }
314
315  void AddBackEdge(HBasicBlock* back_edge) {
316    if (loop_information_ == nullptr) {
317      loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_);
318    }
319    DCHECK_EQ(loop_information_->GetHeader(), this);
320    loop_information_->AddBackEdge(back_edge);
321  }
322
323  HGraph* GetGraph() const { return graph_; }
324
325  int GetBlockId() const { return block_id_; }
326  void SetBlockId(int id) { block_id_ = id; }
327
328  HBasicBlock* GetDominator() const { return dominator_; }
329  void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; }
330  void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.Add(block); }
331
332  int NumberOfBackEdges() const {
333    return loop_information_ == nullptr
334        ? 0
335        : loop_information_->NumberOfBackEdges();
336  }
337
338  HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; }
339  HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; }
340  const HInstructionList& GetInstructions() const { return instructions_; }
341  const HInstructionList& GetPhis() const { return phis_; }
342  HInstruction* GetFirstPhi() const { return phis_.first_instruction_; }
343
344  void AddSuccessor(HBasicBlock* block) {
345    successors_.Add(block);
346    block->predecessors_.Add(this);
347  }
348
349  void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) {
350    size_t successor_index = GetSuccessorIndexOf(existing);
351    DCHECK_NE(successor_index, static_cast<size_t>(-1));
352    existing->RemovePredecessor(this);
353    new_block->predecessors_.Add(this);
354    successors_.Put(successor_index, new_block);
355  }
356
357  void RemovePredecessor(HBasicBlock* block) {
358    predecessors_.Delete(block);
359  }
360
361  void ClearAllPredecessors() {
362    predecessors_.Reset();
363  }
364
365  void AddPredecessor(HBasicBlock* block) {
366    predecessors_.Add(block);
367    block->successors_.Add(this);
368  }
369
370  void SwapPredecessors() {
371    DCHECK_EQ(predecessors_.Size(), 2u);
372    HBasicBlock* temp = predecessors_.Get(0);
373    predecessors_.Put(0, predecessors_.Get(1));
374    predecessors_.Put(1, temp);
375  }
376
377  size_t GetPredecessorIndexOf(HBasicBlock* predecessor) {
378    for (size_t i = 0, e = predecessors_.Size(); i < e; ++i) {
379      if (predecessors_.Get(i) == predecessor) {
380        return i;
381      }
382    }
383    return -1;
384  }
385
386  size_t GetSuccessorIndexOf(HBasicBlock* successor) {
387    for (size_t i = 0, e = successors_.Size(); i < e; ++i) {
388      if (successors_.Get(i) == successor) {
389        return i;
390      }
391    }
392    return -1;
393  }
394
395  void AddInstruction(HInstruction* instruction);
396  void RemoveInstruction(HInstruction* instruction);
397  void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor);
398  // Replace instruction `initial` with `replacement` within this block.
399  void ReplaceAndRemoveInstructionWith(HInstruction* initial,
400                                       HInstruction* replacement);
401  void AddPhi(HPhi* phi);
402  void RemovePhi(HPhi* phi);
403
404  bool IsLoopHeader() const {
405    return (loop_information_ != nullptr) && (loop_information_->GetHeader() == this);
406  }
407
408  bool IsLoopPreHeaderFirstPredecessor() const {
409    DCHECK(IsLoopHeader());
410    DCHECK(!GetPredecessors().IsEmpty());
411    return GetPredecessors().Get(0) == GetLoopInformation()->GetPreHeader();
412  }
413
414  HLoopInformation* GetLoopInformation() const {
415    return loop_information_;
416  }
417
418  // Set the loop_information_ on this block. This method overrides the current
419  // loop_information if it is an outer loop of the passed loop information.
420  void SetInLoop(HLoopInformation* info) {
421    if (IsLoopHeader()) {
422      // Nothing to do. This just means `info` is an outer loop.
423    } else if (loop_information_ == nullptr) {
424      loop_information_ = info;
425    } else if (loop_information_->Contains(*info->GetHeader())) {
426      // Block is currently part of an outer loop. Make it part of this inner loop.
427      // Note that a non loop header having a loop information means this loop information
428      // has already been populated
429      loop_information_ = info;
430    } else {
431      // Block is part of an inner loop. Do not update the loop information.
432      // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()`
433      // at this point, because this method is being called while populating `info`.
434    }
435  }
436
437  bool IsInLoop() const { return loop_information_ != nullptr; }
438
439  // Returns wheter this block dominates the blocked passed as parameter.
440  bool Dominates(HBasicBlock* block) const;
441
442  size_t GetLifetimeStart() const { return lifetime_start_; }
443  size_t GetLifetimeEnd() const { return lifetime_end_; }
444
445  void SetLifetimeStart(size_t start) { lifetime_start_ = start; }
446  void SetLifetimeEnd(size_t end) { lifetime_end_ = end; }
447
448  uint32_t GetDexPc() const { return dex_pc_; }
449
450 private:
451  HGraph* const graph_;
452  GrowableArray<HBasicBlock*> predecessors_;
453  GrowableArray<HBasicBlock*> successors_;
454  HInstructionList instructions_;
455  HInstructionList phis_;
456  HLoopInformation* loop_information_;
457  HBasicBlock* dominator_;
458  GrowableArray<HBasicBlock*> dominated_blocks_;
459  int block_id_;
460  // The dex program counter of the first instruction of this block.
461  const uint32_t dex_pc_;
462  size_t lifetime_start_;
463  size_t lifetime_end_;
464
465  DISALLOW_COPY_AND_ASSIGN(HBasicBlock);
466};
467
468#define FOR_EACH_CONCRETE_INSTRUCTION(M)                                \
469  M(Add, BinaryOperation)                                               \
470  M(Condition, BinaryOperation)                                         \
471  M(Equal, Condition)                                                   \
472  M(NotEqual, Condition)                                                \
473  M(LessThan, Condition)                                                \
474  M(LessThanOrEqual, Condition)                                         \
475  M(GreaterThan, Condition)                                             \
476  M(GreaterThanOrEqual, Condition)                                      \
477  M(Exit, Instruction)                                                  \
478  M(Goto, Instruction)                                                  \
479  M(If, Instruction)                                                    \
480  M(IntConstant, Constant)                                              \
481  M(InvokeStatic, Invoke)                                               \
482  M(InvokeVirtual, Invoke)                                              \
483  M(LoadLocal, Instruction)                                             \
484  M(Local, Instruction)                                                 \
485  M(LongConstant, Constant)                                             \
486  M(NewInstance, Instruction)                                           \
487  M(Not, Instruction)                                                   \
488  M(ParameterValue, Instruction)                                        \
489  M(ParallelMove, Instruction)                                          \
490  M(Phi, Instruction)                                                   \
491  M(Return, Instruction)                                                \
492  M(ReturnVoid, Instruction)                                            \
493  M(StoreLocal, Instruction)                                            \
494  M(Sub, BinaryOperation)                                               \
495  M(Compare, BinaryOperation)                                           \
496  M(InstanceFieldGet, Instruction)                                      \
497  M(InstanceFieldSet, Instruction)                                      \
498  M(ArrayGet, Instruction)                                              \
499  M(ArraySet, Instruction)                                              \
500  M(ArrayLength, Instruction)                                           \
501  M(BoundsCheck, Instruction)                                           \
502  M(NullCheck, Instruction)                                             \
503  M(Temporary, Instruction)                                             \
504  M(SuspendCheck, Instruction)                                          \
505
506#define FOR_EACH_INSTRUCTION(M)                                         \
507  FOR_EACH_CONCRETE_INSTRUCTION(M)                                      \
508  M(Constant, Instruction)                                              \
509  M(BinaryOperation, Instruction) \
510  M(Invoke, Instruction)
511
512#define FORWARD_DECLARATION(type, super) class H##type;
513FOR_EACH_INSTRUCTION(FORWARD_DECLARATION)
514#undef FORWARD_DECLARATION
515
516#define DECLARE_INSTRUCTION(type)                                       \
517  virtual InstructionKind GetKind() const { return k##type; }           \
518  virtual const char* DebugName() const { return #type; }               \
519  virtual const H##type* As##type() const OVERRIDE { return this; }     \
520  virtual H##type* As##type() OVERRIDE { return this; }                 \
521  virtual bool InstructionTypeEquals(HInstruction* other) const {       \
522    return other->Is##type();                                           \
523  }                                                                     \
524  virtual void Accept(HGraphVisitor* visitor)
525
526template <typename T>
527class HUseListNode : public ArenaObject {
528 public:
529  HUseListNode(T* user, size_t index, HUseListNode* tail)
530      : user_(user), index_(index), tail_(tail) {}
531
532  HUseListNode* GetTail() const { return tail_; }
533  T* GetUser() const { return user_; }
534  size_t GetIndex() const { return index_; }
535
536  void SetTail(HUseListNode<T>* node) { tail_ = node; }
537
538 private:
539  T* const user_;
540  const size_t index_;
541  HUseListNode<T>* tail_;
542
543  DISALLOW_COPY_AND_ASSIGN(HUseListNode);
544};
545
546// Represents the side effects an instruction may have.
547class SideEffects : public ValueObject {
548 public:
549  SideEffects() : flags_(0) {}
550
551  static SideEffects None() {
552    return SideEffects(0);
553  }
554
555  static SideEffects All() {
556    return SideEffects(ChangesSomething().flags_ | DependsOnSomething().flags_);
557  }
558
559  static SideEffects ChangesSomething() {
560    return SideEffects((1 << kFlagChangesCount) - 1);
561  }
562
563  static SideEffects DependsOnSomething() {
564    int count = kFlagDependsOnCount - kFlagChangesCount;
565    return SideEffects(((1 << count) - 1) << kFlagChangesCount);
566  }
567
568  SideEffects Union(SideEffects other) const {
569    return SideEffects(flags_ | other.flags_);
570  }
571
572  bool HasSideEffects() const {
573    size_t all_bits_set = (1 << kFlagChangesCount) - 1;
574    return (flags_ & all_bits_set) != 0;
575  }
576
577  bool HasAllSideEffects() const {
578    size_t all_bits_set = (1 << kFlagChangesCount) - 1;
579    return all_bits_set == (flags_ & all_bits_set);
580  }
581
582  bool DependsOn(SideEffects other) const {
583    size_t depends_flags = other.ComputeDependsFlags();
584    return (flags_ & depends_flags) != 0;
585  }
586
587  bool HasDependencies() const {
588    int count = kFlagDependsOnCount - kFlagChangesCount;
589    size_t all_bits_set = (1 << count) - 1;
590    return ((flags_ >> kFlagChangesCount) & all_bits_set) != 0;
591  }
592
593 private:
594  static constexpr int kFlagChangesSomething = 0;
595  static constexpr int kFlagChangesCount = kFlagChangesSomething + 1;
596
597  static constexpr int kFlagDependsOnSomething = kFlagChangesCount;
598  static constexpr int kFlagDependsOnCount = kFlagDependsOnSomething + 1;
599
600  explicit SideEffects(size_t flags) : flags_(flags) {}
601
602  size_t ComputeDependsFlags() const {
603    return flags_ << kFlagChangesCount;
604  }
605
606  size_t flags_;
607};
608
609class HInstruction : public ArenaObject {
610 public:
611  explicit HInstruction(SideEffects side_effects)
612      : previous_(nullptr),
613        next_(nullptr),
614        block_(nullptr),
615        id_(-1),
616        ssa_index_(-1),
617        uses_(nullptr),
618        env_uses_(nullptr),
619        environment_(nullptr),
620        locations_(nullptr),
621        live_interval_(nullptr),
622        lifetime_position_(kNoLifetime),
623        side_effects_(side_effects) {}
624
625  virtual ~HInstruction() {}
626
627#define DECLARE_KIND(type, super) k##type,
628  enum InstructionKind {
629    FOR_EACH_INSTRUCTION(DECLARE_KIND)
630  };
631#undef DECLARE_KIND
632
633  HInstruction* GetNext() const { return next_; }
634  HInstruction* GetPrevious() const { return previous_; }
635
636  HBasicBlock* GetBlock() const { return block_; }
637  void SetBlock(HBasicBlock* block) { block_ = block; }
638  bool IsInBlock() const { return block_ != nullptr; }
639  bool IsInLoop() const { return block_->IsInLoop(); }
640  bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); }
641
642  virtual size_t InputCount() const = 0;
643  virtual HInstruction* InputAt(size_t i) const = 0;
644
645  virtual void Accept(HGraphVisitor* visitor) = 0;
646  virtual const char* DebugName() const = 0;
647
648  virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; }
649  virtual void SetRawInputAt(size_t index, HInstruction* input) = 0;
650
651  virtual bool NeedsEnvironment() const { return false; }
652  virtual bool IsControlFlow() const { return false; }
653  virtual bool CanThrow() const { return false; }
654  bool HasSideEffects() const { return side_effects_.HasSideEffects(); }
655
656  void AddUseAt(HInstruction* user, size_t index) {
657    uses_ = new (block_->GetGraph()->GetArena()) HUseListNode<HInstruction>(user, index, uses_);
658  }
659
660  void AddEnvUseAt(HEnvironment* user, size_t index) {
661    DCHECK(user != nullptr);
662    env_uses_ = new (block_->GetGraph()->GetArena()) HUseListNode<HEnvironment>(
663        user, index, env_uses_);
664  }
665
666  void RemoveUser(HInstruction* user, size_t index);
667  void RemoveEnvironmentUser(HEnvironment* user, size_t index);
668
669  HUseListNode<HInstruction>* GetUses() const { return uses_; }
670  HUseListNode<HEnvironment>* GetEnvUses() const { return env_uses_; }
671
672  bool HasUses() const { return uses_ != nullptr || env_uses_ != nullptr; }
673  bool HasEnvironmentUses() const { return env_uses_ != nullptr; }
674
675  size_t NumberOfUses() const {
676    // TODO: Optimize this method if it is used outside of the HGraphVisualizer.
677    size_t result = 0;
678    HUseListNode<HInstruction>* current = uses_;
679    while (current != nullptr) {
680      current = current->GetTail();
681      ++result;
682    }
683    return result;
684  }
685
686  // Does this instruction dominate `other_instruction`?  Aborts if
687  // this instruction and `other_instruction` are both phis.
688  bool Dominates(HInstruction* other_instruction) const;
689
690  int GetId() const { return id_; }
691  void SetId(int id) { id_ = id; }
692
693  int GetSsaIndex() const { return ssa_index_; }
694  void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; }
695  bool HasSsaIndex() const { return ssa_index_ != -1; }
696
697  bool HasEnvironment() const { return environment_ != nullptr; }
698  HEnvironment* GetEnvironment() const { return environment_; }
699  void SetEnvironment(HEnvironment* environment) { environment_ = environment; }
700
701  // Returns the number of entries in the environment. Typically, that is the
702  // number of dex registers in a method. It could be more in case of inlining.
703  size_t EnvironmentSize() const;
704
705  LocationSummary* GetLocations() const { return locations_; }
706  void SetLocations(LocationSummary* locations) { locations_ = locations; }
707
708  void ReplaceWith(HInstruction* instruction);
709
710  bool HasOnlyOneUse() const {
711    return uses_ != nullptr && uses_->GetTail() == nullptr;
712  }
713
714#define INSTRUCTION_TYPE_CHECK(type, super)                                    \
715  bool Is##type() const { return (As##type() != nullptr); }                    \
716  virtual const H##type* As##type() const { return nullptr; }                  \
717  virtual H##type* As##type() { return nullptr; }
718
719  FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK)
720#undef INSTRUCTION_TYPE_CHECK
721
722  // Returns whether the instruction can be moved within the graph.
723  virtual bool CanBeMoved() const { return false; }
724
725  // Returns whether the two instructions are of the same kind.
726  virtual bool InstructionTypeEquals(HInstruction* other) const { return false; }
727
728  // Returns whether any data encoded in the two instructions is equal.
729  // This method does not look at the inputs. Both instructions must be
730  // of the same type, otherwise the method has undefined behavior.
731  virtual bool InstructionDataEquals(HInstruction* other) const { return false; }
732
733  // Returns whether two instructions are equal, that is:
734  // 1) They have the same type and contain the same data,
735  // 2) Their inputs are identical.
736  bool Equals(HInstruction* other) const;
737
738  virtual InstructionKind GetKind() const = 0;
739
740  virtual size_t ComputeHashCode() const {
741    size_t result = GetKind();
742    for (size_t i = 0, e = InputCount(); i < e; ++i) {
743      result = (result * 31) + InputAt(i)->GetId();
744    }
745    return result;
746  }
747
748  SideEffects GetSideEffects() const { return side_effects_; }
749
750  size_t GetLifetimePosition() const { return lifetime_position_; }
751  void SetLifetimePosition(size_t position) { lifetime_position_ = position; }
752  LiveInterval* GetLiveInterval() const { return live_interval_; }
753  void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; }
754  bool HasLiveInterval() const { return live_interval_ != nullptr; }
755
756 private:
757  HInstruction* previous_;
758  HInstruction* next_;
759  HBasicBlock* block_;
760
761  // An instruction gets an id when it is added to the graph.
762  // It reflects creation order. A negative id means the instruction
763  // has not been added to the graph.
764  int id_;
765
766  // When doing liveness analysis, instructions that have uses get an SSA index.
767  int ssa_index_;
768
769  // List of instructions that have this instruction as input.
770  HUseListNode<HInstruction>* uses_;
771
772  // List of environments that contain this instruction.
773  HUseListNode<HEnvironment>* env_uses_;
774
775  // The environment associated with this instruction. Not null if the instruction
776  // might jump out of the method.
777  HEnvironment* environment_;
778
779  // Set by the code generator.
780  LocationSummary* locations_;
781
782  // Set by the liveness analysis.
783  LiveInterval* live_interval_;
784
785  // Set by the liveness analysis, this is the position in a linear
786  // order of blocks where this instruction's live interval start.
787  size_t lifetime_position_;
788
789  const SideEffects side_effects_;
790
791  friend class HBasicBlock;
792  friend class HInstructionList;
793
794  DISALLOW_COPY_AND_ASSIGN(HInstruction);
795};
796
797template<typename T>
798class HUseIterator : public ValueObject {
799 public:
800  explicit HUseIterator(HUseListNode<T>* uses) : current_(uses) {}
801
802  bool Done() const { return current_ == nullptr; }
803
804  void Advance() {
805    DCHECK(!Done());
806    current_ = current_->GetTail();
807  }
808
809  HUseListNode<T>* Current() const {
810    DCHECK(!Done());
811    return current_;
812  }
813
814 private:
815  HUseListNode<T>* current_;
816
817  friend class HValue;
818};
819
820// A HEnvironment object contains the values of virtual registers at a given location.
821class HEnvironment : public ArenaObject {
822 public:
823  HEnvironment(ArenaAllocator* arena, size_t number_of_vregs) : vregs_(arena, number_of_vregs) {
824    vregs_.SetSize(number_of_vregs);
825    for (size_t i = 0; i < number_of_vregs; i++) {
826      vregs_.Put(i, nullptr);
827    }
828  }
829
830  void Populate(const GrowableArray<HInstruction*>& env) {
831    for (size_t i = 0; i < env.Size(); i++) {
832      HInstruction* instruction = env.Get(i);
833      vregs_.Put(i, instruction);
834      if (instruction != nullptr) {
835        instruction->AddEnvUseAt(this, i);
836      }
837    }
838  }
839
840  void SetRawEnvAt(size_t index, HInstruction* instruction) {
841    vregs_.Put(index, instruction);
842  }
843
844  HInstruction* GetInstructionAt(size_t index) const {
845    return vregs_.Get(index);
846  }
847
848  GrowableArray<HInstruction*>* GetVRegs() {
849    return &vregs_;
850  }
851
852  size_t Size() const { return vregs_.Size(); }
853
854 private:
855  GrowableArray<HInstruction*> vregs_;
856
857  DISALLOW_COPY_AND_ASSIGN(HEnvironment);
858};
859
860class HInputIterator : public ValueObject {
861 public:
862  explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {}
863
864  bool Done() const { return index_ == instruction_->InputCount(); }
865  HInstruction* Current() const { return instruction_->InputAt(index_); }
866  void Advance() { index_++; }
867
868 private:
869  HInstruction* instruction_;
870  size_t index_;
871
872  DISALLOW_COPY_AND_ASSIGN(HInputIterator);
873};
874
875class HInstructionIterator : public ValueObject {
876 public:
877  explicit HInstructionIterator(const HInstructionList& instructions)
878      : instruction_(instructions.first_instruction_) {
879    next_ = Done() ? nullptr : instruction_->GetNext();
880  }
881
882  bool Done() const { return instruction_ == nullptr; }
883  HInstruction* Current() const { return instruction_; }
884  void Advance() {
885    instruction_ = next_;
886    next_ = Done() ? nullptr : instruction_->GetNext();
887  }
888
889 private:
890  HInstruction* instruction_;
891  HInstruction* next_;
892
893  DISALLOW_COPY_AND_ASSIGN(HInstructionIterator);
894};
895
896class HBackwardInstructionIterator : public ValueObject {
897 public:
898  explicit HBackwardInstructionIterator(const HInstructionList& instructions)
899      : instruction_(instructions.last_instruction_) {
900    next_ = Done() ? nullptr : instruction_->GetPrevious();
901  }
902
903  bool Done() const { return instruction_ == nullptr; }
904  HInstruction* Current() const { return instruction_; }
905  void Advance() {
906    instruction_ = next_;
907    next_ = Done() ? nullptr : instruction_->GetPrevious();
908  }
909
910 private:
911  HInstruction* instruction_;
912  HInstruction* next_;
913
914  DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator);
915};
916
917// An embedded container with N elements of type T.  Used (with partial
918// specialization for N=0) because embedded arrays cannot have size 0.
919template<typename T, intptr_t N>
920class EmbeddedArray {
921 public:
922  EmbeddedArray() : elements_() {}
923
924  intptr_t GetLength() const { return N; }
925
926  const T& operator[](intptr_t i) const {
927    DCHECK_LT(i, GetLength());
928    return elements_[i];
929  }
930
931  T& operator[](intptr_t i) {
932    DCHECK_LT(i, GetLength());
933    return elements_[i];
934  }
935
936  const T& At(intptr_t i) const {
937    return (*this)[i];
938  }
939
940  void SetAt(intptr_t i, const T& val) {
941    (*this)[i] = val;
942  }
943
944 private:
945  T elements_[N];
946};
947
948template<typename T>
949class EmbeddedArray<T, 0> {
950 public:
951  intptr_t length() const { return 0; }
952  const T& operator[](intptr_t i) const {
953    LOG(FATAL) << "Unreachable";
954    static T sentinel = 0;
955    return sentinel;
956  }
957  T& operator[](intptr_t i) {
958    LOG(FATAL) << "Unreachable";
959    static T sentinel = 0;
960    return sentinel;
961  }
962};
963
964template<intptr_t N>
965class HTemplateInstruction: public HInstruction {
966 public:
967  HTemplateInstruction<N>(SideEffects side_effects)
968      : HInstruction(side_effects), inputs_() {}
969  virtual ~HTemplateInstruction() {}
970
971  virtual size_t InputCount() const { return N; }
972  virtual HInstruction* InputAt(size_t i) const { return inputs_[i]; }
973
974 protected:
975  virtual void SetRawInputAt(size_t i, HInstruction* instruction) {
976    inputs_[i] = instruction;
977  }
978
979 private:
980  EmbeddedArray<HInstruction*, N> inputs_;
981
982  friend class SsaBuilder;
983};
984
985template<intptr_t N>
986class HExpression : public HTemplateInstruction<N> {
987 public:
988  HExpression<N>(Primitive::Type type, SideEffects side_effects)
989      : HTemplateInstruction<N>(side_effects), type_(type) {}
990  virtual ~HExpression() {}
991
992  virtual Primitive::Type GetType() const { return type_; }
993
994 private:
995  const Primitive::Type type_;
996};
997
998// Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow
999// instruction that branches to the exit block.
1000class HReturnVoid : public HTemplateInstruction<0> {
1001 public:
1002  HReturnVoid() : HTemplateInstruction(SideEffects::None()) {}
1003
1004  virtual bool IsControlFlow() const { return true; }
1005
1006  DECLARE_INSTRUCTION(ReturnVoid);
1007
1008 private:
1009  DISALLOW_COPY_AND_ASSIGN(HReturnVoid);
1010};
1011
1012// Represents dex's RETURN opcodes. A HReturn is a control flow
1013// instruction that branches to the exit block.
1014class HReturn : public HTemplateInstruction<1> {
1015 public:
1016  explicit HReturn(HInstruction* value) : HTemplateInstruction(SideEffects::None()) {
1017    SetRawInputAt(0, value);
1018  }
1019
1020  virtual bool IsControlFlow() const { return true; }
1021
1022  DECLARE_INSTRUCTION(Return);
1023
1024 private:
1025  DISALLOW_COPY_AND_ASSIGN(HReturn);
1026};
1027
1028// The exit instruction is the only instruction of the exit block.
1029// Instructions aborting the method (HTrow and HReturn) must branch to the
1030// exit block.
1031class HExit : public HTemplateInstruction<0> {
1032 public:
1033  HExit() : HTemplateInstruction(SideEffects::None()) {}
1034
1035  virtual bool IsControlFlow() const { return true; }
1036
1037  DECLARE_INSTRUCTION(Exit);
1038
1039 private:
1040  DISALLOW_COPY_AND_ASSIGN(HExit);
1041};
1042
1043// Jumps from one block to another.
1044class HGoto : public HTemplateInstruction<0> {
1045 public:
1046  HGoto() : HTemplateInstruction(SideEffects::None()) {}
1047
1048  virtual bool IsControlFlow() const { return true; }
1049
1050  HBasicBlock* GetSuccessor() const {
1051    return GetBlock()->GetSuccessors().Get(0);
1052  }
1053
1054  DECLARE_INSTRUCTION(Goto);
1055
1056 private:
1057  DISALLOW_COPY_AND_ASSIGN(HGoto);
1058};
1059
1060
1061// Conditional branch. A block ending with an HIf instruction must have
1062// two successors.
1063class HIf : public HTemplateInstruction<1> {
1064 public:
1065  explicit HIf(HInstruction* input) : HTemplateInstruction(SideEffects::None()) {
1066    SetRawInputAt(0, input);
1067  }
1068
1069  virtual bool IsControlFlow() const { return true; }
1070
1071  HBasicBlock* IfTrueSuccessor() const {
1072    return GetBlock()->GetSuccessors().Get(0);
1073  }
1074
1075  HBasicBlock* IfFalseSuccessor() const {
1076    return GetBlock()->GetSuccessors().Get(1);
1077  }
1078
1079  DECLARE_INSTRUCTION(If);
1080
1081  virtual bool IsIfInstruction() const { return true; }
1082
1083 private:
1084  DISALLOW_COPY_AND_ASSIGN(HIf);
1085};
1086
1087class HBinaryOperation : public HExpression<2> {
1088 public:
1089  HBinaryOperation(Primitive::Type result_type,
1090                   HInstruction* left,
1091                   HInstruction* right) : HExpression(result_type, SideEffects::None()) {
1092    SetRawInputAt(0, left);
1093    SetRawInputAt(1, right);
1094  }
1095
1096  HInstruction* GetLeft() const { return InputAt(0); }
1097  HInstruction* GetRight() const { return InputAt(1); }
1098  Primitive::Type GetResultType() const { return GetType(); }
1099
1100  virtual bool IsCommutative() { return false; }
1101
1102  virtual bool CanBeMoved() const { return true; }
1103  virtual bool InstructionDataEquals(HInstruction* other) const { return true; }
1104
1105  // Try to statically evaluate `operation` and return an HConstant
1106  // containing the result of this evaluation.  If `operation` cannot
1107  // be evaluated as a constant, return nullptr.
1108  HConstant* TryStaticEvaluation(ArenaAllocator* allocator) const;
1109
1110  // Apply this operation to `x` and `y`.
1111  virtual int32_t Evaluate(int32_t x, int32_t y) const = 0;
1112  virtual int64_t Evaluate(int64_t x, int64_t y) const = 0;
1113
1114  DECLARE_INSTRUCTION(BinaryOperation);
1115
1116 private:
1117  DISALLOW_COPY_AND_ASSIGN(HBinaryOperation);
1118};
1119
1120class HCondition : public HBinaryOperation {
1121 public:
1122  HCondition(HInstruction* first, HInstruction* second)
1123      : HBinaryOperation(Primitive::kPrimBoolean, first, second),
1124        needs_materialization_(true) {}
1125
1126  virtual bool IsCommutative() { return true; }
1127
1128  bool NeedsMaterialization() const { return needs_materialization_; }
1129  void ClearNeedsMaterialization() { needs_materialization_ = false; }
1130
1131  // For code generation purposes, returns whether this instruction is just before
1132  // `if_`, and disregard moves in between.
1133  bool IsBeforeWhenDisregardMoves(HIf* if_) const;
1134
1135  DECLARE_INSTRUCTION(Condition);
1136
1137  virtual IfCondition GetCondition() const = 0;
1138
1139 private:
1140  // For register allocation purposes, returns whether this instruction needs to be
1141  // materialized (that is, not just be in the processor flags).
1142  bool needs_materialization_;
1143
1144  DISALLOW_COPY_AND_ASSIGN(HCondition);
1145};
1146
1147// Instruction to check if two inputs are equal to each other.
1148class HEqual : public HCondition {
1149 public:
1150  HEqual(HInstruction* first, HInstruction* second)
1151      : HCondition(first, second) {}
1152
1153  virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
1154    return x == y ? 1 : 0;
1155  }
1156  virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
1157    return x == y ? 1 : 0;
1158  }
1159
1160  DECLARE_INSTRUCTION(Equal);
1161
1162  virtual IfCondition GetCondition() const {
1163    return kCondEQ;
1164  }
1165
1166 private:
1167  DISALLOW_COPY_AND_ASSIGN(HEqual);
1168};
1169
1170class HNotEqual : public HCondition {
1171 public:
1172  HNotEqual(HInstruction* first, HInstruction* second)
1173      : HCondition(first, second) {}
1174
1175  virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
1176    return x != y ? 1 : 0;
1177  }
1178  virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
1179    return x != y ? 1 : 0;
1180  }
1181
1182  DECLARE_INSTRUCTION(NotEqual);
1183
1184  virtual IfCondition GetCondition() const {
1185    return kCondNE;
1186  }
1187
1188 private:
1189  DISALLOW_COPY_AND_ASSIGN(HNotEqual);
1190};
1191
1192class HLessThan : public HCondition {
1193 public:
1194  HLessThan(HInstruction* first, HInstruction* second)
1195      : HCondition(first, second) {}
1196
1197  virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
1198    return x < y ? 1 : 0;
1199  }
1200  virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
1201    return x < y ? 1 : 0;
1202  }
1203
1204  DECLARE_INSTRUCTION(LessThan);
1205
1206  virtual IfCondition GetCondition() const {
1207    return kCondLT;
1208  }
1209
1210 private:
1211  DISALLOW_COPY_AND_ASSIGN(HLessThan);
1212};
1213
1214class HLessThanOrEqual : public HCondition {
1215 public:
1216  HLessThanOrEqual(HInstruction* first, HInstruction* second)
1217      : HCondition(first, second) {}
1218
1219  virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
1220    return x <= y ? 1 : 0;
1221  }
1222  virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
1223    return x <= y ? 1 : 0;
1224  }
1225
1226  DECLARE_INSTRUCTION(LessThanOrEqual);
1227
1228  virtual IfCondition GetCondition() const {
1229    return kCondLE;
1230  }
1231
1232 private:
1233  DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual);
1234};
1235
1236class HGreaterThan : public HCondition {
1237 public:
1238  HGreaterThan(HInstruction* first, HInstruction* second)
1239      : HCondition(first, second) {}
1240
1241  virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
1242    return x > y ? 1 : 0;
1243  }
1244  virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
1245    return x > y ? 1 : 0;
1246  }
1247
1248  DECLARE_INSTRUCTION(GreaterThan);
1249
1250  virtual IfCondition GetCondition() const {
1251    return kCondGT;
1252  }
1253
1254 private:
1255  DISALLOW_COPY_AND_ASSIGN(HGreaterThan);
1256};
1257
1258class HGreaterThanOrEqual : public HCondition {
1259 public:
1260  HGreaterThanOrEqual(HInstruction* first, HInstruction* second)
1261      : HCondition(first, second) {}
1262
1263  virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
1264    return x >= y ? 1 : 0;
1265  }
1266  virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
1267    return x >= y ? 1 : 0;
1268  }
1269
1270  DECLARE_INSTRUCTION(GreaterThanOrEqual);
1271
1272  virtual IfCondition GetCondition() const {
1273    return kCondGE;
1274  }
1275
1276 private:
1277  DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual);
1278};
1279
1280
1281// Instruction to check how two inputs compare to each other.
1282// Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1.
1283class HCompare : public HBinaryOperation {
1284 public:
1285  HCompare(Primitive::Type type, HInstruction* first, HInstruction* second)
1286      : HBinaryOperation(Primitive::kPrimInt, first, second) {
1287    DCHECK_EQ(type, first->GetType());
1288    DCHECK_EQ(type, second->GetType());
1289  }
1290
1291  virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
1292    return
1293      x == y ? 0 :
1294      x > y ? 1 :
1295      -1;
1296  }
1297  virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
1298    return
1299      x == y ? 0 :
1300      x > y ? 1 :
1301      -1;
1302  }
1303
1304  DECLARE_INSTRUCTION(Compare);
1305
1306 private:
1307  DISALLOW_COPY_AND_ASSIGN(HCompare);
1308};
1309
1310// A local in the graph. Corresponds to a Dex register.
1311class HLocal : public HTemplateInstruction<0> {
1312 public:
1313  explicit HLocal(uint16_t reg_number)
1314      : HTemplateInstruction(SideEffects::None()), reg_number_(reg_number) {}
1315
1316  DECLARE_INSTRUCTION(Local);
1317
1318  uint16_t GetRegNumber() const { return reg_number_; }
1319
1320 private:
1321  // The Dex register number.
1322  const uint16_t reg_number_;
1323
1324  DISALLOW_COPY_AND_ASSIGN(HLocal);
1325};
1326
1327// Load a given local. The local is an input of this instruction.
1328class HLoadLocal : public HExpression<1> {
1329 public:
1330  HLoadLocal(HLocal* local, Primitive::Type type)
1331      : HExpression(type, SideEffects::None()) {
1332    SetRawInputAt(0, local);
1333  }
1334
1335  HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); }
1336
1337  DECLARE_INSTRUCTION(LoadLocal);
1338
1339 private:
1340  DISALLOW_COPY_AND_ASSIGN(HLoadLocal);
1341};
1342
1343// Store a value in a given local. This instruction has two inputs: the value
1344// and the local.
1345class HStoreLocal : public HTemplateInstruction<2> {
1346 public:
1347  HStoreLocal(HLocal* local, HInstruction* value) : HTemplateInstruction(SideEffects::None()) {
1348    SetRawInputAt(0, local);
1349    SetRawInputAt(1, value);
1350  }
1351
1352  HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); }
1353
1354  DECLARE_INSTRUCTION(StoreLocal);
1355
1356 private:
1357  DISALLOW_COPY_AND_ASSIGN(HStoreLocal);
1358};
1359
1360class HConstant : public HExpression<0> {
1361 public:
1362  explicit HConstant(Primitive::Type type) : HExpression(type, SideEffects::None()) {}
1363
1364  virtual bool CanBeMoved() const { return true; }
1365
1366  DECLARE_INSTRUCTION(Constant);
1367
1368 private:
1369  DISALLOW_COPY_AND_ASSIGN(HConstant);
1370};
1371
1372// Constants of the type int. Those can be from Dex instructions, or
1373// synthesized (for example with the if-eqz instruction).
1374class HIntConstant : public HConstant {
1375 public:
1376  explicit HIntConstant(int32_t value) : HConstant(Primitive::kPrimInt), value_(value) {}
1377
1378  int32_t GetValue() const { return value_; }
1379
1380  virtual bool InstructionDataEquals(HInstruction* other) const {
1381    return other->AsIntConstant()->value_ == value_;
1382  }
1383
1384  virtual size_t ComputeHashCode() const { return GetValue(); }
1385
1386  DECLARE_INSTRUCTION(IntConstant);
1387
1388 private:
1389  const int32_t value_;
1390
1391  DISALLOW_COPY_AND_ASSIGN(HIntConstant);
1392};
1393
1394class HLongConstant : public HConstant {
1395 public:
1396  explicit HLongConstant(int64_t value) : HConstant(Primitive::kPrimLong), value_(value) {}
1397
1398  int64_t GetValue() const { return value_; }
1399
1400  virtual bool InstructionDataEquals(HInstruction* other) const {
1401    return other->AsLongConstant()->value_ == value_;
1402  }
1403
1404  virtual size_t ComputeHashCode() const { return static_cast<size_t>(GetValue()); }
1405
1406  DECLARE_INSTRUCTION(LongConstant);
1407
1408 private:
1409  const int64_t value_;
1410
1411  DISALLOW_COPY_AND_ASSIGN(HLongConstant);
1412};
1413
1414class HInvoke : public HInstruction {
1415 public:
1416  HInvoke(ArenaAllocator* arena,
1417          uint32_t number_of_arguments,
1418          Primitive::Type return_type,
1419          uint32_t dex_pc)
1420    : HInstruction(SideEffects::All()),
1421      inputs_(arena, number_of_arguments),
1422      return_type_(return_type),
1423      dex_pc_(dex_pc) {
1424    inputs_.SetSize(number_of_arguments);
1425  }
1426
1427  virtual size_t InputCount() const { return inputs_.Size(); }
1428  virtual HInstruction* InputAt(size_t i) const { return inputs_.Get(i); }
1429
1430  // Runtime needs to walk the stack, so Dex -> Dex calls need to
1431  // know their environment.
1432  virtual bool NeedsEnvironment() const { return true; }
1433
1434  void SetArgumentAt(size_t index, HInstruction* argument) {
1435    SetRawInputAt(index, argument);
1436  }
1437
1438  virtual void SetRawInputAt(size_t index, HInstruction* input) {
1439    inputs_.Put(index, input);
1440  }
1441
1442  virtual Primitive::Type GetType() const { return return_type_; }
1443
1444  uint32_t GetDexPc() const { return dex_pc_; }
1445
1446  DECLARE_INSTRUCTION(Invoke);
1447
1448 protected:
1449  GrowableArray<HInstruction*> inputs_;
1450  const Primitive::Type return_type_;
1451  const uint32_t dex_pc_;
1452
1453 private:
1454  DISALLOW_COPY_AND_ASSIGN(HInvoke);
1455};
1456
1457class HInvokeStatic : public HInvoke {
1458 public:
1459  HInvokeStatic(ArenaAllocator* arena,
1460                uint32_t number_of_arguments,
1461                Primitive::Type return_type,
1462                uint32_t dex_pc,
1463                uint32_t index_in_dex_cache)
1464      : HInvoke(arena, number_of_arguments, return_type, dex_pc),
1465        index_in_dex_cache_(index_in_dex_cache) {}
1466
1467  uint32_t GetIndexInDexCache() const { return index_in_dex_cache_; }
1468
1469  DECLARE_INSTRUCTION(InvokeStatic);
1470
1471 private:
1472  const uint32_t index_in_dex_cache_;
1473
1474  DISALLOW_COPY_AND_ASSIGN(HInvokeStatic);
1475};
1476
1477class HInvokeVirtual : public HInvoke {
1478 public:
1479  HInvokeVirtual(ArenaAllocator* arena,
1480                 uint32_t number_of_arguments,
1481                 Primitive::Type return_type,
1482                 uint32_t dex_pc,
1483                 uint32_t vtable_index)
1484      : HInvoke(arena, number_of_arguments, return_type, dex_pc),
1485        vtable_index_(vtable_index) {}
1486
1487  uint32_t GetVTableIndex() const { return vtable_index_; }
1488
1489  DECLARE_INSTRUCTION(InvokeVirtual);
1490
1491 private:
1492  const uint32_t vtable_index_;
1493
1494  DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual);
1495};
1496
1497class HNewInstance : public HExpression<0> {
1498 public:
1499  HNewInstance(uint32_t dex_pc, uint16_t type_index)
1500      : HExpression(Primitive::kPrimNot, SideEffects::None()),
1501        dex_pc_(dex_pc),
1502        type_index_(type_index) {}
1503
1504  uint32_t GetDexPc() const { return dex_pc_; }
1505  uint16_t GetTypeIndex() const { return type_index_; }
1506
1507  // Calls runtime so needs an environment.
1508  virtual bool NeedsEnvironment() const { return true; }
1509
1510  DECLARE_INSTRUCTION(NewInstance);
1511
1512 private:
1513  const uint32_t dex_pc_;
1514  const uint16_t type_index_;
1515
1516  DISALLOW_COPY_AND_ASSIGN(HNewInstance);
1517};
1518
1519class HAdd : public HBinaryOperation {
1520 public:
1521  HAdd(Primitive::Type result_type, HInstruction* left, HInstruction* right)
1522      : HBinaryOperation(result_type, left, right) {}
1523
1524  virtual bool IsCommutative() { return true; }
1525
1526  virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
1527    return x + y;
1528  }
1529  virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
1530    return x + y;
1531  }
1532
1533  DECLARE_INSTRUCTION(Add);
1534
1535 private:
1536  DISALLOW_COPY_AND_ASSIGN(HAdd);
1537};
1538
1539class HSub : public HBinaryOperation {
1540 public:
1541  HSub(Primitive::Type result_type, HInstruction* left, HInstruction* right)
1542      : HBinaryOperation(result_type, left, right) {}
1543
1544  virtual bool IsCommutative() { return false; }
1545
1546  virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
1547    return x - y;
1548  }
1549  virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
1550    return x - y;
1551  }
1552
1553  DECLARE_INSTRUCTION(Sub);
1554
1555 private:
1556  DISALLOW_COPY_AND_ASSIGN(HSub);
1557};
1558
1559// The value of a parameter in this method. Its location depends on
1560// the calling convention.
1561class HParameterValue : public HExpression<0> {
1562 public:
1563  HParameterValue(uint8_t index, Primitive::Type parameter_type)
1564      : HExpression(parameter_type, SideEffects::None()), index_(index) {}
1565
1566  uint8_t GetIndex() const { return index_; }
1567
1568  DECLARE_INSTRUCTION(ParameterValue);
1569
1570 private:
1571  // The index of this parameter in the parameters list. Must be less
1572  // than HGraph::number_of_in_vregs_;
1573  const uint8_t index_;
1574
1575  DISALLOW_COPY_AND_ASSIGN(HParameterValue);
1576};
1577
1578class HNot : public HExpression<1> {
1579 public:
1580  explicit HNot(HInstruction* input) : HExpression(Primitive::kPrimBoolean, SideEffects::None()) {
1581    SetRawInputAt(0, input);
1582  }
1583
1584  virtual bool CanBeMoved() const { return true; }
1585  virtual bool InstructionDataEquals(HInstruction* other) const { return true; }
1586
1587  DECLARE_INSTRUCTION(Not);
1588
1589 private:
1590  DISALLOW_COPY_AND_ASSIGN(HNot);
1591};
1592
1593class HPhi : public HInstruction {
1594 public:
1595  HPhi(ArenaAllocator* arena, uint32_t reg_number, size_t number_of_inputs, Primitive::Type type)
1596      : HInstruction(SideEffects::None()),
1597        inputs_(arena, number_of_inputs),
1598        reg_number_(reg_number),
1599        type_(type),
1600        is_live_(false) {
1601    inputs_.SetSize(number_of_inputs);
1602  }
1603
1604  virtual size_t InputCount() const { return inputs_.Size(); }
1605  virtual HInstruction* InputAt(size_t i) const { return inputs_.Get(i); }
1606
1607  virtual void SetRawInputAt(size_t index, HInstruction* input) {
1608    inputs_.Put(index, input);
1609  }
1610
1611  void AddInput(HInstruction* input);
1612
1613  virtual Primitive::Type GetType() const { return type_; }
1614  void SetType(Primitive::Type type) { type_ = type; }
1615
1616  uint32_t GetRegNumber() const { return reg_number_; }
1617
1618  void SetDead() { is_live_ = false; }
1619  void SetLive() { is_live_ = true; }
1620  bool IsDead() const { return !is_live_; }
1621  bool IsLive() const { return is_live_; }
1622
1623  DECLARE_INSTRUCTION(Phi);
1624
1625 private:
1626  GrowableArray<HInstruction*> inputs_;
1627  const uint32_t reg_number_;
1628  Primitive::Type type_;
1629  bool is_live_;
1630
1631  DISALLOW_COPY_AND_ASSIGN(HPhi);
1632};
1633
1634class HNullCheck : public HExpression<1> {
1635 public:
1636  HNullCheck(HInstruction* value, uint32_t dex_pc)
1637      : HExpression(value->GetType(), SideEffects::None()), dex_pc_(dex_pc) {
1638    SetRawInputAt(0, value);
1639  }
1640
1641  virtual bool CanBeMoved() const { return true; }
1642  virtual bool InstructionDataEquals(HInstruction* other) const { return true; }
1643
1644  virtual bool NeedsEnvironment() const { return true; }
1645
1646  virtual bool CanThrow() const { return true; }
1647
1648  uint32_t GetDexPc() const { return dex_pc_; }
1649
1650  DECLARE_INSTRUCTION(NullCheck);
1651
1652 private:
1653  const uint32_t dex_pc_;
1654
1655  DISALLOW_COPY_AND_ASSIGN(HNullCheck);
1656};
1657
1658class FieldInfo : public ValueObject {
1659 public:
1660  FieldInfo(MemberOffset field_offset, Primitive::Type field_type)
1661      : field_offset_(field_offset), field_type_(field_type) {}
1662
1663  MemberOffset GetFieldOffset() const { return field_offset_; }
1664  Primitive::Type GetFieldType() const { return field_type_; }
1665
1666 private:
1667  const MemberOffset field_offset_;
1668  const Primitive::Type field_type_;
1669};
1670
1671class HInstanceFieldGet : public HExpression<1> {
1672 public:
1673  HInstanceFieldGet(HInstruction* value,
1674                    Primitive::Type field_type,
1675                    MemberOffset field_offset)
1676      : HExpression(field_type, SideEffects::DependsOnSomething()),
1677        field_info_(field_offset, field_type) {
1678    SetRawInputAt(0, value);
1679  }
1680
1681  virtual bool CanBeMoved() const { return true; }
1682  virtual bool InstructionDataEquals(HInstruction* other) const {
1683    size_t other_offset = other->AsInstanceFieldGet()->GetFieldOffset().SizeValue();
1684    return other_offset == GetFieldOffset().SizeValue();
1685  }
1686
1687  virtual size_t ComputeHashCode() const {
1688    return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue();
1689  }
1690
1691  MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); }
1692  Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); }
1693
1694  DECLARE_INSTRUCTION(InstanceFieldGet);
1695
1696 private:
1697  const FieldInfo field_info_;
1698
1699  DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet);
1700};
1701
1702class HInstanceFieldSet : public HTemplateInstruction<2> {
1703 public:
1704  HInstanceFieldSet(HInstruction* object,
1705                    HInstruction* value,
1706                    Primitive::Type field_type,
1707                    MemberOffset field_offset)
1708      : HTemplateInstruction(SideEffects::ChangesSomething()),
1709        field_info_(field_offset, field_type) {
1710    SetRawInputAt(0, object);
1711    SetRawInputAt(1, value);
1712  }
1713
1714  MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); }
1715  Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); }
1716
1717  DECLARE_INSTRUCTION(InstanceFieldSet);
1718
1719 private:
1720  const FieldInfo field_info_;
1721
1722  DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet);
1723};
1724
1725class HArrayGet : public HExpression<2> {
1726 public:
1727  HArrayGet(HInstruction* array, HInstruction* index, Primitive::Type type)
1728      : HExpression(type, SideEffects::DependsOnSomething()) {
1729    SetRawInputAt(0, array);
1730    SetRawInputAt(1, index);
1731  }
1732
1733  virtual bool CanBeMoved() const { return true; }
1734  virtual bool InstructionDataEquals(HInstruction* other) const { return true; }
1735
1736  DECLARE_INSTRUCTION(ArrayGet);
1737
1738 private:
1739  DISALLOW_COPY_AND_ASSIGN(HArrayGet);
1740};
1741
1742class HArraySet : public HTemplateInstruction<3> {
1743 public:
1744  HArraySet(HInstruction* array,
1745            HInstruction* index,
1746            HInstruction* value,
1747            Primitive::Type component_type,
1748            uint32_t dex_pc)
1749      : HTemplateInstruction(SideEffects::ChangesSomething()),
1750        dex_pc_(dex_pc),
1751        component_type_(component_type) {
1752    SetRawInputAt(0, array);
1753    SetRawInputAt(1, index);
1754    SetRawInputAt(2, value);
1755  }
1756
1757  virtual bool NeedsEnvironment() const {
1758    // We currently always call a runtime method to catch array store
1759    // exceptions.
1760    return InputAt(2)->GetType() == Primitive::kPrimNot;
1761  }
1762
1763  uint32_t GetDexPc() const { return dex_pc_; }
1764
1765  Primitive::Type GetComponentType() const { return component_type_; }
1766
1767  DECLARE_INSTRUCTION(ArraySet);
1768
1769 private:
1770  const uint32_t dex_pc_;
1771  const Primitive::Type component_type_;
1772
1773  DISALLOW_COPY_AND_ASSIGN(HArraySet);
1774};
1775
1776class HArrayLength : public HExpression<1> {
1777 public:
1778  explicit HArrayLength(HInstruction* array)
1779      : HExpression(Primitive::kPrimInt, SideEffects::None()) {
1780    // Note that arrays do not change length, so the instruction does not
1781    // depend on any write.
1782    SetRawInputAt(0, array);
1783  }
1784
1785  virtual bool CanBeMoved() const { return true; }
1786  virtual bool InstructionDataEquals(HInstruction* other) const { return true; }
1787
1788  DECLARE_INSTRUCTION(ArrayLength);
1789
1790 private:
1791  DISALLOW_COPY_AND_ASSIGN(HArrayLength);
1792};
1793
1794class HBoundsCheck : public HExpression<2> {
1795 public:
1796  HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc)
1797      : HExpression(index->GetType(), SideEffects::None()), dex_pc_(dex_pc) {
1798    DCHECK(index->GetType() == Primitive::kPrimInt);
1799    SetRawInputAt(0, index);
1800    SetRawInputAt(1, length);
1801  }
1802
1803  virtual bool CanBeMoved() const { return true; }
1804  virtual bool InstructionDataEquals(HInstruction* other) const { return true; }
1805
1806  virtual bool NeedsEnvironment() const { return true; }
1807
1808  virtual bool CanThrow() const { return true; }
1809
1810  uint32_t GetDexPc() const { return dex_pc_; }
1811
1812  DECLARE_INSTRUCTION(BoundsCheck);
1813
1814 private:
1815  const uint32_t dex_pc_;
1816
1817  DISALLOW_COPY_AND_ASSIGN(HBoundsCheck);
1818};
1819
1820/**
1821 * Some DEX instructions are folded into multiple HInstructions that need
1822 * to stay live until the last HInstruction. This class
1823 * is used as a marker for the baseline compiler to ensure its preceding
1824 * HInstruction stays live. `index` is the temporary number that is used
1825 * for knowing the stack offset where to store the instruction.
1826 */
1827class HTemporary : public HTemplateInstruction<0> {
1828 public:
1829  explicit HTemporary(size_t index) : HTemplateInstruction(SideEffects::None()), index_(index) {}
1830
1831  size_t GetIndex() const { return index_; }
1832
1833  DECLARE_INSTRUCTION(Temporary);
1834
1835 private:
1836  const size_t index_;
1837
1838  DISALLOW_COPY_AND_ASSIGN(HTemporary);
1839};
1840
1841class HSuspendCheck : public HTemplateInstruction<0> {
1842 public:
1843  explicit HSuspendCheck(uint32_t dex_pc)
1844      : HTemplateInstruction(SideEffects::None()), dex_pc_(dex_pc) {}
1845
1846  virtual bool NeedsEnvironment() const {
1847    return true;
1848  }
1849
1850  uint32_t GetDexPc() const { return dex_pc_; }
1851
1852  DECLARE_INSTRUCTION(SuspendCheck);
1853
1854 private:
1855  const uint32_t dex_pc_;
1856
1857  DISALLOW_COPY_AND_ASSIGN(HSuspendCheck);
1858};
1859
1860class MoveOperands : public ArenaObject {
1861 public:
1862  MoveOperands(Location source, Location destination, HInstruction* instruction)
1863      : source_(source), destination_(destination), instruction_(instruction) {}
1864
1865  Location GetSource() const { return source_; }
1866  Location GetDestination() const { return destination_; }
1867
1868  void SetSource(Location value) { source_ = value; }
1869  void SetDestination(Location value) { destination_ = value; }
1870
1871  // The parallel move resolver marks moves as "in-progress" by clearing the
1872  // destination (but not the source).
1873  Location MarkPending() {
1874    DCHECK(!IsPending());
1875    Location dest = destination_;
1876    destination_ = Location::NoLocation();
1877    return dest;
1878  }
1879
1880  void ClearPending(Location dest) {
1881    DCHECK(IsPending());
1882    destination_ = dest;
1883  }
1884
1885  bool IsPending() const {
1886    DCHECK(!source_.IsInvalid() || destination_.IsInvalid());
1887    return destination_.IsInvalid() && !source_.IsInvalid();
1888  }
1889
1890  // True if this blocks a move from the given location.
1891  bool Blocks(Location loc) const {
1892    return !IsEliminated() && source_.Equals(loc);
1893  }
1894
1895  // A move is redundant if it's been eliminated, if its source and
1896  // destination are the same, or if its destination is unneeded.
1897  bool IsRedundant() const {
1898    return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_);
1899  }
1900
1901  // We clear both operands to indicate move that's been eliminated.
1902  void Eliminate() {
1903    source_ = destination_ = Location::NoLocation();
1904  }
1905
1906  bool IsEliminated() const {
1907    DCHECK(!source_.IsInvalid() || destination_.IsInvalid());
1908    return source_.IsInvalid();
1909  }
1910
1911  HInstruction* GetInstruction() const { return instruction_; }
1912
1913 private:
1914  Location source_;
1915  Location destination_;
1916  // The instruction this move is assocatied with. Null when this move is
1917  // for moving an input in the expected locations of user (including a phi user).
1918  // This is only used in debug mode, to ensure we do not connect interval siblings
1919  // in the same parallel move.
1920  HInstruction* instruction_;
1921
1922  DISALLOW_COPY_AND_ASSIGN(MoveOperands);
1923};
1924
1925static constexpr size_t kDefaultNumberOfMoves = 4;
1926
1927class HParallelMove : public HTemplateInstruction<0> {
1928 public:
1929  explicit HParallelMove(ArenaAllocator* arena)
1930      : HTemplateInstruction(SideEffects::None()), moves_(arena, kDefaultNumberOfMoves) {}
1931
1932  void AddMove(MoveOperands* move) {
1933    if (kIsDebugBuild && move->GetInstruction() != nullptr) {
1934      for (size_t i = 0, e = moves_.Size(); i < e; ++i) {
1935        DCHECK_NE(moves_.Get(i)->GetInstruction(), move->GetInstruction())
1936          << "Doing parallel moves for the same instruction.";
1937      }
1938    }
1939    moves_.Add(move);
1940  }
1941
1942  MoveOperands* MoveOperandsAt(size_t index) const {
1943    return moves_.Get(index);
1944  }
1945
1946  size_t NumMoves() const { return moves_.Size(); }
1947
1948  DECLARE_INSTRUCTION(ParallelMove);
1949
1950 private:
1951  GrowableArray<MoveOperands*> moves_;
1952
1953  DISALLOW_COPY_AND_ASSIGN(HParallelMove);
1954};
1955
1956class HGraphVisitor : public ValueObject {
1957 public:
1958  explicit HGraphVisitor(HGraph* graph) : graph_(graph) {}
1959  virtual ~HGraphVisitor() {}
1960
1961  virtual void VisitInstruction(HInstruction* instruction) {}
1962  virtual void VisitBasicBlock(HBasicBlock* block);
1963
1964  // Visit the graph following basic block insertion order.
1965  void VisitInsertionOrder();
1966
1967  // Visit the graph following dominator tree reverse post-order.
1968  void VisitReversePostOrder();
1969
1970  HGraph* GetGraph() const { return graph_; }
1971
1972  // Visit functions for instruction classes.
1973#define DECLARE_VISIT_INSTRUCTION(name, super)                                        \
1974  virtual void Visit##name(H##name* instr) { VisitInstruction(instr); }
1975
1976  FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
1977
1978#undef DECLARE_VISIT_INSTRUCTION
1979
1980 private:
1981  HGraph* graph_;
1982
1983  DISALLOW_COPY_AND_ASSIGN(HGraphVisitor);
1984};
1985
1986class HGraphDelegateVisitor : public HGraphVisitor {
1987 public:
1988  explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {}
1989  virtual ~HGraphDelegateVisitor() {}
1990
1991  // Visit functions that delegate to to super class.
1992#define DECLARE_VISIT_INSTRUCTION(name, super)                                        \
1993  virtual void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); }
1994
1995  FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
1996
1997#undef DECLARE_VISIT_INSTRUCTION
1998
1999 private:
2000  DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor);
2001};
2002
2003class HInsertionOrderIterator : public ValueObject {
2004 public:
2005  explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {}
2006
2007  bool Done() const { return index_ == graph_.GetBlocks().Size(); }
2008  HBasicBlock* Current() const { return graph_.GetBlocks().Get(index_); }
2009  void Advance() { ++index_; }
2010
2011 private:
2012  const HGraph& graph_;
2013  size_t index_;
2014
2015  DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator);
2016};
2017
2018class HReversePostOrderIterator : public ValueObject {
2019 public:
2020  explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {}
2021
2022  bool Done() const { return index_ == graph_.GetReversePostOrder().Size(); }
2023  HBasicBlock* Current() const { return graph_.GetReversePostOrder().Get(index_); }
2024  void Advance() { ++index_; }
2025
2026 private:
2027  const HGraph& graph_;
2028  size_t index_;
2029
2030  DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator);
2031};
2032
2033class HPostOrderIterator : public ValueObject {
2034 public:
2035  explicit HPostOrderIterator(const HGraph& graph)
2036      : graph_(graph), index_(graph_.GetReversePostOrder().Size()) {}
2037
2038  bool Done() const { return index_ == 0; }
2039  HBasicBlock* Current() const { return graph_.GetReversePostOrder().Get(index_ - 1); }
2040  void Advance() { --index_; }
2041
2042 private:
2043  const HGraph& graph_;
2044  size_t index_;
2045
2046  DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator);
2047};
2048
2049}  // namespace art
2050
2051#endif  // ART_COMPILER_OPTIMIZING_NODES_H_
2052