Skip to content

Commit

Permalink
Rollup merge of #112791 - WaffleLapkin:wag_the_llvm, r=cuviper
Browse files Browse the repository at this point in the history
llvm ffi: Expose `CallInst->setTailCallKind`

This is needed for the explicit tail calls experiment.
  • Loading branch information
fee1-dead committed Jul 6, 2023
2 parents 6e9bdac + bf5eaa4 commit e461502
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
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 @@ -1196,6 +1206,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 @@ -121,6 +121,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

0 comments on commit e461502

Please sign in to comment.