]> git.lizzy.rs Git - rust.git/commitdiff
rustc_codegen_llvm: use safe references for BasicBlock.
authorIrina Popa <irinagpopa@gmail.com>
Tue, 10 Jul 2018 11:34:34 +0000 (14:34 +0300)
committerIrina Popa <irinagpopa@gmail.com>
Mon, 30 Jul 2018 16:49:20 +0000 (19:49 +0300)
src/librustc_codegen_llvm/builder.rs
src/librustc_codegen_llvm/llvm/ffi.rs
src/librustc_codegen_llvm/mir/block.rs
src/librustc_codegen_llvm/mir/mod.rs

index 19ae990fa65ffcc1e92236c090a8cd08563f0001..dbc16cbbf0ded651f4e08ffc04f5e03ec558f294 100644 (file)
@@ -12,7 +12,7 @@
 
 use llvm::{AtomicRmwBinOp, AtomicOrdering, SynchronizationScope, AsmDialect};
 use llvm::{Opcode, IntPredicate, RealPredicate, False, OperandBundleDef};
-use llvm::{self, BasicBlockRef};
+use llvm::{self, BasicBlock};
 use common::*;
 use type_::Type;
 use value::Value;
@@ -102,7 +102,7 @@ pub fn llfn(&self) -> &'ll Value {
         }
     }
 
-    pub fn llbb(&self) -> BasicBlockRef {
+    pub fn llbb(&self) -> &'ll BasicBlock {
         unsafe {
             llvm::LLVMGetInsertBlock(self.llbuilder)
         }
@@ -134,13 +134,13 @@ pub fn position_before(&self, insn: &'ll Value) {
         }
     }
 
-    pub fn position_at_end(&self, llbb: BasicBlockRef) {
+    pub fn position_at_end(&self, llbb: &'ll BasicBlock) {
         unsafe {
             llvm::LLVMPositionBuilderAtEnd(self.llbuilder, llbb);
         }
     }
 
-    pub fn position_at_start(&self, llbb: BasicBlockRef) {
+    pub fn position_at_start(&self, llbb: &'ll BasicBlock) {
         unsafe {
             llvm::LLVMRustPositionBuilderAtStart(self.llbuilder, llbb);
         }
@@ -168,21 +168,21 @@ pub fn aggregate_ret(&self, ret_vals: &[&'ll Value]) {
         }
     }
 
-    pub fn br(&self, dest: BasicBlockRef) {
+    pub fn br(&self, dest: &'ll BasicBlock) {
         self.count_insn("br");
         unsafe {
             llvm::LLVMBuildBr(self.llbuilder, dest);
         }
     }
 
-    pub fn cond_br(&self, cond: &'ll Value, then_llbb: BasicBlockRef, else_llbb: BasicBlockRef) {
+    pub fn cond_br(&self, cond: &'ll Value, then_llbb: &'ll BasicBlock, else_llbb: &'ll BasicBlock) {
         self.count_insn("condbr");
         unsafe {
             llvm::LLVMBuildCondBr(self.llbuilder, cond, then_llbb, else_llbb);
         }
     }
 
-    pub fn switch(&self, v: &'ll Value, else_llbb: BasicBlockRef, num_cases: usize) -> &'ll Value {
+    pub fn switch(&self, v: &'ll Value, else_llbb: &'ll BasicBlock, num_cases: usize) -> &'ll Value {
         unsafe {
             llvm::LLVMBuildSwitch(self.llbuilder, v, else_llbb, num_cases as c_uint)
         }
@@ -198,8 +198,8 @@ pub fn indirect_br(&self, addr: &'ll Value, num_dests: usize) {
     pub fn invoke(&self,
                   llfn: &'ll Value,
                   args: &[&'ll Value],
-                  then: BasicBlockRef,
-                  catch: BasicBlockRef,
+                  then: &'ll BasicBlock,
+                  catch: &'ll BasicBlock,
                   bundle: Option<&OperandBundleDef>) -> &'ll Value {
         self.count_insn("invoke");
 
@@ -830,7 +830,7 @@ pub fn empty_phi(&self, ty: &'ll Type) -> &'ll Value {
         }
     }
 
-    pub fn phi(&self, ty: &'ll Type, vals: &[&'ll Value], bbs: &[BasicBlockRef]) -> &'ll Value {
+    pub fn phi(&self, ty: &'ll Type, vals: &[&'ll Value], bbs: &[&'ll BasicBlock]) -> &'ll Value {
         assert_eq!(vals.len(), bbs.len());
         let phi = self.empty_phi(ty);
         self.count_insn("addincoming");
@@ -1167,10 +1167,11 @@ pub fn cleanup_pad(&self,
         ret.expect("LLVM does not have support for cleanuppad")
     }
 
-    pub fn cleanup_ret(&self, cleanup: &'ll Value,
-                       unwind: Option<BasicBlockRef>) -> &'ll Value {
+    pub fn cleanup_ret(
+        &self, cleanup: &'ll Value,
+        unwind: Option<&'ll BasicBlock>,
+    ) -> &'ll Value {
         self.count_insn("cleanupret");
-        let unwind = unwind.and_then(NonNull::new);
         let ret = unsafe {
             llvm::LLVMRustBuildCleanupRet(self.llbuilder, cleanup, unwind)
         };
@@ -1190,7 +1191,7 @@ pub fn catch_pad(&self,
         ret.expect("LLVM does not have support for catchpad")
     }
 
-    pub fn catch_ret(&self, pad: &'ll Value, unwind: BasicBlockRef) -> &'ll Value {
+    pub fn catch_ret(&self, pad: &'ll Value, unwind: &'ll BasicBlock) -> &'ll Value {
         self.count_insn("catchret");
         let ret = unsafe {
             llvm::LLVMRustBuildCatchRet(self.llbuilder, pad, unwind)
@@ -1201,11 +1202,10 @@ pub fn catch_ret(&self, pad: &'ll Value, unwind: BasicBlockRef) -> &'ll Value {
     pub fn catch_switch(
         &self,
         parent: Option<&'ll Value>,
-        unwind: Option<BasicBlockRef>,
+        unwind: Option<&'ll BasicBlock>,
         num_handlers: usize,
     ) -> &'ll Value {
         self.count_insn("catchswitch");
-        let unwind = unwind.and_then(NonNull::new);
         let name = CString::new("catchswitch").unwrap();
         let ret = unsafe {
             llvm::LLVMRustBuildCatchSwitch(self.llbuilder, parent, unwind,
@@ -1215,7 +1215,7 @@ pub fn catch_switch(
         ret.expect("LLVM does not have support for catchswitch")
     }
 
-    pub fn add_handler(&self, catch_switch: &'ll Value, handler: BasicBlockRef) {
+    pub fn add_handler(&self, catch_switch: &'ll Value, handler: &'ll BasicBlock) {
         unsafe {
             llvm::LLVMRustAddHandler(catch_switch, handler);
         }
@@ -1260,13 +1260,13 @@ pub fn atomic_fence(&self, order: AtomicOrdering, scope: SynchronizationScope) {
         }
     }
 
-    pub fn add_case(&self, s: &'ll Value, on_val: &'ll Value, dest: BasicBlockRef) {
+    pub fn add_case(&self, s: &'ll Value, on_val: &'ll Value, dest: &'ll BasicBlock) {
         unsafe {
             llvm::LLVMAddCase(s, on_val, dest)
         }
     }
 
-    pub fn add_incoming_to_phi(&self, phi: &'ll Value, val: &'ll Value, bb: BasicBlockRef) {
+    pub fn add_incoming_to_phi(&self, phi: &'ll Value, val: &'ll Value, bb: &'ll BasicBlock) {
         self.count_insn("addincoming");
         unsafe {
             llvm::LLVMAddIncoming(phi, &val, &bb, 1 as c_uint);
index bf016bb8e3c6ad79c810f4cd47db53c96f4f4d28..1b6014b495246fc2f3ed502a11396ff835eb949e 100644 (file)
@@ -381,7 +381,6 @@ pub enum ThreadLocalMode {
 extern { pub type Value; }
 extern { pub type Metadata; }
 extern { pub type BasicBlock; }
-pub type BasicBlockRef = *mut BasicBlock;
 extern { pub type Builder; }
 extern { pub type MemoryBuffer; }
 pub type MemoryBufferRef = *mut MemoryBuffer;
@@ -716,18 +715,18 @@ pub fn LLVMRustAddFunctionAttrStringValue(Fn: &Value,
     pub fn LLVMGetParam(Fn: &Value, Index: c_uint) -> &Value;
 
     // Operations on basic blocks
-    pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> &'a Value;
-    pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> &'a Value;
+    pub fn LLVMBasicBlockAsValue(BB: &BasicBlock) -> &Value;
+    pub fn LLVMGetBasicBlockParent(BB: &BasicBlock) -> &Value;
     pub fn LLVMAppendBasicBlockInContext(C: &'a Context,
                                          Fn: &'a Value,
                                          Name: *const c_char)
-                                         -> BasicBlockRef;
-    pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
+                                         -> &'a BasicBlock;
+    pub fn LLVMDeleteBasicBlock(BB: &BasicBlock);
 
     // Operations on instructions
-    pub fn LLVMGetInstructionParent(Inst: &Value) -> BasicBlockRef;
-    pub fn LLVMGetFirstBasicBlock(Fn: &Value) -> BasicBlockRef;
-    pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> &'a Value;
+    pub fn LLVMGetInstructionParent(Inst: &Value) -> &BasicBlock;
+    pub fn LLVMGetFirstBasicBlock(Fn: &Value) -> &BasicBlock;
+    pub fn LLVMGetFirstInstruction(BB: &BasicBlock) -> &'a Value;
     pub fn LLVMInstructionEraseFromParent(Inst: &Value);
 
     // Operations on call sites
@@ -745,15 +744,15 @@ pub fn LLVMRustAddDereferenceableOrNullCallSiteAttr(Instr: &Value,
     // Operations on phi nodes
     pub fn LLVMAddIncoming(PhiNode: &'a Value,
                            IncomingValues: *const &'a Value,
-                           IncomingBlocks: *const BasicBlockRef,
+                           IncomingBlocks: *const &'a BasicBlock,
                            Count: c_uint);
 
     // Instruction builders
     pub fn LLVMCreateBuilderInContext(C: &Context) -> &Builder;
-    pub fn LLVMPositionBuilder(Builder: &'a Builder, Block: BasicBlockRef, Instr: &'a Value);
+    pub fn LLVMPositionBuilder(Builder: &'a Builder, Block: &'a BasicBlock, Instr: &'a Value);
     pub fn LLVMPositionBuilderBefore(Builder: &'a Builder, Instr: &'a Value);
-    pub fn LLVMPositionBuilderAtEnd(Builder: &Builder, Block: BasicBlockRef);
-    pub fn LLVMGetInsertBlock(Builder: &Builder) -> BasicBlockRef;
+    pub fn LLVMPositionBuilderAtEnd(Builder: &'a Builder, Block: &'a BasicBlock);
+    pub fn LLVMGetInsertBlock(Builder: &Builder) -> &BasicBlock;
     pub fn LLVMDisposeBuilder(Builder: &Builder);
 
     // Metadata
@@ -765,15 +764,15 @@ pub fn LLVMAddIncoming(PhiNode: &'a Value,
     pub fn LLVMBuildRetVoid(B: &Builder) -> &Value;
     pub fn LLVMBuildRet(B: &'a Builder, V: &'a Value) -> &'a Value;
     pub fn LLVMBuildAggregateRet(B: &'a Builder, RetVals: *const &'a Value, N: c_uint) -> &'a Value;
-    pub fn LLVMBuildBr(B: &Builder, Dest: BasicBlockRef) -> &Value;
+    pub fn LLVMBuildBr(B: &'a Builder, Dest: &'a BasicBlock) -> &'a Value;
     pub fn LLVMBuildCondBr(B: &'a Builder,
                            If: &'a Value,
-                           Then: BasicBlockRef,
-                           Else: BasicBlockRef)
+                           Then: &'a BasicBlock,
+                           Else: &'a BasicBlock)
                            -> &'a Value;
     pub fn LLVMBuildSwitch(B: &'a Builder,
                            V: &'a Value,
-                           Else: BasicBlockRef,
+                           Else: &'a BasicBlock,
                            NumCases: c_uint)
                            -> &'a Value;
     pub fn LLVMBuildIndirectBr(B: &'a Builder, Addr: &'a Value, NumDests: c_uint) -> &'a Value;
@@ -781,8 +780,8 @@ pub fn LLVMRustBuildInvoke(B: &'a Builder,
                                Fn: &'a Value,
                                Args: *const &'a Value,
                                NumArgs: c_uint,
-                               Then: BasicBlockRef,
-                               Catch: BasicBlockRef,
+                               Then: &'a BasicBlock,
+                               Catch: &'a BasicBlock,
                                Bundle: Option<NonNull<OperandBundleDef>>,
                                Name: *const c_char)
                                -> &'a Value;
@@ -803,7 +802,7 @@ pub fn LLVMRustBuildCleanupPad(B: &'a Builder,
                                    -> Option<&'a Value>;
     pub fn LLVMRustBuildCleanupRet(B: &'a Builder,
                                    CleanupPad: &'a Value,
-                                   UnwindBB: Option<NonNull<BasicBlock>>)
+                                   UnwindBB: Option<&'a BasicBlock>)
                                    -> Option<&'a Value>;
     pub fn LLVMRustBuildCatchPad(B: &'a Builder,
                                  ParentPad: &'a Value,
@@ -811,18 +810,18 @@ pub fn LLVMRustBuildCatchPad(B: &'a Builder,
                                  Args: *const &'a Value,
                                  Name: *const c_char)
                                  -> Option<&'a Value>;
-    pub fn LLVMRustBuildCatchRet(B: &'a Builder, Pad: &'a Value, BB: BasicBlockRef) -> Option<&'a Value>;
+    pub fn LLVMRustBuildCatchRet(B: &'a Builder, Pad: &'a Value, BB: &'a BasicBlock) -> Option<&'a Value>;
     pub fn LLVMRustBuildCatchSwitch(Builder: &'a Builder,
                                     ParentPad: Option<&'a Value>,
-                                    BB: Option<NonNull<BasicBlock>>,
+                                    BB: Option<&'a BasicBlock>,
                                     NumHandlers: c_uint,
                                     Name: *const c_char)
                                     -> Option<&'a Value>;
-    pub fn LLVMRustAddHandler(CatchSwitch: &Value, Handler: BasicBlockRef);
+    pub fn LLVMRustAddHandler(CatchSwitch: &'a Value, Handler: &'a BasicBlock);
     pub fn LLVMSetPersonalityFn(Func: &'a Value, Pers: &'a Value);
 
     // Add a case to the switch instruction
-    pub fn LLVMAddCase(Switch: &'a Value, OnVal: &'a Value, Dest: BasicBlockRef);
+    pub fn LLVMAddCase(Switch: &'a Value, OnVal: &'a Value, Dest: &'a BasicBlock);
 
     // Add a clause to the landing pad instruction
     pub fn LLVMAddClause(LandingPad: &'a Value, ClauseVal: &'a Value);
@@ -1503,7 +1502,7 @@ pub fn LLVMRustDIBuilderInsertDeclareAtEnd(Builder: &'a DIBuilder,
                                                AddrOps: *const i64,
                                                AddrOpsCount: c_uint,
                                                DL: &'a Value,
-                                               InsertAtEnd: BasicBlockRef)
+                                               InsertAtEnd: &'a BasicBlock)
                                                -> &'a Value;
 
     pub fn LLVMRustDIBuilderCreateEnumerator(Builder: &DIBuilder,
@@ -1691,7 +1690,7 @@ pub fn LLVMRustBuildOperandBundleDef(Name: *const c_char,
                                          -> OperandBundleDefRef;
     pub fn LLVMRustFreeOperandBundleDef(Bundle: OperandBundleDefRef);
 
-    pub fn LLVMRustPositionBuilderAtStart(B: &Builder, BB: BasicBlockRef);
+    pub fn LLVMRustPositionBuilderAtStart(B: &'a Builder, BB: &'a BasicBlock);
 
     pub fn LLVMRustSetComdat(M: &'a Module, V: &'a Value, Name: *const c_char);
     pub fn LLVMRustUnsetComdat(V: &Value);
index 587165dfe77f208335a517e83701d753ee00736a..684ecfaeec8f159d858f736e22b2d45b6a6699cd 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use llvm::{self, BasicBlockRef};
+use llvm::{self, BasicBlock};
 use rustc::middle::lang_items;
 use rustc::ty::{self, Ty, TypeFoldable};
 use rustc::ty::layout::{self, LayoutOf};
@@ -754,7 +754,7 @@ fn get_personality_slot(&mut self, bx: &Builder<'a, 'll, 'tcx>) -> PlaceRef<'ll,
     /// Return the landingpad wrapper around the given basic block
     ///
     /// No-op in MSVC SEH scheme.
-    fn landing_pad_to(&mut self, target_bb: mir::BasicBlock) -> BasicBlockRef {
+    fn landing_pad_to(&mut self, target_bb: mir::BasicBlock) -> &'ll BasicBlock {
         if let Some(block) = self.landing_pads[target_bb] {
             return block;
         }
@@ -765,7 +765,7 @@ fn landing_pad_to(&mut self, target_bb: mir::BasicBlock) -> BasicBlockRef {
         landing_pad
     }
 
-    fn landing_pad_uncached(&mut self, target_bb: BasicBlockRef) -> BasicBlockRef {
+    fn landing_pad_uncached(&mut self, target_bb: &'ll BasicBlock) -> &'ll BasicBlock {
         if base::wants_msvc_seh(self.cx.sess()) {
             span_bug!(self.mir.span, "landing pad was not inserted?")
         }
@@ -790,7 +790,7 @@ fn landing_pad_type(&self) -> &'ll Type {
         Type::struct_(cx, &[Type::i8p(cx), Type::i32(cx)], false)
     }
 
-    fn unreachable_block(&mut self) -> BasicBlockRef {
+    fn unreachable_block(&mut self) -> &'ll BasicBlock {
         self.unreachable_block.unwrap_or_else(|| {
             let bl = self.new_block("unreachable");
             bl.unreachable();
index be9cd005013f72f210d5e0358f64d7c4e888f418..8cdd0398eff96d02e28dfea807c8523429dc968b 100644 (file)
@@ -10,7 +10,7 @@
 
 use common::{C_i32, C_null};
 use libc::c_uint;
-use llvm::{self, BasicBlockRef};
+use llvm::{self, BasicBlock};
 use llvm::debuginfo::DIScope;
 use rustc::ty::{self, Ty, TypeFoldable, UpvarSubsts};
 use rustc::ty::layout::{LayoutOf, TyLayout};
@@ -66,7 +66,7 @@ pub struct FunctionCx<'a, 'll: 'a, 'tcx: 'll> {
     personality_slot: Option<PlaceRef<'ll, 'tcx>>,
 
     /// A `Block` for each MIR `BasicBlock`
-    blocks: IndexVec<mir::BasicBlock, BasicBlockRef>,
+    blocks: IndexVec<mir::BasicBlock, &'ll BasicBlock>,
 
     /// The funclet status of each basic block
     cleanup_kinds: IndexVec<mir::BasicBlock, analyze::CleanupKind>,
@@ -77,10 +77,10 @@ pub struct FunctionCx<'a, 'll: 'a, 'tcx: 'll> {
 
     /// This stores the landing-pad block for a given BB, computed lazily on GNU
     /// and eagerly on MSVC.
-    landing_pads: IndexVec<mir::BasicBlock, Option<BasicBlockRef>>,
+    landing_pads: IndexVec<mir::BasicBlock, Option<&'ll BasicBlock>>,
 
     /// Cached unreachable block
-    unreachable_block: Option<BasicBlockRef>,
+    unreachable_block: Option<&'ll BasicBlock>,
 
     /// The location where each MIR arg/var/tmp/ret is stored. This is
     /// usually an `PlaceRef` representing an alloca, but not always:
@@ -219,7 +219,7 @@ pub fn codegen_mir(
     // Allocate a `Block` for every basic block, except
     // the start block, if nothing loops back to it.
     let reentrant_start_block = !mir.predecessors_for(mir::START_BLOCK).is_empty();
-    let block_bxs: IndexVec<mir::BasicBlock, BasicBlockRef> =
+    let block_bxs: IndexVec<mir::BasicBlock, &'ll BasicBlock> =
         mir.basic_blocks().indices().map(|bb| {
             if bb == mir::START_BLOCK && !reentrant_start_block {
                 bx.llbb()
@@ -348,8 +348,8 @@ fn create_funclets(
     mir: &'a Mir<'tcx>,
     bx: &Builder<'a, 'll, 'tcx>,
     cleanup_kinds: &IndexVec<mir::BasicBlock, CleanupKind>,
-    block_bxs: &IndexVec<mir::BasicBlock, BasicBlockRef>)
-    -> (IndexVec<mir::BasicBlock, Option<BasicBlockRef>>,
+    block_bxs: &IndexVec<mir::BasicBlock, &'ll BasicBlock>)
+    -> (IndexVec<mir::BasicBlock, Option<&'ll BasicBlock>>,
         IndexVec<mir::BasicBlock, Option<Funclet<'ll>>>)
 {
     block_bxs.iter_enumerated().zip(cleanup_kinds).map(|((bb, &llbb), cleanup_kind)| {