about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/llvm/mod.rs
diff options
context:
space:
mode:
authorThe rustc-dev-guide Cronjob Bot <github-actions@github.com>2025-06-19 04:07:39 +0000
committerThe rustc-dev-guide Cronjob Bot <github-actions@github.com>2025-06-19 04:07:39 +0000
commitd854d563445082268ca8e7dd76b6ccde0342c2b3 (patch)
tree59d2cbb81c6cf1bb95feb51963d037fd67fc51bf /compiler/rustc_codegen_llvm/src/llvm/mod.rs
parent48b36ee8ad3a2dc61e5ed1248621b4371bd1f147 (diff)
parentd1d8e386c5e84c4ba857f56c3291f73c27e2d62a (diff)
downloadrust-d854d563445082268ca8e7dd76b6ccde0342c2b3.tar.gz
rust-d854d563445082268ca8e7dd76b6ccde0342c2b3.zip
Merge from rustc
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/llvm/mod.rs')
-rw-r--r--compiler/rustc_codegen_llvm/src/llvm/mod.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_llvm/src/llvm/mod.rs b/compiler/rustc_codegen_llvm/src/llvm/mod.rs
index ed23f911930..661174a80df 100644
--- a/compiler/rustc_codegen_llvm/src/llvm/mod.rs
+++ b/compiler/rustc_codegen_llvm/src/llvm/mod.rs
@@ -1,6 +1,7 @@
 #![allow(non_snake_case)]
 
 use std::ffi::{CStr, CString};
+use std::num::NonZero;
 use std::ptr;
 use std::str::FromStr;
 use std::string::FromUtf8Error;
@@ -327,6 +328,28 @@ pub(crate) fn get_value_name(value: &Value) -> &[u8] {
     }
 }
 
+#[derive(Debug, Copy, Clone)]
+pub(crate) struct Intrinsic {
+    id: NonZero<c_uint>,
+}
+
+impl Intrinsic {
+    pub(crate) fn lookup(name: &[u8]) -> Option<Self> {
+        let id = unsafe { LLVMLookupIntrinsicID(name.as_c_char_ptr(), name.len()) };
+        NonZero::new(id).map(|id| Self { id })
+    }
+
+    pub(crate) fn get_declaration<'ll>(
+        self,
+        llmod: &'ll Module,
+        type_params: &[&'ll Type],
+    ) -> &'ll Value {
+        unsafe {
+            LLVMGetIntrinsicDeclaration(llmod, self.id, type_params.as_ptr(), type_params.len())
+        }
+    }
+}
+
 /// Safe wrapper for `LLVMSetValueName2` from a byte slice
 pub(crate) fn set_value_name(value: &Value, name: &[u8]) {
     unsafe {