Skip to content

Commit cd0476a

Browse files
committed
Add Builder::array_alloca.
1 parent 9f0168a commit cd0476a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/librustc_codegen_llvm/builder.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,25 @@ impl Builder<'a, 'll, 'tcx> {
445445
}
446446
}
447447

448+
pub fn array_alloca(&self,
449+
ty: &'ll Type,
450+
len: &'ll Value,
451+
name: &str,
452+
align: Align) -> &'ll Value {
453+
self.count_insn("alloca");
454+
unsafe {
455+
let alloca = if name.is_empty() {
456+
llvm::LLVMBuildArrayAlloca(self.llbuilder, ty, len, noname())
457+
} else {
458+
let name = SmallCStr::new(name);
459+
llvm::LLVMBuildArrayAlloca(self.llbuilder, ty, len,
460+
name.as_ptr())
461+
};
462+
llvm::LLVMSetAlignment(alloca, align.abi() as c_uint);
463+
alloca
464+
}
465+
}
466+
448467
pub fn load(&self, ptr: &'ll Value, align: Align) -> &'ll Value {
449468
self.count_insn("load");
450469
unsafe {

src/librustc_codegen_llvm/llvm/ffi.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,11 @@ extern "C" {
875875

876876
// Memory
877877
pub fn LLVMBuildAlloca(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
878+
pub fn LLVMBuildArrayAlloca(B: &Builder<'a>,
879+
Ty: &'a Type,
880+
Val: &'a Value,
881+
Name: *const c_char)
882+
-> &'a Value;
878883
pub fn LLVMBuildLoad(B: &Builder<'a>, PointerVal: &'a Value, Name: *const c_char) -> &'a Value;
879884

880885
pub fn LLVMBuildStore(B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value) -> &'a Value;

0 commit comments

Comments
 (0)