1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::ir::entities::DynamicType;
use crate::ir::types::*;
use crate::ir::GlobalValue;
use crate::ir::PrimaryMap;
use crate::ir::Type;
#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};
#[derive(Clone, PartialEq, Hash)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
pub struct DynamicTypeData {
pub base_vector_ty: Type,
pub dynamic_scale: GlobalValue,
}
impl DynamicTypeData {
pub fn new(base_vector_ty: Type, dynamic_scale: GlobalValue) -> Self {
assert!(base_vector_ty.is_vector());
Self {
base_vector_ty,
dynamic_scale,
}
}
pub fn concrete(&self) -> Option<Type> {
self.base_vector_ty.vector_to_dynamic()
}
}
pub type DynamicTypes = PrimaryMap<DynamicType, DynamicTypeData>;
pub fn dynamic_to_fixed(ty: Type) -> Type {
match ty {
I8X8XN => I8X8,
I8X16XN => I8X16,
I16X4XN => I16X4,
I16X8XN => I16X8,
I32X2XN => I32X2,
I32X4XN => I32X4,
I64X2XN => I64X2,
F32X4XN => F32X4,
F64X2XN => F64X2,
_ => unreachable!("unhandled type: {}", ty),
}
}