diff --git a/src/compiler/crystal/codegen/crystal_llvm_builder.cr b/src/compiler/crystal/codegen/crystal_llvm_builder.cr index 55ad6f49735a..9bf84dc25d7f 100644 --- a/src/compiler/crystal/codegen/crystal_llvm_builder.cr +++ b/src/compiler/crystal/codegen/crystal_llvm_builder.cr @@ -61,6 +61,14 @@ module Crystal @builder.build_operand_bundle_def(name, values) end + def current_debug_location_metadata + {% if LibLLVM::IS_LT_90 %} + LibLLVM.value_as_metadata LibLLVM.get_current_debug_location(@builder) + {% else %} + LibLLVM.get_current_debug_location2(@builder) + {% end %} + end + def to_unsafe @builder.to_unsafe end diff --git a/src/compiler/crystal/codegen/debug.cr b/src/compiler/crystal/codegen/debug.cr index df1b33b23bd8..f866e14e12f8 100644 --- a/src/compiler/crystal/codegen/debug.cr +++ b/src/compiler/crystal/codegen/debug.cr @@ -2,12 +2,18 @@ require "./codegen" module Crystal class CodeGenVisitor - CRYSTAL_LANG_DEBUG_IDENTIFIER = 0x28_u32 - # - # We have to use it because LLDB has builtin type system support for C++/clang that we can use for now for free. - # Later on we can implement LLDB Crystal type system so we can get official Language ID - # - CPP_LANG_DEBUG_IDENTIFIER = 0x0004_u32 + # workaround for `LLVM::Builder` not being GC'ed (#13250) + private class DIBuilder + def initialize(mod : LLVM::Module) + @builder = LLVM::DIBuilder.new(mod) + end + + def finalize + @builder.dispose + end + + forward_missing_to @builder + end record FunMetadata, filename : String, metadata : LibLLVM::MetadataRef @@ -20,13 +26,14 @@ module Crystal @debug_types_per_module = {} of LLVM::Module => Hash(Type, LibLLVM::MetadataRef?) def di_builder(llvm_module = @llvm_mod || @main_mod) - di_builders = @di_builders ||= {} of LLVM::Module => LLVM::DIBuilder - di_builders[llvm_module] ||= LLVM::DIBuilder.new(llvm_module).tap do |di_builder| + di_builders = @di_builders ||= {} of LLVM::Module => DIBuilder + di_builders[llvm_module] ||= DIBuilder.new(llvm_module).tap do |di_builder| file, dir = file_and_dir(llvm_module.name == "" ? "main" : llvm_module.name) # @debug.variables? is set to true if parameter --debug is set in command line. # This flag affects only debug variables generation. It sets Optimized parameter to false. is_optimised = !@debug.variables? - di_builder.create_compile_unit(CPP_LANG_DEBUG_IDENTIFIER, file, dir, "Crystal", is_optimised, "", 0_u32) + # TODO: switch to Crystal's language code for LLVM 16+ (#13174) + di_builder.create_compile_unit(LLVM::DwarfSourceLanguage::C_plus_plus, file, dir, "Crystal", is_optimised, "", 0_u32) end end @@ -66,8 +73,7 @@ module Crystal int = di_builder.create_basic_type("int", 32, 32, LLVM::DwarfTypeEncoding::Signed) debug_types << int end - debug_types_array = di_builder.get_or_create_type_array(debug_types) - di_builder.create_subroutine_type(nil, debug_types_array) + di_builder.create_subroutine_type(nil, debug_types) end def debug_type_cache @@ -141,7 +147,6 @@ module Crystal end di_builder.create_enumerator(name, value) end - elements = di_builder.get_or_create_array(elements) di_builder.create_enumeration_type(nil, original_type.to_s, nil, 1, 32, 32, elements, get_debug_type(type.base_type)) end @@ -165,11 +170,10 @@ module Crystal end size = @program.target_machine.data_layout.size_in_bits(struct_type) - elements = di_builder.get_or_create_type_array(element_types) if type.extern_union? - debug_type = di_builder.create_union_type(nil, original_type.to_s, current_debug_file, 1, size, size, LLVM::DIFlags::Zero, elements) + debug_type = di_builder.create_union_type(nil, original_type.to_s, current_debug_file, 1, size, size, LLVM::DIFlags::Zero, element_types) else - debug_type = di_builder.create_struct_type(nil, original_type.to_s, nil, 1, size, size, LLVM::DIFlags::Zero, nil, elements) + debug_type = di_builder.create_struct_type(nil, original_type.to_s, nil, 1, size, size, LLVM::DIFlags::Zero, nil, element_types) unless type.struct? debug_type = di_builder.create_pointer_type(debug_type, 8u64 * llvm_typer.pointer_size, 8u64 * llvm_typer.pointer_size, original_type.to_s) end @@ -206,12 +210,12 @@ module Crystal size = @program.target_machine.data_layout.size_in_bits(struct_type.struct_element_types[is_struct ? 0 : 1]) offset = @program.target_machine.data_layout.offset_of_element(struct_type, 1) * 8u64 - debug_type = di_builder.create_union_type(nil, nil, current_debug_file, 1, size, size, LLVM::DIFlags::Zero, di_builder.get_or_create_type_array(element_types)) + debug_type = di_builder.create_union_type(nil, "", current_debug_file, 1, size, size, LLVM::DIFlags::Zero, element_types) unless is_struct element_types.clear element_types << di_builder.create_member_type(nil, "type_id", nil, 1, 32, 32, 0, LLVM::DIFlags::Zero, get_debug_type(@program.uint32)) element_types << di_builder.create_member_type(nil, "union", nil, 1, size, size, offset, LLVM::DIFlags::Zero, debug_type) - debug_type = di_builder.create_struct_type(nil, original_type.to_s, nil, 1, struct_type_size, struct_type_size, LLVM::DIFlags::Zero, nil, di_builder.get_or_create_type_array(element_types)) + debug_type = di_builder.create_struct_type(nil, original_type.to_s, nil, 1, struct_type_size, struct_type_size, LLVM::DIFlags::Zero, nil, element_types) end di_builder.replace_temporary(tmp_debug_type, debug_type) debug_type @@ -234,7 +238,7 @@ module Crystal end size = @program.target_machine.data_layout.size_in_bits(struct_type) - debug_type = di_builder.create_union_type(nil, original_type.to_s, current_debug_file, 1, size, size, LLVM::DIFlags::Zero, di_builder.get_or_create_type_array(element_types)) + debug_type = di_builder.create_union_type(nil, original_type.to_s, current_debug_file, 1, size, size, LLVM::DIFlags::Zero, element_types) di_builder.replace_temporary(tmp_debug_type, debug_type) debug_type end @@ -274,7 +278,7 @@ module Crystal end size = @program.target_machine.data_layout.size_in_bits(struct_type) - debug_type = di_builder.create_struct_type(nil, original_type.to_s, nil, 1, size, size, LLVM::DIFlags::Zero, nil, di_builder.get_or_create_type_array(element_types)) + debug_type = di_builder.create_struct_type(nil, original_type.to_s, nil, 1, size, size, LLVM::DIFlags::Zero, nil, element_types) unless type.struct? debug_type = di_builder.create_pointer_type(debug_type, 8u64 * llvm_typer.pointer_size, 8u64 * llvm_typer.pointer_size, original_type.to_s) end @@ -302,7 +306,7 @@ module Crystal end size = @program.target_machine.data_layout.size_in_bits(struct_type) - debug_type = di_builder.create_struct_type(nil, original_type.to_s, nil, 1, size, size, LLVM::DIFlags::Zero, nil, di_builder.get_or_create_type_array(element_types)) + debug_type = di_builder.create_struct_type(nil, original_type.to_s, nil, 1, size, size, LLVM::DIFlags::Zero, nil, element_types) unless type.struct? debug_type = di_builder.create_pointer_type(debug_type, 8u64 * llvm_typer.pointer_size, 8u64 * llvm_typer.pointer_size, original_type.to_s) end @@ -370,7 +374,7 @@ module Crystal old_debug_location = @current_debug_location set_current_debug_location location if builder.current_debug_location != llvm_nil && (ptr = alloca) - di_builder.insert_declare_at_end(ptr, var, expr, builder.current_debug_location, block) + di_builder.insert_declare_at_end(ptr, var, expr, builder.current_debug_location_metadata, block) set_current_debug_location old_debug_location true else diff --git a/src/llvm/di_builder.cr b/src/llvm/di_builder.cr index 451594865689..1fca2301f1dd 100644 --- a/src/llvm/di_builder.cr +++ b/src/llvm/di_builder.cr @@ -1,122 +1,200 @@ require "./lib_llvm" struct LLVM::DIBuilder - def initialize(@llvm_module : Module) - @unwrap = LibLLVMExt.create_di_builder(llvm_module) + private DW_TAG_structure_type = 19 + + private def initialize(@unwrap : LibLLVM::DIBuilderRef, @llvm_module : Module) + end + + def self.new(mod : LLVM::Module) + new(LibLLVM.create_di_builder(mod), mod) + end + + def dispose + LibLLVM.dispose_di_builder(self) + end + + def create_compile_unit(lang : DwarfSourceLanguage, file, dir, producer, optimized, flags, runtime_version) + file = create_file(file, dir) + {% if LibLLVM::IS_LT_110 %} + LibLLVM.di_builder_create_compile_unit(self, + lang, file, producer, producer.bytesize, optimized ? 1 : 0, flags, flags.bytesize, runtime_version, + split_name: nil, split_name_len: 0, kind: LibLLVM::DWARFEmissionKind::Full, dwo_id: 0, + split_debug_inlining: 1, debug_info_for_profiling: 0, + ) + {% else %} + LibLLVM.di_builder_create_compile_unit(self, + lang, file, producer, producer.bytesize, optimized ? 1 : 0, flags, flags.bytesize, runtime_version, + split_name: nil, split_name_len: 0, kind: LibLLVM::DWARFEmissionKind::Full, dwo_id: 0, + split_debug_inlining: 1, debug_info_for_profiling: 0, sys_root: nil, sys_root_len: 0, sdk: nil, sdk_len: 0, + ) + {% end %} end - def create_compile_unit(lang, file, dir, producer, optimized, flags, runtime_version) - LibLLVMExt.di_builder_create_compile_unit(self, lang, file, dir, producer, optimized ? 1 : 0, flags, runtime_version) + @[Deprecated("Pass an `LLVM::DwarfSourceLanguage` for `lang` instead")] + def create_compile_unit(lang cpp_lang_code, file, dir, producer, optimized, flags, runtime_version) + # map the c++ values from `llvm::dwarf::SourceLanguage` to the c values from `LLVMDWARFSourceLanguage` + c_lang_code = + case cpp_lang_code + when 0x8001; DwarfSourceLanguage::Mips_Assembler + when 0x8e57; DwarfSourceLanguage::GOOGLE_RenderScript + when 0xb000; DwarfSourceLanguage::BORLAND_Delphi + else DwarfSourceLanguage.new(lang - 1) + end + + create_compile_unit(c_lang_code, file, dir, producer, optimized, flags, runtime_version) end def create_basic_type(name, size_in_bits, align_in_bits, encoding) - LibLLVMExt.di_builder_create_basic_type(self, name, size_in_bits, align_in_bits, encoding.value) + LibLLVM.di_builder_create_basic_type(self, name, name.bytesize, size_in_bits, encoding.value, DIFlags::Zero) end def get_or_create_type_array(types : Array(LibLLVM::MetadataRef)) - LibLLVMExt.di_builder_get_or_create_type_array(self, types, types.size) + LibLLVM.di_builder_get_or_create_type_array(self, types, types.size) end def create_subroutine_type(file, parameter_types) - LibLLVMExt.di_builder_create_subroutine_type(self, file, parameter_types) + LibLLVM.di_builder_create_subroutine_type(self, file, parameter_types, parameter_types.size, DIFlags::Zero) end def create_file(file, dir) - LibLLVMExt.di_builder_create_file(self, file, dir) + LibLLVM.di_builder_create_file(self, file, file.bytesize, dir, dir.bytesize) end def create_lexical_block(scope, file_scope, line, column) - LibLLVMExt.di_builder_create_lexical_block(self, scope, file_scope, line, column) + LibLLVM.di_builder_create_lexical_block(self, scope, file_scope, line, column) end def create_lexical_block_file(scope, file_scope, discriminator = 0) - LibLLVMExt.di_builder_create_lexical_block_file(self, scope, file_scope, discriminator) + LibLLVM.di_builder_create_lexical_block_file(self, scope, file_scope, discriminator) end def create_function(scope, name, linkage_name, file, line, composite_type, is_local_to_unit, is_definition, scope_line, flags, is_optimized, func) - LibLLVMExt.di_builder_create_function(self, scope, name, linkage_name, file, line, composite_type, - is_local_to_unit, is_definition, scope_line, flags, is_optimized, func) + sub = LibLLVM.di_builder_create_function(self, scope, name, name.bytesize, + linkage_name, linkage_name.bytesize, file, line, composite_type, is_local_to_unit ? 1 : 0, + is_definition ? 1 : 0, scope_line, flags, is_optimized ? 1 : 0) + LibLLVM.set_subprogram(func, sub) + sub end def create_auto_variable(scope, name, file, line, type, align_in_bits, flags = DIFlags::Zero) - LibLLVMExt.di_builder_create_auto_variable(self, scope, name, file, line, type, 1, flags, align_in_bits) + LibLLVM.di_builder_create_auto_variable(self, scope, name, name.bytesize, file, line, type, 1, flags, align_in_bits) end def create_parameter_variable(scope, name, argno, file, line, type, flags = DIFlags::Zero) - LibLLVMExt.di_builder_create_parameter_variable(self, scope, name, argno, file, line, type, 1, flags) + LibLLVM.di_builder_create_parameter_variable(self, scope, name, name.bytesize, argno, file, line, type, 1, flags) end def create_expression(addr, length) - LibLLVMExt.di_builder_create_expression(self, addr, length) + LibLLVM.di_builder_create_expression(self, addr, length) end - def insert_declare_at_end(storage, var_info, expr, dl, block) - LibLLVMExt.di_builder_insert_declare_at_end(self, storage, var_info, expr, dl, block) + def insert_declare_at_end(storage, var_info, expr, dl : LibLLVM::MetadataRef, block) + LibLLVM.di_builder_insert_declare_at_end(self, storage, var_info, expr, dl, block) end def get_or_create_array(elements : Array(LibLLVM::MetadataRef)) - LibLLVMExt.di_builder_get_or_create_array(self, elements, elements.size) + LibLLVM.di_builder_get_or_create_array(self, elements, elements.size) end def create_enumerator(name, value) - LibLLVMExt.di_builder_create_enumerator(self, name, value) + {% if LibLLVM::IS_LT_90 %} + LibLLVMExt.di_builder_create_enumerator(self, name, value) + {% else %} + LibLLVM.di_builder_create_enumerator(self, name, name.bytesize, value, 0) + {% end %} end def create_enumeration_type(scope, name, file, line_number, size_in_bits, align_in_bits, elements, underlying_type) - LibLLVMExt.di_builder_create_enumeration_type(self, scope, name, file, line_number, size_in_bits, - align_in_bits, elements, underlying_type) + LibLLVM.di_builder_create_enumeration_type(self, scope, name, name.bytesize, file, line_number, + size_in_bits, align_in_bits, elements, elements.size, underlying_type) end def create_struct_type(scope, name, file, line, size_in_bits, align_in_bits, flags, derived_from, element_types) - LibLLVMExt.di_builder_create_struct_type(self, scope, name, file, line, size_in_bits, align_in_bits, - flags, derived_from, element_types) + LibLLVM.di_builder_create_struct_type(self, scope, name, name.bytesize, file, line, + size_in_bits, align_in_bits, flags, derived_from, element_types, element_types.size, 0, nil, nil, 0) end def create_union_type(scope, name, file, line, size_in_bits, align_in_bits, flags, element_types) - LibLLVMExt.di_builder_create_union_type(self, scope, name, file, line, size_in_bits, align_in_bits, - flags, element_types) + LibLLVM.di_builder_create_union_type(self, scope, name, name.bytesize, file, line, + size_in_bits, align_in_bits, flags, element_types, element_types.size, 0, nil, 0) end def create_array_type(size_in_bits, align_in_bits, type, subs) - elements = self.get_or_create_array(subs) - LibLLVMExt.di_builder_create_array_type(self, size_in_bits, align_in_bits, type, elements) + LibLLVM.di_builder_create_array_type(self, size_in_bits, align_in_bits, type, subs, subs.size) end def create_member_type(scope, name, file, line, size_in_bits, align_in_bits, offset_in_bits, flags, ty) - LibLLVMExt.di_builder_create_member_type(self, scope, name, file, line, size_in_bits, align_in_bits, + LibLLVM.di_builder_create_member_type(self, scope, name, name.bytesize, file, line, size_in_bits, align_in_bits, offset_in_bits, flags, ty) end def create_pointer_type(pointee, size_in_bits, align_in_bits, name) - LibLLVMExt.di_builder_create_pointer_type(self, pointee, size_in_bits, align_in_bits, name) + LibLLVM.di_builder_create_pointer_type(self, pointee, size_in_bits, align_in_bits, 0, name, name.bytesize) end def create_replaceable_composite_type(scope, name, file, line) - LibLLVMExt.di_builder_create_replaceable_composite_type(self, scope, name, file, line) + LibLLVM.di_builder_create_replaceable_composite_type(self, DW_TAG_structure_type, name, name.bytesize, + scope, file, line, 0, 0, 0, DIFlags::FwdDecl, nil, 0) end def replace_temporary(from, to) - LibLLVMExt.di_builder_replace_temporary(self, from, to) + LibLLVM.metadata_replace_all_uses_with(from, to) end def create_unspecified_type(name : String) - LibLLVMExt.di_builder_create_unspecified_type(self, name, name.size) + LibLLVM.di_builder_create_unspecified_type(self, name, name.bytesize) end def get_or_create_array_subrange(lo, count) - LibLLVMExt.di_builder_get_or_create_array_subrange(self, lo, count) - end - - def create_reference_type(debug_type) - LibLLVM.di_builder_create_reference_type(self, 16, debug_type) # 16 is the code for DW_TAG_reference_type + LibLLVM.di_builder_get_or_create_subrange(self, lo, count) end def end - LibLLVMExt.di_builder_finalize(self) + LibLLVM.di_builder_finalize(self) end def to_unsafe @unwrap end + + @[Deprecated("Use a `LibLLVM::MetadataRef` for `dl` instead")] + def insert_declare_at_end(storage, var_info, expr, dl : LibLLVM::ValueRef | LLVM::Value, block) + dl = dl.to_unsafe unless dl.is_a?(LibLLVM::ValueRef) + insert_declare_at_end(storage, var_info, expr, LibLLVM.value_as_metadata(dl), block) + end + + @[Deprecated("Pass an array for `parameter_types` directly")] + def create_subroutine_type(file, parameter_types : LibLLVM::MetadataRef) + create_subroutine_type(file, extract_metadata_array(parameter_types)) + end + + @[Deprecated("Pass an array for `elements` directly")] + def create_enumeration_type(scope, name, file, line_number, size_in_bits, align_in_bits, elements : LibLLVM::MetadataRef, underlying_type) + create_enumeration_type(scope, name, file, line_number, size_in_bits, align_in_bits, extract_metadata_array(elements), underlying_type) + end + + @[Deprecated("Pass an array for `element_types` directly")] + def create_struct_type(scope, name, file, line, size_in_bits, align_in_bits, flags, derived_from, element_types : LibLLVM::MetadataRef) + create_struct_type(scope, name, file, line, size_in_bits, align_in_bits, flags, derived_from, extract_metadata_array(element_types)) + end + + @[Deprecated("Pass an array for `element_types` directly")] + def create_union_type(scope, name, file, line, size_in_bits, align_in_bits, flags, element_types : LibLLVM::MetadataRef) + create_union_type(scope, name, file, line, size_in_bits, align_in_bits, flags, extract_metadata_array(element_types)) + end + + @[Deprecated("Pass an array for `subs` directly")] + def create_array_type(size_in_bits, align_in_bits, type, subs : LibLLVM::MetadataRef) + create_array_type(size_in_bits, align_in_bits, type, extract_metadata_array(subs)) + end + + private def extract_metadata_array(metadata : LibLLVM::MetadataRef) + metadata_as_value = LibLLVM.metadata_as_value(@llvm_module.context, metadata) + operand_count = LibLLVM.get_md_node_num_operands(metadata_as_value).to_i + operands = Pointer(LibLLVM::ValueRef).malloc(operand_count) + LibLLVM.get_md_node_operands(metadata_as_value, operands) + Slice.new(operand_count) { |i| LibLLVM.value_as_metadata(operands[i]) } + end end diff --git a/src/llvm/enums.cr b/src/llvm/enums.cr index 9c868fbdeb86..b8e06fb46f89 100644 --- a/src/llvm/enums.cr +++ b/src/llvm/enums.cr @@ -322,14 +322,87 @@ module LLVM HiUser = 0xff end + enum DwarfSourceLanguage + C89 + C + Ada83 + C_plus_plus + Cobol74 + Cobol85 + Fortran77 + Fortran90 + Pascal83 + Modula2 + + # New in DWARF v3: + + Java + C99 + Ada95 + Fortran95 + PLI + ObjC + ObjC_plus_plus + UPC + D + + # New in DWARF v4: + + Python + + # New in DWARF v5: + + OpenCL + Go + Modula3 + Haskell + C_plus_plus_03 + C_plus_plus_11 + OCaml + Rust + C11 + Swift + Julia + Dylan + C_plus_plus_14 + Fortran03 + Fortran08 + RenderScript + BLISS + + {% unless LibLLVM::IS_LT_160 %} + Kotlin + Zig + Crystal + C_plus_plus_17 + C_plus_plus_20 + C17 + Fortran18 + Ada2005 + Ada2012 + {% end %} + + # Vendor extensions: + + Mips_Assembler + GOOGLE_RenderScript + BORLAND_Delphi + end + enum DIFlags : UInt32 - Zero = 0 - Private = 1 - Protected = 2 - Public = 3 - FwdDecl = 1 << 2 - AppleBlock = 1 << 3 - BlockByrefStruct = 1 << 4 + Zero = 0 + Private = 1 + Protected = 2 + Public = 3 + FwdDecl = 1 << 2 + AppleBlock = 1 << 3 + + {% if LibLLVM::IS_LT_100 %} + BlockByrefStruct = 1 << 4 + {% else %} + ReservedBit4 = 1 << 4 + {% end %} + Virtual = 1 << 5 Artificial = 1 << 6 Explicit = 1 << 7 @@ -347,14 +420,24 @@ module LLVM IntroducedVirtual = 1 << 18 BitField = 1 << 19 NoReturn = 1 << 20 - MainSubprogram = 1 << 21 + + {% if LibLLVM::IS_LT_90 %} + MainSubprogram = 1 << 21 + {% end %} + PassByValue = 1 << 22 TypePassByReference = 1 << 23 EnumClass = 1 << 24 Thunk = 1 << 25 - NonTrivial = 1 << 26 - BigEndian = 1 << 27 - LittleEndian = 1 << 28 + + {% if LibLLVM::IS_LT_90 %} + Trivial = 1 << 26 + {% else %} + NonTrivial = 1 << 26 + {% end %} + + BigEndian = 1 << 27 + LittleEndian = 1 << 28 end struct Value diff --git a/src/llvm/ext/llvm_ext.cc b/src/llvm/ext/llvm_ext.cc index 77054025dad9..184f0b3d6e90 100644 --- a/src/llvm/ext/llvm_ext.cc +++ b/src/llvm/ext/llvm_ext.cc @@ -1,10 +1,6 @@ #include #include -#include -#include #include -#include -#include #include #include #include @@ -25,217 +21,20 @@ using namespace llvm; #include #include -typedef DIBuilder *DIBuilderRef; -#define DIArray DINodeArray template T *unwrapDIptr(LLVMMetadataRef v) { return (T *)(v ? unwrap(v) : NULL); } -#define DIDescriptor DIScope -#define unwrapDI unwrapDIptr - extern "C" { -LLVMDIBuilderRef LLVMExtNewDIBuilder(LLVMModuleRef mref) { - Module *m = unwrap(mref); - return wrap(new DIBuilder(*m)); -} - -LLVMMetadataRef LLVMExtDIBuilderCreateFile( - DIBuilderRef Dref, const char *File, const char *Dir) { - return wrap(Dref->createFile(File, Dir)); -} - -LLVMMetadataRef LLVMExtDIBuilderCreateCompileUnit( - DIBuilderRef Dref, unsigned Lang, const char *File, const char *Dir, - const char *Producer, int Optimized, const char *Flags, - unsigned RuntimeVersion) { - DIFile *F = Dref->createFile(File, Dir); - return wrap(Dref->createCompileUnit(Lang, F, Producer, Optimized, - Flags, RuntimeVersion)); -} - -LLVMMetadataRef LLVMExtDIBuilderCreateFunction( - DIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, - const char *LinkageName, LLVMMetadataRef File, unsigned Line, - LLVMMetadataRef CompositeType, bool IsLocalToUnit, bool IsDefinition, - unsigned ScopeLine, - DINode::DIFlags Flags, - bool IsOptimized, - LLVMValueRef Func) { - DISubprogram *Sub = Dref->createFunction( - unwrapDI(Scope), StringRef(Name), StringRef(LinkageName), unwrapDI(File), Line, - unwrapDI(CompositeType), - ScopeLine, Flags, DISubprogram::toSPFlags(IsLocalToUnit, IsDefinition, IsOptimized)); - unwrap(Func)->setSubprogram(Sub); - return wrap(Sub); -} - -LLVMMetadataRef LLVMExtDIBuilderCreateLexicalBlock( - DIBuilderRef Dref, LLVMMetadataRef Scope, LLVMMetadataRef File, - unsigned Line, unsigned Column) { - return wrap(Dref->createLexicalBlock(unwrapDI(Scope), - unwrapDI(File), Line, Column)); -} - -LLVMMetadataRef LLVMExtDIBuilderCreateBasicType( - DIBuilderRef Dref, const char *Name, uint64_t SizeInBits, - uint64_t AlignInBits, unsigned Encoding) { - return wrap(Dref->createBasicType(Name, SizeInBits, Encoding)); -} - -LLVMMetadataRef LLVMExtDIBuilderGetOrCreateTypeArray( - DIBuilderRef Dref, LLVMMetadataRef *Data, unsigned Length) { - Metadata **DataValue = unwrap(Data); - return wrap( - Dref->getOrCreateTypeArray(ArrayRef(DataValue, Length)) - .get()); -} - -LLVMMetadataRef LLVMExtDIBuilderGetOrCreateArray( - DIBuilderRef Dref, LLVMMetadataRef *Data, unsigned Length) { - Metadata **DataValue = unwrap(Data); - return wrap( - Dref->getOrCreateArray(ArrayRef(DataValue, Length)).get()); -} - -LLVMMetadataRef LLVMExtDIBuilderCreateSubroutineType( - DIBuilderRef Dref, LLVMMetadataRef File, LLVMMetadataRef ParameterTypes) { - DISubroutineType *CT = Dref->createSubroutineType(DITypeRefArray(unwrap(ParameterTypes))); - return wrap(CT); -} - -LLVMMetadataRef LLVMExtDIBuilderCreateAutoVariable( - DIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, - LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty, - int AlwaysPreserve, - DINode::DIFlags Flags, - uint32_t AlignInBits) { - DILocalVariable *V = Dref->createAutoVariable( - unwrapDI(Scope), Name, unwrapDI(File), Line, - unwrapDI(Ty), AlwaysPreserve, Flags, AlignInBits); - return wrap(V); -} - -LLVMMetadataRef LLVMExtDIBuilderCreateParameterVariable( - DIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, - unsigned ArgNo, LLVMMetadataRef File, unsigned Line, - LLVMMetadataRef Ty, int AlwaysPreserve, - DINode::DIFlags Flags - ) { - DILocalVariable *V = Dref->createParameterVariable - (unwrapDI(Scope), Name, ArgNo, unwrapDI(File), Line, - unwrapDI(Ty), AlwaysPreserve, Flags); - return wrap(V); -} - -LLVMValueRef LLVMExtDIBuilderInsertDeclareAtEnd( - DIBuilderRef Dref, LLVMValueRef Storage, LLVMMetadataRef VarInfo, - LLVMMetadataRef Expr, LLVMValueRef DL, LLVMBasicBlockRef Block) { - Instruction *Instr = - Dref->insertDeclare(unwrap(Storage), unwrap(VarInfo), - unwrapDI(Expr), - DebugLoc(cast(unwrap(DL)->getMetadata())), - unwrap(Block)); - return wrap(Instr); -} - -LLVMMetadataRef LLVMExtDIBuilderCreateExpression( - DIBuilderRef Dref, uint64_t *Addr, size_t Length) { - return wrap(Dref->createExpression(ArrayRef(Addr, Length))); -} - -LLVMMetadataRef LLVMExtDIBuilderCreateEnumerationType( - DIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, - LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, - uint64_t AlignInBits, LLVMMetadataRef Elements, - LLVMMetadataRef UnderlyingType) { - DICompositeType *enumType = Dref->createEnumerationType( - unwrapDI(Scope), Name, unwrapDI(File), LineNumber, - SizeInBits, AlignInBits, DINodeArray(unwrapDI(Elements)), - unwrapDI(UnderlyingType)); - return wrap(enumType); -} - +#if LLVM_VERSION_GE(9, 0) +#else LLVMMetadataRef LLVMExtDIBuilderCreateEnumerator( - DIBuilderRef Dref, const char *Name, int64_t Value) { - DIEnumerator *e = Dref->createEnumerator(Name, Value); + LLVMDIBuilderRef Dref, const char *Name, int64_t Value) { + DIEnumerator *e = unwrap(Dref)->createEnumerator(Name, Value); return wrap(e); } - -LLVMMetadataRef LLVMExtDIBuilderCreateStructType( - DIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, - LLVMMetadataRef File, unsigned Line, uint64_t SizeInBits, - uint64_t AlignInBits, - DINode::DIFlags Flags, - LLVMMetadataRef DerivedFrom, LLVMMetadataRef Elements) { - DICompositeType *CT = Dref->createStructType( - unwrapDI(Scope), Name, unwrapDI(File), Line, - SizeInBits, AlignInBits, Flags, unwrapDI(DerivedFrom), - DINodeArray(unwrapDI(Elements))); - return wrap(CT); -} - -LLVMMetadataRef LLVMExtDIBuilderCreateUnionType( - DIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, - LLVMMetadataRef File, unsigned Line, uint64_t SizeInBits, - uint64_t AlignInBits, - DINode::DIFlags Flags, - LLVMMetadataRef Elements) { - DICompositeType *CT = Dref->createUnionType( - unwrapDI(Scope), Name, unwrapDI(File), Line, - SizeInBits, AlignInBits, Flags, - DINodeArray(unwrapDI(Elements))); - return wrap(CT); -} - -LLVMMetadataRef LLVMExtDIBuilderCreateArrayType( - DIBuilderRef Dref, uint64_t Size, uint64_t AlignInBits, - LLVMMetadataRef Type, LLVMMetadataRef Subs) { - return wrap(Dref->createArrayType(Size, AlignInBits, unwrapDI(Type), DINodeArray(unwrapDI(Subs)))); -} - - -LLVMMetadataRef LLVMExtDIBuilderCreateReplaceableCompositeType( - DIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, - LLVMMetadataRef File, unsigned Line) { - DICompositeType *CT = Dref->createReplaceableCompositeType(llvm::dwarf::DW_TAG_structure_type, - Name, - unwrapDI(Scope), - unwrapDI(File), - Line); - return wrap(CT); -} - -void LLVMExtDIBuilderReplaceTemporary( - DIBuilderRef Dref, LLVMMetadataRef From, LLVMMetadataRef To) { - auto *Node = unwrap(From); - auto *Type = unwrap(To); - - llvm::TempMDNode fwd_decl(Node); - Dref->replaceTemporary(std::move(fwd_decl), Type); -} - -LLVMMetadataRef LLVMExtDIBuilderCreateMemberType( - DIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, LLVMMetadataRef File, - unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits, - DINode::DIFlags Flags, - LLVMMetadataRef Ty) { - DIDerivedType *DT = Dref->createMemberType( - unwrapDI(Scope), Name, unwrapDI(File), Line, - SizeInBits, AlignInBits, OffsetInBits, Flags, unwrapDI(Ty)); - return wrap(DT); -} - -LLVMMetadataRef LLVMExtDIBuilderCreatePointerType( - DIBuilderRef Dref, LLVMMetadataRef PointeeType, - uint64_t SizeInBits, uint64_t AlignInBits, const char *Name) { - DIDerivedType *T = Dref->createPointerType(unwrapDI(PointeeType), - SizeInBits, AlignInBits, - None, - Name); - return wrap(T); -} +#endif void LLVMExtSetCurrentDebugLocation( LLVMBuilderRef Bref, unsigned Line, unsigned Col, LLVMMetadataRef Scope, @@ -246,8 +45,8 @@ void LLVMExtSetCurrentDebugLocation( else unwrap(Bref)->SetCurrentDebugLocation( DILocation::get(unwrap(Scope)->getContext(), Line, Col, - unwrapDI(Scope), - unwrapDI(InlinedAt))); + unwrapDIptr(Scope), + unwrapDIptr(InlinedAt))); #else unwrap(Bref)->SetCurrentDebugLocation( DebugLoc::get(Line, Col, Scope ? unwrap(Scope) : nullptr, @@ -375,9 +174,4 @@ LLVMBool LLVMExtCreateMCJITCompilerForModule( return 1; } -LLVMMetadataRef LLVMExtDIBuilderGetOrCreateArraySubrange( - DIBuilderRef Dref, uint64_t Lo, - uint64_t Count) { - return wrap(Dref->getOrCreateSubrange(Lo, Count)); - } -} +} // extern "C" diff --git a/src/llvm/lib_llvm.cr b/src/llvm/lib_llvm.cr index 613a8cdd4a71..e4b1f5a9efbd 100644 --- a/src/llvm/lib_llvm.cr +++ b/src/llvm/lib_llvm.cr @@ -36,6 +36,7 @@ end IS_LT_130 = {{compare_versions(LibLLVM::VERSION, "13.0.0") < 0}} IS_LT_140 = {{compare_versions(LibLLVM::VERSION, "14.0.0") < 0}} IS_LT_150 = {{compare_versions(LibLLVM::VERSION, "15.0.0") < 0}} + IS_LT_160 = {{compare_versions(LibLLVM::VERSION, "16.0.0") < 0}} end {% end %} @@ -43,6 +44,7 @@ lib LibLLVM alias Char = LibC::Char alias Int = LibC::Int alias UInt = LibC::UInt + alias SizeT = LibC::SizeT type ContextRef = Void* type ModuleRef = Void* @@ -62,6 +64,7 @@ lib LibLLVM type MemoryBufferRef = Void* type PassBuilderOptionsRef = Void* type ErrorRef = Void* + type DIBuilderRef = Void* struct JITCompilerOptions opt_level : UInt32 @@ -75,11 +78,17 @@ lib LibLLVM Intel end - # `LLVMModuleFlagBehavior` (_not_ `LLVM::Module::ModFlagBehavior`, their values disagree) + # NOTE: the following C enums usually have different values from their C++ + # counterparts (e.g. `LLVMModuleFlagBehavior` v.s. `LLVM::Module::ModFlagBehavior`) + enum ModuleFlagBehavior Warning = 1 end + enum DWARFEmissionKind + Full = 1 + end + fun add_case = LLVMAddCase(switch : ValueRef, onval : ValueRef, dest : BasicBlockRef) fun add_clause = LLVMAddClause(lpad : ValueRef, clause_val : ValueRef) fun add_function = LLVMAddFunction(module : ModuleRef, name : UInt8*, type : TypeRef) : ValueRef @@ -180,6 +189,9 @@ lib LibLLVM fun generic_value_to_pointer = LLVMGenericValueToPointer(value : GenericValueRef) : Void* fun get_basic_block_name = LLVMGetBasicBlockName(basic_block : BasicBlockRef) : Char* fun get_current_debug_location = LLVMGetCurrentDebugLocation(builder : BuilderRef) : ValueRef + {% unless LibLLVM::IS_LT_90 %} + fun get_current_debug_location2 = LLVMGetCurrentDebugLocation2(builder : BuilderRef) : MetadataRef + {% end %} fun get_first_instruction = LLVMGetFirstInstruction(block : BasicBlockRef) : ValueRef fun get_first_target = LLVMGetFirstTarget : TargetRef fun get_first_basic_block = LLVMGetFirstBasicBlock(fn : ValueRef) : BasicBlockRef @@ -379,6 +391,7 @@ lib LibLLVM fun md_string_in_context = LLVMMDStringInContext(c : ContextRef, str : UInt8*, length : Int32) : ValueRef fun value_as_metadata = LLVMValueAsMetadata(val : ValueRef) : MetadataRef + fun metadata_as_value = LLVMMetadataAsValue(c : ContextRef, md : MetadataRef) : ValueRef fun append_basic_block_in_context = LLVMAppendBasicBlockInContext(ctx : ContextRef, fn : ValueRef, name : UInt8*) : BasicBlockRef fun create_builder_in_context = LLVMCreateBuilderInContext(c : ContextRef) : BuilderRef @@ -394,6 +407,9 @@ lib LibLLVM fun get_num_arg_operands = LLVMGetNumArgOperands(instr : ValueRef) : UInt fun get_arg_operand = LLVMGetArgOperand(val : ValueRef, index : UInt) : ValueRef + fun get_md_node_num_operands = LLVMGetMDNodeNumOperands(v : ValueRef) : UInt + fun get_md_node_operands = LLVMGetMDNodeOperands(v : ValueRef, dest : ValueRef*) + fun set_instr_param_alignment = LLVMSetInstrParamAlignment(instr : ValueRef, index : UInt, align : UInt) fun set_param_alignment = LLVMSetParamAlignment(arg : ValueRef, align : UInt) @@ -403,4 +419,121 @@ lib LibLLVM fun create_pass_builder_options = LLVMCreatePassBuilderOptions : PassBuilderOptionsRef fun dispose_pass_builder_options = LLVMDisposePassBuilderOptions(options : PassBuilderOptionsRef) {% end %} + + fun create_di_builder = LLVMCreateDIBuilder(m : ModuleRef) : DIBuilderRef + fun dispose_di_builder = LLVMDisposeDIBuilder(builder : DIBuilderRef) + fun di_builder_finalize = LLVMDIBuilderFinalize(builder : DIBuilderRef) + + {% if LibLLVM::IS_LT_110 %} + fun di_builder_create_compile_unit = LLVMDIBuilderCreateCompileUnit( + builder : DIBuilderRef, lang : LLVM::DwarfSourceLanguage, file_ref : MetadataRef, producer : Char*, + producer_len : SizeT, is_optimized : Int, flags : Char*, flags_len : SizeT, runtime_ver : UInt, + split_name : Char*, split_name_len : SizeT, kind : DWARFEmissionKind, dwo_id : UInt, + split_debug_inlining : Int, debug_info_for_profiling : Int + ) : MetadataRef + {% else %} + fun di_builder_create_compile_unit = LLVMDIBuilderCreateCompileUnit( + builder : DIBuilderRef, lang : LLVM::DwarfSourceLanguage, file_ref : MetadataRef, producer : Char*, + producer_len : SizeT, is_optimized : Int, flags : Char*, flags_len : SizeT, runtime_ver : UInt, + split_name : Char*, split_name_len : SizeT, kind : DWARFEmissionKind, dwo_id : UInt, + split_debug_inlining : Int, debug_info_for_profiling : Int, sys_root : Char*, + sys_root_len : SizeT, sdk : Char*, sdk_len : SizeT + ) : MetadataRef + {% end %} + + fun di_builder_create_file = LLVMDIBuilderCreateFile( + builder : DIBuilderRef, filename : Char*, filename_len : SizeT, + directory : Char*, directory_len : SizeT + ) : MetadataRef + + fun di_builder_create_function = LLVMDIBuilderCreateFunction( + builder : DIBuilderRef, scope : MetadataRef, name : Char*, name_len : SizeT, + linkage_name : Char*, linkage_name_len : SizeT, file : MetadataRef, line_no : UInt, + ty : MetadataRef, is_local_to_unit : Int, is_definition : Int, scope_line : UInt, + flags : LLVM::DIFlags, is_optimized : Int + ) : MetadataRef + + fun di_builder_create_lexical_block = LLVMDIBuilderCreateLexicalBlock( + builder : DIBuilderRef, scope : MetadataRef, file : MetadataRef, line : UInt, column : UInt + ) : MetadataRef + fun di_builder_create_lexical_block_file = LLVMDIBuilderCreateLexicalBlockFile( + builder : DIBuilderRef, scope : MetadataRef, file_scope : MetadataRef, discriminator : UInt + ) : MetadataRef + + {% unless LibLLVM::IS_LT_90 %} + fun di_builder_create_enumerator = LLVMDIBuilderCreateEnumerator( + builder : DIBuilderRef, name : Char*, name_len : SizeT, value : Int64, is_unsigned : Int + ) : MetadataRef + {% end %} + + fun di_builder_create_subroutine_type = LLVMDIBuilderCreateSubroutineType( + builder : DIBuilderRef, file : MetadataRef, parameter_types : MetadataRef*, + num_parameter_types : UInt, flags : LLVM::DIFlags + ) : MetadataRef + fun di_builder_create_enumeration_type = LLVMDIBuilderCreateEnumerationType( + builder : DIBuilderRef, scope : MetadataRef, name : Char*, name_len : SizeT, file : MetadataRef, + line_number : UInt, size_in_bits : UInt64, align_in_bits : UInt32, + elements : MetadataRef*, num_elements : UInt, class_ty : MetadataRef + ) : MetadataRef + fun di_builder_create_union_type = LLVMDIBuilderCreateUnionType( + builder : DIBuilderRef, scope : MetadataRef, name : Char*, name_len : SizeT, file : MetadataRef, + line_number : UInt, size_in_bits : UInt64, align_in_bits : UInt32, flags : LLVM::DIFlags, + elements : MetadataRef*, num_elements : UInt, run_time_lang : UInt, unique_id : Char*, unique_id_len : SizeT + ) : MetadataRef + fun di_builder_create_array_type = LLVMDIBuilderCreateArrayType( + builder : DIBuilderRef, size : UInt64, align_in_bits : UInt32, + ty : MetadataRef, subscripts : MetadataRef*, num_subscripts : UInt + ) : MetadataRef + fun di_builder_create_unspecified_type = LLVMDIBuilderCreateUnspecifiedType(builder : DIBuilderRef, name : Char*, name_len : SizeT) : MetadataRef + fun di_builder_create_basic_type = LLVMDIBuilderCreateBasicType( + builder : DIBuilderRef, name : Char*, name_len : SizeT, size_in_bits : UInt64, + encoding : UInt, flags : LLVM::DIFlags + ) : MetadataRef + fun di_builder_create_pointer_type = LLVMDIBuilderCreatePointerType( + builder : DIBuilderRef, pointee_ty : MetadataRef, size_in_bits : UInt64, align_in_bits : UInt32, + address_space : UInt, name : Char*, name_len : SizeT + ) : MetadataRef + fun di_builder_create_struct_type = LLVMDIBuilderCreateStructType( + builder : DIBuilderRef, scope : MetadataRef, name : Char*, name_len : SizeT, file : MetadataRef, + line_number : UInt, size_in_bits : UInt64, align_in_bits : UInt32, flags : LLVM::DIFlags, + derived_from : MetadataRef, elements : MetadataRef*, num_elements : UInt, + run_time_lang : UInt, v_table_holder : MetadataRef, unique_id : Char*, unique_id_len : SizeT + ) : MetadataRef + fun di_builder_create_member_type = LLVMDIBuilderCreateMemberType( + builder : DIBuilderRef, scope : MetadataRef, name : Char*, name_len : SizeT, file : MetadataRef, + line_no : UInt, size_in_bits : UInt64, align_in_bits : UInt32, offset_in_bits : UInt64, + flags : LLVM::DIFlags, ty : MetadataRef + ) : MetadataRef + fun di_builder_create_replaceable_composite_type = LLVMDIBuilderCreateReplaceableCompositeType( + builder : DIBuilderRef, tag : UInt, name : Char*, name_len : SizeT, scope : MetadataRef, + file : MetadataRef, line : UInt, runtime_lang : UInt, size_in_bits : UInt64, align_in_bits : UInt32, + flags : LLVM::DIFlags, unique_identifier : Char*, unique_identifier_len : SizeT + ) : MetadataRef + + fun di_builder_get_or_create_subrange = LLVMDIBuilderGetOrCreateSubrange(builder : DIBuilderRef, lo : Int64, count : Int64) : MetadataRef + fun di_builder_get_or_create_array = LLVMDIBuilderGetOrCreateArray(builder : DIBuilderRef, data : MetadataRef*, length : SizeT) : MetadataRef + fun di_builder_get_or_create_type_array = LLVMDIBuilderGetOrCreateTypeArray(builder : DIBuilderRef, types : MetadataRef*, length : SizeT) : MetadataRef + + {% if LibLLVM::IS_LT_140 %} + fun di_builder_create_expression = LLVMDIBuilderCreateExpression(builder : DIBuilderRef, addr : Int64*, length : SizeT) : MetadataRef + {% else %} + fun di_builder_create_expression = LLVMDIBuilderCreateExpression(builder : DIBuilderRef, addr : UInt64*, length : SizeT) : MetadataRef + {% end %} + + fun di_builder_insert_declare_at_end = LLVMDIBuilderInsertDeclareAtEnd( + builder : DIBuilderRef, storage : ValueRef, var_info : MetadataRef, + expr : MetadataRef, debug_loc : MetadataRef, block : BasicBlockRef + ) : ValueRef + + fun di_builder_create_auto_variable = LLVMDIBuilderCreateAutoVariable( + builder : DIBuilderRef, scope : MetadataRef, name : Char*, name_len : SizeT, file : MetadataRef, + line_no : UInt, ty : MetadataRef, always_preserve : Int, flags : LLVM::DIFlags, align_in_bits : UInt32 + ) : MetadataRef + fun di_builder_create_parameter_variable = LLVMDIBuilderCreateParameterVariable( + builder : DIBuilderRef, scope : MetadataRef, name : Char*, name_len : SizeT, arg_no : UInt, + file : MetadataRef, line_no : UInt, ty : MetadataRef, always_preserve : Int, flags : LLVM::DIFlags + ) : MetadataRef + + fun set_subprogram = LLVMSetSubprogram(func : ValueRef, sp : MetadataRef) + fun metadata_replace_all_uses_with = LLVMMetadataReplaceAllUsesWith(target_metadata : MetadataRef, replacement : MetadataRef) end diff --git a/src/llvm/lib_llvm_ext.cr b/src/llvm/lib_llvm_ext.cr index c99656f5e81c..b1f30763ab9e 100644 --- a/src/llvm/lib_llvm_ext.cr +++ b/src/llvm/lib_llvm_ext.cr @@ -8,112 +8,12 @@ lib LibLLVMExt alias Char = LibC::Char alias Int = LibC::Int alias UInt = LibC::UInt - alias SizeT = LibC::SizeT - type DIBuilder = Void* type OperandBundleDefRef = Void* - fun create_di_builder = LLVMExtNewDIBuilder(LibLLVM::ModuleRef) : DIBuilder - fun di_builder_finalize = LLVMDIBuilderFinalize(DIBuilder) - - fun di_builder_create_function = LLVMExtDIBuilderCreateFunction( - builder : DIBuilder, scope : LibLLVM::MetadataRef, name : Char*, - linkage_name : Char*, file : LibLLVM::MetadataRef, line : UInt, - composite_type : LibLLVM::MetadataRef, is_local_to_unit : Bool, is_definition : Bool, - scope_line : UInt, flags : LLVM::DIFlags, is_optimized : Bool, func : LibLLVM::ValueRef - ) : LibLLVM::MetadataRef - - fun di_builder_create_file = LLVMExtDIBuilderCreateFile(builder : DIBuilder, file : Char*, dir : Char*) : LibLLVM::MetadataRef - fun di_builder_create_compile_unit = LLVMExtDIBuilderCreateCompileUnit(builder : DIBuilder, - lang : UInt, file : Char*, - dir : Char*, - producer : Char*, - optimized : Int, flags : Char*, - runtime_version : UInt) : LibLLVM::MetadataRef - fun di_builder_create_lexical_block = LLVMExtDIBuilderCreateLexicalBlock(builder : DIBuilder, - scope : LibLLVM::MetadataRef, - file : LibLLVM::MetadataRef, - line : Int, - column : Int) : LibLLVM::MetadataRef - - fun di_builder_create_basic_type = LLVMExtDIBuilderCreateBasicType(builder : DIBuilder, - name : Char*, - size_in_bits : UInt64, - align_in_bits : UInt64, - encoding : UInt) : LibLLVM::MetadataRef - - fun di_builder_create_auto_variable = LLVMExtDIBuilderCreateAutoVariable(builder : DIBuilder, - scope : LibLLVM::MetadataRef, - name : Char*, - file : LibLLVM::MetadataRef, line : UInt, - type : LibLLVM::MetadataRef, - always_preserve : Int, - flags : LLVM::DIFlags, - align_in_bits : UInt32) : LibLLVM::MetadataRef - - fun di_builder_create_parameter_variable = LLVMExtDIBuilderCreateParameterVariable(builder : DIBuilder, - scope : LibLLVM::MetadataRef, - name : Char*, arg_no : UInt, - file : LibLLVM::MetadataRef, line : UInt, type : LibLLVM::MetadataRef, - always_preserve : Int, flags : LLVM::DIFlags) : LibLLVM::MetadataRef - - fun di_builder_insert_declare_at_end = LLVMExtDIBuilderInsertDeclareAtEnd(builder : DIBuilder, - storage : LibLLVM::ValueRef, - var_info : LibLLVM::MetadataRef, - expr : LibLLVM::MetadataRef, - dl : LibLLVM::ValueRef, - block : LibLLVM::BasicBlockRef) : LibLLVM::ValueRef - - fun di_builder_create_expression = LLVMExtDIBuilderCreateExpression(builder : DIBuilder, - addr : UInt64*, length : SizeT) : LibLLVM::MetadataRef - - fun di_builder_get_or_create_array = LLVMExtDIBuilderGetOrCreateArray(builder : DIBuilder, data : LibLLVM::MetadataRef*, length : SizeT) : LibLLVM::MetadataRef - fun di_builder_create_enumerator = LLVMExtDIBuilderCreateEnumerator(builder : DIBuilder, name : Char*, value : Int64) : LibLLVM::MetadataRef - fun di_builder_create_enumeration_type = LLVMExtDIBuilderCreateEnumerationType(builder : DIBuilder, - scope : LibLLVM::MetadataRef, name : Char*, file : LibLLVM::MetadataRef, line_number : UInt, - size_in_bits : UInt64, align_in_bits : UInt64, elements : LibLLVM::MetadataRef, underlying_type : LibLLVM::MetadataRef) : LibLLVM::MetadataRef - - fun di_builder_get_or_create_type_array = LLVMExtDIBuilderGetOrCreateTypeArray(builder : DIBuilder, data : LibLLVM::MetadataRef*, length : SizeT) : LibLLVM::MetadataRef - fun di_builder_create_subroutine_type = LLVMExtDIBuilderCreateSubroutineType(builder : DIBuilder, file : LibLLVM::MetadataRef, parameter_types : LibLLVM::MetadataRef) : LibLLVM::MetadataRef - - fun di_builder_create_struct_type = LLVMExtDIBuilderCreateStructType(builder : DIBuilder, - scope : LibLLVM::MetadataRef, name : Char*, file : LibLLVM::MetadataRef, line : UInt, size_in_bits : UInt64, - align_in_bits : UInt64, flags : LLVM::DIFlags, derived_from : LibLLVM::MetadataRef, element_types : LibLLVM::MetadataRef) : LibLLVM::MetadataRef - - fun di_builder_create_union_type = LLVMExtDIBuilderCreateUnionType(builder : DIBuilder, - scope : LibLLVM::MetadataRef, name : Char*, file : LibLLVM::MetadataRef, line : UInt, size_in_bits : UInt64, - align_in_bits : UInt64, flags : LLVM::DIFlags, element_types : LibLLVM::MetadataRef) : LibLLVM::MetadataRef - - fun di_builder_create_array_type = LLVMExtDIBuilderCreateArrayType(builder : DIBuilder, size : UInt64, - alignInBits : UInt64, ty : LibLLVM::MetadataRef, - subscripts : LibLLVM::MetadataRef) : LibLLVM::MetadataRef - - fun di_builder_create_member_type = LLVMExtDIBuilderCreateMemberType(builder : DIBuilder, - scope : LibLLVM::MetadataRef, name : Char*, file : LibLLVM::MetadataRef, line : UInt, size_in_bits : UInt64, - align_in_bits : UInt64, offset_in_bits : UInt64, flags : LLVM::DIFlags, ty : LibLLVM::MetadataRef) : LibLLVM::MetadataRef - - fun di_builder_create_pointer_type = LLVMExtDIBuilderCreatePointerType(builder : DIBuilder, - pointee_type : LibLLVM::MetadataRef, - size_in_bits : UInt64, - align_in_bits : UInt64, - name : Char*) : LibLLVM::MetadataRef - - fun di_builder_create_replaceable_composite_type = LLVMExtDIBuilderCreateReplaceableCompositeType(builder : DIBuilder, - scope : LibLLVM::MetadataRef, - name : Char*, - file : LibLLVM::MetadataRef, - line : UInt) : LibLLVM::MetadataRef - - fun di_builder_create_unspecified_type = LLVMDIBuilderCreateUnspecifiedType(builder : LibLLVMExt::DIBuilder, - name : Void*, - size : LibC::SizeT) : LibLLVM::MetadataRef - - fun di_builder_create_lexical_block_file = LLVMDIBuilderCreateLexicalBlockFile(builder : LibLLVMExt::DIBuilder, - scope : LibLLVM::MetadataRef, - file_scope : LibLLVM::MetadataRef, - discriminator : UInt32) : LibLLVM::MetadataRef - - fun di_builder_replace_temporary = LLVMExtDIBuilderReplaceTemporary(builder : DIBuilder, from : LibLLVM::MetadataRef, to : LibLLVM::MetadataRef) + {% if LibLLVM::IS_LT_90 %} + fun di_builder_create_enumerator = LLVMExtDIBuilderCreateEnumerator(builder : LibLLVM::DIBuilderRef, name : Char*, value : Int64) : LibLLVM::MetadataRef + {% end %} fun set_current_debug_location = LLVMExtSetCurrentDebugLocation(LibLLVM::BuilderRef, Int, Int, LibLLVM::MetadataRef, LibLLVM::MetadataRef) @@ -134,8 +34,6 @@ lib LibLLVMExt fun write_bitcode_with_summary_to_file = LLVMExtWriteBitcodeWithSummaryToFile(module : LibLLVM::ModuleRef, path : UInt8*) : Void - fun di_builder_get_or_create_array_subrange = LLVMExtDIBuilderGetOrCreateArraySubrange(builder : DIBuilder, lo : UInt64, count : UInt64) : LibLLVM::MetadataRef - fun target_machine_enable_global_isel = LLVMExtTargetMachineEnableGlobalIsel(machine : LibLLVM::TargetMachineRef, enable : Bool) fun create_mc_jit_compiler_for_module = LLVMExtCreateMCJITCompilerForModule(jit : LibLLVM::ExecutionEngineRef*, m : LibLLVM::ModuleRef, options : LibLLVM::JITCompilerOptions*, options_length : UInt32, enable_global_isel : Bool, error : UInt8**) : Int32 end