Talvos  0.1
SPIR-V interpreter and dynamic analysis framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | List of all members
talvos::Module Class Reference

This class represents a SPIR-V module. More...

#include <talvos/Module.h>

Public Member Functions

 Module (uint32_t IdBound)
 Create an empty module. More...
 
 ~Module ()
 
void addEntryPoint (EntryPoint *EP)
 Add an entry point to the module. More...
 
void addFunction (std::unique_ptr< Function > Func)
 Add a function to this module. More...
 
void addLocalSize (uint32_t Entry, Dim3 LocalSize)
 Add a local size execution mode to an entry point. More...
 
void addObject (uint32_t Id, const Object &Obj)
 Add an object to this module. More...
 
void addSpecConstant (uint32_t SpecId, uint32_t ResultId)
 Add a specialization constant ID mapping. More...
 
void addSpecConstantOp (Instruction *Op)
 Add a specialization constant operation instruction to this module. More...
 
void addType (uint32_t Id, std::unique_ptr< Type > Ty)
 Add a type to this module. More...
 
void addVariable (Variable *Var)
 Add a variable to this module, transferring ownership to the module. More...
 
const EntryPointgetEntryPoint (const std::string &Name, uint32_t ExecutionModel) const
 Get the entry point with the specified name and SPIR-V execution model. More...
 
const FunctiongetFunction (uint32_t Id) const
 Returns the function with the specified ID. More...
 
uint32_t getIdBound () const
 Returns the ID bound of the results in this module. More...
 
Dim3 getLocalSize (uint32_t Entry) const
 Returns the LocalSize execution mode for an entry point. More...
 
const ObjectgetObject (uint32_t Id) const
 Returns the object with the specified ID. More...
 
const std::vector< Object > & getObjects () const
 Returns a list of all result objects in this module. More...
 
uint32_t getSpecConstant (uint32_t SpecId) const
 Returns the result ID for the given specialization constant ID. More...
 
const std::vector< Instruction * > & getSpecConstantOps () const
 Returns the list of specialization constant operation instructions. More...
 
const TypegetType (uint32_t Id) const
 Returns the type with the specified ID. More...
 
const VariableListgetVariables () const
 Returns the list of module scope variables. More...
 
uint32_t getWorkgroupSizeId () const
 Returns the ID of the object decorated with WorkgroupSize. More...
 
void setWorkgroupSizeId (uint32_t Id)
 Set the ID of the object decorated with WorkgroupSize. More...
 
 Module (const Module &)=delete
 
Moduleoperator= (const Module &)=delete
 

Static Public Member Functions

static std::shared_ptr< Moduleload (const uint32_t *Words, size_t NumWords)
 Create a new module from the supplied SPIR-V binary data. More...
 
static std::shared_ptr< Moduleload (const std::string &FileName)
 Create a new module from the given SPIR-V binary filename. More...
 

Private Types

typedef std::map< uint32_t,
std::unique_ptr< Type > > 
TypeMap
 Map from SPIR-V result ID to talvos::Type. More...
 
typedef std::map< uint32_t,
std::unique_ptr< Function > > 
FunctionMap
 Map from SPIR-V result ID to talvos::Function. More...
 

Private Attributes

uint32_t IdBound
 The ID bound of the module. More...
 
std::vector< ObjectObjects
 Constant instruction results. More...
 
TypeMap Types
 Type mapping. More...
 
FunctionMap Functions
 Function mapping. More...
 
std::vector< EntryPoint * > EntryPoints
 List of entry points. More...
 
std::map< uint32_t, Dim3LocalSizes
 LocalSize execution modes. More...
 
std::map< uint32_t, uint32_t > SpecConstants
 Map specialization constant IDs to result IDs. More...
 
std::vector< Instruction * > SpecConstantOps
 List of specialization constant operation instructions. More...
 
uint32_t WorkgroupSizeId
 The ID of the object decorated with WorkgroupSize. More...
 
VariableList Variables
 Module scope variables. More...
 

Detailed Description

This class represents a SPIR-V module.

This class contains types, functions, global variables, and constant instruction results. Factory methods are provided to create a module from a SPIR-V binary filename or from data in memory.

Definition at line 37 of file Module.h.

Member Typedef Documentation

typedef std::map<uint32_t, std::unique_ptr<Function> > talvos::Module::FunctionMap
private

Map from SPIR-V result ID to talvos::Function.

Definition at line 135 of file Module.h.

typedef std::map<uint32_t, std::unique_ptr<Type> > talvos::Module::TypeMap
private

Map from SPIR-V result ID to talvos::Type.

Definition at line 132 of file Module.h.

Constructor & Destructor Documentation

talvos::Module::Module ( uint32_t  IdBound)

Create an empty module.

Definition at line 695 of file Module.cpp.

talvos::Module::~Module ( )

Definition at line 702 of file Module.cpp.

talvos::Module::Module ( const Module )
delete

Member Function Documentation

void talvos::Module::addEntryPoint ( EntryPoint EP)

Add an entry point to the module.

The function and input/output variables must all exist in this module. Transfers ownership of EP to the module.

Definition at line 714 of file Module.cpp.

void talvos::Module::addFunction ( std::unique_ptr< Function Func)

Add a function to this module.

Definition at line 720 of file Module.cpp.

void talvos::Module::addLocalSize ( uint32_t  Entry,
Dim3  LocalSize 
)

Add a local size execution mode to an entry point.

Definition at line 726 of file Module.cpp.

void talvos::Module::addObject ( uint32_t  Id,
const Object Obj 
)

Add an object to this module.

Definition at line 732 of file Module.cpp.

void talvos::Module::addSpecConstant ( uint32_t  SpecId,
uint32_t  ResultId 
)

Add a specialization constant ID mapping.

Definition at line 738 of file Module.cpp.

void talvos::Module::addSpecConstantOp ( Instruction Op)

Add a specialization constant operation instruction to this module.

Transfers ownership of Op to the module.

Definition at line 745 of file Module.cpp.

void talvos::Module::addType ( uint32_t  Id,
std::unique_ptr< Type Ty 
)

Add a type to this module.

Definition at line 750 of file Module.cpp.

void talvos::Module::addVariable ( Variable Var)
inline

Add a variable to this module, transferring ownership to the module.

Definition at line 77 of file Module.h.

const EntryPoint * talvos::Module::getEntryPoint ( const std::string &  Name,
uint32_t  ExecutionModel 
) const

Get the entry point with the specified name and SPIR-V execution model.

Returns nullptr if no entry point called Name with a matching execution model is found.

Definition at line 756 of file Module.cpp.

const Function * talvos::Module::getFunction ( uint32_t  Id) const

Returns the function with the specified ID.

Definition at line 767 of file Module.cpp.

uint32_t talvos::Module::getIdBound ( ) const
inline

Returns the ID bound of the results in this module.

Definition at line 89 of file Module.h.

Dim3 talvos::Module::getLocalSize ( uint32_t  Entry) const

Returns the LocalSize execution mode for an entry point.

This will return (1,1,1) if it has not been explicitly set for Entry.

Definition at line 774 of file Module.cpp.

const Object & talvos::Module::getObject ( uint32_t  Id) const

Returns the object with the specified ID.

Id must be valid constant instruction result.

Definition at line 782 of file Module.cpp.

const std::vector< Object > & talvos::Module::getObjects ( ) const

Returns a list of all result objects in this module.

Definition at line 784 of file Module.cpp.

uint32_t talvos::Module::getSpecConstant ( uint32_t  SpecId) const

Returns the result ID for the given specialization constant ID.

Returns 0 if no specialization constants with this ID are present.

Definition at line 786 of file Module.cpp.

const std::vector< Instruction * > & talvos::Module::getSpecConstantOps ( ) const

Returns the list of specialization constant operation instructions.

Definition at line 793 of file Module.cpp.

const Type * talvos::Module::getType ( uint32_t  Id) const

Returns the type with the specified ID.

Definition at line 798 of file Module.cpp.

const VariableList& talvos::Module::getVariables ( ) const
inline

Returns the list of module scope variables.

Definition at line 113 of file Module.h.

uint32_t talvos::Module::getWorkgroupSizeId ( ) const
inline

Returns the ID of the object decorated with WorkgroupSize.

Returns 0 if no object has been decorated with WorkgroupSize.

Definition at line 117 of file Module.h.

std::shared_ptr< Module > talvos::Module::load ( const uint32_t *  Words,
size_t  NumWords 
)
static

Create a new module from the supplied SPIR-V binary data.

Returns nullptr on failure.

Definition at line 805 of file Module.cpp.

std::shared_ptr< Module > talvos::Module::load ( const std::string &  FileName)
static

Create a new module from the given SPIR-V binary filename.

Returns nullptr on failure.

Definition at line 830 of file Module.cpp.

Module& talvos::Module::operator= ( const Module )
delete
void talvos::Module::setWorkgroupSizeId ( uint32_t  Id)
inline

Set the ID of the object decorated with WorkgroupSize.

Definition at line 120 of file Module.h.

Member Data Documentation

std::vector<EntryPoint *> talvos::Module::EntryPoints
private

List of entry points.

Definition at line 142 of file Module.h.

FunctionMap talvos::Module::Functions
private

Function mapping.

Definition at line 141 of file Module.h.

uint32_t talvos::Module::IdBound
private

The ID bound of the module.

Definition at line 137 of file Module.h.

std::map<uint32_t, Dim3> talvos::Module::LocalSizes
private

LocalSize execution modes.

Definition at line 143 of file Module.h.

std::vector<Object> talvos::Module::Objects
private

Constant instruction results.

Definition at line 138 of file Module.h.

std::vector<Instruction *> talvos::Module::SpecConstantOps
private

List of specialization constant operation instructions.

Definition at line 149 of file Module.h.

std::map<uint32_t, uint32_t> talvos::Module::SpecConstants
private

Map specialization constant IDs to result IDs.

Definition at line 146 of file Module.h.

TypeMap talvos::Module::Types
private

Type mapping.

Definition at line 139 of file Module.h.

VariableList talvos::Module::Variables
private

Module scope variables.

Definition at line 155 of file Module.h.

uint32_t talvos::Module::WorkgroupSizeId
private

The ID of the object decorated with WorkgroupSize.

Definition at line 152 of file Module.h.