[PATCH] D91514: Expose CastInst::getCastOpcode in C API
Jack Andersen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 15 20:26:41 PST 2020
jackoalan created this revision.
jackoalan added a reviewer: chandlerc.
Herald added a reviewer: deadalnix.
Herald added subscribers: llvm-commits, dexonsmith, hiraditya.
Herald added a project: LLVM.
jackoalan requested review of this revision.
Users of `LLVMBuildCast` currently need to implement their own logic to determine the best cast opcode. In cases where the source value and destination type is known, LLVM already has the `CastInst::getCastOpcode` function to determine the opcode based on type combinations.
This simply exposes the existing function to users of the C API.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91514
Files:
llvm/docs/ReleaseNotes.rst
llvm/include/llvm-c/Core.h
llvm/lib/IR/Core.cpp
Index: llvm/lib/IR/Core.cpp
===================================================================
--- llvm/lib/IR/Core.cpp
+++ llvm/lib/IR/Core.cpp
@@ -3837,6 +3837,12 @@
return wrap(unwrap(B)->CreateFPCast(unwrap(Val), unwrap(DestTy), Name));
}
+LLVMOpcode LLVMGetCastOpcode(LLVMValueRef Src, LLVMBool SrcIsSigned,
+ LLVMTypeRef DestTy, LLVMBool DestIsSigned) {
+ return map_to_llvmopcode(CastInst::getCastOpcode(
+ unwrap(Src), SrcIsSigned, unwrap(DestTy), DestIsSigned));
+}
+
/*--.. Comparisons .........................................................--*/
LLVMValueRef LLVMBuildICmp(LLVMBuilderRef B, LLVMIntPredicate Op,
Index: llvm/include/llvm-c/Core.h
===================================================================
--- llvm/include/llvm-c/Core.h
+++ llvm/include/llvm-c/Core.h
@@ -3892,6 +3892,9 @@
LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
LLVMTypeRef DestTy, const char *Name);
+LLVMOpcode LLVMGetCastOpcode(LLVMValueRef Src, LLVMBool SrcIsSigned,
+ LLVMTypeRef DestTy, LLVMBool DestIsSigned);
+
/* Comparisons */
LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
LLVMValueRef LHS, LLVMValueRef RHS,
Index: llvm/docs/ReleaseNotes.rst
===================================================================
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -156,6 +156,9 @@
Changes to the C API
--------------------
+* Add `LLVMGetCastOpcode` function to aid users of `LLVMBuildCast` resolve the
+ best cast operation given a source value and destination type.
+ This function is a direct wrapper of `CastInst::getCastOpcode`.
Changes to the Go bindings
--------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91514.305410.patch
Type: text/x-patch
Size: 1804 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201116/a51d783c/attachment.bin>
More information about the llvm-commits
mailing list