Skip to content

Commit 03a73fa

Browse files
committed
Use IRBuilder to create memset
To avoid creating memsets with outdated signature. For some reason SROA chokes on this when using NewPM.
1 parent cd5441f commit 03a73fa

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

src/librustc_codegen_llvm/builder.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -781,13 +781,18 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
781781
align: Align,
782782
flags: MemFlags,
783783
) {
784-
let ptr_width = &self.sess().target.target.target_pointer_width;
785-
let intrinsic_key = format!("llvm.memset.p0i8.i{}", ptr_width);
786-
let llintrinsicfn = self.get_intrinsic(&intrinsic_key);
784+
let is_volatile = flags.contains(MemFlags::VOLATILE);
787785
let ptr = self.pointercast(ptr, self.type_i8p());
788-
let align = self.const_u32(align.bytes() as u32);
789-
let volatile = self.const_bool(flags.contains(MemFlags::VOLATILE));
790-
self.call(llintrinsicfn, &[ptr, fill_byte, size, align, volatile], None);
786+
unsafe {
787+
llvm::LLVMRustBuildMemSet(
788+
self.llbuilder,
789+
ptr,
790+
align.bytes() as c_uint,
791+
fill_byte,
792+
size,
793+
is_volatile,
794+
);
795+
}
791796
}
792797

793798
fn select(

src/librustc_codegen_llvm/context.rs

-4
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,6 @@ impl CodegenCx<'b, 'tcx> {
562562
t_v8f64: t_f64, 8;
563563
}
564564

565-
ifn!("llvm.memset.p0i8.i16", fn(i8p, t_i8, t_i16, t_i32, i1) -> void);
566-
ifn!("llvm.memset.p0i8.i32", fn(i8p, t_i8, t_i32, t_i32, i1) -> void);
567-
ifn!("llvm.memset.p0i8.i64", fn(i8p, t_i8, t_i64, t_i32, i1) -> void);
568-
569565
ifn!("llvm.trap", fn() -> void);
570566
ifn!("llvm.debugtrap", fn() -> void);
571567
ifn!("llvm.frameaddress", fn(t_i32) -> i8p);

src/librustc_codegen_llvm/llvm/ffi.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,14 @@ extern "C" {
13151315
Size: &'a Value,
13161316
IsVolatile: bool,
13171317
) -> &'a Value;
1318+
pub fn LLVMRustBuildMemSet(
1319+
B: &Builder<'a>,
1320+
Dst: &'a Value,
1321+
DstAlign: c_uint,
1322+
Val: &'a Value,
1323+
Size: &'a Value,
1324+
IsVolatile: bool,
1325+
) -> &'a Value;
13181326
pub fn LLVMBuildSelect(
13191327
B: &Builder<'a>,
13201328
If: &'a Value,

src/rustllvm/RustWrapper.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,14 @@ extern "C" LLVMValueRef LLVMRustBuildMemMove(LLVMBuilderRef B,
12961296
#endif
12971297
}
12981298

1299+
extern "C" LLVMValueRef LLVMRustBuildMemSet(LLVMBuilderRef B,
1300+
LLVMValueRef Dst, unsigned DstAlign,
1301+
LLVMValueRef Val,
1302+
LLVMValueRef Size, bool IsVolatile) {
1303+
return wrap(unwrap(B)->CreateMemSet(
1304+
unwrap(Dst), unwrap(Val), unwrap(Size), DstAlign, IsVolatile));
1305+
}
1306+
12991307
extern "C" LLVMValueRef
13001308
LLVMRustBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args,
13011309
unsigned NumArgs, LLVMBasicBlockRef Then,

0 commit comments

Comments
 (0)