MLIR 22.0.0git
ModuleCombiner.cpp File Reference
#include "mlir/Dialect/SPIRV/Linking/ModuleCombiner.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/Hashing.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"

Go to the source code of this file.

Namespaces

namespace  mlir
 Include the generated interface declarations.
namespace  mlir::spirv

Functions

static StringAttr renameSymbol (StringRef oldSymName, unsigned &lastUsedID, spirv::ModuleOp module)
 Returns an unused symbol in module for oldSymbolName by trying numeric suffix in lastUsedID.
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.
static llvm::hash_code computeHash (SymbolOpInterface symbolOp)
 Computes a hash code to represent symbolOp based on all its attributes except for the symbol name.
OwningOpRef< spirv::ModuleOp > mlir::spirv::combine (ArrayRef< spirv::ModuleOp > inputModules, OpBuilder &combinedModuleBuilder, SymbolRenameListener symRenameListener)

Variables

static constexpr unsigned maxFreeID = 1 << 20

Function Documentation

◆ computeHash()

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 72 of file ModuleCombiner.cpp.

Referenced by mlir::spirv::combine(), and mlir::Op< ConcreteType, Traits >::computePropertiesHash().

◆ renameSymbol()

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

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

Definition at line 29 of file ModuleCombiner.cpp.

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

Referenced by updateSymbolAndAllUses().

◆ updateSymbolAndAllUses()

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 47 of file ModuleCombiner.cpp.

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

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

Variable Documentation

◆ maxFreeID

unsigned maxFreeID = 1 << 20
staticconstexpr

Definition at line 25 of file ModuleCombiner.cpp.

Referenced by renameSymbol().