Use Cow<'static, str> for InlineAsmTemplatePiece::String
This commit is contained in:
parent
2ccafed862
commit
db8cdc5d37
@ -36,6 +36,7 @@
|
|||||||
use rustc_span::source_map::{respan, Spanned};
|
use rustc_span::source_map::{respan, Spanned};
|
||||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
|
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
@ -2272,7 +2273,7 @@ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|||||||
|
|
||||||
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Hash, HashStable_Generic)]
|
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Hash, HashStable_Generic)]
|
||||||
pub enum InlineAsmTemplatePiece {
|
pub enum InlineAsmTemplatePiece {
|
||||||
String(String),
|
String(Cow<'static, str>),
|
||||||
Placeholder { operand_idx: usize, modifier: Option<char>, span: Span },
|
Placeholder { operand_idx: usize, modifier: Option<char>, span: Span },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,7 +459,7 @@ fn expand_preparsed_asm(
|
|||||||
|
|
||||||
for (i, template_expr) in args.templates.into_iter().enumerate() {
|
for (i, template_expr) in args.templates.into_iter().enumerate() {
|
||||||
if i != 0 {
|
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";
|
let msg = "asm template must be a string literal";
|
||||||
@ -527,7 +527,7 @@ fn expand_preparsed_asm(
|
|||||||
|
|
||||||
// Don't treat raw asm as a format string.
|
// Don't treat raw asm as a format string.
|
||||||
if args.options.contains(ast::InlineAsmOptions::RAW) {
|
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();
|
let template_num_lines = 1 + template_str.matches('\n').count();
|
||||||
line_spans.extend(std::iter::repeat(template_sp).take(template_num_lines));
|
line_spans.extend(std::iter::repeat(template_sp).take(template_num_lines));
|
||||||
continue;
|
continue;
|
||||||
@ -577,7 +577,7 @@ fn expand_preparsed_asm(
|
|||||||
for piece in unverified_pieces {
|
for piece in unverified_pieces {
|
||||||
match piece {
|
match piece {
|
||||||
parse::Piece::String(s) => {
|
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) => {
|
parse::Piece::NextArgument(arg) => {
|
||||||
let span = arg_spans.next().unwrap_or(template_sp);
|
let span = arg_spans.next().unwrap_or(template_sp);
|
||||||
|
@ -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
|
// 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
|
// asm!() by accident and breaks with the GNU assembler as well as global_asm!() for
|
||||||
// the LLVM backend.
|
// the LLVM backend.
|
||||||
if template.len() == 1
|
if template.len() == 1 && template[0] == InlineAsmTemplatePiece::String("int $$0x29".into()) {
|
||||||
&& template[0] == InlineAsmTemplatePiece::String("int $$0x29".to_string())
|
|
||||||
{
|
|
||||||
fx.bcx.ins().trap(TrapCode::User(1));
|
fx.bcx.ins().trap(TrapCode::User(1));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
|
|||||||
shl rdx, 32
|
shl rdx, 32
|
||||||
or rax, rdx
|
or rax, rdx
|
||||||
"
|
"
|
||||||
.to_string(),
|
.into(),
|
||||||
)],
|
)],
|
||||||
&[
|
&[
|
||||||
CInlineAsmOperand::In {
|
CInlineAsmOperand::In {
|
||||||
@ -471,7 +471,7 @@ fn select4(
|
|||||||
// into 0x80000000 for which Cranelift doesn't have a native instruction.
|
// into 0x80000000 for which Cranelift doesn't have a native instruction.
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String(format!("cvtps2dq xmm0, xmm0"))],
|
&[InlineAsmTemplatePiece::String("cvtps2dq xmm0, xmm0".into())],
|
||||||
&[CInlineAsmOperand::InOut {
|
&[CInlineAsmOperand::InOut {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
||||||
_late: true,
|
_late: true,
|
||||||
@ -875,7 +875,7 @@ fn select4(
|
|||||||
|
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String(asm.to_string())],
|
&[InlineAsmTemplatePiece::String(asm.into())],
|
||||||
&[
|
&[
|
||||||
CInlineAsmOperand::InOut {
|
CInlineAsmOperand::InOut {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)),
|
||||||
@ -914,7 +914,7 @@ fn select4(
|
|||||||
|
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String(format!("pcmpestri xmm0, xmm1, {imm8}"))],
|
&[InlineAsmTemplatePiece::String(format!("pcmpestri xmm0, xmm1, {imm8}").into())],
|
||||||
&[
|
&[
|
||||||
CInlineAsmOperand::In {
|
CInlineAsmOperand::In {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
||||||
@ -967,7 +967,7 @@ fn select4(
|
|||||||
|
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String(format!("pcmpestrm xmm0, xmm1, {imm8}"))],
|
&[InlineAsmTemplatePiece::String(format!("pcmpestrm xmm0, xmm1, {imm8}").into())],
|
||||||
&[
|
&[
|
||||||
CInlineAsmOperand::InOut {
|
CInlineAsmOperand::InOut {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
||||||
@ -1015,7 +1015,7 @@ fn select4(
|
|||||||
|
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String(format!("pclmulqdq xmm0, xmm1, {imm8}"))],
|
&[InlineAsmTemplatePiece::String(format!("pclmulqdq xmm0, xmm1, {imm8}").into())],
|
||||||
&[
|
&[
|
||||||
CInlineAsmOperand::InOut {
|
CInlineAsmOperand::InOut {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
||||||
@ -1052,7 +1052,9 @@ fn select4(
|
|||||||
|
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String(format!("aeskeygenassist xmm0, xmm0, {imm8}"))],
|
&[InlineAsmTemplatePiece::String(
|
||||||
|
format!("aeskeygenassist xmm0, xmm0, {imm8}").into(),
|
||||||
|
)],
|
||||||
&[CInlineAsmOperand::InOut {
|
&[CInlineAsmOperand::InOut {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
||||||
_late: true,
|
_late: true,
|
||||||
@ -1071,7 +1073,7 @@ fn select4(
|
|||||||
|
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String("aesimc xmm0, xmm0".to_string())],
|
&[InlineAsmTemplatePiece::String("aesimc xmm0, xmm0".into())],
|
||||||
&[CInlineAsmOperand::InOut {
|
&[CInlineAsmOperand::InOut {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
||||||
_late: true,
|
_late: true,
|
||||||
@ -1091,7 +1093,7 @@ fn select4(
|
|||||||
|
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String("aesenc xmm0, xmm1".to_string())],
|
&[InlineAsmTemplatePiece::String("aesenc xmm0, xmm1".into())],
|
||||||
&[
|
&[
|
||||||
CInlineAsmOperand::InOut {
|
CInlineAsmOperand::InOut {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
||||||
@ -1117,7 +1119,7 @@ fn select4(
|
|||||||
|
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String("aesenclast xmm0, xmm1".to_string())],
|
&[InlineAsmTemplatePiece::String("aesenclast xmm0, xmm1".into())],
|
||||||
&[
|
&[
|
||||||
CInlineAsmOperand::InOut {
|
CInlineAsmOperand::InOut {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
||||||
@ -1143,7 +1145,7 @@ fn select4(
|
|||||||
|
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String("aesdec xmm0, xmm1".to_string())],
|
&[InlineAsmTemplatePiece::String("aesdec xmm0, xmm1".into())],
|
||||||
&[
|
&[
|
||||||
CInlineAsmOperand::InOut {
|
CInlineAsmOperand::InOut {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
||||||
@ -1169,7 +1171,7 @@ fn select4(
|
|||||||
|
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String("aesdeclast xmm0, xmm1".to_string())],
|
&[InlineAsmTemplatePiece::String("aesdeclast xmm0, xmm1".into())],
|
||||||
&[
|
&[
|
||||||
CInlineAsmOperand::InOut {
|
CInlineAsmOperand::InOut {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
|
||||||
@ -1207,7 +1209,7 @@ fn select4(
|
|||||||
|
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String(format!("sha1rnds4 xmm1, xmm2, {func}"))],
|
&[InlineAsmTemplatePiece::String(format!("sha1rnds4 xmm1, xmm2, {func}").into())],
|
||||||
&[
|
&[
|
||||||
CInlineAsmOperand::InOut {
|
CInlineAsmOperand::InOut {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
|
||||||
@ -1233,7 +1235,7 @@ fn select4(
|
|||||||
|
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String("sha1msg1 xmm1, xmm2".to_string())],
|
&[InlineAsmTemplatePiece::String("sha1msg1 xmm1, xmm2".into())],
|
||||||
&[
|
&[
|
||||||
CInlineAsmOperand::InOut {
|
CInlineAsmOperand::InOut {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
|
||||||
@ -1259,7 +1261,7 @@ fn select4(
|
|||||||
|
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String("sha1msg2 xmm1, xmm2".to_string())],
|
&[InlineAsmTemplatePiece::String("sha1msg2 xmm1, xmm2".into())],
|
||||||
&[
|
&[
|
||||||
CInlineAsmOperand::InOut {
|
CInlineAsmOperand::InOut {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
|
||||||
@ -1285,7 +1287,7 @@ fn select4(
|
|||||||
|
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String("sha1nexte xmm1, xmm2".to_string())],
|
&[InlineAsmTemplatePiece::String("sha1nexte xmm1, xmm2".into())],
|
||||||
&[
|
&[
|
||||||
CInlineAsmOperand::InOut {
|
CInlineAsmOperand::InOut {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
|
||||||
@ -1312,7 +1314,7 @@ fn select4(
|
|||||||
|
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String("sha256rnds2 xmm1, xmm2".to_string())],
|
&[InlineAsmTemplatePiece::String("sha256rnds2 xmm1, xmm2".into())],
|
||||||
&[
|
&[
|
||||||
CInlineAsmOperand::InOut {
|
CInlineAsmOperand::InOut {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
|
||||||
@ -1343,7 +1345,7 @@ fn select4(
|
|||||||
|
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String("sha256msg1 xmm1, xmm2".to_string())],
|
&[InlineAsmTemplatePiece::String("sha256msg1 xmm1, xmm2".into())],
|
||||||
&[
|
&[
|
||||||
CInlineAsmOperand::InOut {
|
CInlineAsmOperand::InOut {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
|
||||||
@ -1369,7 +1371,7 @@ fn select4(
|
|||||||
|
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String("sha256msg2 xmm1, xmm2".to_string())],
|
&[InlineAsmTemplatePiece::String("sha256msg2 xmm1, xmm2".into())],
|
||||||
&[
|
&[
|
||||||
CInlineAsmOperand::InOut {
|
CInlineAsmOperand::InOut {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
|
||||||
@ -1435,7 +1437,7 @@ fn select4(
|
|||||||
let edx_place = res_place.place_field(fx, FieldIdx::new(1));
|
let edx_place = res_place.place_field(fx, FieldIdx::new(1));
|
||||||
codegen_inline_asm_inner(
|
codegen_inline_asm_inner(
|
||||||
fx,
|
fx,
|
||||||
&[InlineAsmTemplatePiece::String("rdtsc".to_string())],
|
&[InlineAsmTemplatePiece::String("rdtsc".into())],
|
||||||
&[
|
&[
|
||||||
CInlineAsmOperand::Out {
|
CInlineAsmOperand::Out {
|
||||||
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)),
|
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)),
|
||||||
|
Loading…
Reference in New Issue
Block a user