public GamaValueRef Call(LLVMBuilderRef builder, params GamaValueRef[] parms) => Callback(builder, parms);
public static extern LLVMValueRef* BuildCall(LLVMBuilderRef* LLVMBuilderRef, LLVMValueRef* Fn, System.IntPtr[] Args, uint NumArgs, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
public static extern LLVMValueRef* BuildShuffleVector(LLVMBuilderRef* LLVMBuilderRef, LLVMValueRef* V1, LLVMValueRef* V2, LLVMValueRef* Mask, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
public static extern LLVMValueRef* BuildFree(LLVMBuilderRef* LLVMBuilderRef, LLVMValueRef* PointerVal);
public static extern LLVMValueRef* BuildStructGEP(LLVMBuilderRef* B, LLVMValueRef* Pointer, uint Idx, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
public static extern LLVMValueRef* BuildIndirectBr(LLVMBuilderRef* B, LLVMValueRef* Addr, uint NumDests);
public static extern LLVMValueRef* BuildUnreachable(LLVMBuilderRef* LLVMBuilderRef);
internal IRBuilder(LLVMBuilderRef builderRef) { this._instance = builderRef; }
public void Process(MethodCompiler compiler, Instruction insn, LLVMBuilderRef builder) { var value = LLVM.ConstReal(LLVM.FloatType(), (double)(float)insn.Operand); compiler.CurrentBasicBlock.GetState().StackPush(new EmulatedStateValue(value, TypeInfo.FloatingPrimitive)); }
public override StackEntry Duplicate(LLVMBuilderRef builder) { return(new SpilledExpressionEntry(Kind, Name, Type, LocalIndex, _importer)); }
public CodeGenVisitor(LLVMModuleRef module, LLVMBuilderRef builder) { this.module = module; this.builder = builder; }
protected override LLVMValueRef ValueAsTypeInternal(LLVMTypeRef type, LLVMBuilderRef builder, bool signExtend) { throw new InvalidOperationException(); }
public LLVMValueRef BuildCast(LLVMBuilderRef builder, LLVMValueRef elem, LLVMTypeRef targetType) { // Check if the type of the element equals the targe type if (CompareType(elem, targetType)) { // There is no need to cast // Just return the element return(elem); } // Strings need special handling if (CompareType(targetType, StringType)) { LLVMValueRef indices; var gep = LLVM.BuildGEP(builder, elem, out indices, 0u, "tmpgep"); var ptr = LLVM.BuildPointerCast(builder, gep, StringType, "tmpptrcast"); return(ptr); } string strtype1, strtype2; switch (targetType.TypeKind) { case LLVMTypeKind.LLVMIntegerTypeKind: // Check if the integer fits if (IsInteger(elem)) { var lwidth = elem.TypeOf().GetIntTypeWidth(); var rwidth = targetType.GetIntTypeWidth(); if (lwidth > rwidth) { // The width of the result type is higher // than the width of the element type // Throw an exception strtype1 = elem.TypeOf().PrintTypeToString(); strtype2 = targetType.PrintTypeToString(); throw LoreException.Create(Visitor.Location) .Describe($"Unable to cast element of type '{strtype1}' to '{strtype2}':") .Describe($"The element is too big for the target integer type."); } } // Perform a float to signed integer cast if needed else if (IsFloatOrDouble(elem)) { elem = LLVM.BuildFPToSI(builder, elem, targetType, "tmpfptosicast"); } // Unsupported element type else { // Unable to perform a meaningful cast strtype1 = elem.TypeOf().PrintTypeToString(); strtype2 = targetType.PrintTypeToString(); throw LoreException.Create(Visitor.Location).Describe($"Unable to cast element of type '{strtype1}' to '{strtype2}':"); } // Perform an integer cast return(LLVM.BuildIntCast(builder, elem, targetType, "tmpcast")); case LLVMTypeKind.LLVMFloatTypeKind: case LLVMTypeKind.LLVMDoubleTypeKind: // Perform a signed integer to float cast if needed if (IsInteger(elem)) { elem = LLVM.BuildSIToFP(builder, elem, targetType, "tmpsitofpcast"); } return(LLVM.BuildFPCast(builder, elem, targetType, "tmpfcast")); } // Unable to perform a meaningful cast strtype1 = elem.TypeOf().PrintTypeToString(); strtype2 = targetType.PrintTypeToString(); throw LoreException.Create(Visitor.Location).Describe($"Unable to cast element of type '{strtype1}' to '{strtype2}':"); }
public LLVMValueRef ValueAsInt64(LLVMBuilderRef builder, bool signExtend) { return(ValueAsTypeInternal(ILImporter.Context.Int64Type, builder, signExtend)); }
public static extern LLVMValueRef* BuildAggregateRet(LLVMBuilderRef* LLVMBuilderRef, System.IntPtr[] RetVals, uint N);
public ClepsClassNamesGeneratorParser(ClassManager classManager, CompileStatus status, LLVMContextRef context, LLVMModuleRef module, LLVMBuilderRef builder, out Dictionary <string, LLVMTypeRef> classSkeletons) { ClassManager = classManager; Status = status; Context = context; Module = module; Builder = builder; classSkeletons = new Dictionary <string, LLVMTypeRef>(); ClassSkeletons = classSkeletons; }
public static extern LLVMValueRef* BuildCondBr(LLVMBuilderRef* LLVMBuilderRef, LLVMValueRef* If, LLVMBasicBlockRef* Then, LLVMBasicBlockRef* Else);
private void GetCodeForReadyToRunGenericHelper(WebAssemblyCodegenCompilation compilation, ReadyToRunGenericHelperNode node, NodeFactory factory) { LLVMBuilderRef builder = compilation.Module.Context.CreateBuilder(); var args = new List <LLVMTypeRef>(); MethodDesc delegateCtor = null; if (node.Id == ReadyToRunHelperId.DelegateCtor) { DelegateCreationInfo target = (DelegateCreationInfo)node.Target; delegateCtor = target.Constructor.Method; bool isStatic = delegateCtor.Signature.IsStatic; int argCount = delegateCtor.Signature.Length; if (!isStatic) { argCount++; } for (int i = 0; i < argCount; i++) { TypeDesc argType; if (i == 0 && !isStatic) { argType = delegateCtor.OwningType; } else { argType = delegateCtor.Signature[i - (isStatic ? 0 : 1)]; } args.Add(ILImporter.GetLLVMTypeForTypeDesc(argType)); } } LLVMValueRef helperFunc = Module.GetNamedFunction(node.GetMangledName(factory.NameMangler)); if (helperFunc.Handle == IntPtr.Zero) { throw new Exception("if the function is requested here, it should have been created earlier"); } var helperBlock = helperFunc.AppendBasicBlock("genericHelper"); builder.PositionAtEnd(helperBlock); var importer = new ILImporter(builder, compilation, Module, helperFunc, delegateCtor); LLVMValueRef ctx; string gepName; if (node is ReadyToRunGenericLookupFromTypeNode) { // Locate the VTable slot that points to the dictionary int vtableSlot = VirtualMethodSlotHelper.GetGenericDictionarySlot(factory, (TypeDesc)node.DictionaryOwner); int pointerSize = factory.Target.PointerSize; // Load the dictionary pointer from the VTable int slotOffset = EETypeNode.GetVTableOffset(pointerSize) + (vtableSlot * pointerSize); var slotGep = builder.BuildGEP(helperFunc.GetParam(1), new[] { LLVMValueRef.CreateConstInt(LLVMTypeRef.Int32, (ulong)slotOffset, false) }, "slotGep"); var slotGepPtrPtr = builder.BuildPointerCast(slotGep, LLVMTypeRef.CreatePointer(LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0), 0), "slotGepPtrPtr"); ctx = builder.BuildLoad(slotGepPtrPtr, "dictGep"); gepName = "typeNodeGep"; } else { ctx = helperFunc.GetParam(1); gepName = "paramGep"; } LLVMValueRef resVar = OutputCodeForDictionaryLookup(builder, factory, node, node.LookupSignature, ctx, gepName); switch (node.Id) { case ReadyToRunHelperId.GetNonGCStaticBase: { MetadataType target = (MetadataType)node.Target; if (compilation.TypeSystemContext.HasLazyStaticConstructor(target)) { importer.OutputCodeForTriggerCctor(target, resVar); } } break; case ReadyToRunHelperId.GetGCStaticBase: { MetadataType target = (MetadataType)node.Target; var ptrPtrPtr = builder.BuildBitCast(resVar, LLVMTypeRef.CreatePointer(LLVMTypeRef.CreatePointer(LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0), 0), 0), "ptrPtrPtr"); resVar = builder.BuildLoad(builder.BuildLoad(ptrPtrPtr, "ind1"), "ind2"); if (compilation.TypeSystemContext.HasLazyStaticConstructor(target)) { GenericLookupResult nonGcRegionLookup = factory.GenericLookup.TypeNonGCStaticBase(target); var nonGcStaticsBase = OutputCodeForDictionaryLookup(builder, factory, node, nonGcRegionLookup, ctx, "lazyGep"); importer.OutputCodeForTriggerCctor(target, nonGcStaticsBase); } } break; case ReadyToRunHelperId.GetThreadStaticBase: { MetadataType target = (MetadataType)node.Target; if (compilation.TypeSystemContext.HasLazyStaticConstructor(target)) { GenericLookupResult nonGcRegionLookup = factory.GenericLookup.TypeNonGCStaticBase(target); var threadStaticBase = OutputCodeForDictionaryLookup(builder, factory, node, nonGcRegionLookup, ctx, "tsGep"); importer.OutputCodeForTriggerCctor(target, threadStaticBase); } resVar = importer.OutputCodeForGetThreadStaticBaseForType(resVar).ValueAsType(LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0), builder); } break; case ReadyToRunHelperId.DelegateCtor: { DelegateCreationInfo target = (DelegateCreationInfo)node.Target; MethodDesc constructor = target.Constructor.Method; var fatPtr = ILImporter.MakeFatPointer(builder, resVar, compilation); importer.OutputCodeForDelegateCtorInit(builder, helperFunc, constructor, fatPtr); } break; // These are all simple: just get the thing from the dictionary and we're done case ReadyToRunHelperId.TypeHandle: case ReadyToRunHelperId.MethodHandle: case ReadyToRunHelperId.FieldHandle: case ReadyToRunHelperId.MethodDictionary: case ReadyToRunHelperId.MethodEntry: case ReadyToRunHelperId.VirtualDispatchCell: case ReadyToRunHelperId.DefaultConstructor: break; default: throw new NotImplementedException(); } if (node.Id != ReadyToRunHelperId.DelegateCtor) { builder.BuildRet(resVar); } else { builder.BuildRetVoid(); } }
public static extern LLVMValueRef* BuildLandingPad(LLVMBuilderRef* B, LLVMTypeRef* Ty, LLVMValueRef* PersFn, uint NumClauses, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
private void AddEntryPoint(ClassManager classManager, CompileStatus status, LLVMContextRef context, LLVMModuleRef module, LLVMBuilderRef builder) { LLVMTypeRef functionType = LLVM.FunctionType(LLVM.Int32TypeInContext(context), new LLVMTypeRef[] { }, false); LLVMValueRef functionValue = LLVM.AddFunction(module, "main", functionType); LLVMBasicBlockRef blockValue = LLVM.AppendBasicBlockInContext(context, functionValue, "entry"); LLVM.PositionBuilderAtEnd(builder, blockValue); LLVMValueRef intRet = LLVM.ConstInt(LLVM.Int32Type(), 0, false); if (classManager.MainFunctionFullNames.Count < 1) { status.AddError(new CompilerError("", 0, 0, "No main functions found in the program")); } else if (classManager.MainFunctionFullNames.Count > 1) { status.AddError(new CompilerError("", 0, 0, "Multiple main functions found in the program: " + String.Join(",", classManager.MainFunctionFullNames))); } else { LLVMValueRef functionToCall = LLVM.GetNamedFunction(module, classManager.MainFunctionFullNames.First()); LLVMValueRef intOrIntMappedTypeRet = LLVM.BuildCall(builder, functionToCall, new LLVMValueRef[0], "entryPointCall"); LLVMTypeRef returnType = LLVM.TypeOf(intOrIntMappedTypeRet); if (returnType.TypeKind == LLVMTypeKind.LLVMIntegerTypeKind && returnType.GetIntTypeWidth() == 32) { intRet = intOrIntMappedTypeRet; } else { LLVMValueRef intMappedTypeRetPtr = LLVM.BuildAlloca(builder, LLVM.TypeOf(intOrIntMappedTypeRet), "intMappedType"); LLVM.BuildStore(builder, intOrIntMappedTypeRet, intMappedTypeRetPtr); //Extract the first field to get the int value from the mapped type //See rawtypemap for more details LLVMValueRef fieldPtr = LLVM.BuildStructGEP(builder, intMappedTypeRetPtr, 0, "returnIntFieldPtr"); intRet = LLVM.BuildLoad(builder, fieldPtr, "returnValue"); } } LLVM.BuildRet(builder, intRet); }
public static extern LLVMValueRef* BuildNUWNeg(LLVMBuilderRef* B, LLVMValueRef* V, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
internal static LLVMValueRef MakeFatPointer(LLVMBuilderRef builder, LLVMValueRef targetLlvmFunction, WebAssemblyCodegenCompilation compilation) { var asInt = builder.BuildPtrToInt(targetLlvmFunction, LLVMTypeRef.Int32, "toInt"); return(builder.BuildBinOp(LLVMOpcode.LLVMOr, asInt, LLVMValueRef.CreateConstInt(LLVMTypeRef.Int32, (ulong)compilation.TypeSystemContext.Target.FatFunctionPointerOffset, false), "makeFat")); }
public static extern LLVMValueRef* BuildStore(LLVMBuilderRef* LLVMBuilderRef, LLVMValueRef* Val, LLVMValueRef* Ptr);
public LLVMHelper(LLVMBuilderRef builder) { _builder = builder; }
public static extern LLVMValueRef* BuildFPCast(LLVMBuilderRef* LLVMBuilderRef, LLVMValueRef* Val, LLVMTypeRef* DestTy, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
/// <summary> /// Creates a new query of the current warp size. /// </summary> /// <param name="builder">The current builder.</param> /// <returns>A value that represents the current warp size.</returns> private LLVMValueRef MakeWarpSize(LLVMBuilderRef builder) { return(BuildCall(builder, GetWarpSize.Value)); }
public static extern LLVMValueRef* BuildVAArg(LLVMBuilderRef* LLVMBuilderRef, LLVMValueRef* List, LLVMTypeRef* Ty, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
public void Process(MethodCompiler compiler, Instruction insn, LLVMBuilderRef builder) { var value = compiler.CurrentBasicBlock.GetState().StackPop(); LLVMValueRef result; TypeInfo typeInfo; Code code = insn.OpCode.Code; switch (code) { case Code.Conv_R4: result = ToFP(value, builder, LLVM.FloatType(), out typeInfo); break; case Code.Conv_R8: result = ToFP(value, builder, LLVM.DoubleType(), out typeInfo); break; case Code.Conv_I: result = ToSiInt(value, builder, compiler.TypeLookup.NativeInt, out typeInfo); break; case Code.Conv_I1: result = ToSiInt(value, builder, LLVM.Int8Type(), out typeInfo); break; case Code.Conv_I2: result = ToSiInt(value, builder, LLVM.Int16Type(), out typeInfo); break; case Code.Conv_I4: result = ToSiInt(value, builder, LLVM.Int32Type(), out typeInfo); break; case Code.Conv_I8: result = ToSiInt(value, builder, LLVM.Int64Type(), out typeInfo); break; case Code.Conv_U: result = ToUnInt(value, builder, compiler.TypeLookup.NativeInt, out typeInfo); break; case Code.Conv_U1: result = ToUnInt(value, builder, LLVM.Int8Type(), out typeInfo); break; case Code.Conv_U2: result = ToUnInt(value, builder, LLVM.Int16Type(), out typeInfo); break; case Code.Conv_U4: result = ToUnInt(value, builder, LLVM.Int32Type(), out typeInfo); break; case Code.Conv_U8: result = ToUnInt(value, builder, LLVM.Int64Type(), out typeInfo); break; default: throw new InvalidOperationException("Unexpected code " + code); } compiler.CurrentBasicBlock.GetState().StackPush(new EmulatedStateValue(result, typeInfo)); }
public static extern LLVMValueRef* BuildIsNotNull(LLVMBuilderRef* LLVMBuilderRef, LLVMValueRef* Val, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
public LLVMValueRef ValueAsType(LLVMTypeRef type, LLVMBuilderRef builder) { return(ValueAsTypeInternal(type, builder, Type != null && (Type.IsWellKnownType(WellKnownType.SByte) || Type.IsWellKnownType(WellKnownType.Int16)))); }
public static extern LLVMValueRef* BuildRet(LLVMBuilderRef* LLVMBuilderRef, LLVMValueRef* V);
public LLVMValueRef ValueAsType(TypeDesc type, LLVMBuilderRef builder) { return(ValueAsType(ILImporter.GetLLVMTypeForTypeDesc(type), builder)); }
public static extern LLVMValueRef* BuildBr(LLVMBuilderRef* LLVMBuilderRef, LLVMBasicBlockRef* Dest);
public LLVMValueRef ValueAsInt64(LLVMBuilderRef builder, bool signExtend) { return(ValueAsTypeInternal(LLVM.Int64Type(), builder, signExtend)); }
public static extern LLVMValueRef* BuildSwitch(LLVMBuilderRef* LLVMBuilderRef, LLVMValueRef* V, LLVMBasicBlockRef* Else, uint NumCases);
protected abstract LLVMValueRef ValueAsTypeInternal(LLVMTypeRef type, LLVMBuilderRef builder, bool signExtend);
public static extern LLVMValueRef* BuildInvoke(LLVMBuilderRef* LLVMBuilderRef, LLVMValueRef* Fn, System.IntPtr[] Args, uint NumArgs, LLVMBasicBlockRef* Then, LLVMBasicBlockRef* Catch, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
/// <summary> /// Add representation of current entry in <paramref name="builder"/>. /// </summary> /// <param name="builder">Generation buffer used for appending new content.</param> //public abstract void Append(CppGenerationBuffer builder); /// <summary> /// Create a new copy of current entry. /// </summary> /// <returns>A new instance of the same type as the current entry.</returns> public abstract StackEntry Duplicate(LLVMBuilderRef builder);
public static extern LLVMValueRef* BuildResume(LLVMBuilderRef* B, LLVMValueRef* Exn);
protected override LLVMValueRef ValueAsTypeInternal(LLVMTypeRef type, LLVMBuilderRef builder, bool signExtend) { return(LLVM.ConstReal(type, Value)); }
public static extern LLVMValueRef* BuildBinOp(LLVMBuilderRef* B, LLVMOpcode Op, LLVMValueRef* LHS, LLVMValueRef* RHS, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
public override StackEntry Duplicate(LLVMBuilderRef builder) { return(new FloatConstantEntry(Value, Type)); }
public static extern LLVMValueRef* BuildArrayAlloca(LLVMBuilderRef* LLVMBuilderRef, LLVMTypeRef* Ty, LLVMValueRef* Val, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
public override StackEntry Duplicate(LLVMBuilderRef builder) { return(new ExpressionEntry(Kind, "duplicate_" + Name, ILImporter.LoadValue(builder, RawLLVMValue, Type, ILImporter.GetLLVMTypeForTypeDesc(Type), false, "load_duplicate_" + Name), Type)); }
public static extern LLVMValueRef* BuildLoad(LLVMBuilderRef* LLVMBuilderRef, LLVMValueRef* PointerVal, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
protected override LLVMValueRef ValueAsTypeInternal(LLVMTypeRef type, LLVMBuilderRef builder, bool signExtend) { return(ILImporter.LoadValue(builder, RawLLVMValue, Type, type, signExtend, $"Load{Name}")); }
public static extern LLVMValueRef* BuildInBoundsGEP(LLVMBuilderRef* B, LLVMValueRef* Pointer, System.IntPtr[] Indices, uint NumIndices, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
public override StackEntry Duplicate(LLVMBuilderRef builder) { return(new AddressExpressionEntry(Kind, Name, RawLLVMValue, Type)); }
public static extern LLVMValueRef* BuildGlobalStringPtr(LLVMBuilderRef* B, [In][MarshalAs(UnmanagedType.LPStr)] string Str, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
protected override LLVMValueRef ValueAsTypeInternal(LLVMTypeRef type, LLVMBuilderRef builder, bool signExtend) { return(ILImporter.CastIfNecessary(builder, RawLLVMValue, type, Name)); }
public static extern LLVMValueRef* BuildFCmp(LLVMBuilderRef* LLVMBuilderRef, LLVMRealPredicate Op, LLVMValueRef* LHS, LLVMValueRef* RHS, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
public override StackEntry Duplicate(LLVMBuilderRef builder) { return(new FunctionPointerEntry(Name, Method, RawLLVMValue, Type, IsVirtual)); }
public static extern LLVMValueRef* BuildSelect(LLVMBuilderRef* LLVMBuilderRef, LLVMValueRef* If, LLVMValueRef* Then, LLVMValueRef* Else, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
public override StackEntry Duplicate(LLVMBuilderRef builder) { return(new LdTokenEntry <T>(Kind, Name, LdToken, RawLLVMValue, Type)); }
public static extern LLVMValueRef* BuildInsertElement(LLVMBuilderRef* LLVMBuilderRef, LLVMValueRef* VecVal, LLVMValueRef* EltVal, LLVMValueRef* Index, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
public override StackEntry Duplicate(LLVMBuilderRef builder) { return(this); }
public static extern LLVMValueRef* BuildInsertValue(LLVMBuilderRef* LLVMBuilderRef, LLVMValueRef* AggVal, LLVMValueRef* EltVal, uint Index, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
public static extern LLVMValueRef* BuildRetVoid(LLVMBuilderRef* LLVMBuilderRef);
public static extern LLVMValueRef* BuildPtrDiff(LLVMBuilderRef* LLVMBuilderRef, LLVMValueRef* LHS, LLVMValueRef* RHS, [In][MarshalAs(UnmanagedType.LPStr)] string Name);
protected override LLVMValueRef ProcessIntegral(MethodCompiler compiler, LLVMValueRef lhs, LLVMValueRef rhs, LLVMBuilderRef builder) => LLVM.BuildMul(builder, lhs, rhs, string.Empty);