1 /*
   2  * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.loop;
  24 
  25 import org.graalvm.compiler.core.common.type.Stamp;
  26 import org.graalvm.compiler.nodes.ValueNode;
  27 import org.graalvm.compiler.nodes.calc.IntegerConvertNode;
  28 
  29 public class DerivedConvertedInductionVariable extends DerivedInductionVariable {
  30 
  31     private final Stamp stamp;
  32     private final ValueNode value;
  33 
  34     public DerivedConvertedInductionVariable(LoopEx loop, InductionVariable base, Stamp stamp, ValueNode value) {
  35         super(loop, base);
  36         this.stamp = stamp;
  37         this.value = value;
  38     }
  39 
  40     @Override
  41     public ValueNode valueNode() {
  42         return value;
  43     }
  44 
  45     @Override
  46     public Direction direction() {
  47         return base.direction();
  48     }
  49 
  50     @Override
  51     public ValueNode initNode() {
  52         return IntegerConvertNode.convert(base.initNode(), stamp, graph());
  53     }
  54 
  55     @Override
  56     public ValueNode strideNode() {
  57         return IntegerConvertNode.convert(base.strideNode(), stamp, graph());
  58     }
  59 
  60     @Override
  61     public boolean isConstantInit() {
  62         return base.isConstantInit();
  63     }
  64 
  65     @Override
  66     public boolean isConstantStride() {
  67         return base.isConstantStride();
  68     }
  69 
  70     @Override
  71     public long constantInit() {
  72         return base.constantInit();
  73     }
  74 
  75     @Override
  76     public long constantStride() {
  77         return base.constantStride();
  78     }
  79 
  80     @Override
  81     public ValueNode extremumNode(boolean assumePositiveTripCount, Stamp s) {
  82         return base.extremumNode(assumePositiveTripCount, s);
  83     }
  84 
  85     @Override
  86     public ValueNode exitValueNode() {
  87         return IntegerConvertNode.convert(base.exitValueNode(), stamp, graph());
  88     }
  89 
  90     @Override
  91     public boolean isConstantExtremum() {
  92         return base.isConstantExtremum();
  93     }
  94 
  95     @Override
  96     public long constantExtremum() {
  97         return base.constantExtremum();
  98     }
  99 
 100     @Override
 101     public void deleteUnusedNodes() {
 102     }
 103 
 104     @Override
 105     public String toString() {
 106         return String.format("DerivedConvertedInductionVariable base (%s) %s %s", base, value.getNodeClass().shortName(), stamp);
 107     }
 108 }