Skip to content

Commit bf5eaa4

Browse files
committed
llvm ffi: Expose CallInst->setTailCallKind
1 parent 8d1fa47 commit bf5eaa4

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)]
@@ -1195,6 +1205,7 @@ extern "C" {
11951205
NameLen: size_t,
11961206
) -> Option<&Value>;
11971207
pub fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);
1208+
pub fn LLVMRustSetTailCallKind(CallInst: &Value, TKC: TailCallKind);
11981209

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

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

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

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

0 commit comments

Comments
 (0)