239 lines · plain
1(*===-- llvm_target.mli - LLVM OCaml Interface -----------------*- OCaml -*-===*2 *3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4 * See https://llvm.org/LICENSE.txt for license information.5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6 *7 *===----------------------------------------------------------------------===*)8 9(** Target Information.10 11 This interface provides an OCaml API for LLVM target information,12 the classes in the Target library. *)13 14module Endian : sig15 type t =16 | Big17 | Little18end19 20module CodeGenOptLevel : sig21 type t =22 | None23 | Less24 | Default25 | Aggressive26end27 28module RelocMode : sig29 type t =30 | Default31 | Static32 | PIC33 | DynamicNoPIC34end35 36module CodeModel : sig37 type t =38 | Default39 | JITDefault40 | Small41 | Kernel42 | Medium43 | Large44end45 46module CodeGenFileType : sig47 type t =48 | AssemblyFile49 | ObjectFile50end51 52module GlobalISelAbortMode : sig53 type t =54 | Enable55 | Disable56 | DisableWithDiag57end58 59(** {6 Exceptions} *)60 61exception Error of string62 63(** {6 Data Layout} *)64 65module DataLayout : sig66 type t67 68 (** [of_string rep] parses the data layout string representation [rep].69 See the constructor [llvm::DataLayout::DataLayout]. *)70 val of_string : string -> t71 72 (** [as_string dl] is the string representation of the data layout [dl].73 See the method [llvm::DataLayout::getStringRepresentation]. *)74 val as_string : t -> string75 76 (** Returns the byte order of a target, either [Endian.Big] or77 [Endian.Little].78 See the method [llvm::DataLayout::isLittleEndian]. *)79 val byte_order : t -> Endian.t80 81 (** Returns the pointer size in bytes for a target.82 See the method [llvm::DataLayout::getPointerSize]. *)83 val pointer_size : t -> int84 85 (** Returns the integer type that is the same size as a pointer on a target.86 See the method [llvm::DataLayout::getIntPtrType]. *)87 val intptr_type : Llvm.llcontext -> t -> Llvm.lltype88 89 (** Returns the pointer size in bytes for a target in a given address space.90 See the method [llvm::DataLayout::getPointerSize]. *)91 val qualified_pointer_size : int -> t -> int92 93 (** Returns the integer type that is the same size as a pointer on a target94 in a given address space.95 See the method [llvm::DataLayout::getIntPtrType]. *)96 val qualified_intptr_type : Llvm.llcontext -> int -> t -> Llvm.lltype97 98 (** Computes the size of a type in bits for a target.99 See the method [llvm::DataLayout::getTypeSizeInBits]. *)100 val size_in_bits : Llvm.lltype -> t -> Int64.t101 102 (** Computes the storage size of a type in bytes for a target.103 See the method [llvm::DataLayout::getTypeStoreSize]. *)104 val store_size : Llvm.lltype -> t -> Int64.t105 106 (** Computes the ABI size of a type in bytes for a target.107 See the method [llvm::DataLayout::getTypeAllocSize]. *)108 val abi_size : Llvm.lltype -> t -> Int64.t109 110 (** Computes the ABI alignment of a type in bytes for a target.111 See the method [llvm::DataLayout::getTypeABISize]. *)112 val abi_align : Llvm.lltype -> t -> int113 114 (** Computes the call frame alignment of a type in bytes for a target.115 See the method [llvm::DataLayout::getTypeABISize]. *)116 val stack_align : Llvm.lltype -> t -> int117 118 (** Computes the preferred alignment of a type in bytes for a target.119 See the method [llvm::DataLayout::getTypeABISize]. *)120 val preferred_align : Llvm.lltype -> t -> int121 122 (** Computes the preferred alignment of a global variable in bytes for123 a target. See the method [llvm::DataLayout::getPreferredAlignment]. *)124 val preferred_align_of_global : Llvm.llvalue -> t -> int125 126 (** Computes the structure element that contains the byte offset for a target.127 See the method [llvm::StructLayout::getElementContainingOffset]. *)128 val element_at_offset : Llvm.lltype -> Int64.t -> t -> int129 130 (** Computes the byte offset of the indexed struct element for a target.131 See the method [llvm::StructLayout::getElementContainingOffset]. *)132 val offset_of_element : Llvm.lltype -> int -> t -> Int64.t133end134 135(** {6 Target} *)136 137module Target : sig138 type t139 140 (** [default_triple ()] returns the default target triple for current141 platform. *)142 val default_triple : unit -> string143 144 (** [first ()] returns the first target in the registered targets145 list, or [None]. *)146 val first : unit -> t option147 148 (** [succ t] returns the next target after [t], or [None]149 if [t] was the last target. *)150 val succ : t -> t option151 152 (** [all ()] returns a list of known targets. *)153 val all : unit -> t list154 155 (** [by_name name] returns [Some t] if a target [t] named [name] is156 registered, or [None] otherwise. *)157 val by_name : string -> t option158 159 (** [by_triple triple] returns a target for a triple [triple], or raises160 [Error] if [triple] does not correspond to a registered target. *)161 val by_triple : string -> t162 163 (** Returns the name of a target. See [llvm::Target::getName]. *)164 val name : t -> string165 166 (** Returns the description of a target.167 See [llvm::Target::getDescription]. *)168 val description : t -> string169 170 (** Returns [true] if the target has a JIT. *)171 val has_jit : t -> bool172 173 (** Returns [true] if the target has a target machine associated. *)174 val has_target_machine : t -> bool175 176 (** Returns [true] if the target has an ASM backend (required for177 emitting output). *)178 val has_asm_backend : t -> bool179end180 181(** {6 Target Machine} *)182 183module TargetMachine : sig184 type t185 186 (** Creates a new target machine.187 See [llvm::Target::createTargetMachine]. *)188 val create : triple:string -> ?cpu:string -> ?features:string ->189 ?level:CodeGenOptLevel.t -> ?reloc_mode:RelocMode.t ->190 ?code_model:CodeModel.t -> Target.t -> t191 192 (** Returns the Target used in a TargetMachine *)193 val target : t -> Target.t194 195 (** Returns the triple used while creating this target machine. See196 [llvm::TargetMachine::getTriple]. *)197 val triple : t -> string198 199 (** Returns the CPU used while creating this target machine. See200 [llvm::TargetMachine::getCPU]. *)201 val cpu : t -> string202 203 (** Returns the data layout of this target machine. *)204 val data_layout : t -> DataLayout.t205 206 (** Returns the feature string used while creating this target machine. See207 [llvm::TargetMachine::getFeatureString]. *)208 val features : t -> string209 210 (** Sets the assembly verbosity of this target machine.211 See [llvm::TargetMachine::setAsmVerbosity]. *)212 val set_verbose_asm : bool -> t -> unit213 214 (** Enable fast-path instruction selection.215 See [llvm::TargetMachine::setFastISel]. *)216 val set_fast_isel : bool -> t -> unit217 218 (** Enable global instruction selection.219 See [llvm::TargetMachine::setGlobalISel]. *)220 val set_global_isel : bool -> t -> unit221 222 (** Set abort behaviour when global instruction selection fails to lower/select an instruction.223 See [llvm::TargetMachine::setGlobalISelAbort]. *)224 val set_global_isel_abort : ?mode:GlobalISelAbortMode.t -> t -> unit225 226 (** Enable the MachineOutliner pass.227 See [llvm::TargetMachine::setMachineOutliner]. *)228 val set_machine_outliner : bool -> t -> unit229 230 (** Emits assembly or object data for the given module to the given231 file or raise [Error]. *)232 val emit_to_file : Llvm.llmodule -> CodeGenFileType.t -> string -> t -> unit233 234 (** Emits assembly or object data for the given module to a fresh memory235 buffer or raise [Error]. *)236 val emit_to_memory_buffer : Llvm.llmodule -> CodeGenFileType.t -> t ->237 Llvm.llmemorybuffer238end239