Skip to content

Commit dee279d

Browse files
committed
llvm ffi: Expose CallInst->setTailCallKind
1 parent 4005890 commit dee279d

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+12
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,17 @@ 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+
Last,
597+
}
598+
588599
/// LLVMRustChecksumKind
589600
#[derive(Copy, Clone)]
590601
#[repr(C)]
@@ -1195,6 +1206,7 @@ extern "C" {
11951206
NameLen: size_t,
11961207
) -> Option<&Value>;
11971208
pub fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);
1209+
pub fn LLVMRustSetTailCallKind(CallInst: &Value, TKC: TailCallKind);
11981210

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

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,33 @@ 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+
Last,
125+
};
126+
127+
static CallInst::TailCallKind fromRust(LLVMRustTailCallKind Kind) {
128+
switch (Kind) {
129+
case LLVMRustTailCallKind::None:
130+
return CallInst::TailCallKind::TCK_None;
131+
case LLVMRustTailCallKind::Tail:
132+
return CallInst::TailCallKind::TCK_Tail;
133+
case LLVMRustTailCallKind::MustTail:
134+
return CallInst::TailCallKind::TCK_MustTail;
135+
case LLVMRustTailCallKind::Last:
136+
return CallInst::TailCallKind::TCK_NoTail;
137+
default:
138+
report_fatal_error("bad CallInst::TailCallKind.");
139+
}
140+
}
141+
142+
extern "C" void LLVMRustSetTailCallKind(LLVMValueRef Call, LLVMRustTailCallKind TCK) {
143+
unwrap<CallInst>(Call)->setTailCallKind(fromRust(TCK));
144+
}
145+
119146
extern "C" LLVMValueRef LLVMRustGetOrInsertFunction(LLVMModuleRef M,
120147
const char *Name,
121148
size_t NameLen,
@@ -1672,6 +1699,7 @@ extern "C" void LLVMRustSetDSOLocal(LLVMValueRef Global, bool is_dso_local) {
16721699
unwrap<GlobalValue>(Global)->setDSOLocal(is_dso_local);
16731700
}
16741701

1702+
16751703
struct LLVMRustModuleBuffer {
16761704
std::string data;
16771705
};

0 commit comments

Comments
 (0)