Skip to content

Commit e461502

Browse files
authored
Rollup merge of #112791 - WaffleLapkin:wag_the_llvm, r=cuviper
llvm ffi: Expose `CallInst->setTailCallKind` This is needed for the explicit tail calls experiment.
2 parents 6e9bdac + bf5eaa4 commit e461502

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+11
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,16 @@ pub enum ThreadLocalMode {
585585
LocalExec,
586586
}
587587

588+
/// LLVMRustTailCallKind
589+
#[derive(Copy, Clone)]
590+
#[repr(C)]
591+
pub enum TailCallKind {
592+
None,
593+
Tail,
594+
MustTail,
595+
NoTail,
596+
}
597+
588598
/// LLVMRustChecksumKind
589599
#[derive(Copy, Clone)]
590600
#[repr(C)]
@@ -1196,6 +1206,7 @@ extern "C" {
11961206
NameLen: size_t,
11971207
) -> Option<&Value>;
11981208
pub fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);
1209+
pub fn LLVMRustSetTailCallKind(CallInst: &Value, TKC: TailCallKind);
11991210

12001211
// Operations on attributes
12011212
pub fn LLVMRustCreateAttrNoValue(C: &Context, attr: AttributeKind) -> &Attribute;

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,32 @@ extern "C" LLVMValueRef LLVMRustGetNamedValue(LLVMModuleRef M, const char *Name,
121121
return wrap(unwrap(M)->getNamedValue(StringRef(Name, NameLen)));
122122
}
123123

124+
enum class LLVMRustTailCallKind {
125+
None,
126+
Tail,
127+
MustTail,
128+
NoTail,
129+
};
130+
131+
static CallInst::TailCallKind fromRust(LLVMRustTailCallKind Kind) {
132+
switch (Kind) {
133+
case LLVMRustTailCallKind::None:
134+
return CallInst::TailCallKind::TCK_None;
135+
case LLVMRustTailCallKind::Tail:
136+
return CallInst::TailCallKind::TCK_Tail;
137+
case LLVMRustTailCallKind::MustTail:
138+
return CallInst::TailCallKind::TCK_MustTail;
139+
case LLVMRustTailCallKind::NoTail:
140+
return CallInst::TailCallKind::TCK_NoTail;
141+
default:
142+
report_fatal_error("bad CallInst::TailCallKind.");
143+
}
144+
}
145+
146+
extern "C" void LLVMRustSetTailCallKind(LLVMValueRef Call, LLVMRustTailCallKind TCK) {
147+
unwrap<CallInst>(Call)->setTailCallKind(fromRust(TCK));
148+
}
149+
124150
extern "C" LLVMValueRef LLVMRustGetOrInsertFunction(LLVMModuleRef M,
125151
const char *Name,
126152
size_t NameLen,

0 commit comments

Comments
 (0)