@@ -118,24 +118,16 @@ macro_rules! builder_methods_for_value_instructions {
118118}
119119
120120impl BuilderMethods < ' a , ' tcx > for Builder < ' a , ' ll , ' tcx > {
121- fn new_block < ' b > ( cx : & ' a CodegenCx < ' ll , ' tcx > , llfn : & ' ll Value , name : & ' b str ) -> Self {
122- let mut bx = Builder :: with_cx ( cx) ;
123- let llbb = unsafe {
124- let name = SmallCStr :: new ( name) ;
125- llvm:: LLVMAppendBasicBlockInContext ( cx. llcx , llfn, name. as_ptr ( ) )
126- } ;
127- bx. position_at_end ( llbb) ;
121+ fn build ( cx : & ' a CodegenCx < ' ll , ' tcx > , llbb : & ' ll BasicBlock ) -> Self {
122+ let bx = Builder :: with_cx ( cx) ;
123+ unsafe {
124+ llvm:: LLVMPositionBuilderAtEnd ( bx. llbuilder , llbb) ;
125+ }
128126 bx
129127 }
130128
131- fn with_cx ( cx : & ' a CodegenCx < ' ll , ' tcx > ) -> Self {
132- // Create a fresh builder from the crate context.
133- let llbuilder = unsafe { llvm:: LLVMCreateBuilderInContext ( cx. llcx ) } ;
134- Builder { llbuilder, cx }
135- }
136-
137- fn build_sibling_block ( & self , name : & str ) -> Self {
138- Builder :: new_block ( self . cx , self . llfn ( ) , name)
129+ fn cx ( & self ) -> & CodegenCx < ' ll , ' tcx > {
130+ self . cx
139131 }
140132
141133 fn llbb ( & self ) -> & ' ll BasicBlock {
@@ -144,12 +136,22 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
144136
145137 fn set_span ( & mut self , _span : Span ) { }
146138
147- fn position_at_end ( & mut self , llbb : & ' ll BasicBlock ) {
139+ fn append_block ( cx : & ' a CodegenCx < ' ll , ' tcx > , llfn : & ' ll Value , name : & str ) -> & ' ll BasicBlock {
148140 unsafe {
149- llvm:: LLVMPositionBuilderAtEnd ( self . llbuilder , llbb) ;
141+ let name = SmallCStr :: new ( name) ;
142+ llvm:: LLVMAppendBasicBlockInContext ( cx. llcx , llfn, name. as_ptr ( ) )
150143 }
151144 }
152145
146+ fn append_sibling_block ( & mut self , name : & str ) -> & ' ll BasicBlock {
147+ Self :: append_block ( self . cx , self . llfn ( ) , name)
148+ }
149+
150+ fn build_sibling_block ( & mut self , name : & str ) -> Self {
151+ let llbb = self . append_sibling_block ( name) ;
152+ Self :: build ( self . cx , llbb)
153+ }
154+
153155 fn ret_void ( & mut self ) {
154156 unsafe {
155157 llvm:: LLVMBuildRetVoid ( self . llbuilder ) ;
@@ -1144,10 +1146,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11441146 unsafe { llvm:: LLVMBuildZExt ( self . llbuilder , val, dest_ty, UNNAMED ) }
11451147 }
11461148
1147- fn cx ( & self ) -> & CodegenCx < ' ll , ' tcx > {
1148- self . cx
1149- }
1150-
11511149 fn do_not_inline ( & mut self , llret : & ' ll Value ) {
11521150 llvm:: Attribute :: NoInline . apply_callsite ( llvm:: AttributePlace :: Function , llret) ;
11531151 }
@@ -1161,6 +1159,12 @@ impl StaticBuilderMethods for Builder<'a, 'll, 'tcx> {
11611159}
11621160
11631161impl Builder < ' a , ' ll , ' tcx > {
1162+ fn with_cx ( cx : & ' a CodegenCx < ' ll , ' tcx > ) -> Self {
1163+ // Create a fresh builder from the crate context.
1164+ let llbuilder = unsafe { llvm:: LLVMCreateBuilderInContext ( cx. llcx ) } ;
1165+ Builder { llbuilder, cx }
1166+ }
1167+
11641168 pub fn llfn ( & self ) -> & ' ll Value {
11651169 unsafe { llvm:: LLVMGetBasicBlockParent ( self . llbb ( ) ) }
11661170 }
0 commit comments