// Module structure
//===--------------------------------------------------------------------===//
- uint32_t findSpecConstID(StringRef constName) const {
+ uint32_t getSpecConstID(StringRef constName) const {
return specConstIDMap.lookup(constName);
}
- uint32_t findVariableID(StringRef varName) const {
+ uint32_t getVariableID(StringRef varName) const {
return globalVarIDMap.lookup(varName);
}
- uint32_t findFunctionID(StringRef fnName) const {
+ uint32_t getFunctionID(StringRef fnName) const {
return funcIDMap.lookup(fnName);
}
// Types
//===--------------------------------------------------------------------===//
- uint32_t findTypeID(Type type) const { return typeIDMap.lookup(type); }
+ uint32_t getTypeID(Type type) const { return typeIDMap.lookup(type); }
Type getVoidType() { return mlirBuilder.getNoneType(); }
// Constant
//===--------------------------------------------------------------------===//
- uint32_t findConstantID(Attribute value) const {
+ uint32_t getConstantID(Attribute value) const {
return constIDMap.lookup(value);
}
// Control flow
//===--------------------------------------------------------------------===//
- uint32_t findBlockID(Block *block) const { return blockIDMap.lookup(block); }
+ uint32_t getBlockID(Block *block) const { return blockIDMap.lookup(block); }
uint32_t assignBlockID(Block *block);
uint32_t opcode,
ArrayRef<uint32_t> operands);
- uint32_t findValueID(Value *val) const { return valueIDMap.lookup(val); }
+ uint32_t getValueID(Value *val) const { return valueIDMap.lookup(val); }
LogicalResult processAddressOfOp(spirv::AddressOfOp addressOfOp);
.getPointeeType()
.cast<spirv::StructType>();
if (failed(
- emitDecoration(findTypeID(structType), spirv::Decoration::Block))) {
+ emitDecoration(getTypeID(structType), spirv::Decoration::Block))) {
return varOp.emitError("cannot decorate ")
<< structType << " with Block decoration";
}
// Encode initialization.
if (auto initializer = varOp.initializer()) {
- auto initializerID = findVariableID(initializer.getValue());
+ auto initializerID = getVariableID(initializer.getValue());
if (!initializerID) {
return emitError(varOp.getLoc(),
"invalid usage of undefined variable as initializer");
LogicalResult Serializer::processType(Location loc, Type type,
uint32_t &typeID) {
- typeID = findTypeID(type);
+ typeID = getTypeID(type);
if (typeID) {
return success();
}
// This is a composite literal. We need to handle each component separately
// and then emit an OpConstantComposite for the whole.
- if (auto id = findConstantID(valueAttr)) {
+ if (auto id = getConstantID(valueAttr)) {
return id;
}
bool isSpec) {
if (!isSpec) {
// We can de-duplicate nomral contants, but not specialization constants.
- if (auto id = findConstantID(boolAttr)) {
+ if (auto id = getConstantID(boolAttr)) {
return id;
}
}
bool isSpec) {
if (!isSpec) {
// We can de-duplicate nomral contants, but not specialization constants.
- if (auto id = findConstantID(intAttr)) {
+ if (auto id = getConstantID(intAttr)) {
return id;
}
}
bool isSpec) {
if (!isSpec) {
// We can de-duplicate nomral contants, but not specialization constants.
- if (auto id = findConstantID(floatAttr)) {
+ if (auto id = getConstantID(floatAttr)) {
return id;
}
}
Serializer::processBlock(Block *block, bool omitLabel,
llvm::function_ref<void()> actionBeforeTerminator) {
if (!omitLabel) {
- auto blockID = findBlockID(block);
+ auto blockID = getBlockID(block);
if (blockID == 0) {
blockID = assignBlockID(block);
}
auto *headerBlock = selectionOp.getHeaderBlock();
auto *mergeBlock = selectionOp.getMergeBlock();
- auto mergeID = findBlockID(mergeBlock);
+ auto mergeID = getBlockID(mergeBlock);
// Emit the selection header block, which dominates all other blocks, first.
// We need to emit an OpSelectionMerge instruction before the loop header
auto *headerBlock = loopOp.getHeaderBlock();
auto *continueBlock = loopOp.getContinueBlock();
auto *mergeBlock = loopOp.getMergeBlock();
- auto headerID = findBlockID(headerBlock);
- auto continueID = findBlockID(continueBlock);
- auto mergeID = findBlockID(mergeBlock);
+ auto headerID = getBlockID(headerBlock);
+ auto continueID = getBlockID(continueBlock);
+ auto mergeID = getBlockID(mergeBlock);
// This LoopOp is in some MLIR block with preceding and following ops. In the
// binary format, it should reside in separate SPIR-V blocks from its
LogicalResult Serializer::processBranchConditionalOp(
spirv::BranchConditionalOp condBranchOp) {
- auto conditionID = findValueID(condBranchOp.condition());
- auto trueLabelID = findBlockID(condBranchOp.getTrueBlock());
- auto falseLabelID = findBlockID(condBranchOp.getFalseBlock());
+ auto conditionID = getValueID(condBranchOp.condition());
+ auto trueLabelID = getBlockID(condBranchOp.getTrueBlock());
+ auto falseLabelID = getBlockID(condBranchOp.getFalseBlock());
SmallVector<uint32_t, 5> arguments{conditionID, trueLabelID, falseLabelID};
if (auto weights = condBranchOp.branch_weights()) {
LogicalResult Serializer::processBranchOp(spirv::BranchOp branchOp) {
return encodeInstructionInto(functions, spirv::Opcode::OpBranch,
- {findBlockID(branchOp.getTarget())});
+ {getBlockID(branchOp.getTarget())});
}
//===----------------------------------------------------------------------===//
LogicalResult Serializer::processAddressOfOp(spirv::AddressOfOp addressOfOp) {
auto varName = addressOfOp.variable();
- auto variableID = findVariableID(varName);
+ auto variableID = getVariableID(varName);
if (!variableID) {
return addressOfOp.emitError("unknown result <id> for variable ")
<< varName;
LogicalResult
Serializer::processReferenceOfOp(spirv::ReferenceOfOp referenceOfOp) {
auto constName = referenceOfOp.spec_const();
- auto constID = findSpecConstID(constName);
+ auto constID = getSpecConstID(constName);
if (!constID) {
return referenceOfOp.emitError(
"unknown result <id> for specialization constant ")
// Add the ExectionModel.
operands.push_back(static_cast<uint32_t>(op.execution_model()));
// Add the function <id>.
- auto funcID = findFunctionID(op.fn());
+ auto funcID = getFunctionID(op.fn());
if (!funcID) {
return op.emitError("missing <id> for function ")
<< op.fn()
// Add the interface values.
if (auto interface = op.interface()) {
for (auto var : interface.getValue()) {
- auto id = findVariableID(var.cast<SymbolRefAttr>().getValue());
+ auto id = getVariableID(var.cast<SymbolRefAttr>().getValue());
if (!id) {
return op.emitError("referencing undefined global variable."
"spv.EntryPoint is at the end of spv.module. All "
Serializer::processOp<spirv::ExecutionModeOp>(spirv::ExecutionModeOp op) {
SmallVector<uint32_t, 4> operands;
// Add the function <id>.
- auto funcID = findFunctionID(op.fn());
+ auto funcID = getFunctionID(op.fn());
if (!funcID) {
return op.emitError("missing <id> for function ")
<< op.fn()
SmallVector<uint32_t, 8> operands{resTypeID, funcCallID, funcID};
for (auto *value : op.arguments()) {
- auto valueID = findValueID(value);
+ auto valueID = getValueID(value);
assert(valueID && "cannot find a value for spv.FunctionCall");
operands.push_back(valueID);
}