is_intrinsic
の機能を超えて、正式なLLVM OCamlバインディングでは、組み込み関数への参照が見つからないようです。LLVM OCamlバインディングには本質的なサポートが含まれていますか?
ターゲット固有のコード生成(SSE、AVX、およびNEON用)を実行する必要があるバックエンドを構築しており、組み込み関数はC++ APIの標準パスです。
is_intrinsic
の機能を超えて、正式なLLVM OCamlバインディングでは、組み込み関数への参照が見つからないようです。LLVM OCamlバインディングには本質的なサポートが含まれていますか?
ターゲット固有のコード生成(SSE、AVX、およびNEON用)を実行する必要があるバックエンドを構築しており、組み込み関数はC++ APIの標準パスです。
のOCamlバインディングC言語とまったく同じ方法でサポート組み込み関数を結合:
あり(フルC++インタフェースでありとして)インタフェースでそれらのための特別なサポートはありませんが、彼らは宣言することができます他の関数と同様に呼び出されます。
は、例えば:
open Llvm
let() =
let c = create_context() in
let f32_t = float_type c in
let f32x4_t = vector_type f32_t 4 in
let m = create_module c "test" in
(* declare void @printv(<4 x float>)
* nonce extern which forces preservation of vector results *)
let printv =
declare_function "printv"
(function_type (void_type c) [|f32x4_t|]) m in
(* declare <4 x float> @llvm.x86.sse.sqrt.ps(<4 x float>) nounwind readnone *)
let sqrtps =
declare_function "llvm.x86.sse.sqrt.ps"
(function_type f32x4_t [|f32x4_t|]) m in
(* define i32 @main() { entry: *)
let main = define_function "main" (function_type i32_t [| |]) m in
let at_entry = builder_at_end c (entry_block main) in
(*%sqrtps = call <4 x float> @llvm.x86.sse.sqrt.ps(<4 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00>)*)
let cv1234 = const_vector [| const_float f32_t 1.0; const_float f32_t 2.0;
const_float f32_t 3.0; const_float f32_t 4.0 |] in
let sqrt = build_call sqrtps [| cv1234 |] "sqrtps" at_entry in
(* call void printv(sqrtps) *)
ignore (build_call printv [| sqrt |] "" at_entry);
(* ret void *)
ignore (build_ret (const_null i32_t) at_entry);
(* Print .ll to stderr *)
dump_module m
が生成:正常xmm
レジスタにsqrtps
を呼び出すのx86にコンパイル
; ModuleID = 'test'
declare void @printv(<4 x float>)
declare <4 x float> @llvm.x86.sse.sqrt.ps(<4 x float>) nounwind readnone
define i32 @main() {
entry:
%sqrtps = call <4 x float> @llvm.x86.sse.sqrt.ps(<4 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00>)
call void @printv(<4 x float> %sqrtps)
ret i32 0
}
。
免責事項:私はLLVMを一度も使用しませんでした。バインディング文書を簡単に見てみると、答えは「いいえ」のように見えます。しかし、あなたのニーズに合っているかもしれないし、そうでないかもしれないインラインアセンブリーのサポートがあります。
最後に、OCamlバインディングが完全ではないということは、LLVM開発者によって受け入れられたようです:あなたが望むなら、いくつかの機能を追加することができます(OCamlに慣れていない場合はCバインディングは本当に最も簡単な部分ですが、LLVMバインディングは他のLLVM関数にうまく適応できるサンプルコードでいっぱいです)、LLVMdevリストにパッチを提供してください。