NFC: Rename SPIR-V serializer find*ID() to get*ID() to be consistent
authorLei Zhang <antiagainst@google.com>
Sat, 19 Oct 2019 01:15:28 +0000 (18:15 -0700)
committerA. Unique TensorFlower <gardener@tensorflow.org>
Sat, 19 Oct 2019 01:16:05 +0000 (18:16 -0700)
We use get*() in deserizer and other places across the codebase.

PiperOrigin-RevId: 275582390

mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp

index b927a02..58a3335 100644 (file)
@@ -101,15 +101,15 @@ private:
   // 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);
   }
 
@@ -161,7 +161,7 @@ private:
   // 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(); }
 
@@ -189,7 +189,7 @@ private:
   // Constant
   //===--------------------------------------------------------------------===//
 
-  uint32_t findConstantID(Attribute value) const {
+  uint32_t getConstantID(Attribute value) const {
     return constIDMap.lookup(value);
   }
 
@@ -244,7 +244,7 @@ private:
   // 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);
 
@@ -274,7 +274,7 @@ private:
                                            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);
 
@@ -634,7 +634,7 @@ Serializer::processGlobalVariableOp(spirv::GlobalVariableOp varOp) {
                           .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";
     }
@@ -659,7 +659,7 @@ Serializer::processGlobalVariableOp(spirv::GlobalVariableOp varOp) {
 
   // 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");
@@ -704,7 +704,7 @@ bool Serializer::isInterfaceStructPtrType(Type type) const {
 
 LogicalResult Serializer::processType(Location loc, Type type,
                                       uint32_t &typeID) {
-  typeID = findTypeID(type);
+  typeID = getTypeID(type);
   if (typeID) {
     return success();
   }
@@ -872,7 +872,7 @@ uint32_t Serializer::prepareConstant(Location loc, Type constType,
   // 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;
   }
 
@@ -1074,7 +1074,7 @@ uint32_t Serializer::prepareConstantBool(Location loc, BoolAttr boolAttr,
                                          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;
     }
   }
@@ -1103,7 +1103,7 @@ uint32_t Serializer::prepareConstantInt(Location loc, IntegerAttr intAttr,
                                         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;
     }
   }
@@ -1169,7 +1169,7 @@ uint32_t Serializer::prepareConstantFp(Location loc, FloatAttr floatAttr,
                                        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;
     }
   }
@@ -1230,7 +1230,7 @@ LogicalResult
 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);
     }
@@ -1329,7 +1329,7 @@ LogicalResult Serializer::processSelectionOp(spirv::SelectionOp selectionOp) {
 
   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
@@ -1376,9 +1376,9 @@ LogicalResult Serializer::processLoopOp(spirv::LoopOp loopOp) {
   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
@@ -1420,9 +1420,9 @@ LogicalResult Serializer::processLoopOp(spirv::LoopOp loopOp) {
 
 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()) {
@@ -1436,7 +1436,7 @@ LogicalResult Serializer::processBranchConditionalOp(
 
 LogicalResult Serializer::processBranchOp(spirv::BranchOp branchOp) {
   return encodeInstructionInto(functions, spirv::Opcode::OpBranch,
-                               {findBlockID(branchOp.getTarget())});
+                               {getBlockID(branchOp.getTarget())});
 }
 
 //===----------------------------------------------------------------------===//
@@ -1477,7 +1477,7 @@ LogicalResult Serializer::encodeExtensionInstruction(
 
 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;
@@ -1489,7 +1489,7 @@ LogicalResult Serializer::processAddressOfOp(spirv::AddressOfOp addressOfOp) {
 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 ")
@@ -1552,7 +1552,7 @@ Serializer::processOp<spirv::EntryPointOp>(spirv::EntryPointOp op) {
   // 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()
@@ -1566,7 +1566,7 @@ Serializer::processOp<spirv::EntryPointOp>(spirv::EntryPointOp op) {
   // 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 "
@@ -1604,7 +1604,7 @@ LogicalResult
 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()
@@ -1664,7 +1664,7 @@ Serializer::processOp<spirv::FunctionCallOp>(spirv::FunctionCallOp op) {
   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);
   }
index acca4b3..184c17f 100644 (file)
@@ -125,7 +125,7 @@ static void emitOperandSerialization(const Operator &op, ArrayRef<SMLoc> loc,
       os << tabs
          << formatv("  for (auto arg : {0}.getODSOperands({1})) {{\n", opVar,
                     operandNum);
-      os << tabs << "    auto argID = findValueID(arg);\n";
+      os << tabs << "    auto argID = getValueID(arg);\n";
       os << tabs << "    if (!argID) {\n";
       os << tabs
          << formatv(