Skip to content

Commit d1bb310

Browse files
committed
Use LLVMGetInlineAsm
This LLVM-C binding replaces the existing `LLVMRustInlineAsm` function.
1 parent 8764ecd commit d1bb310

File tree

3 files changed

+17
-43
lines changed

3 files changed

+17
-43
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,11 @@ pub(crate) fn inline_asm_call<'ll>(
488488
debug!("constraint verification result: {:?}", constraints_ok);
489489
if constraints_ok {
490490
let v = unsafe {
491-
llvm::LLVMRustInlineAsm(
491+
llvm::LLVMGetInlineAsm(
492492
fty,
493-
asm.as_c_char_ptr(),
493+
asm.as_ptr(),
494494
asm.len(),
495-
cons.as_c_char_ptr(),
495+
cons.as_ptr(),
496496
cons.len(),
497497
volatile,
498498
alignstack,

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ pub(crate) enum MetadataType {
471471
MD_kcfi_type = 36,
472472
}
473473

474-
/// LLVMRustAsmDialect
474+
/// Must match the layout of `LLVMInlineAsmDialect`.
475475
#[derive(Copy, Clone, PartialEq)]
476476
#[repr(C)]
477477
pub(crate) enum AsmDialect {
@@ -1017,6 +1017,19 @@ unsafe extern "C" {
10171017
/// See Module::setModuleInlineAsm.
10181018
pub(crate) fn LLVMAppendModuleInlineAsm(M: &Module, Asm: *const c_char, Len: size_t);
10191019

1020+
/// Create the specified uniqued inline asm string. See `InlineAsm::get()`.
1021+
pub(crate) fn LLVMGetInlineAsm<'ll>(
1022+
Ty: &'ll Type,
1023+
AsmString: *const c_uchar, // See "PTR_LEN_STR".
1024+
AsmStringSize: size_t,
1025+
Constraints: *const c_uchar, // See "PTR_LEN_STR".
1026+
ConstraintsSize: size_t,
1027+
HasSideEffects: llvm::Bool,
1028+
IsAlignStack: llvm::Bool,
1029+
Dialect: AsmDialect,
1030+
CanThrow: llvm::Bool,
1031+
) -> &'ll Value;
1032+
10201033
// Operations on integer types
10211034
pub(crate) fn LLVMInt1TypeInContext(C: &Context) -> &Type;
10221035
pub(crate) fn LLVMInt8TypeInContext(C: &Context) -> &Type;
@@ -1994,18 +2007,6 @@ unsafe extern "C" {
19942007
/// Prints the statistics collected by `-Zprint-codegen-stats`.
19952008
pub(crate) fn LLVMRustPrintStatistics(OutStr: &RustString);
19962009

1997-
/// Prepares inline assembly.
1998-
pub(crate) fn LLVMRustInlineAsm(
1999-
Ty: &Type,
2000-
AsmString: *const c_char,
2001-
AsmStringLen: size_t,
2002-
Constraints: *const c_char,
2003-
ConstraintsLen: size_t,
2004-
SideEffects: Bool,
2005-
AlignStack: Bool,
2006-
Dialect: AsmDialect,
2007-
CanThrow: Bool,
2008-
) -> &Value;
20092010
pub(crate) fn LLVMRustInlineAsmVerify(
20102011
Ty: &Type,
20112012
Constraints: *const c_char,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -622,37 +622,10 @@ extern "C" LLVMValueRef LLVMRustBuildAtomicStore(LLVMBuilderRef B,
622622
return wrap(SI);
623623
}
624624

625-
enum class LLVMRustAsmDialect {
626-
Att,
627-
Intel,
628-
};
629-
630-
static InlineAsm::AsmDialect fromRust(LLVMRustAsmDialect Dialect) {
631-
switch (Dialect) {
632-
case LLVMRustAsmDialect::Att:
633-
return InlineAsm::AD_ATT;
634-
case LLVMRustAsmDialect::Intel:
635-
return InlineAsm::AD_Intel;
636-
default:
637-
report_fatal_error("bad AsmDialect.");
638-
}
639-
}
640-
641625
extern "C" uint64_t LLVMRustGetArrayNumElements(LLVMTypeRef Ty) {
642626
return unwrap(Ty)->getArrayNumElements();
643627
}
644628

645-
extern "C" LLVMValueRef
646-
LLVMRustInlineAsm(LLVMTypeRef Ty, char *AsmString, size_t AsmStringLen,
647-
char *Constraints, size_t ConstraintsLen,
648-
LLVMBool HasSideEffects, LLVMBool IsAlignStack,
649-
LLVMRustAsmDialect Dialect, LLVMBool CanThrow) {
650-
return wrap(InlineAsm::get(
651-
unwrap<FunctionType>(Ty), StringRef(AsmString, AsmStringLen),
652-
StringRef(Constraints, ConstraintsLen), HasSideEffects, IsAlignStack,
653-
fromRust(Dialect), CanThrow));
654-
}
655-
656629
extern "C" bool LLVMRustInlineAsmVerify(LLVMTypeRef Ty, char *Constraints,
657630
size_t ConstraintsLen) {
658631
// llvm::Error converts to true if it is an error.

0 commit comments

Comments
 (0)