Skip to content

Commit c1c6a8b

Browse files
committed
[cc] remove dead arch code
1 parent 5917ea6 commit c1c6a8b

File tree

2 files changed

+11
-195
lines changed

2 files changed

+11
-195
lines changed

cc/arch/aarch64/lir.rs

Lines changed: 7 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
// enabling peephole optimizations before final assembly emission.
1414
//
1515

16-
// Allow unused variants/methods - LIR defines complete instruction set for future use
17-
#![allow(dead_code)]
18-
1916
use super::codegen::{Reg, VReg};
2017
use crate::arch::lir::{Directive, EmitAsm, FpSize, Label, OperandSize, Symbol};
2118
use crate::target::{Os, Target};
@@ -26,6 +23,7 @@ use std::fmt::{self, Write};
2623
// ============================================================================
2724

2825
/// AArch64 memory addressing mode
26+
#[allow(dead_code)] // Documents full instruction set
2927
#[derive(Debug, Clone, PartialEq)]
3028
pub enum MemAddr {
3129
/// [base] - Register indirect
@@ -96,49 +94,26 @@ impl GpOperand {
9694
GpOperand::Imm(v) => format!("#{}", v),
9795
}
9896
}
99-
100-
/// Check if this is a register operand
101-
pub fn is_reg(&self) -> bool {
102-
matches!(self, GpOperand::Reg(_))
103-
}
104-
105-
/// Get register if this is a register operand
106-
pub fn as_reg(&self) -> Option<Reg> {
107-
match self {
108-
GpOperand::Reg(r) => Some(*r),
109-
_ => None,
110-
}
111-
}
11297
}
11398

11499
// ============================================================================
115100
// FP/SIMD Operands
116101
// ============================================================================
117102

118103
/// AArch64 FP/SIMD operand (register)
104+
#[allow(dead_code)] // Documents full instruction set
119105
#[derive(Debug, Clone, PartialEq)]
120106
pub enum FpOperand {
121107
/// FP register operand
122108
Reg(VReg),
123109
}
124110

125-
impl FpOperand {
126-
/// Format operand in AArch64 syntax
127-
pub fn format(&self, size: FpSize) -> String {
128-
match self {
129-
FpOperand::Reg(r) => match size {
130-
FpSize::Single => r.name_s().to_string(),
131-
FpSize::Double => r.name_d().to_string(),
132-
},
133-
}
134-
}
135-
}
136-
137111
// ============================================================================
138112
// Condition Codes
139113
// ============================================================================
140114

141115
/// AArch64 condition codes for comparisons and conditional operations
116+
#[allow(dead_code)] // Documents full instruction set
142117
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
143118
pub enum Cond {
144119
/// Equal (Z=1)
@@ -197,28 +172,6 @@ impl Cond {
197172
Cond::Nv => "nv",
198173
}
199174
}
200-
201-
/// Get the inverse condition
202-
pub fn inverse(&self) -> Cond {
203-
match self {
204-
Cond::Eq => Cond::Ne,
205-
Cond::Ne => Cond::Eq,
206-
Cond::Cs => Cond::Cc,
207-
Cond::Cc => Cond::Cs,
208-
Cond::Mi => Cond::Pl,
209-
Cond::Pl => Cond::Mi,
210-
Cond::Vs => Cond::Vc,
211-
Cond::Vc => Cond::Vs,
212-
Cond::Hi => Cond::Ls,
213-
Cond::Ls => Cond::Hi,
214-
Cond::Ge => Cond::Lt,
215-
Cond::Lt => Cond::Ge,
216-
Cond::Gt => Cond::Le,
217-
Cond::Le => Cond::Gt,
218-
Cond::Al => Cond::Nv,
219-
Cond::Nv => Cond::Al,
220-
}
221-
}
222175
}
223176

224177
impl fmt::Display for Cond {
@@ -232,6 +185,7 @@ impl fmt::Display for Cond {
232185
// ============================================================================
233186

234187
/// Shift type for shifted register operands
188+
#[allow(dead_code)] // Documents full instruction set
235189
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
236190
pub enum ShiftType {
237191
/// Logical shift left
@@ -244,22 +198,12 @@ pub enum ShiftType {
244198
Ror,
245199
}
246200

247-
impl ShiftType {
248-
pub fn as_str(&self) -> &'static str {
249-
match self {
250-
ShiftType::Lsl => "lsl",
251-
ShiftType::Lsr => "lsr",
252-
ShiftType::Asr => "asr",
253-
ShiftType::Ror => "ror",
254-
}
255-
}
256-
}
257-
258201
// ============================================================================
259202
// Extend Type
260203
// ============================================================================
261204

262205
/// Extend type for extended register operands
206+
#[allow(dead_code)] // Documents full instruction set
263207
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
264208
pub enum ExtendType {
265209
/// Unsigned extend byte
@@ -280,26 +224,12 @@ pub enum ExtendType {
280224
Sxtx,
281225
}
282226

283-
impl ExtendType {
284-
pub fn as_str(&self) -> &'static str {
285-
match self {
286-
ExtendType::Uxtb => "uxtb",
287-
ExtendType::Uxth => "uxth",
288-
ExtendType::Uxtw => "uxtw",
289-
ExtendType::Uxtx => "uxtx",
290-
ExtendType::Sxtb => "sxtb",
291-
ExtendType::Sxth => "sxth",
292-
ExtendType::Sxtw => "sxtw",
293-
ExtendType::Sxtx => "sxtx",
294-
}
295-
}
296-
}
297-
298227
// ============================================================================
299228
// Call Target
300229
// ============================================================================
301230

302231
/// Target for call instructions
232+
#[allow(dead_code)] // Documents full instruction set
303233
#[derive(Debug, Clone, PartialEq)]
304234
pub enum CallTarget {
305235
/// Direct call to symbol
@@ -313,6 +243,7 @@ pub enum CallTarget {
313243
// ============================================================================
314244

315245
/// AArch64 Low-level IR instruction
246+
#[allow(dead_code)] // Documents full instruction set
316247
#[derive(Debug, Clone)]
317248
pub enum Aarch64Inst {
318249
// ========================================================================
@@ -1553,19 +1484,6 @@ fn size_bits(size: FpSize) -> u32 {
15531484
}
15541485
}
15551486

1556-
// ============================================================================
1557-
// Utility Functions
1558-
// ============================================================================
1559-
1560-
/// Emit a sequence of LIR instructions to assembly text
1561-
pub fn emit_instrs(instrs: &[Aarch64Inst], target: &Target) -> String {
1562-
let mut out = String::new();
1563-
for inst in instrs {
1564-
inst.emit(target, &mut out);
1565-
}
1566-
out
1567-
}
1568-
15691487
// ============================================================================
15701488
// Tests
15711489
// ============================================================================
@@ -1768,39 +1686,4 @@ mod tests {
17681686
inst.emit(&macos, &mut out);
17691687
assert!(out.contains("bl _printf"));
17701688
}
1771-
1772-
#[test]
1773-
fn test_condition_inverse() {
1774-
assert_eq!(Cond::Eq.inverse(), Cond::Ne);
1775-
assert_eq!(Cond::Lt.inverse(), Cond::Ge);
1776-
assert_eq!(Cond::Hi.inverse(), Cond::Ls);
1777-
}
1778-
1779-
#[test]
1780-
fn test_emit_instrs() {
1781-
let target = linux_target();
1782-
1783-
let instrs = vec![
1784-
Aarch64Inst::Stp {
1785-
size: OperandSize::B64,
1786-
src1: Reg::X29,
1787-
src2: Reg::X30,
1788-
addr: MemAddr::PreIndex {
1789-
base: Reg::X29,
1790-
offset: -16,
1791-
},
1792-
},
1793-
Aarch64Inst::Mov {
1794-
size: OperandSize::B64,
1795-
src: GpOperand::Imm(42),
1796-
dst: Reg::X0,
1797-
},
1798-
Aarch64Inst::Ret,
1799-
];
1800-
1801-
let out = emit_instrs(&instrs, &target);
1802-
assert!(out.contains("stp x29, x30"));
1803-
assert!(out.contains("mov x0, #42"));
1804-
assert!(out.contains("ret"));
1805-
}
18061689
}

cc/arch/x86_64/lir.rs

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
// enabling peephole optimizations before final assembly emission.
1414
//
1515

16-
// Allow dead code - LIR infrastructure for future phases
17-
#![allow(dead_code)]
18-
1916
use super::codegen::{Reg, XmmReg};
2017
use crate::arch::lir::{Directive, EmitAsm, FpSize, Label, OperandSize, Symbol};
2118
use crate::target::{Os, Target};
@@ -26,6 +23,7 @@ use std::fmt::{self, Write};
2623
// ============================================================================
2724

2825
/// x86-64 memory addressing mode
26+
#[allow(dead_code)] // Documents full instruction set
2927
#[derive(Debug, Clone, PartialEq)]
3028
pub enum MemAddr {
3129
/// [base + offset] - Register indirect with displacement
@@ -103,19 +101,6 @@ impl GpOperand {
103101
GpOperand::Imm(v) => format!("${}", v),
104102
}
105103
}
106-
107-
/// Check if this is a register operand
108-
pub fn is_reg(&self) -> bool {
109-
matches!(self, GpOperand::Reg(_))
110-
}
111-
112-
/// Get register if this is a register operand
113-
pub fn as_reg(&self) -> Option<Reg> {
114-
match self {
115-
GpOperand::Reg(r) => Some(*r),
116-
_ => None,
117-
}
118-
}
119104
}
120105

121106
// ============================================================================
@@ -146,6 +131,7 @@ impl XmmOperand {
146131
// ============================================================================
147132

148133
/// Integer condition codes for comparisons and conditional jumps/sets
134+
#[allow(dead_code)] // Documents full instruction set
149135
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
150136
pub enum IntCC {
151137
/// Equal (ZF=1)
@@ -198,26 +184,6 @@ impl IntCC {
198184
IntCC::Np => "np",
199185
}
200186
}
201-
202-
/// Get the inverse condition
203-
pub fn inverse(&self) -> IntCC {
204-
match self {
205-
IntCC::E => IntCC::Ne,
206-
IntCC::Ne => IntCC::E,
207-
IntCC::L => IntCC::Ge,
208-
IntCC::Le => IntCC::G,
209-
IntCC::G => IntCC::Le,
210-
IntCC::Ge => IntCC::L,
211-
IntCC::B => IntCC::Ae,
212-
IntCC::Be => IntCC::A,
213-
IntCC::A => IntCC::Be,
214-
IntCC::Ae => IntCC::B,
215-
IntCC::S => IntCC::Ns,
216-
IntCC::Ns => IntCC::S,
217-
IntCC::P => IntCC::Np,
218-
IntCC::Np => IntCC::P,
219-
}
220-
}
221187
}
222188

223189
impl fmt::Display for IntCC {
@@ -244,6 +210,7 @@ pub enum ShiftCount {
244210
// ============================================================================
245211

246212
/// Target for call instructions
213+
#[allow(dead_code)] // Documents full instruction set
247214
#[derive(Debug, Clone, PartialEq)]
248215
pub enum CallTarget {
249216
/// Direct call to symbol
@@ -259,6 +226,7 @@ pub enum CallTarget {
259226
// ============================================================================
260227

261228
/// x86-64 Low-level IR instruction
229+
#[allow(dead_code)] // Documents full instruction set
262230
#[derive(Debug, Clone)]
263231
pub enum X86Inst {
264232
// ========================================================================
@@ -1098,19 +1066,6 @@ impl EmitAsm for X86Inst {
10981066
}
10991067
}
11001068

1101-
// ============================================================================
1102-
// Utility Functions
1103-
// ============================================================================
1104-
1105-
/// Emit a sequence of LIR instructions to assembly text
1106-
pub fn emit_instrs(instrs: &[X86Inst], target: &Target) -> String {
1107-
let mut out = String::new();
1108-
for inst in instrs {
1109-
inst.emit(target, &mut out);
1110-
}
1111-
out
1112-
}
1113-
11141069
// ============================================================================
11151070
// Tests
11161071
// ============================================================================
@@ -1255,26 +1210,4 @@ mod tests {
12551210
inst.emit(&target, &mut out);
12561211
assert!(out.contains("addss"));
12571212
}
1258-
1259-
#[test]
1260-
fn test_emit_instrs() {
1261-
let target = linux_target();
1262-
1263-
let instrs = vec![
1264-
X86Inst::Push {
1265-
src: GpOperand::Reg(Reg::Rbp),
1266-
},
1267-
X86Inst::Mov {
1268-
size: OperandSize::B64,
1269-
src: GpOperand::Reg(Reg::Rsp),
1270-
dst: GpOperand::Reg(Reg::Rbp),
1271-
},
1272-
X86Inst::Ret,
1273-
];
1274-
1275-
let out = emit_instrs(&instrs, &target);
1276-
assert!(out.contains("pushq %rbp"));
1277-
assert!(out.contains("movq %rsp, %rbp"));
1278-
assert!(out.contains("ret"));
1279-
}
12801213
}

0 commit comments

Comments
 (0)