示例#1
0
        public string GetVariableType(Variable variable)
        {
            switch (variable)
            {
            case PrimitiveVariable primitiveVariable:
                return(CLTypeGenerator.GetBasicValueType(primitiveVariable.BasicValueType));

            case PointerVariable pointerType:
            {
                var addressSpacePrefix = CLInstructions.GetAddressSpacePrefix(pointerType.AddressSpace);
                var elementTypeName    = TypeGenerator[pointerType.ElementType];
                if (!string.IsNullOrEmpty(addressSpacePrefix))
                {
                    elementTypeName = addressSpacePrefix + " " + elementTypeName;
                }
                return(elementTypeName + CLInstructions.DereferenceOperation);
            }

            case ObjectVariable objectVariable:
                return(TypeGenerator[objectVariable.Type]);

            default:
                throw new NotSupportedException();
            }
        }
示例#2
0
            /// <summary>
            /// Appends a pointer cast to an intrinsic atomic pointer type.
            /// </summary>
            /// <param name="type">The arithmetic type to use.</param>
            public void AppendAtomicCast(ArithmeticBasicValueType type)
            {
                var typeExpression = CLTypeGenerator.GetAtomicType(type);

                if (typeExpression == null)
                {
                    return;
                }
                AppendCast(typeExpression + CLInstructions.DereferenceOperation);
            }
示例#3
0
 internal GeneratorArgs(
     CLBackend backend,
     CLTypeGenerator typeGenerator,
     SeparateViewEntryPoint entryPoint,
     ABI abi)
 {
     Backend       = backend;
     TypeGenerator = typeGenerator;
     EntryPoint    = entryPoint;
     ABI           = abi;
 }
示例#4
0
 internal GeneratorArgs(
     CLBackend backend,
     CLTypeGenerator typeGenerator,
     SeparateViewEntryPoint entryPoint)
 {
     Backend             = backend;
     TypeGenerator       = typeGenerator;
     EntryPoint          = entryPoint;
     KernelTypeGenerator = new CLKernelTypeGenerator(
         typeGenerator,
         entryPoint);
 }
示例#5
0
 /// <summary>
 /// Appends the address of the given register argument with a cast.
 /// </summary>
 /// <param name="argument">The argument to append.</param>
 /// <param name="valueType">The value type.</param>
 public void AppendArgumentAddressWithCast(
     Variable argument,
     ArithmeticBasicValueType valueType)
 {
     AppendArgument();
     stringBuilder.Append('(');
     stringBuilder.Append(
         CLTypeGenerator.GetBasicValueType(valueType));
     stringBuilder.Append(CLInstructions.DereferenceOperation);
     stringBuilder.Append(')');
     AppendCommand(CLInstructions.AddressOfOperation);
     Append(argument);
 }
示例#6
0
 internal GeneratorArgs(
     CLBackend backend,
     CLTypeGenerator typeGenerator,
     SeparateViewEntryPoint entryPoint,
     in AllocaKindInformation sharedAllocations,
示例#7
0
 /// <summary>
 /// Creates a new internal type lookup.
 /// </summary>
 /// <param name="parent">The parent type generator.</param>
 public InternalTypeLookup(CLTypeGenerator parent)
 {
     Parent = parent;
 }
示例#8
0
 /// <summary>
 /// Constructs a new specialized function setup logic.
 /// </summary>
 /// <param name="typeGenerator">The parent type generator.</param>
 public FunctionParameterSetupLogic(CLTypeGenerator typeGenerator)
 {
     TypeGenerator = typeGenerator;
 }
示例#9
0
        /// <summary cref="IValueVisitor.Visit(AtomicCAS)"/>
        public void Visit(AtomicCAS atomicCAS)
        {
            var target  = Load(atomicCAS.Target);
            var value   = Load(atomicCAS.Value);
            var compare = Load(atomicCAS.CompareValue);

            var tempVariable   = AllocateType(BasicValueType.Int1) as PrimitiveVariable;
            var targetVariable = Allocate(atomicCAS);

            using (var statement = BeginStatement(tempVariable))
            {
                statement.AppendCommand(CLInstructions.AtomicCASOperation);
                statement.BeginArguments();
                statement.AppendAtomicCast(atomicCAS.ArithmeticBasicValueType);
                statement.AppendArgument(target);
                statement.AppendArgumentAddressWithCast(value, $"{CLInstructions.GetAddressSpacePrefix(MemoryAddressSpace.Generic)} {CLTypeGenerator.GetBasicValueType(atomicCAS.ArithmeticBasicValueType)} {CLInstructions.DereferenceOperation}");
                statement.AppendArgument(compare);
                statement.EndArguments();
            }

            // The OpenCL way is not compatible with the internal CAS semantic
            // We should adapt to the more general way of returning a bool in the future
            // For now, check the result of the operation and emit an atomic load
            // in the case of a failure.
            using (var statement = BeginStatement(targetVariable))
            {
                statement.Append(tempVariable);
                statement.AppendCommand(CLInstructions.SelectOperation1);
                statement.Append(value);
                statement.AppendCommand(CLInstructions.SelectOperation2);

                statement.AppendCommand(CLInstructions.AtomicLoadOperation);
                statement.BeginArguments();
                statement.AppendAtomicCast(atomicCAS.ArithmeticBasicValueType);
                statement.AppendArgument(target);
                statement.EndArguments();
            }
        }
示例#10
0
 /// <summary>
 /// Constructs a new register allocator.
 /// </summary>
 /// <param name="typeGenerator">The associated type generator.</param>
 public CLVariableAllocator(CLTypeGenerator typeGenerator)
 {
     TypeGenerator = typeGenerator;
 }
示例#11
0
            /// <summary>
            /// Appends a cast to the given arithmetic basic value type.
            /// </summary>
            /// <param name="type">The target type.</param>
            public void AppendCast(ArithmeticBasicValueType type)
            {
                var typeExpression = CLTypeGenerator.GetBasicValueType(type);

                AppendCast(typeExpression);
            }
示例#12
0
            /// <summary>
            /// Appends the specified field name.
            /// </summary>
            /// <param name="fieldIndex">The field index.</param>
            private void AppendFieldName(int fieldIndex)
            {
                var fieldName = CLTypeGenerator.GetFieldName(fieldIndex);

                stringBuilder.Append(fieldName);
            }
示例#13
0
 /// <summary>
 /// Constructs a new type visitor.
 /// </summary>
 /// <param name="typeGenerator">The parent type generator.</param>
 public TypeVisitor(CLTypeGenerator typeGenerator)
 {
     TypeGenerator = typeGenerator;
     Builder       = typeGenerator.Builder;
 }