Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llvm ffi: Expose CallInst->setTailCallKind #112791

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,16 @@ pub enum ThreadLocalMode {
LocalExec,
}

/// LLVMRustTailCallKind
#[derive(Copy, Clone)]
#[repr(C)]
pub enum TailCallKind {
None,
Tail,
MustTail,
NoTail,
}

/// LLVMRustChecksumKind
#[derive(Copy, Clone)]
#[repr(C)]
Expand Down Expand Up @@ -1195,6 +1205,7 @@ extern "C" {
NameLen: size_t,
) -> Option<&Value>;
pub fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);
pub fn LLVMRustSetTailCallKind(CallInst: &Value, TKC: TailCallKind);

// Operations on attributes
pub fn LLVMRustCreateAttrNoValue(C: &Context, attr: AttributeKind) -> &Attribute;
Expand Down
26 changes: 26 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,32 @@ extern "C" LLVMValueRef LLVMRustGetNamedValue(LLVMModuleRef M, const char *Name,
return wrap(unwrap(M)->getNamedValue(StringRef(Name, NameLen)));
}

enum class LLVMRustTailCallKind {
None,
Tail,
MustTail,
NoTail,
};

static CallInst::TailCallKind fromRust(LLVMRustTailCallKind Kind) {
switch (Kind) {
case LLVMRustTailCallKind::None:
return CallInst::TailCallKind::TCK_None;
case LLVMRustTailCallKind::Tail:
return CallInst::TailCallKind::TCK_Tail;
case LLVMRustTailCallKind::MustTail:
return CallInst::TailCallKind::TCK_MustTail;
case LLVMRustTailCallKind::NoTail:
return CallInst::TailCallKind::TCK_NoTail;
default:
report_fatal_error("bad CallInst::TailCallKind.");
}
}

extern "C" void LLVMRustSetTailCallKind(LLVMValueRef Call, LLVMRustTailCallKind TCK) {
unwrap<CallInst>(Call)->setTailCallKind(fromRust(TCK));
}

extern "C" LLVMValueRef LLVMRustGetOrInsertFunction(LLVMModuleRef M,
const char *Name,
size_t NameLen,
Expand Down