Skip to content

Commit 97e43a4

Browse files
committed
Move unwinding related methods to UnwindBuilderMethods
1 parent 14c3492 commit 97e43a4

File tree

2 files changed

+157
-152
lines changed

2 files changed

+157
-152
lines changed

src/librustc_codegen_llvm/builder.rs

+122-120
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,128 @@ impl NumBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
898898
}
899899
}
900900

901+
impl UnwindBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
902+
fn invoke(
903+
&mut self,
904+
llfn: &'ll Value,
905+
args: &[&'ll Value],
906+
then: &'ll BasicBlock,
907+
catch: &'ll BasicBlock,
908+
funclet: Option<&Funclet<'ll>>,
909+
) -> &'ll Value {
910+
self.count_insn("invoke");
911+
912+
debug!("Invoke {:?} with args ({:?})",
913+
llfn,
914+
args);
915+
916+
let args = self.check_call("invoke", llfn, args);
917+
let bundle = funclet.map(|funclet| funclet.bundle());
918+
let bundle = bundle.as_ref().map(|b| &*b.raw);
919+
920+
unsafe {
921+
llvm::LLVMRustBuildInvoke(self.llbuilder,
922+
llfn,
923+
args.as_ptr(),
924+
args.len() as c_uint,
925+
then,
926+
catch,
927+
bundle,
928+
noname())
929+
}
930+
}
931+
932+
fn landing_pad(&mut self, ty: &'ll Type, pers_fn: &'ll Value,
933+
num_clauses: usize) -> &'ll Value {
934+
self.count_insn("landingpad");
935+
unsafe {
936+
llvm::LLVMBuildLandingPad(self.llbuilder, ty, pers_fn,
937+
num_clauses as c_uint, noname())
938+
}
939+
}
940+
941+
fn set_cleanup(&mut self, landing_pad: &'ll Value) {
942+
self.count_insn("setcleanup");
943+
unsafe {
944+
llvm::LLVMSetCleanup(landing_pad, llvm::True);
945+
}
946+
}
947+
948+
fn resume(&mut self, exn: &'ll Value) -> &'ll Value {
949+
self.count_insn("resume");
950+
unsafe {
951+
llvm::LLVMBuildResume(self.llbuilder, exn)
952+
}
953+
}
954+
955+
fn cleanup_pad(&mut self,
956+
parent: Option<&'ll Value>,
957+
args: &[&'ll Value]) -> Funclet<'ll> {
958+
self.count_insn("cleanuppad");
959+
let name = const_cstr!("cleanuppad");
960+
let ret = unsafe {
961+
llvm::LLVMRustBuildCleanupPad(self.llbuilder,
962+
parent,
963+
args.len() as c_uint,
964+
args.as_ptr(),
965+
name.as_ptr())
966+
};
967+
Funclet::new(ret.expect("LLVM does not have support for cleanuppad"))
968+
}
969+
970+
fn cleanup_ret(
971+
&mut self, funclet: &Funclet<'ll>,
972+
unwind: Option<&'ll BasicBlock>,
973+
) -> &'ll Value {
974+
self.count_insn("cleanupret");
975+
let ret = unsafe {
976+
llvm::LLVMRustBuildCleanupRet(self.llbuilder, funclet.cleanuppad(), unwind)
977+
};
978+
ret.expect("LLVM does not have support for cleanupret")
979+
}
980+
981+
fn catch_pad(&mut self,
982+
parent: &'ll Value,
983+
args: &[&'ll Value]) -> Funclet<'ll> {
984+
self.count_insn("catchpad");
985+
let name = const_cstr!("catchpad");
986+
let ret = unsafe {
987+
llvm::LLVMRustBuildCatchPad(self.llbuilder, parent,
988+
args.len() as c_uint, args.as_ptr(),
989+
name.as_ptr())
990+
};
991+
Funclet::new(ret.expect("LLVM does not have support for catchpad"))
992+
}
993+
994+
fn catch_switch(
995+
&mut self,
996+
parent: Option<&'ll Value>,
997+
unwind: Option<&'ll BasicBlock>,
998+
num_handlers: usize,
999+
) -> &'ll Value {
1000+
self.count_insn("catchswitch");
1001+
let name = const_cstr!("catchswitch");
1002+
let ret = unsafe {
1003+
llvm::LLVMRustBuildCatchSwitch(self.llbuilder, parent, unwind,
1004+
num_handlers as c_uint,
1005+
name.as_ptr())
1006+
};
1007+
ret.expect("LLVM does not have support for catchswitch")
1008+
}
1009+
1010+
fn add_handler(&mut self, catch_switch: &'ll Value, handler: &'ll BasicBlock) {
1011+
unsafe {
1012+
llvm::LLVMRustAddHandler(catch_switch, handler);
1013+
}
1014+
}
1015+
1016+
fn set_personality_fn(&mut self, personality: &'ll Value) {
1017+
unsafe {
1018+
llvm::LLVMSetPersonalityFn(self.llfn(), personality);
1019+
}
1020+
}
1021+
}
1022+
9011023
impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
9021024
fn new_block<'b>(
9031025
cx: &'a CodegenCx<'ll, 'tcx>,
@@ -988,36 +1110,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
9881110
}
9891111
}
9901112

991-
fn invoke(
992-
&mut self,
993-
llfn: &'ll Value,
994-
args: &[&'ll Value],
995-
then: &'ll BasicBlock,
996-
catch: &'ll BasicBlock,
997-
funclet: Option<&Funclet<'ll>>,
998-
) -> &'ll Value {
999-
self.count_insn("invoke");
1000-
1001-
debug!("Invoke {:?} with args ({:?})",
1002-
llfn,
1003-
args);
1004-
1005-
let args = self.check_call("invoke", llfn, args);
1006-
let bundle = funclet.map(|funclet| funclet.bundle());
1007-
let bundle = bundle.as_ref().map(|b| &*b.raw);
1008-
1009-
unsafe {
1010-
llvm::LLVMRustBuildInvoke(self.llbuilder,
1011-
llfn,
1012-
args.as_ptr(),
1013-
args.len() as c_uint,
1014-
then,
1015-
catch,
1016-
bundle,
1017-
noname())
1018-
}
1019-
}
1020-
10211113
fn unreachable(&mut self) {
10221114
self.count_insn("unreachable");
10231115
unsafe {
@@ -1119,96 +1211,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11191211
}
11201212
}
11211213

1122-
fn landing_pad(&mut self, ty: &'ll Type, pers_fn: &'ll Value,
1123-
num_clauses: usize) -> &'ll Value {
1124-
self.count_insn("landingpad");
1125-
unsafe {
1126-
llvm::LLVMBuildLandingPad(self.llbuilder, ty, pers_fn,
1127-
num_clauses as c_uint, noname())
1128-
}
1129-
}
1130-
1131-
fn set_cleanup(&mut self, landing_pad: &'ll Value) {
1132-
self.count_insn("setcleanup");
1133-
unsafe {
1134-
llvm::LLVMSetCleanup(landing_pad, llvm::True);
1135-
}
1136-
}
1137-
1138-
fn resume(&mut self, exn: &'ll Value) -> &'ll Value {
1139-
self.count_insn("resume");
1140-
unsafe {
1141-
llvm::LLVMBuildResume(self.llbuilder, exn)
1142-
}
1143-
}
1144-
1145-
fn cleanup_pad(&mut self,
1146-
parent: Option<&'ll Value>,
1147-
args: &[&'ll Value]) -> Funclet<'ll> {
1148-
self.count_insn("cleanuppad");
1149-
let name = const_cstr!("cleanuppad");
1150-
let ret = unsafe {
1151-
llvm::LLVMRustBuildCleanupPad(self.llbuilder,
1152-
parent,
1153-
args.len() as c_uint,
1154-
args.as_ptr(),
1155-
name.as_ptr())
1156-
};
1157-
Funclet::new(ret.expect("LLVM does not have support for cleanuppad"))
1158-
}
1159-
1160-
fn cleanup_ret(
1161-
&mut self, funclet: &Funclet<'ll>,
1162-
unwind: Option<&'ll BasicBlock>,
1163-
) -> &'ll Value {
1164-
self.count_insn("cleanupret");
1165-
let ret = unsafe {
1166-
llvm::LLVMRustBuildCleanupRet(self.llbuilder, funclet.cleanuppad(), unwind)
1167-
};
1168-
ret.expect("LLVM does not have support for cleanupret")
1169-
}
1170-
1171-
fn catch_pad(&mut self,
1172-
parent: &'ll Value,
1173-
args: &[&'ll Value]) -> Funclet<'ll> {
1174-
self.count_insn("catchpad");
1175-
let name = const_cstr!("catchpad");
1176-
let ret = unsafe {
1177-
llvm::LLVMRustBuildCatchPad(self.llbuilder, parent,
1178-
args.len() as c_uint, args.as_ptr(),
1179-
name.as_ptr())
1180-
};
1181-
Funclet::new(ret.expect("LLVM does not have support for catchpad"))
1182-
}
1183-
1184-
fn catch_switch(
1185-
&mut self,
1186-
parent: Option<&'ll Value>,
1187-
unwind: Option<&'ll BasicBlock>,
1188-
num_handlers: usize,
1189-
) -> &'ll Value {
1190-
self.count_insn("catchswitch");
1191-
let name = const_cstr!("catchswitch");
1192-
let ret = unsafe {
1193-
llvm::LLVMRustBuildCatchSwitch(self.llbuilder, parent, unwind,
1194-
num_handlers as c_uint,
1195-
name.as_ptr())
1196-
};
1197-
ret.expect("LLVM does not have support for catchswitch")
1198-
}
1199-
1200-
fn add_handler(&mut self, catch_switch: &'ll Value, handler: &'ll BasicBlock) {
1201-
unsafe {
1202-
llvm::LLVMRustAddHandler(catch_switch, handler);
1203-
}
1204-
}
1205-
1206-
fn set_personality_fn(&mut self, personality: &'ll Value) {
1207-
unsafe {
1208-
llvm::LLVMSetPersonalityFn(self.llfn(), personality);
1209-
}
1210-
}
1211-
12121214
fn add_case(&mut self, s: &'ll Value, on_val: &'ll Value, dest: &'ll BasicBlock) {
12131215
unsafe {
12141216
llvm::LLVMAddCase(s, on_val, dest)

src/librustc_codegen_ssa/traits/builder.rs

+35-32
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,40 @@ pub trait NumBuilderMethods<'tcx>: HasCodegen<'tcx> {
184184
fn fcmp(&mut self, op: RealPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
185185
}
186186

187+
pub trait UnwindBuilderMethods<'tcx>: HasCodegen<'tcx> {
188+
fn invoke(
189+
&mut self,
190+
llfn: Self::Value,
191+
args: &[Self::Value],
192+
then: Self::BasicBlock,
193+
catch: Self::BasicBlock,
194+
funclet: Option<&Self::Funclet>,
195+
) -> Self::Value;
196+
fn landing_pad(
197+
&mut self,
198+
ty: Self::Type,
199+
pers_fn: Self::Value,
200+
num_clauses: usize,
201+
) -> Self::Value;
202+
fn set_cleanup(&mut self, landing_pad: Self::Value);
203+
fn resume(&mut self, exn: Self::Value) -> Self::Value;
204+
fn cleanup_pad(&mut self, parent: Option<Self::Value>, args: &[Self::Value]) -> Self::Funclet;
205+
fn cleanup_ret(
206+
&mut self,
207+
funclet: &Self::Funclet,
208+
unwind: Option<Self::BasicBlock>,
209+
) -> Self::Value;
210+
fn catch_pad(&mut self, parent: Self::Value, args: &[Self::Value]) -> Self::Funclet;
211+
fn catch_switch(
212+
&mut self,
213+
parent: Option<Self::Value>,
214+
unwind: Option<Self::BasicBlock>,
215+
num_handlers: usize,
216+
) -> Self::Value;
217+
fn add_handler(&mut self, catch_switch: Self::Value, handler: Self::BasicBlock);
218+
fn set_personality_fn(&mut self, personality: Self::Value);
219+
}
220+
187221
pub trait BuilderMethods<'a, 'tcx: 'a>:
188222
HasCodegen<'tcx>
189223
+ DebugInfoBuilderMethods<'tcx>
@@ -194,6 +228,7 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
194228
+ StaticBuilderMethods<'tcx>
195229
+ MemoryBuilderMethods<'tcx>
196230
+ NumBuilderMethods<'tcx>
231+
+ UnwindBuilderMethods<'tcx>
197232
{
198233
fn new_block<'b>(cx: &'a Self::CodegenCx, llfn: Self::Value, name: &'b str) -> Self;
199234
fn with_cx(cx: &'a Self::CodegenCx) -> Self;
@@ -216,14 +251,6 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
216251
else_llbb: Self::BasicBlock,
217252
num_cases: usize,
218253
) -> Self::Value;
219-
fn invoke(
220-
&mut self,
221-
llfn: Self::Value,
222-
args: &[Self::Value],
223-
then: Self::BasicBlock,
224-
catch: Self::BasicBlock,
225-
funclet: Option<&Self::Funclet>,
226-
) -> Self::Value;
227254
fn unreachable(&mut self);
228255

229256
fn inline_asm_call(
@@ -250,30 +277,6 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
250277
fn extract_value(&mut self, agg_val: Self::Value, idx: u64) -> Self::Value;
251278
fn insert_value(&mut self, agg_val: Self::Value, elt: Self::Value, idx: u64) -> Self::Value;
252279

253-
fn landing_pad(
254-
&mut self,
255-
ty: Self::Type,
256-
pers_fn: Self::Value,
257-
num_clauses: usize,
258-
) -> Self::Value;
259-
fn set_cleanup(&mut self, landing_pad: Self::Value);
260-
fn resume(&mut self, exn: Self::Value) -> Self::Value;
261-
fn cleanup_pad(&mut self, parent: Option<Self::Value>, args: &[Self::Value]) -> Self::Funclet;
262-
fn cleanup_ret(
263-
&mut self,
264-
funclet: &Self::Funclet,
265-
unwind: Option<Self::BasicBlock>,
266-
) -> Self::Value;
267-
fn catch_pad(&mut self, parent: Self::Value, args: &[Self::Value]) -> Self::Funclet;
268-
fn catch_switch(
269-
&mut self,
270-
parent: Option<Self::Value>,
271-
unwind: Option<Self::BasicBlock>,
272-
num_handlers: usize,
273-
) -> Self::Value;
274-
fn add_handler(&mut self, catch_switch: Self::Value, handler: Self::BasicBlock);
275-
fn set_personality_fn(&mut self, personality: Self::Value);
276-
277280
fn add_case(&mut self, s: Self::Value, on_val: Self::Value, dest: Self::BasicBlock);
278281
fn set_invariant_load(&mut self, load: Self::Value);
279282

0 commit comments

Comments
 (0)