From 715111e4217d0af4809b225fe6a32b6dc438ef1d Mon Sep 17 00:00:00 2001 From: JP Date: Wed, 10 Jul 2024 10:44:01 -0400 Subject: [PATCH 1/2] adding Fnc param + return attributes --- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 9 +++++++++ compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 5b94b80502109..4546a5b8b9d27 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -3,6 +3,8 @@ use rustc_ast::expand::autodiff_attrs::DiffActivity; +use crate::llvm::{LLVMRustAddFncParamAttr, LLVMRustAddRetAttr}; + use super::debuginfo::{ DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DILocation, DINameSpace, @@ -1022,6 +1024,13 @@ extern "C" { // EraseFromParent doesn't exist :( //pub fn LLVMEraseFromParent(BB: &BasicBlock) -> &Value; // Enzyme + pub fn LLVMRustAddFncParamAttr<'a>( + Instr: &'a Value, + index: c_uint, + Attr: &'a Attribute + ); + + pub fn LLVMRustAddRetAttr(V: &Value, attr: AttributeKind); pub fn LLVMRustRemoveFncAttr(V: &Value, attr: AttributeKind); pub fn LLVMRustHasDbgMetadata(I: &Value) -> bool; pub fn LLVMRustHasMetadata(I: &Value, KindID: c_uint) -> bool; diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index 078c8918939b0..8f17c26f10177 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -857,6 +857,20 @@ extern "C" void LLVMRustRemoveFncAttr(LLVMValueRef F, } } +extern "C" void LLVMRustAddFncParamAttr(LLVMValueRef F, unsigned i, + LLVMAttributeRef RustAttr) { + if (auto *Fn = dyn_cast(unwrap(F))) { + Fn->addParamAttr(i, unwrap(RustAttr)); + } +} + +extern "C" void LLVMRustAddRetFncAttr(LLVMValueRef F, + LLVMRustAttribute RustAttr) { + if (auto *Fn = dyn_cast(unwrap(F))) { + Fn->addRetAttr(fromRust(RustAttr)); + } +} + extern "C" LLVMMetadataRef LLVMRustDIGetInstMetadata(LLVMValueRef x) { if (auto *I = dyn_cast(unwrap(x))) { // auto *MD = I->getMetadata(LLVMContext::MD_dbg); From 788b2615b3cf86623be7f72e90c259e579066e7e Mon Sep 17 00:00:00 2001 From: JP Date: Wed, 10 Jul 2024 11:53:42 -0400 Subject: [PATCH 2/2] removing double definition --- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 4546a5b8b9d27..260e66d2ce92a 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -3,8 +3,6 @@ use rustc_ast::expand::autodiff_attrs::DiffActivity; -use crate::llvm::{LLVMRustAddFncParamAttr, LLVMRustAddRetAttr}; - use super::debuginfo::{ DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DILocation, DINameSpace,