Skip to content

Commit fe79fa8

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 79bf498 commit fe79fa8

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

src/librustc_codegen_llvm/builder.rs

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

792797
fn select(

src/librustc_codegen_llvm/context.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,6 @@ impl CodegenCx<'b, 'tcx> {
543543
t_v8f64: t_f64, 8;
544544
}
545545

546-
ifn!("llvm.memset.p0i8.i16", fn(i8p, t_i8, t_i16, t_i32, i1) -> void);
547-
ifn!("llvm.memset.p0i8.i32", fn(i8p, t_i8, t_i32, t_i32, i1) -> void);
548-
ifn!("llvm.memset.p0i8.i64", fn(i8p, t_i8, t_i64, t_i32, i1) -> void);
549-
550546
ifn!("llvm.trap", fn() -> void);
551547
ifn!("llvm.debugtrap", fn() -> void);
552548
ifn!("llvm.frameaddress", fn(t_i32) -> i8p);

src/librustc_codegen_llvm/llvm/ffi.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,14 @@ extern "C" {
13171317
Size: &'a Value,
13181318
IsVolatile: bool,
13191319
) -> &'a Value;
1320+
pub fn LLVMRustBuildMemSet(
1321+
B: &Builder<'a>,
1322+
Dst: &'a Value,
1323+
DstAlign: c_uint,
1324+
Val: &'a Value,
1325+
Size: &'a Value,
1326+
IsVolatile: bool,
1327+
) -> &'a Value;
13201328
pub fn LLVMBuildSelect(
13211329
B: &Builder<'a>,
13221330
If: &'a Value,

src/rustllvm/RustWrapper.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,14 @@ extern "C" LLVMValueRef LLVMRustBuildMemMove(LLVMBuilderRef B,
12691269
unwrap(Size), IsVolatile));
12701270
}
12711271

1272+
extern "C" LLVMValueRef LLVMRustBuildMemSet(LLVMBuilderRef B,
1273+
LLVMValueRef Dst, unsigned DstAlign,
1274+
LLVMValueRef Val,
1275+
LLVMValueRef Size, bool IsVolatile) {
1276+
return wrap(unwrap(B)->CreateMemSet(
1277+
unwrap(Dst), unwrap(Val), unwrap(Size), DstAlign, IsVolatile));
1278+
}
1279+
12721280
extern "C" LLVMValueRef
12731281
LLVMRustBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args,
12741282
unsigned NumArgs, LLVMBasicBlockRef Then,

0 commit comments

Comments
 (0)