MLIR  16.0.0git
Namespaces | Functions | Variables
ModuleCombiner.cpp File Reference
#include "mlir/Dialect/SPIRV/Linking/ModuleCombiner.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/SymbolTable.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
+ Include dependency graph for ModuleCombiner.cpp:

Go to the source code of this file.

Namespaces

 mlir
 Include the generated interface declarations.
 
 mlir::spirv
 

Functions

static StringAttr renameSymbol (StringRef oldSymName, unsigned &lastUsedID, spirv::ModuleOp module)
 Returns an unsed symbol in module for oldSymbolName by trying numeric suffix in lastUsedID. More...
 
static LogicalResult updateSymbolAndAllUses (SymbolOpInterface op, spirv::ModuleOp target, spirv::ModuleOp source, unsigned &lastUsedID)
 Checks if a symbol with the same name as op already exists in source. More...
 
static llvm::hash_code computeHash (SymbolOpInterface symbolOp)
 Computes a hash code to represent symbolOp based on all its attributes except for the symbol name. More...
 
OwningOpRef< spirv::ModuleOp > mlir::spirv::combine (ArrayRef< spirv::ModuleOp > inputModules, OpBuilder &combinedModuleBuilder, SymbolRenameListener symRenameListener)
 Combines a list of SPIR-V inputModules into one. More...
 

Variables

static constexpr unsigned maxFreeID = 1 << 20
 

Function Documentation

◆ computeHash()

static llvm::hash_code computeHash ( SymbolOpInterface  symbolOp)
static

Computes a hash code to represent symbolOp based on all its attributes except for the symbol name.

Note: We use the operation's name (not the symbol name) as part of the hash computation. This prevents, for example, mistakenly considering a global variable and a spec constant as duplicates because their descriptor set + binding and spec_id, respectively, happen to hash to the same value.

Definition at line 76 of file ModuleCombiner.cpp.

References mlir::SymbolTable::getSymbolAttrName().

Referenced by mlir::spirv::combine().

◆ renameSymbol()

static StringAttr renameSymbol ( StringRef  oldSymName,
unsigned lastUsedID,
spirv::ModuleOp  module 
)
static

Returns an unsed symbol in module for oldSymbolName by trying numeric suffix in lastUsedID.

Definition at line 33 of file ModuleCombiner.cpp.

References mlir::SymbolTable::lookupSymbolIn(), and maxFreeID.

Referenced by updateSymbolAndAllUses().

◆ updateSymbolAndAllUses()

static LogicalResult updateSymbolAndAllUses ( SymbolOpInterface  op,
spirv::ModuleOp  target,
spirv::ModuleOp  source,
unsigned lastUsedID 
)
static

Checks if a symbol with the same name as op already exists in source.

If so, renames op and updates all its references in target.

Definition at line 51 of file ModuleCombiner.cpp.

References mlir::failed(), mlir::SymbolTable::lookupSymbolIn(), renameSymbol(), mlir::SymbolTable::replaceAllSymbolUses(), mlir::SymbolTable::setSymbolName(), and mlir::success().

Referenced by mlir::spirv::combine().

Variable Documentation

◆ maxFreeID

constexpr unsigned maxFreeID = 1 << 20
static

Definition at line 29 of file ModuleCombiner.cpp.

Referenced by renameSymbol().