Skip to content

Commit f35f7ee

Browse files
committed
add and use generic get_const_int function
1 parent 7d3a1d4 commit f35f7ee

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

compiler/rustc_codegen_llvm/src/builder/autodiff.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn match_args_from_caller_to_enzyme<'ll>(
114114
let mul = unsafe {
115115
llvm::LLVMBuildMul(
116116
builder.llbuilder,
117-
cx.get_const_i64(elem_bytes_size),
117+
cx.get_const_int(cx.type_i64(), elem_bytes_size),
118118
next_outer_arg,
119119
UNNAMED,
120120
)
@@ -385,7 +385,7 @@ fn generate_enzyme_call<'ll>(
385385
if attrs.width > 1 {
386386
let enzyme_width = cx.create_metadata("enzyme_width".to_string()).unwrap();
387387
args.push(cx.get_metadata_value(enzyme_width));
388-
args.push(cx.get_const_i64(attrs.width as u64));
388+
args.push(cx.get_const_int(cx.type_i64(), attrs.width as u64));
389389
}
390390

391391
let has_sret = has_sret(outer_fn);

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,11 +678,10 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
678678
llvm::LLVMMetadataAsValue(self.llcx(), metadata)
679679
}
680680

681-
// FIXME(autodiff): We should split `ConstCodegenMethods` to pull the reusable parts
682-
// onto a trait that is also implemented for GenericCx.
683-
pub(crate) fn get_const_i64(&self, n: u64) -> &'ll Value {
684-
let ty = unsafe { llvm::LLVMInt64TypeInContext(self.llcx()) };
685-
unsafe { llvm::LLVMConstInt(ty, n, llvm::False) }
681+
pub(crate) fn get_const_int(&self, ty: &'ll Type, val: u64) -> &'ll Value {
682+
let num_bits = self.int_width(ty).try_into().expect("integer width is too large for u32");
683+
let ty = unsafe { llvm::LLVMIntTypeInContext(self.llcx(), num_bits) };
684+
unsafe { llvm::LLVMConstInt(ty, val, llvm::False) }
686685
}
687686

688687
pub(crate) fn get_function(&self, name: &str) -> Option<&'ll Value> {

0 commit comments

Comments
 (0)