Skip to content

Commit

Permalink
Use Cow<'static, str> for InlineAsmTemplatePiece::String
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Jun 24, 2024
1 parent 2c243d9 commit 4bc8ec3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
3 changes: 2 additions & 1 deletion compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use rustc_macros::{Decodable, Encodable, HashStable_Generic};
use rustc_span::source_map::{respan, Spanned};
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
use std::borrow::Cow;
use std::cmp;
use std::fmt;
use std::mem;
Expand Down Expand Up @@ -2264,7 +2265,7 @@ impl std::fmt::Debug for InlineAsmOptions {

#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Hash, HashStable_Generic)]
pub enum InlineAsmTemplatePiece {
String(String),
String(Cow<'static, str>),
Placeholder { operand_idx: usize, modifier: Option<char>, span: Span },
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ fn expand_preparsed_asm(

for (i, template_expr) in args.templates.into_iter().enumerate() {
if i != 0 {
template.push(ast::InlineAsmTemplatePiece::String("\n".to_string()));
template.push(ast::InlineAsmTemplatePiece::String("\n".into()));
}

let msg = "asm template must be a string literal";
Expand Down Expand Up @@ -529,7 +529,7 @@ fn expand_preparsed_asm(

// Don't treat raw asm as a format string.
if args.options.contains(ast::InlineAsmOptions::RAW) {
template.push(ast::InlineAsmTemplatePiece::String(template_str.to_string()));
template.push(ast::InlineAsmTemplatePiece::String(template_str.to_string().into()));
let template_num_lines = 1 + template_str.matches('\n').count();
line_spans.extend(std::iter::repeat(template_sp).take(template_num_lines));
continue;
Expand Down Expand Up @@ -579,7 +579,7 @@ fn expand_preparsed_asm(
for piece in unverified_pieces {
match piece {
parse::Piece::String(s) => {
template.push(ast::InlineAsmTemplatePiece::String(s.to_string()))
template.push(ast::InlineAsmTemplatePiece::String(s.to_string().into()))
}
parse::Piece::NextArgument(arg) => {
let span = arg_spans.next().unwrap_or(template_sp);
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_codegen_cranelift/src/inline_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
// Used by panic_abort on Windows, but uses a syntax which only happens to work with
// asm!() by accident and breaks with the GNU assembler as well as global_asm!() for
// the LLVM backend.
if template.len() == 1
&& template[0] == InlineAsmTemplatePiece::String("int $$0x29".to_string())
{
if template.len() == 1 && template[0] == InlineAsmTemplatePiece::String("int $$0x29".into()) {
fx.bcx.ins().trap(TrapCode::User(1));
return;
}
Expand Down
40 changes: 21 additions & 19 deletions compiler/rustc_codegen_cranelift/src/intrinsics/llvm_x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
shl rdx, 32
or rax, rdx
"
.to_string(),
.into(),
)],
&[
CInlineAsmOperand::In {
Expand Down Expand Up @@ -463,7 +463,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
// into 0x80000000 for which Cranelift doesn't have a native instruction.
codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String(format!("cvttps2dq xmm0, xmm0"))],
&[InlineAsmTemplatePiece::String("cvttps2dq xmm0, xmm0".into())],
&[CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
_late: true,
Expand Down Expand Up @@ -867,7 +867,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String(asm.to_string())],
&[InlineAsmTemplatePiece::String(asm.into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)),
Expand Down Expand Up @@ -906,7 +906,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String(format!("pcmpestri xmm0, xmm1, {imm8}"))],
&[InlineAsmTemplatePiece::String(format!("pcmpestri xmm0, xmm1, {imm8}").into())],
&[
CInlineAsmOperand::In {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
Expand Down Expand Up @@ -959,7 +959,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String(format!("pcmpestrm xmm0, xmm1, {imm8}"))],
&[InlineAsmTemplatePiece::String(format!("pcmpestrm xmm0, xmm1, {imm8}").into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
Expand Down Expand Up @@ -1007,7 +1007,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String(format!("pclmulqdq xmm0, xmm1, {imm8}"))],
&[InlineAsmTemplatePiece::String(format!("pclmulqdq xmm0, xmm1, {imm8}").into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
Expand Down Expand Up @@ -1044,7 +1044,9 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String(format!("aeskeygenassist xmm0, xmm0, {imm8}"))],
&[InlineAsmTemplatePiece::String(
format!("aeskeygenassist xmm0, xmm0, {imm8}").into(),
)],
&[CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
_late: true,
Expand All @@ -1063,7 +1065,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String("aesimc xmm0, xmm0".to_string())],
&[InlineAsmTemplatePiece::String("aesimc xmm0, xmm0".into())],
&[CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
_late: true,
Expand All @@ -1083,7 +1085,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String("aesenc xmm0, xmm1".to_string())],
&[InlineAsmTemplatePiece::String("aesenc xmm0, xmm1".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
Expand All @@ -1109,7 +1111,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String("aesenclast xmm0, xmm1".to_string())],
&[InlineAsmTemplatePiece::String("aesenclast xmm0, xmm1".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
Expand All @@ -1135,7 +1137,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String("aesdec xmm0, xmm1".to_string())],
&[InlineAsmTemplatePiece::String("aesdec xmm0, xmm1".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
Expand All @@ -1161,7 +1163,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String("aesdeclast xmm0, xmm1".to_string())],
&[InlineAsmTemplatePiece::String("aesdeclast xmm0, xmm1".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
Expand Down Expand Up @@ -1199,7 +1201,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String(format!("sha1rnds4 xmm1, xmm2, {func}"))],
&[InlineAsmTemplatePiece::String(format!("sha1rnds4 xmm1, xmm2, {func}").into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
Expand All @@ -1225,7 +1227,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String("sha1msg1 xmm1, xmm2".to_string())],
&[InlineAsmTemplatePiece::String("sha1msg1 xmm1, xmm2".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
Expand All @@ -1251,7 +1253,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String("sha1msg2 xmm1, xmm2".to_string())],
&[InlineAsmTemplatePiece::String("sha1msg2 xmm1, xmm2".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
Expand All @@ -1277,7 +1279,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String("sha1nexte xmm1, xmm2".to_string())],
&[InlineAsmTemplatePiece::String("sha1nexte xmm1, xmm2".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
Expand All @@ -1304,7 +1306,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String("sha256rnds2 xmm1, xmm2".to_string())],
&[InlineAsmTemplatePiece::String("sha256rnds2 xmm1, xmm2".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
Expand Down Expand Up @@ -1335,7 +1337,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String("sha256msg1 xmm1, xmm2".to_string())],
&[InlineAsmTemplatePiece::String("sha256msg1 xmm1, xmm2".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
Expand All @@ -1361,7 +1363,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

codegen_inline_asm_inner(
fx,
&[InlineAsmTemplatePiece::String("sha256msg2 xmm1, xmm2".to_string())],
&[InlineAsmTemplatePiece::String("sha256msg2 xmm1, xmm2".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
Expand Down

0 comments on commit 4bc8ec3

Please sign in to comment.