Start converting the translation to one type type

This commit is contained in:
Andrzej Janik 2021-05-05 22:56:58 +02:00
commit 9d92a6e284
3 changed files with 666 additions and 682 deletions

View file

@ -1,6 +1,6 @@
use half::f16; use half::f16;
use lalrpop_util::{lexer::Token, ParseError}; use lalrpop_util::{lexer::Token, ParseError};
use std::{convert::From, convert::TryFrom, mem, num::ParseFloatError, str::FromStr}; use std::{convert::From, mem, num::ParseFloatError, str::FromStr};
use std::{marker::PhantomData, num::ParseIntError}; use std::{marker::PhantomData, num::ParseIntError};
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
@ -110,35 +110,7 @@ pub enum Type {
Scalar(ScalarType), Scalar(ScalarType),
Vector(ScalarType, u8), Vector(ScalarType, u8),
Array(ScalarType, Vec<u32>), Array(ScalarType, Vec<u32>),
Pointer(PointerType, LdStateSpace), Pointer(ScalarType),
}
#[derive(PartialEq, Eq, Clone)]
pub enum PointerType {
Scalar(ScalarType),
Vector(ScalarType, u8),
Array(ScalarType, Vec<u32>),
// Instances of this variant are generated during stateful conversion
Pointer(ScalarType, LdStateSpace),
}
impl From<ScalarType> for PointerType {
fn from(t: ScalarType) -> Self {
PointerType::Scalar(t.into())
}
}
impl TryFrom<PointerType> for ScalarType {
type Error = ();
fn try_from(value: PointerType) -> Result<Self, Self::Error> {
match value {
PointerType::Scalar(t) => Ok(t),
PointerType::Vector(_, _) => Err(()),
PointerType::Array(_, _) => Err(()),
PointerType::Pointer(_, _) => Err(()),
}
}
} }
#[derive(PartialEq, Eq, Hash, Clone, Copy)] #[derive(PartialEq, Eq, Hash, Clone, Copy)]
@ -222,6 +194,7 @@ pub enum StateSpace {
Shared, Shared,
Param, Param,
Generic, Generic,
Sreg,
} }
pub struct PredAt<ID> { pub struct PredAt<ID> {
@ -397,9 +370,9 @@ pub enum VectorPrefix {
pub struct LdDetails { pub struct LdDetails {
pub qualifier: LdStQualifier, pub qualifier: LdStQualifier,
pub state_space: LdStateSpace, pub state_space: StateSpace,
pub caching: LdCacheOperator, pub caching: LdCacheOperator,
pub typ: PointerType, pub typ: Type,
pub non_coherent: bool, pub non_coherent: bool,
} }
@ -418,17 +391,6 @@ pub enum MemScope {
Sys, Sys,
} }
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[repr(u8)]
pub enum LdStateSpace {
Generic,
Const,
Global,
Local,
Param,
Shared,
}
#[derive(Copy, Clone, PartialEq, Eq)] #[derive(Copy, Clone, PartialEq, Eq)]
pub enum LdCacheOperator { pub enum LdCacheOperator {
Cached, Cached,
@ -612,20 +574,11 @@ impl CvtDetails {
} }
pub struct CvtaDetails { pub struct CvtaDetails {
pub to: CvtaStateSpace, pub to: StateSpace,
pub from: CvtaStateSpace, pub from: StateSpace,
pub size: CvtaSize, pub size: CvtaSize,
} }
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum CvtaStateSpace {
Generic,
Const,
Global,
Local,
Shared,
}
pub enum CvtaSize { pub enum CvtaSize {
U32, U32,
U64, U64,
@ -633,18 +586,9 @@ pub enum CvtaSize {
pub struct StData { pub struct StData {
pub qualifier: LdStQualifier, pub qualifier: LdStQualifier,
pub state_space: StStateSpace, pub state_space: StateSpace,
pub caching: StCacheOperator, pub caching: StCacheOperator,
pub typ: PointerType, pub typ: Type,
}
#[derive(PartialEq, Eq, Copy, Clone)]
pub enum StStateSpace {
Generic,
Global,
Local,
Param,
Shared,
} }
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq)]
@ -717,7 +661,7 @@ pub struct MinMaxFloat {
pub struct AtomDetails { pub struct AtomDetails {
pub semantics: AtomSemantics, pub semantics: AtomSemantics,
pub scope: MemScope, pub scope: MemScope,
pub space: AtomSpace, pub space: StateSpace,
pub inner: AtomInnerDetails, pub inner: AtomInnerDetails,
} }
@ -729,13 +673,6 @@ pub enum AtomSemantics {
AcquireRelease, AcquireRelease,
} }
#[derive(Copy, Clone)]
pub enum AtomSpace {
Generic,
Global,
Shared,
}
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum AtomInnerDetails { pub enum AtomInnerDetails {
Bit { op: AtomBitOp, typ: ScalarType }, Bit { op: AtomBitOp, typ: ScalarType },
@ -777,7 +714,7 @@ pub enum AtomFloatOp {
pub struct AtomCasDetails { pub struct AtomCasDetails {
pub semantics: AtomSemantics, pub semantics: AtomSemantics,
pub scope: MemScope, pub scope: MemScope,
pub space: AtomSpace, pub space: StateSpace,
pub typ: ScalarType, pub typ: ScalarType,
} }

View file

@ -619,9 +619,9 @@ ModuleVariable: ast::Variable<&'input str> = {
return Err(ParseError::User { error: ast::PtxError::NonExternPointer }); return Err(ParseError::User { error: ast::PtxError::NonExternPointer });
} }
if space == ".global" { if space == ".global" {
(ast::Type::Pointer(ast::PointerType::Scalar(t), ast::LdStateSpace::Global), ast::StateSpace::Global, Vec::new()) (ast::Type::Pointer(t), ast::StateSpace::Global, Vec::new())
} else { } else {
(ast::Type::Pointer(ast::PointerType::Scalar(t), ast::LdStateSpace::Shared), ast::StateSpace::Shared, Vec::new()) (ast::Type::Pointer(t), ast::StateSpace::Shared, Vec::new())
} }
} }
}; };
@ -643,7 +643,7 @@ ParamVariable: (Option<u32>, Vec<u8>, ast::Type, &'input str) = {
(ast::Type::Array(t, dimensions), init) (ast::Type::Array(t, dimensions), init)
} }
ast::ArrayOrPointer::Pointer => { ast::ArrayOrPointer::Pointer => {
(ast::Type::Pointer(ast::PointerType::Scalar(t), ast::LdStateSpace::Param), Vec::new()) (ast::Type::Pointer(t), Vec::new())
} }
}; };
(align, array_init, v_type, name) (align, array_init, v_type, name)
@ -763,7 +763,7 @@ InstLd: ast::Instruction<ast::ParsedArgParams<'input>> = {
ast::Instruction::Ld( ast::Instruction::Ld(
ast::LdDetails { ast::LdDetails {
qualifier: q.unwrap_or(ast::LdStQualifier::Weak), qualifier: q.unwrap_or(ast::LdStQualifier::Weak),
state_space: ss.unwrap_or(ast::LdStateSpace::Generic), state_space: ss.unwrap_or(ast::StateSpace::Generic),
caching: cop.unwrap_or(ast::LdCacheOperator::Cached), caching: cop.unwrap_or(ast::LdCacheOperator::Cached),
typ: t, typ: t,
non_coherent: false non_coherent: false
@ -775,7 +775,7 @@ InstLd: ast::Instruction<ast::ParsedArgParams<'input>> = {
ast::Instruction::Ld( ast::Instruction::Ld(
ast::LdDetails { ast::LdDetails {
qualifier: q.unwrap_or(ast::LdStQualifier::Weak), qualifier: q.unwrap_or(ast::LdStQualifier::Weak),
state_space: ast::LdStateSpace::Global, state_space: ast::StateSpace::Global,
caching: cop.unwrap_or(ast::LdCacheOperator::Cached), caching: cop.unwrap_or(ast::LdCacheOperator::Cached),
typ: t, typ: t,
non_coherent: false non_coherent: false
@ -787,7 +787,7 @@ InstLd: ast::Instruction<ast::ParsedArgParams<'input>> = {
ast::Instruction::Ld( ast::Instruction::Ld(
ast::LdDetails { ast::LdDetails {
qualifier: ast::LdStQualifier::Weak, qualifier: ast::LdStQualifier::Weak,
state_space: ast::LdStateSpace::Global, state_space: ast::StateSpace::Global,
caching: cop.unwrap_or(ast::LdCacheOperator::Cached), caching: cop.unwrap_or(ast::LdCacheOperator::Cached),
typ: t, typ: t,
non_coherent: true non_coherent: true
@ -797,9 +797,9 @@ InstLd: ast::Instruction<ast::ParsedArgParams<'input>> = {
} }
}; };
LdStType: ast::PointerType = { LdStType: ast::Type = {
<v:VectorPrefix> <t:LdStScalarType> => ast::PointerType::Vector(t, v), <v:VectorPrefix> <t:LdStScalarType> => ast::Type::Vector(t, v),
<t:LdStScalarType> => ast::PointerType::Scalar(t), <t:LdStScalarType> => ast::Type::Scalar(t),
} }
LdStQualifier: ast::LdStQualifier = { LdStQualifier: ast::LdStQualifier = {
@ -815,11 +815,11 @@ MemScope: ast::MemScope = {
".sys" => ast::MemScope::Sys ".sys" => ast::MemScope::Sys
}; };
LdNonGlobalStateSpace: ast::LdStateSpace = { LdNonGlobalStateSpace: ast::StateSpace = {
".const" => ast::LdStateSpace::Const, ".const" => ast::StateSpace::Const,
".local" => ast::LdStateSpace::Local, ".local" => ast::StateSpace::Local,
".param" => ast::LdStateSpace::Param, ".param" => ast::StateSpace::Param,
".shared" => ast::LdStateSpace::Shared, ".shared" => ast::StateSpace::Shared,
}; };
LdCacheOperator: ast::LdCacheOperator = { LdCacheOperator: ast::LdCacheOperator = {
@ -1235,7 +1235,7 @@ InstSt: ast::Instruction<ast::ParsedArgParams<'input>> = {
ast::Instruction::St( ast::Instruction::St(
ast::StData { ast::StData {
qualifier: q.unwrap_or(ast::LdStQualifier::Weak), qualifier: q.unwrap_or(ast::LdStQualifier::Weak),
state_space: ss.unwrap_or(ast::StStateSpace::Generic), state_space: ss.unwrap_or(ast::StateSpace::Generic),
caching: cop.unwrap_or(ast::StCacheOperator::Writeback), caching: cop.unwrap_or(ast::StCacheOperator::Writeback),
typ: t typ: t
}, },
@ -1249,11 +1249,11 @@ MemoryOperand: ast::Operand<&'input str> = {
"[" <o:Operand> "]" => o "[" <o:Operand> "]" => o
} }
StStateSpace: ast::StStateSpace = { StStateSpace: ast::StateSpace = {
".global" => ast::StStateSpace::Global, ".global" => ast::StateSpace::Global,
".local" => ast::StStateSpace::Local, ".local" => ast::StateSpace::Local,
".param" => ast::StStateSpace::Param, ".param" => ast::StateSpace::Param,
".shared" => ast::StStateSpace::Shared, ".shared" => ast::StateSpace::Shared,
}; };
StCacheOperator: ast::StCacheOperator = { StCacheOperator: ast::StCacheOperator = {
@ -1272,7 +1272,7 @@ InstRet: ast::Instruction<ast::ParsedArgParams<'input>> = {
InstCvta: ast::Instruction<ast::ParsedArgParams<'input>> = { InstCvta: ast::Instruction<ast::ParsedArgParams<'input>> = {
"cvta" <from:CvtaStateSpace> <s:CvtaSize> <a:Arg2> => { "cvta" <from:CvtaStateSpace> <s:CvtaSize> <a:Arg2> => {
ast::Instruction::Cvta(ast::CvtaDetails { ast::Instruction::Cvta(ast::CvtaDetails {
to: ast::CvtaStateSpace::Generic, to: ast::StateSpace::Generic,
from, from,
size: s size: s
}, },
@ -1281,18 +1281,18 @@ InstCvta: ast::Instruction<ast::ParsedArgParams<'input>> = {
"cvta" ".to" <to:CvtaStateSpace> <s:CvtaSize> <a:Arg2> => { "cvta" ".to" <to:CvtaStateSpace> <s:CvtaSize> <a:Arg2> => {
ast::Instruction::Cvta(ast::CvtaDetails { ast::Instruction::Cvta(ast::CvtaDetails {
to, to,
from: ast::CvtaStateSpace::Generic, from: ast::StateSpace::Generic,
size: s size: s
}, },
a) a)
} }
} }
CvtaStateSpace: ast::CvtaStateSpace = { CvtaStateSpace: ast::StateSpace = {
".const" => ast::CvtaStateSpace::Const, ".const" => ast::StateSpace::Const,
".global" => ast::CvtaStateSpace::Global, ".global" => ast::StateSpace::Global,
".local" => ast::CvtaStateSpace::Local, ".local" => ast::StateSpace::Local,
".shared" => ast::CvtaStateSpace::Shared, ".shared" => ast::StateSpace::Shared,
} }
CvtaSize: ast::CvtaSize = { CvtaSize: ast::CvtaSize = {
@ -1450,7 +1450,7 @@ InstAtom: ast::Instruction<ast::ParsedArgParams<'input>> = {
let details = ast::AtomDetails { let details = ast::AtomDetails {
semantics: sema.unwrap_or(ast::AtomSemantics::Relaxed), semantics: sema.unwrap_or(ast::AtomSemantics::Relaxed),
scope: scope.unwrap_or(ast::MemScope::Gpu), scope: scope.unwrap_or(ast::MemScope::Gpu),
space: space.unwrap_or(ast::AtomSpace::Generic), space: space.unwrap_or(ast::StateSpace::Generic),
inner: ast::AtomInnerDetails::Bit { op, typ } inner: ast::AtomInnerDetails::Bit { op, typ }
}; };
ast::Instruction::Atom(details,a) ast::Instruction::Atom(details,a)
@ -1459,7 +1459,7 @@ InstAtom: ast::Instruction<ast::ParsedArgParams<'input>> = {
let details = ast::AtomDetails { let details = ast::AtomDetails {
semantics: sema.unwrap_or(ast::AtomSemantics::Relaxed), semantics: sema.unwrap_or(ast::AtomSemantics::Relaxed),
scope: scope.unwrap_or(ast::MemScope::Gpu), scope: scope.unwrap_or(ast::MemScope::Gpu),
space: space.unwrap_or(ast::AtomSpace::Generic), space: space.unwrap_or(ast::StateSpace::Generic),
inner: ast::AtomInnerDetails::Unsigned { inner: ast::AtomInnerDetails::Unsigned {
op: ast::AtomUIntOp::Inc, op: ast::AtomUIntOp::Inc,
typ: ast::ScalarType::U32 typ: ast::ScalarType::U32
@ -1471,7 +1471,7 @@ InstAtom: ast::Instruction<ast::ParsedArgParams<'input>> = {
let details = ast::AtomDetails { let details = ast::AtomDetails {
semantics: sema.unwrap_or(ast::AtomSemantics::Relaxed), semantics: sema.unwrap_or(ast::AtomSemantics::Relaxed),
scope: scope.unwrap_or(ast::MemScope::Gpu), scope: scope.unwrap_or(ast::MemScope::Gpu),
space: space.unwrap_or(ast::AtomSpace::Generic), space: space.unwrap_or(ast::StateSpace::Generic),
inner: ast::AtomInnerDetails::Unsigned { inner: ast::AtomInnerDetails::Unsigned {
op: ast::AtomUIntOp::Dec, op: ast::AtomUIntOp::Dec,
typ: ast::ScalarType::U32 typ: ast::ScalarType::U32
@ -1484,7 +1484,7 @@ InstAtom: ast::Instruction<ast::ParsedArgParams<'input>> = {
let details = ast::AtomDetails { let details = ast::AtomDetails {
semantics: sema.unwrap_or(ast::AtomSemantics::Relaxed), semantics: sema.unwrap_or(ast::AtomSemantics::Relaxed),
scope: scope.unwrap_or(ast::MemScope::Gpu), scope: scope.unwrap_or(ast::MemScope::Gpu),
space: space.unwrap_or(ast::AtomSpace::Generic), space: space.unwrap_or(ast::StateSpace::Generic),
inner: ast::AtomInnerDetails::Float { op, typ } inner: ast::AtomInnerDetails::Float { op, typ }
}; };
ast::Instruction::Atom(details,a) ast::Instruction::Atom(details,a)
@ -1493,7 +1493,7 @@ InstAtom: ast::Instruction<ast::ParsedArgParams<'input>> = {
let details = ast::AtomDetails { let details = ast::AtomDetails {
semantics: sema.unwrap_or(ast::AtomSemantics::Relaxed), semantics: sema.unwrap_or(ast::AtomSemantics::Relaxed),
scope: scope.unwrap_or(ast::MemScope::Gpu), scope: scope.unwrap_or(ast::MemScope::Gpu),
space: space.unwrap_or(ast::AtomSpace::Generic), space: space.unwrap_or(ast::StateSpace::Generic),
inner: ast::AtomInnerDetails::Unsigned { op, typ } inner: ast::AtomInnerDetails::Unsigned { op, typ }
}; };
ast::Instruction::Atom(details,a) ast::Instruction::Atom(details,a)
@ -1502,7 +1502,7 @@ InstAtom: ast::Instruction<ast::ParsedArgParams<'input>> = {
let details = ast::AtomDetails { let details = ast::AtomDetails {
semantics: sema.unwrap_or(ast::AtomSemantics::Relaxed), semantics: sema.unwrap_or(ast::AtomSemantics::Relaxed),
scope: scope.unwrap_or(ast::MemScope::Gpu), scope: scope.unwrap_or(ast::MemScope::Gpu),
space: space.unwrap_or(ast::AtomSpace::Generic), space: space.unwrap_or(ast::StateSpace::Generic),
inner: ast::AtomInnerDetails::Signed { op, typ } inner: ast::AtomInnerDetails::Signed { op, typ }
}; };
ast::Instruction::Atom(details,a) ast::Instruction::Atom(details,a)
@ -1514,7 +1514,7 @@ InstAtomCas: ast::Instruction<ast::ParsedArgParams<'input>> = {
let details = ast::AtomCasDetails { let details = ast::AtomCasDetails {
semantics: sema.unwrap_or(ast::AtomSemantics::Relaxed), semantics: sema.unwrap_or(ast::AtomSemantics::Relaxed),
scope: scope.unwrap_or(ast::MemScope::Gpu), scope: scope.unwrap_or(ast::MemScope::Gpu),
space: space.unwrap_or(ast::AtomSpace::Generic), space: space.unwrap_or(ast::StateSpace::Generic),
typ, typ,
}; };
ast::Instruction::AtomCas(details,a) ast::Instruction::AtomCas(details,a)
@ -1528,9 +1528,9 @@ AtomSemantics: ast::AtomSemantics = {
".acq_rel" => ast::AtomSemantics::AcquireRelease ".acq_rel" => ast::AtomSemantics::AcquireRelease
} }
AtomSpace: ast::AtomSpace = { AtomSpace: ast::StateSpace = {
".global" => ast::AtomSpace::Global, ".global" => ast::StateSpace::Global,
".shared" => ast::AtomSpace::Shared ".shared" => ast::StateSpace::Shared
} }
AtomBitOp: ast::AtomBitOp = { AtomBitOp: ast::AtomBitOp = {

File diff suppressed because it is too large Load diff