コード例 #1
0
ファイル: Block.cs プロジェクト: nguyenvuduc/ILGPU
        /// <summary>
        /// Duplicates the element at the top of the stack.
        /// </summary>
        public void Dup()
        {
            var var       = new VariableRef(StackCounter - 1, VariableRefType.Stack);
            var targetVar = new VariableRef(StackCounter++, VariableRefType.Stack);

            SetValue(targetVar, GetValue(var));
        }
コード例 #2
0
ファイル: Variables.cs プロジェクト: nguyenvuduc/ILGPU
        /// <summary>
        /// Loads a variable. This can be an argument or a local reference.
        /// </summary>
        /// <param name="block">The current basic block.</param>
        /// <param name="builder">The current builder.</param>
        /// <param name="var">The variable reference.</param>
        private void LoadVariable(
            Block block,
            IRBuilder builder,
            VariableRef var)
        {
            Debug.Assert(
                var.RefType == VariableRefType.Argument ||
                var.RefType == VariableRefType.Local);
            var addressOrValue = block.GetValue(var);
            var type           = variableTypes[var];

            if (variables.Contains(var))
            {
                block.Push(CreateLoad(
                               builder,
                               addressOrValue,
                               type.Item1,
                               type.Item2));
            }
            else
            {
                block.Push(LoadOntoEvaluationStack(
                               builder,
                               addressOrValue,
                               type.Item2));
            }
        }
コード例 #3
0
ファイル: Block.cs プロジェクト: nguyenvuduc/ILGPU
        /// <summary>
        /// Pops a value from the execution stack.
        /// </summary>
        /// <returns>The popped value.</returns>
        public Value Pop()
        {
            var var   = new VariableRef(--StackCounter, VariableRefType.Stack);
            var value = GetValue(var);

            CodeGenerator.SSABuilder.RemoveValue(CFGNode, var);
            return(value);
        }
コード例 #4
0
        /// <summary>
        /// Loads a variable address. This can be an argument or a local reference.
        /// </summary>
        /// <param name="var">The variable reference.</param>
        private void LoadVariableAddress(VariableRef var)
        {
            Location.Assert(
                var.RefType == VariableRefType.Argument ||
                var.RefType == VariableRefType.Local);
            // Check whether we can load the address of a non-SSA value
            Location.Assert(variables.Contains(var));
            var address = Block.GetValue(var);

            Block.Push(address);
        }
コード例 #5
0
ファイル: Variables.cs プロジェクト: nguyenvuduc/ILGPU
        /// <summary>
        /// Loads a variable address. This can be an argument or a local reference.
        /// </summary>
        /// <param name="block">The current basic block.</param>
        /// <param name="builder">The current builder.</param>
        /// <param name="var">The variable reference.</param>
        private void LoadVariableAddress(
            Block block,
            IRBuilder builder,
            VariableRef var)
        {
            Debug.Assert(
                var.RefType == VariableRefType.Argument ||
                var.RefType == VariableRefType.Local);
            Debug.Assert(variables.Contains(var), "Cannot load address of SSA value");
            var address = block.GetValue(var);

            block.Push(address);
        }
コード例 #6
0
        /// <summary>
        /// Stores a value to the given variable slot.
        /// </summary>
        /// <param name="var">The variable reference.</param>
        private void StoreVariable(VariableRef var)
        {
            Location.Assert(
                var.RefType == VariableRefType.Argument ||
                var.RefType == VariableRefType.Local);
            var variableType = variableTypes[var];
            var storeValue   = Block.Pop(
                variableType.Item1,
                variableType.Item2);

            if (variables.Contains(var))
            {
                var address = Block.GetValue(var);
                Builder.CreateStore(Location, address, storeValue);
            }
            else
            {
                Block.SetValue(var, storeValue);
            }
        }
コード例 #7
0
ファイル: Variables.cs プロジェクト: nguyenvuduc/ILGPU
        /// <summary>
        /// Stores a value to the argument with index idx.
        /// </summary>
        /// <param name="block">The current basic block.</param>
        /// <param name="builder">The current builder.</param>
        /// <param name="var">The variable reference.</param>
        private void StoreVariable(
            Block block,
            IRBuilder builder,
            VariableRef var)
        {
            Debug.Assert(
                var.RefType == VariableRefType.Argument ||
                var.RefType == VariableRefType.Local);
            var variableType = variableTypes[var];
            var storeValue   = block.Pop(variableType.Item1, variableType.Item2);

            if (variables.Contains(var))
            {
                var address = block.GetValue(var);
                builder.CreateStore(address, storeValue);
            }
            else
            {
                block.SetValue(var, storeValue);
            }
        }
コード例 #8
0
ファイル: Block.cs プロジェクト: nguyenvuduc/ILGPU
        /// <summary>
        /// Pushes the value of the given type onto the execution stack.
        /// </summary>
        /// <param name="value">The value to push.</param>
        public void Push(Value value)
        {
            var newStackSlot = new VariableRef(StackCounter++, VariableRefType.Stack);

            SetValue(newStackSlot, value);
        }
コード例 #9
0
ファイル: Block.cs プロジェクト: nguyenvuduc/ILGPU
 public Value GetValue(VariableRef var) =>
 CodeGenerator.SSABuilder.GetValue(CFGNode, var);
コード例 #10
0
ファイル: Block.cs プロジェクト: nguyenvuduc/ILGPU
 public void SetValue(VariableRef var, Value value) =>
 CodeGenerator.SSABuilder.SetValue(CFGNode, var, value);
コード例 #11
0
ファイル: Block.cs プロジェクト: kingland/ILGPU
 public Value GetValue(VariableRef var) =>
 CodeGenerator.SSABuilder.GetValue(BasicBlock, var);
コード例 #12
0
ファイル: Block.cs プロジェクト: kingland/ILGPU
 public void SetValue(VariableRef var, Value value) =>
 CodeGenerator.SSABuilder.SetValue(BasicBlock, var, value);