pub enum ClauseData {
Show 43 variants
Bare(Identifier),
Expression(Expression),
ItemList(Vec<ClauseItem>),
Private {
items: Vec<ClauseItem>,
},
Firstprivate {
items: Vec<ClauseItem>,
},
Lastprivate {
modifier: Option<LastprivateModifier>,
items: Vec<ClauseItem>,
},
Shared {
items: Vec<ClauseItem>,
},
Default(DefaultKind),
Reduction {
operator: ReductionOperator,
items: Vec<ClauseItem>,
},
Map {
map_type: Option<MapType>,
mapper: Option<Identifier>,
items: Vec<ClauseItem>,
},
UseDevicePtr {
items: Vec<ClauseItem>,
},
UseDeviceAddr {
items: Vec<ClauseItem>,
},
IsDevicePtr {
items: Vec<ClauseItem>,
},
HasDeviceAddr {
items: Vec<ClauseItem>,
},
Depend {
depend_type: DependType,
items: Vec<ClauseItem>,
},
Priority {
priority: Expression,
},
Affinity {
items: Vec<ClauseItem>,
},
Schedule {
kind: ScheduleKind,
modifiers: Vec<ScheduleModifier>,
chunk_size: Option<Expression>,
},
Collapse {
n: Expression,
},
Ordered {
n: Option<Expression>,
},
Linear {
modifier: Option<LinearModifier>,
items: Vec<ClauseItem>,
step: Option<Expression>,
},
Aligned {
items: Vec<ClauseItem>,
alignment: Option<Expression>,
},
Safelen {
length: Expression,
},
Simdlen {
length: Expression,
},
If {
directive_name: Option<Identifier>,
condition: Expression,
},
ProcBind(ProcBind),
NumThreads {
num: Expression,
},
Device {
device_num: Expression,
},
DeviceType(DeviceType),
AtomicDefaultMemOrder(MemoryOrder),
AtomicOperation {
op: AtomicOp,
memory_order: Option<MemoryOrder>,
},
Order(OrderKind),
NumTeams {
num: Expression,
},
ThreadLimit {
limit: Expression,
},
Allocate {
allocator: Option<Identifier>,
items: Vec<ClauseItem>,
},
Allocator {
allocator: Identifier,
},
Copyin {
items: Vec<ClauseItem>,
},
Copyprivate {
items: Vec<ClauseItem>,
},
DistSchedule {
kind: ScheduleKind,
chunk_size: Option<Expression>,
},
Grainsize {
grain: Expression,
},
NumTasks {
num: Expression,
},
Filter {
thread_num: Expression,
},
Generic {
name: Identifier,
data: Option<String>,
},
}
Expand description
Complete semantic data for an OpenMP clause
This enum represents the meaning of each OpenMP clause type. Each variant captures the specific data needed for that clause.
§Examples
// default(shared)
let clause = ClauseData::Default(DefaultKind::Shared);
assert_eq!(clause.to_string(), "default(shared)");
// reduction(+: sum)
let clause = ClauseData::Reduction {
operator: ReductionOperator::Add,
items: vec![Identifier::new("sum").into()],
};
assert_eq!(clause.to_string(), "reduction(+: sum)");
§Learning: Large Enums with Complex Data
This enum demonstrates several advanced Rust patterns:
- Many variants: ~30 variants for different clause types
- Variants with data: Most variants contain structured data
- Named fields: Using struct-like syntax for clarity
- Vec for lists: Variable-length lists of items
- Option for optionals: Optional parameters
- Composition: Combines all previous IR types
§Design Philosophy
Each variant captures exactly what’s needed for semantic analysis:
Private
: List of variables to make privateReduction
: Operator + list of reduction variablesMap
: Map type + list of variables to mapSchedule
: Schedule kind + optional modifiers + optional chunk size
This is much richer than the parser’s string-based representation.
Variants§
Bare(Identifier)
Clause with no parameters (e.g., nowait
, nogroup
)
Expression(Expression)
Single expression parameter (e.g., num_threads(4)
)
ItemList(Vec<ClauseItem>)
List of items (e.g., private(x, y, z)
)
Private
private(list)
- Variables are private to each thread
Fields
items: Vec<ClauseItem>
Firstprivate
firstprivate(list)
- Variables initialized from master thread
Fields
items: Vec<ClauseItem>
Lastprivate
lastprivate([modifier:] list)
- Variables updated from last iteration
shared(list)
- Variables shared among all threads
Default(DefaultKind)
default(shared|none|...)
- Default data-sharing attribute
Reduction
reduction([modifier,]operator: list)
- Reduction operation
Map
map([[mapper(id),] map-type:] list)
- Map variables to device
UseDevicePtr
use_device_ptr(list)
- Use device pointers
Fields
items: Vec<ClauseItem>
UseDeviceAddr
use_device_addr(list)
- Use device addresses
Fields
items: Vec<ClauseItem>
IsDevicePtr
is_device_ptr(list)
- Variables are device pointers
Fields
items: Vec<ClauseItem>
HasDeviceAddr
has_device_addr(list)
- Variables have device addresses
Fields
items: Vec<ClauseItem>
Depend
depend([modifier,] type: list)
- Task dependencies
Priority
priority(expression)
- Task priority
Fields
priority: Expression
Affinity
affinity([modifier:] list)
- Task affinity
Fields
items: Vec<ClauseItem>
Schedule
schedule([modifier [, modifier]:]kind[, chunk_size])
- Loop schedule
Collapse
collapse(n)
- Collapse nested loops
Fields
n: Expression
Ordered
ordered[(n)]
- Ordered iterations
Fields
n: Option<Expression>
Linear
linear(list[:step])
- Linear variables in SIMD
Aligned
aligned(list[:alignment])
- Aligned variables
Safelen
safelen(length)
- Safe SIMD vector length
Fields
length: Expression
Simdlen
simdlen(length)
- Preferred SIMD vector length
Fields
length: Expression
If
if([directive-name-modifier:] expression)
- Conditional execution
ProcBind(ProcBind)
proc_bind(master|close|spread|primary)
- Thread affinity policy
NumThreads
num_threads(expression)
- Number of threads
Fields
num: Expression
Device
device(expression)
- Target device
Fields
device_num: Expression
DeviceType(DeviceType)
device_type(host|nohost|any)
- Device type specifier
AtomicDefaultMemOrder(MemoryOrder)
atomic_default_mem_order(seq_cst|acq_rel|...)
- Default memory order
AtomicOperation
Atomic operation modifier
Order(OrderKind)
order(concurrent)
- Iteration execution order
NumTeams
num_teams(expression)
- Number of teams
Fields
num: Expression
ThreadLimit
thread_limit(expression)
- Thread limit per team
Fields
limit: Expression
Allocate
allocate([allocator:] list)
- Memory allocator
Allocator
allocator(allocator-handle)
- Specify allocator
Fields
allocator: Identifier
Copyin
copyin(list)
- Copy master thread value to team threads
Fields
items: Vec<ClauseItem>
Copyprivate
copyprivate(list)
- Broadcast value from one thread
Fields
items: Vec<ClauseItem>
DistSchedule
dist_schedule(kind[, chunk_size])
- Distribute schedule
Grainsize
grainsize(expression)
- Taskloop grainsize
Fields
grain: Expression
NumTasks
num_tasks(expression)
- Number of tasks
Fields
num: Expression
Filter
filter(thread-num)
- Thread filter for masked construct
Fields
thread_num: Expression
Generic
Generic clause with unparsed data (fallback for unknown clauses)
Implementations§
Source§impl<'a> ClauseData
impl<'a> ClauseData
Sourcepub fn is_default(&self) -> bool
pub fn is_default(&self) -> bool
Check if this is a default clause
Sourcepub fn is_private(&self) -> bool
pub fn is_private(&self) -> bool
Check if this is a private clause
Sourcepub fn is_firstprivate(&self) -> bool
pub fn is_firstprivate(&self) -> bool
Check if this is a firstprivate clause
Sourcepub fn is_lastprivate(&self) -> bool
pub fn is_lastprivate(&self) -> bool
Check if this is a lastprivate clause
Check if this is a shared clause
Sourcepub fn is_reduction(&self) -> bool
pub fn is_reduction(&self) -> bool
Check if this is a reduction clause
Sourcepub fn is_num_threads(&self) -> bool
pub fn is_num_threads(&self) -> bool
Check if this is a num_threads clause
Sourcepub fn is_collapse(&self) -> bool
pub fn is_collapse(&self) -> bool
Check if this is a collapse clause
Sourcepub fn is_ordered(&self) -> bool
pub fn is_ordered(&self) -> bool
Check if this is an ordered clause
Sourcepub fn is_schedule(&self) -> bool
pub fn is_schedule(&self) -> bool
Check if this is a schedule clause
Sourcepub fn is_proc_bind(&self) -> bool
pub fn is_proc_bind(&self) -> bool
Check if this is a proc_bind clause
Trait Implementations§
Source§impl Clone for ClauseData
impl Clone for ClauseData
Source§fn clone(&self) -> ClauseData
fn clone(&self) -> ClauseData
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more