P4C
The P4 Compiler
Loading...
Searching...
No Matches
PragmaAlias Class Reference

#include <pa_alias.h>

Inheritance diagram for PragmaAlias:
[legend]

Classes

struct  AliasDestination
 

Public Types

using AliasMap = ordered_map<cstring, AliasDestination>
 Map type from alias sources to destinations.
 
enum  CreatedBy { PRAGMA , COMPILER }
 
- Public Types inherited from P4::Visitor
typedef Visitor_Context Context
 

Public Member Functions

 PragmaAlias (PhvInfo &phv, PragmaNoOverlay &no_ovrl)
 
bool addAlias (const PHV::Field *f1, const PHV::Field *f2, bool suppressWarning=false, CreatedBy who=PRAGMA)
 
const AliasMapgetAliasMap () const
 
std::optional< std::pair< const PHV::Field *, const PHV::Field * > > mayAddAlias (const PHV::Field *f1, const PHV::Field *f2, bool suppressWarning=false, CreatedBy who=PRAGMA)
 
std::string pretty_print () const override
 
- Public Member Functions inherited from P4::Inspector
const IR::Nodeapply_visitor (const IR::Node *, const char *name=0) override
 
profile_t init_apply (const IR::Node *root) override
 
virtual void loop_revisit (const IR::Node *)
 
virtual void postorder (const IR::Node *)
 
virtual bool preorder (const IR::Node *)
 
virtual void revisit (const IR::Node *)
 
void revisit_visited ()
 
bool visit_in_progress (const IR::Node *n) const
 
void visitAgain () const override
 
void visitOnce () const override
 
- Public Member Functions inherited from P4::Visitor
virtual bool check_global (cstring)
 
virtual void clear_globals ()
 
virtual Visitorclone () const
 
virtual ControlFlowVisitorcontrolFlowVisitor ()
 
virtual void end_apply ()
 
virtual void end_apply (const IR::Node *root)
 
virtual void erase_global (cstring)
 
template<class T >
const T * findContext () const
 
template<class T >
const T * findContext (const Context *&c) const
 
template<class T >
const T * findOrigCtxt () const
 
template<class T >
const T * findOrigCtxt (const Context *&c) const
 
virtual Visitorflow_clone ()
 
virtual void flow_merge (Visitor &)
 
virtual bool flow_merge_closure (Visitor &)
 
virtual void flow_merge_global_from (cstring)
 
virtual void flow_merge_global_to (cstring)
 
const ContextgetChildContext () const
 
int getChildrenVisited () const
 
const ContextgetContext () const
 
int getContextDepth () const
 
const IR::NodegetCurrentNode () const
 
template<class T >
const T * getCurrentNode () const
 
const IR::NodegetOriginal () const
 
template<class T >
const T * getOriginal () const
 
template<class T >
const T * getParent () const
 
virtual bool has_flow_joins () const
 
profile_t init_apply (const IR::Node *root, const Context *parent_context)
 
bool isInContext (const IR::Node *n) const
 
virtual const char * name () const
 
template<class T >
void parallel_visit (const IR::Vector< T > &v, const char *name, int cidx)
 
template<class T >
void parallel_visit (const IR::Vector< T > &v, const char *name=0)
 
template<class T >
void parallel_visit (IR::Vector< T > &v, const char *name, int cidx)
 
template<class T >
void parallel_visit (IR::Vector< T > &v, const char *name=0)
 
void print_context () const
 
const VisitorsetCalledBy (const Visitor *visitor)
 
void setName (const char *name)
 
void visit (const IR::Node &n, const char *name, int cidx)
 
void visit (const IR::Node &n, const char *name=0)
 
void visit (const IR::Node *&n, const char *name, int cidx)
 
void visit (const IR::Node *&n, const char *name=0)
 
void visit (const IR::Node *const &n, const char *name, int cidx)
 
void visit (const IR::Node *const &n, const char *name=0)
 
void visit (IR::Node &n, const char *name, int cidx)
 
void visit (IR::Node &n, const char *name=0)
 
void visit (IR::Node *&, const char *=0, int=0)
 
template<class T , typename = std::enable_if_t<Util::has_SourceInfo_v<T> && !std::is_pointer_v<T>>, class... Args>
void warn (const int kind, const char *format, const T &node, Args &&...args)
 The const ref variant of the above.
 
template<class T , typename = std::enable_if_t<Util::has_SourceInfo_v<T>>, class... Args>
void warn (const int kind, const char *format, const T *node, Args &&...args)
 
bool warning_enabled (int warning_kind) const
 
- Public Member Functions inherited from Pragma::PrettyPrint

Static Public Attributes

static const char * description = "Specifies that two fields are aliased"
 
static const char * help
 
static const char * name = "pa_alias"
 BFN::Pragma interface.
 

Additional Inherited Members

- Static Public Member Functions inherited from P4::Visitor
static cstring demangle (const char *)
 
static bool warning_enabled (const Visitor *visitor, int warning_kind)
 
- Public Attributes inherited from P4::Visitor
const Visitorcalled_by = nullptr
 
cstring internalName
 
SplitFlowVisit_base *& split_link
 
SplitFlowVisit_basesplit_link_mem = nullptr
 
- Protected Member Functions inherited from P4::Visitor
virtual void init_join_flows (const IR::Node *)
 
virtual bool join_flows (const IR::Node *)
 
virtual void post_join_flows (const IR::Node *, const IR::Node *)
 
void visit_children (const IR::Node *, std::function< void()> fn)
 
- Protected Attributes inherited from P4::Visitor
bool dontForwardChildrenBeforePreorder = false
 
bool joinFlows = false
 
bool visitDagOnce = true
 

Detailed Description

pa_alias pragma support.

This pass will gather all pa_alias pragmas and generate pa_alias_i: mapping from a field to another field that it aliases with.


Class Documentation

◆ PragmaAlias::AliasDestination

struct PragmaAlias::AliasDestination
Class Members
cstring field The alias destination field.
optional< le_bitrange > range

The range of the field being aliased, or std::nullopt when the entire field is aliased.

CreatedBy who Who created the pragma?

Member Function Documentation

◆ mayAddAlias()

std::optional< std::pair< const PHV::Field *, const PHV::Field * > > PragmaAlias::mayAddAlias ( const PHV::Field * f1,
const PHV::Field * f2,
bool suppressWarning = false,
PragmaAlias::CreatedBy who = PRAGMA )

Checks if alias is possible between f1 and f2. If not, returns std::nullopt. If yes, it returns a pair of fields, the first being the alias destination and the second is the alias source (field being replaced).

◆ pretty_print()

std::string PragmaAlias::pretty_print ( ) const
overridevirtual

Implements Pragma::PrettyPrint.

Member Data Documentation

◆ help

const char * PragmaAlias::help
static
Initial value:
=
"@pragma pa_alias [pipe] gress inst1.field_name_1 inst_2.field_name_2 "
"<inst_3.field_name_3 ...>\n"
"+ attached to P4 header instances\n"
"\n"
"Specifies that each packet and/or metadata field instance specified "
"in the pragma must be considered as an alias to every other field "
"instance specified in the same pragma. The set of field instances "
"(aliasing fields) specified with every pa_alias pragma must have at "
"least two members. "
"Note that the list of aliasing fields can only have a maximum of one "
"packet field/intrinsic metadata field instance. "
"Use this pragma with care, as it merges the constraints of all fields."
"The gress value can be either ingress or egress. "
"If the optional pipe value is provided, the pragma is applied only "
"to the corresponding pipeline. If not provided, it is applied to "
"all pipelines. "
"The fields must all "
"be of the same width. Note that incorrect aliasing may result in "
"incorrect behavior--the compiler will allocate all the fields specified "
"in the pragma to the same containers, without additional correctness "
"checks. "
"Finally, any field can appear in only one pa_alias pragma. If the same "
"field appears in multiple pa_alias pragmas, then the compiler ignores all "
"but one of those pragmas, and emits a warning for all the other pragmas "
"that are not enforced."

◆ name

const char * PragmaAlias::name = "pa_alias"
static

BFN::Pragma interface.

Copyright (C) 2024 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0