LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches

A reference to a "source", which is the base value from which other SSA values are derived. More...

#include <SourceRef.h>

Classes

struct  Hash

Public Types

using Path = std::vector<SourceRefIndex>

Public Member Functions

 SourceRef (mlir::BlockArgument b, Path p={})
 SourceRef (component::CreateStructOp createOp, Path p={})
 SourceRef (NonDetOp nondet, Path p={})
 SourceRef (mlir::OpResult rootResult, Path p={})
 SourceRef (felt::FeltConstantOp c)
 SourceRef (mlir::arith::ConstantIndexOp c)
 SourceRef (polymorphic::ConstReadOp c)
mlir::Type getType () const
bool isConstantFelt () const
bool isConstantIndex () const
bool isTemplateConstant () const
 Return whether this reference originates from a template constant read.
bool isConstant () const
bool isConstantInt () const
bool isFeltVal () const
bool isIndexVal () const
bool isIntegerVal () const
bool isTypeVarVal () const
bool isScalar () const
bool isRooted () const
bool isBlockArgument () const
mlir::FailureOr< mlir::Value > getRoot () const
mlir::FailureOr< mlir::Value > getConstant () const
mlir::FailureOr< mlir::BlockArgument > getBlockArgument () const
mlir::FailureOr< unsigned > getInputNum () const
bool isCreateStructOp () const
mlir::FailureOr< component::CreateStructOp > getCreateStructOp () const
bool isNonDetOp () const
mlir::FailureOr< NonDetOp > getNonDetOp () const
bool isCallResult () const
mlir::FailureOr< function::CallOp > getCallOp () const
mlir::FailureOr< llvm::DynamicAPInt > getConstantFeltValue () const
 Return the field representative, or failure for a nonconstant or unspecified field.
mlir::FailureOr< llvm::DynamicAPInt > getConstantIndexValue () const
mlir::FailureOr< llvm::DynamicAPInt > getConstantValue (const Field &field) const
 Reduce a felt constant's declared-field representative into the supplied analysis field.
mlir::FailureOr< llvm::DynamicAPInt > getConstantValue () const
 Return a known numeric value, failing for fieldless felt constants.
bool isValidPrefix (const SourceRef &prefix) const
 Returns true iff prefix is a valid prefix of this reference.
bool overlaps (const SourceRef &rhs) const
 Return true when both references select overlapping storage at the same path depth.
SourceRef narrowRanges (const SourceRef &rhs) const
 Return a copy with ranged array indices narrowed by concrete indices from rhs.
mlir::FailureOr< std::vector< SourceRefIndex > > getSuffix (const SourceRef &prefix) const
 If prefix is a valid prefix of this reference, return the suffix that remains after removing the prefix.
mlir::FailureOr< SourceRef > translate (const SourceRef &prefix, const SourceRef &other) const
 Create a new reference with prefix replaced with other iff prefix is a valid prefix for this reference.
mlir::FailureOr< SourceRef > getParentPrefix () const
 Create a new reference that is the immediate prefix of this reference if possible.
std::vector< SourceRef > getAllChildren (mlir::SymbolTableCollection &tables, mlir::ModuleOp mod) const
 Get all direct children of this SourceRef, assuming this ref is not a scalar.
mlir::FailureOr< SourceRef > createChild (const SourceRefIndex &r) const
mlir::FailureOr< SourceRef > createChild (const SourceRef &other) const
llvm::ArrayRef< SourceRefIndex > getPieces () const
llvm::ArrayRef< SourceRefIndex > getPath () const
void print (mlir::raw_ostream &os) const
 Print this reference using source-style names.
void dump () const
bool operator== (const SourceRef &rhs) const
bool operator!= (const SourceRef &rhs) const
std::strong_ordering operator<=> (const SourceRef &rhs) const

Static Public Member Functions

static std::vector< SourceRef > getAllSourceRefs (mlir::SymbolTableCollection &tables, mlir::ModuleOp mod, const SourceRef &root)
 Produce all possible SourceRefs that are present starting from the given root.
static std::vector< SourceRef > getAllSourceRefs (component::StructDefOp structDef, function::FuncDefOp fnOp)
 Produce all possible SourceRefs that are present from given struct function.
static std::vector< SourceRef > getAllSourceRefs (component::StructDefOp structDef, component::MemberDefOp memberDef)
 Produce all possible SourceRefs from a specific member in a struct.

Friends

struct llvm::DenseMapInfo< SourceRef >

Detailed Description

A reference to a "source", which is the base value from which other SSA values are derived.

The object may be a reference to an individual felt, felt.const, or a composite type, like an array or an entire struct.

  • SourceRefs are allowed to reference composite types so that references can be generated for intermediate operations (e.g., readm to read a nested struct).

These references are relative to a particular function call, so they are either (1) constants, or (2) rooted at a value (e.g., self, a nondet op, an external call result, an array.new result, an array.read result, or another block argument), and optionally contain indices into root (e.g., a member reference in a struct or a index into an array).

Definition at line 152 of file SourceRef.h.

Member Typedef Documentation

◆ Path

using llzk::SourceRef::Path = std::vector<SourceRefIndex>

Definition at line 154 of file SourceRef.h.

Constructor & Destructor Documentation

◆ SourceRef() [1/7]

llzk::SourceRef::SourceRef ( mlir::BlockArgument b,
Path p = {} )
inline

Definition at line 224 of file SourceRef.h.

◆ SourceRef() [2/7]

llzk::SourceRef::SourceRef ( component::CreateStructOp createOp,
Path p = {} )
inline

Definition at line 226 of file SourceRef.h.

◆ SourceRef() [3/7]

llzk::SourceRef::SourceRef ( NonDetOp nondet,
Path p = {} )
inline

Definition at line 228 of file SourceRef.h.

◆ SourceRef() [4/7]

llzk::SourceRef::SourceRef ( mlir::OpResult rootResult,
Path p = {} )
inline

Definition at line 230 of file SourceRef.h.

◆ SourceRef() [5/7]

llzk::SourceRef::SourceRef ( felt::FeltConstantOp c)
inlineexplicit

Definition at line 235 of file SourceRef.h.

◆ SourceRef() [6/7]

llzk::SourceRef::SourceRef ( mlir::arith::ConstantIndexOp c)
inlineexplicit

Definition at line 237 of file SourceRef.h.

◆ SourceRef() [7/7]

llzk::SourceRef::SourceRef ( polymorphic::ConstReadOp c)
inlineexplicit

Definition at line 239 of file SourceRef.h.

Member Function Documentation

◆ createChild() [1/2]

mlir::FailureOr< SourceRef > llzk::SourceRef::createChild ( const SourceRef & other) const
inline

Definition at line 393 of file SourceRef.h.

◆ createChild() [2/2]

mlir::FailureOr< SourceRef > llzk::SourceRef::createChild ( const SourceRefIndex & r) const
inline

Definition at line 384 of file SourceRef.h.

◆ dump()

void llzk::SourceRef::dump ( ) const
inline

Definition at line 411 of file SourceRef.h.

◆ getAllChildren()

std::vector< SourceRef > llzk::SourceRef::getAllChildren ( mlir::SymbolTableCollection & tables,
mlir::ModuleOp mod ) const

Get all direct children of this SourceRef, assuming this ref is not a scalar.

Definition at line 542 of file SourceRef.cpp.

◆ getAllSourceRefs() [1/3]

std::vector< SourceRef > llzk::SourceRef::getAllSourceRefs ( component::StructDefOp structDef,
component::MemberDefOp memberDef )
static

Produce all possible SourceRefs from a specific member in a struct.

May produce multiple if the given member is of an aggregate type.

Definition at line 341 of file SourceRef.cpp.

◆ getAllSourceRefs() [2/3]

std::vector< SourceRef > llzk::SourceRef::getAllSourceRefs ( component::StructDefOp structDef,
function::FuncDefOp fnOp )
static

Produce all possible SourceRefs that are present from given struct function.

Definition at line 312 of file SourceRef.cpp.

◆ getAllSourceRefs() [3/3]

std::vector< SourceRef > llzk::SourceRef::getAllSourceRefs ( mlir::SymbolTableCollection & tables,
mlir::ModuleOp mod,
const SourceRef & root )
static

Produce all possible SourceRefs that are present starting from the given root.

◆ getBlockArgument()

mlir::FailureOr< mlir::BlockArgument > llzk::SourceRef::getBlockArgument ( ) const
inline

Definition at line 282 of file SourceRef.h.

◆ getCallOp()

mlir::FailureOr< function::CallOp > llzk::SourceRef::getCallOp ( ) const
inline

Definition at line 305 of file SourceRef.h.

◆ getConstant()

mlir::FailureOr< mlir::Value > llzk::SourceRef::getConstant ( ) const
inline

Definition at line 276 of file SourceRef.h.

◆ getConstantFeltValue()

mlir::FailureOr< llvm::DynamicAPInt > llzk::SourceRef::getConstantFeltValue ( ) const
inline

Return the field representative, or failure for a nonconstant or unspecified field.

Definition at line 308 of file SourceRef.h.

◆ getConstantIndexValue()

mlir::FailureOr< llvm::DynamicAPInt > llzk::SourceRef::getConstantIndexValue ( ) const
inline

Definition at line 317 of file SourceRef.h.

◆ getConstantValue() [1/2]

mlir::FailureOr< llvm::DynamicAPInt > llzk::SourceRef::getConstantValue ( ) const
inline

Return a known numeric value, failing for fieldless felt constants.

Definition at line 329 of file SourceRef.h.

◆ getConstantValue() [2/2]

FailureOr< DynamicAPInt > llzk::SourceRef::getConstantValue ( const Field & field) const

Reduce a felt constant's declared-field representative into the supplied analysis field.

Fieldless constants use their raw literals instead. Index constants retain integer semantics.

Definition at line 672 of file SourceRef.cpp.

◆ getCreateStructOp()

mlir::FailureOr< component::CreateStructOp > llzk::SourceRef::getCreateStructOp ( ) const
inline

Definition at line 297 of file SourceRef.h.

◆ getInputNum()

mlir::FailureOr< unsigned > llzk::SourceRef::getInputNum ( ) const
inline

Definition at line 288 of file SourceRef.h.

◆ getNonDetOp()

mlir::FailureOr< NonDetOp > llzk::SourceRef::getNonDetOp ( ) const
inline

Definition at line 302 of file SourceRef.h.

◆ getParentPrefix()

mlir::FailureOr< SourceRef > llzk::SourceRef::getParentPrefix ( ) const
inline

Create a new reference that is the immediate prefix of this reference if possible.

Definition at line 371 of file SourceRef.h.

◆ getPath()

llvm::ArrayRef< SourceRefIndex > llzk::SourceRef::getPath ( ) const
inline

Definition at line 406 of file SourceRef.h.

◆ getPieces()

llvm::ArrayRef< SourceRefIndex > llzk::SourceRef::getPieces ( ) const
inline

Definition at line 403 of file SourceRef.h.

◆ getRoot()

mlir::FailureOr< mlir::Value > llzk::SourceRef::getRoot ( ) const
inline

Definition at line 270 of file SourceRef.h.

◆ getSuffix()

FailureOr< SourceRef::Path > llzk::SourceRef::getSuffix ( const SourceRef & prefix) const

If prefix is a valid prefix of this reference, return the suffix that remains after removing the prefix.

I.e., this = prefix + suffix

Parameters
prefix
Returns
the suffix

Definition at line 458 of file SourceRef.cpp.

◆ getType()

Type llzk::SourceRef::getType ( ) const

Definition at line 360 of file SourceRef.cpp.

◆ isBlockArgument()

bool llzk::SourceRef::isBlockArgument ( ) const
inline

Definition at line 269 of file SourceRef.h.

◆ isCallResult()

bool llzk::SourceRef::isCallResult ( ) const
inline

Definition at line 304 of file SourceRef.h.

◆ isConstant()

bool llzk::SourceRef::isConstant ( ) const
inline

Definition at line 256 of file SourceRef.h.

◆ isConstantFelt()

bool llzk::SourceRef::isConstantFelt ( ) const
inline

Definition at line 244 of file SourceRef.h.

◆ isConstantIndex()

bool llzk::SourceRef::isConstantIndex ( ) const
inline

Definition at line 247 of file SourceRef.h.

◆ isConstantInt()

bool llzk::SourceRef::isConstantInt ( ) const
inline

Definition at line 257 of file SourceRef.h.

◆ isCreateStructOp()

bool llzk::SourceRef::isCreateStructOp ( ) const
inline

Definition at line 296 of file SourceRef.h.

◆ isFeltVal()

bool llzk::SourceRef::isFeltVal ( ) const
inline

Definition at line 259 of file SourceRef.h.

◆ isIndexVal()

bool llzk::SourceRef::isIndexVal ( ) const
inline

Definition at line 260 of file SourceRef.h.

◆ isIntegerVal()

bool llzk::SourceRef::isIntegerVal ( ) const
inline

Definition at line 261 of file SourceRef.h.

◆ isNonDetOp()

bool llzk::SourceRef::isNonDetOp ( ) const
inline

Definition at line 301 of file SourceRef.h.

◆ isRooted()

bool llzk::SourceRef::isRooted ( ) const
inline

Definition at line 267 of file SourceRef.h.

◆ isScalar()

bool llzk::SourceRef::isScalar ( ) const
inline

Definition at line 263 of file SourceRef.h.

◆ isTemplateConstant()

bool llzk::SourceRef::isTemplateConstant ( ) const
inline

Return whether this reference originates from a template constant read.

Definition at line 252 of file SourceRef.h.

◆ isTypeVarVal()

bool llzk::SourceRef::isTypeVarVal ( ) const
inline

Definition at line 262 of file SourceRef.h.

◆ isValidPrefix()

bool llzk::SourceRef::isValidPrefix ( const SourceRef & prefix) const

Returns true iff prefix is a valid prefix of this reference.

Definition at line 387 of file SourceRef.cpp.

◆ narrowRanges()

SourceRef llzk::SourceRef::narrowRanges ( const SourceRef & rhs) const

Return a copy with ranged array indices narrowed by concrete indices from rhs.

Array indices are paired by dimension order; member and POD-record path components are ignored when pairing dimensions. A range is replaced only when the corresponding component in rhs is a concrete index contained in that range. Other path components remain unchanged. For example, narrowing self.out[0:4].values[0:8] with arg0[2][5] produces self.out[2].values[5].

Definition at line 437 of file SourceRef.cpp.

◆ operator!=()

bool llzk::SourceRef::operator!= ( const SourceRef & rhs) const
inline

Definition at line 415 of file SourceRef.h.

◆ operator<=>()

std::strong_ordering llzk::SourceRef::operator<=> ( const SourceRef & rhs) const

Definition at line 702 of file SourceRef.cpp.

◆ operator==()

bool llzk::SourceRef::operator== ( const SourceRef & rhs) const

Definition at line 692 of file SourceRef.cpp.

◆ overlaps()

bool llzk::SourceRef::overlaps ( const SourceRef & rhs) const

Return true when both references select overlapping storage at the same path depth.

Definition at line 405 of file SourceRef.cpp.

◆ print()

void llzk::SourceRef::print ( mlir::raw_ostream & os) const

Print this reference using source-style names.

The entry self argument of a struct constrain function is printed as self.

Definition at line 612 of file SourceRef.cpp.

◆ translate()

FailureOr< SourceRef > llzk::SourceRef::translate ( const SourceRef & prefix,
const SourceRef & other ) const

Create a new reference with prefix replaced with other iff prefix is a valid prefix for this reference.

If this reference is a felt.const, the translation will always succeed and return the felt.const unchanged.

Parameters
prefix
other
Returns

Definition at line 472 of file SourceRef.cpp.

◆ llvm::DenseMapInfo< SourceRef >

friend struct llvm::DenseMapInfo< SourceRef >
friend

Definition at line 418 of file SourceRef.h.


The documentation for this class was generated from the following files: