// Returns the number of operations recursively involved in the DAG tree
// rooted from this node.
- unsigned getNumOps() const;
+ int getNumOps() const;
// Returns the number of immediate arguments to this DAG node.
- unsigned getNumArgs() const;
+ int getNumArgs() const;
// Returns true if the `index`-th argument is a nested DAG construct.
bool isNestedDagArg(unsigned index) const;
DagNode getSourcePattern() const;
// Returns the number of results generated by applying this rewrite pattern.
- unsigned getNumResults() const;
+ int getNumResults() const;
// Returns the DAG tree root node of the `index`-th result pattern.
DagNode getResultPattern(unsigned index) const;
numReservedCols++;
}
- unsigned absolutePos;
+ int absolutePos;
if (kind == IdKind::Dimension) {
absolutePos = pos;
// Print constraints.
os << " : (";
- auto numConstraints = set.getNumConstraints();
+ int numConstraints = set.getNumConstraints();
for (int i = 1; i < numConstraints; ++i) {
printAffineConstraint(set.getConstraint(i - 1), set.isEq(i - 1));
os << ", ";
// Verify that the rank of the indices matches the held type.
auto rank = type.getRank();
- if (rank != index.size())
+ if (static_cast<size_t>(rank) != index.size())
return Attribute();
// Verify that all of the indices are within the shape dimensions.
auto shape = type.getShape();
for (unsigned i = 0; i != rank; ++i)
- if (shape[i] <= index[i])
+ if (shape[i] <= static_cast<int64_t>(index[i]))
return Attribute();
// Reduce the provided multidimensional index into a 1D index.
uint64_t valueIndex = 0;
uint64_t dimMultiplier = 1;
- for (auto i = rank - 1; i >= 0; --i) {
+ for (int i = rank - 1; i >= 0; --i) {
valueIndex += index[i] * dimMultiplier;
dimMultiplier *= shape[i];
}
auto type = getType();
// Verify that the rank of the indices matches the held type.
- auto rank = type.getRank();
+ size_t rank = type.getRank();
if (rank != index.size())
return Attribute();
llvm::SmallDenseMap<llvm::ArrayRef<uint64_t>, size_t> mappedIndices;
auto numSparseIndices = sparseIndices.getType().getDimSize(0);
for (size_t i = 0, e = numSparseIndices; i != e; ++i)
- mappedIndices.try_emplace(
- {sparseIndexValues + (i * rank), static_cast<size_t>(rank)}, i);
+ mappedIndices.try_emplace({sparseIndexValues + (i * rank), rank}, i);
// Look for the provided index key within the mapped indices. If the provided
// index is not found, then return a zero attribute.
auto type = getOperand()->getType();
if (auto tensorType = type.dyn_cast<RankedTensorType>()) {
- if (index >= tensorType.getRank())
+ if (index >= static_cast<uint64_t>(tensorType.getRank()))
return emitOpError("index is out of range");
} else if (auto memrefType = type.dyn_cast<MemRefType>()) {
if (index >= memrefType.getRank())
.first->second;
}
-unsigned tblgen::DagNode::getNumOps() const {
- unsigned count = isReplaceWithValue() ? 0 : 1;
- for (unsigned i = 0, e = getNumArgs(); i != e; ++i) {
+int tblgen::DagNode::getNumOps() const {
+ int count = isReplaceWithValue() ? 0 : 1;
+ for (int i = 0, e = getNumArgs(); i != e; ++i) {
if (auto child = getArgAsNestedDag(i))
count += child.getNumOps();
}
return count;
}
-unsigned tblgen::DagNode::getNumArgs() const { return node->getNumArgs(); }
+int tblgen::DagNode::getNumArgs() const { return node->getNumArgs(); }
bool tblgen::DagNode::isNestedDagArg(unsigned index) const {
return isa<llvm::DagInit>(node->getArg(index));
return tblgen::DagNode(def.getValueAsDag("sourcePattern"));
}
-unsigned tblgen::Pattern::getNumResults() const {
+int tblgen::Pattern::getNumResults() const {
auto *results = def.getValueAsListInit("resultPatterns");
return results->size();
}
boundOps.insert(treeName);
// TODO(jpienaar): Expand to multiple matches.
- for (unsigned i = 0; i != numTreeArgs; ++i) {
+ for (int i = 0; i != numTreeArgs; ++i) {
if (auto treeArg = tree.getArgAsNestedDag(i)) {
// This DAG node argument is a DAG node itself. Go inside recursively.
collectBoundArguments(treeArg);
<< " fused mem: " << fusedMem << "\n"
<< " slice mem: " << sliceMemEstimate << "\n");
- if (fusedMem > srcMemSizeVal + dstMemSizeVal) {
+ if (static_cast<long>(fusedMem) > srcMemSizeVal + dstMemSizeVal) {
LLVM_DEBUG(llvm::dbgs() << "Fusion is not profitable; NOT fusing.\n");
return false;
}
/// Perform the rewrites. Return true if the rewrite converges in
/// `maxIterations`.
- bool simplifyFunction(unsigned maxIterations);
+ bool simplifyFunction(int maxIterations);
void addToWorklist(Operation *op) {
// Check to see if the worklist already contains this op.
}; // end anonymous namespace
/// Perform the rewrites.
-bool GreedyPatternRewriteDriver::simplifyFunction(unsigned maxIterations) {
+bool GreedyPatternRewriteDriver::simplifyFunction(int maxIterations) {
Function *fn = builder.getFunction();
ConstantFoldHelper helper(fn);
}
// CHECK-LABEL: Operation::operand_range OpC::input1()
-// CHECK-NEXT: unsigned variadicOperandSize = (this->getNumOperands() - 0) / 2;
-// CHECK-NEXT: unsigned offset = 0 + variadicOperandSize * 0;
+// CHECK-NEXT: variadicOperandSize = (this->getNumOperands() - 0) / 2;
+// CHECK-NEXT: offset = 0 + variadicOperandSize * 0;
// CHECK-NEXT: return {std::next(operand_begin(), offset), std::next(operand_begin(), offset + variadicOperandSize)};
// CHECK-LABEL: Operation::operand_range OpC::input2()
-// CHECK-NEXT: unsigned variadicOperandSize = (this->getNumOperands() - 0) / 2;
-// CHECK-NEXT: unsigned offset = 0 + variadicOperandSize * 1;
+// CHECK-NEXT: variadicOperandSize = (this->getNumOperands() - 0) / 2;
+// CHECK-NEXT: offset = 0 + variadicOperandSize * 1;
// CHECK-NEXT: return {std::next(operand_begin(), offset), std::next(operand_begin(), offset + variadicOperandSize)};
// CHECK-LABEL: OpC::build
}
// CHECK-LABEL: Operation::operand_range OpD::input1()
-// CHECK-NEXT: unsigned variadicOperandSize = (this->getNumOperands() - 1) / 2;
-// CHECK-NEXT: unsigned offset = 0 + variadicOperandSize * 0;
+// CHECK-NEXT: variadicOperandSize = (this->getNumOperands() - 1) / 2;
+// CHECK-NEXT: offset = 0 + variadicOperandSize * 0;
// CHECK-NEXT: return {std::next(operand_begin(), offset), std::next(operand_begin(), offset + variadicOperandSize)};
// CHECK-LABEL: Value *OpD::input2()
-// CHECK-NEXT: unsigned variadicOperandSize = (this->getNumOperands() - 1) / 2;
-// CHECK-NEXT: unsigned offset = 0 + variadicOperandSize * 1;
+// CHECK-NEXT: variadicOperandSize = (this->getNumOperands() - 1) / 2;
+// CHECK-NEXT: offset = 0 + variadicOperandSize * 1;
// CHECK-NEXT: return this->getOperand(offset);
// CHECK-LABEL: Operation::operand_range OpD::input3()
-// CHECK-NEXT: unsigned variadicOperandSize = (this->getNumOperands() - 1) / 2;
-// CHECK-NEXT: unsigned offset = 1 + variadicOperandSize * 1;
+// CHECK-NEXT: variadicOperandSize = (this->getNumOperands() - 1) / 2;
+// CHECK-NEXT: offset = 1 + variadicOperandSize * 1;
// CHECK-NEXT: return {std::next(operand_begin(), offset), std::next(operand_begin(), offset + variadicOperandSize)};
// CHECK-LABEL: OpD::build
}
// CHECK-LABEL: Operation::result_range OpH::output1()
-// CHECK-NEXT: unsigned variadicResultSize = (this->getNumResults() - 0) / 2;
-// CHECK-NEXT: unsigned offset = 0 + variadicResultSize * 0;
+// CHECK-NEXT: variadicResultSize = (this->getNumResults() - 0) / 2;
+// CHECK-NEXT: offset = 0 + variadicResultSize * 0;
// CHECK-NEXT: return {std::next(result_begin(), offset), std::next(result_begin(), offset + variadicResultSize)};
// CHECK-LABEL: Operation::result_range OpH::output2()
-// CHECK-NEXT: unsigned variadicResultSize = (this->getNumResults() - 0) / 2;
-// CHECK-NEXT: unsigned offset = 0 + variadicResultSize * 1;
+// CHECK-NEXT: variadicResultSize = (this->getNumResults() - 0) / 2;
+// CHECK-NEXT: offset = 0 + variadicResultSize * 1;
// CHECK-NEXT: return {std::next(result_begin(), offset), std::next(result_begin(), offset + variadicResultSize)};
}
// CHECK-LABEL: Operation::result_range OpI::output1()
-// CHECK-NEXT: unsigned variadicResultSize = (this->getNumResults() - 1) / 2;
-// CHECK-NEXT: unsigned offset = 0 + variadicResultSize * 0;
+// CHECK-NEXT: variadicResultSize = (this->getNumResults() - 1) / 2;
+// CHECK-NEXT: offset = 0 + variadicResultSize * 0;
// CHECK-NEXT: return {std::next(result_begin(), offset), std::next(result_begin(), offset + variadicResultSize)};
// CHECK-LABEL: Value *OpI::output2()
-// CHECK-NEXT: unsigned variadicResultSize = (this->getNumResults() - 1) / 2;
-// CHECK-NEXT: unsigned offset = 0 + variadicResultSize * 1;
+// CHECK-NEXT: variadicResultSize = (this->getNumResults() - 1) / 2;
+// CHECK-NEXT: offset = 0 + variadicResultSize * 1;
// CHECK-NEXT: return this->getResult(offset);
// CHECK-LABEL: Operation::result_range OpI::output3()
-// CHECK-NEXT: unsigned variadicResultSize = (this->getNumResults() - 1) / 2;
-// CHECK-NEXT: unsigned offset = 1 + variadicResultSize * 1;
+// CHECK-NEXT: variadicResultSize = (this->getNumResults() - 1) / 2;
+// CHECK-NEXT: offset = 1 + variadicResultSize * 1;
// CHECK-NEXT: return {std::next(result_begin(), offset), std::next(result_begin(), offset + variadicResultSize)};
// CHECK-LABEL: OpI::build
}
void OpEmitter::genNamedOperandGetters() {
- const unsigned numOperands = op.getNumOperands();
- const unsigned numVariadicOperands = op.getNumVariadicOperands();
- const unsigned numNormalOperands = numOperands - numVariadicOperands;
+ const int numOperands = op.getNumOperands();
+ const int numVariadicOperands = op.getNumVariadicOperands();
+ const int numNormalOperands = numOperands - numVariadicOperands;
// Special case for ops without variadic operands: the i-th value is for the
// i-th operand defined in the op.
// operand.
if (numVariadicOperands <= 1) {
bool emittedVariadicOperand = false;
- for (unsigned i = 0; i != numOperands; ++i) {
+ for (int i = 0; i != numOperands; ++i) {
const auto &operand = op.getOperand(i);
if (operand.name.empty())
continue;
"specification over their sizes");
}
- unsigned emittedNormalOperands = 0;
- unsigned emittedVariadicOperands = 0;
+ int emittedNormalOperands = 0;
+ int emittedVariadicOperands = 0;
- for (unsigned i = 0; i != numOperands; ++i) {
+ for (int i = 0; i != numOperands; ++i) {
const auto &operand = op.getOperand(i);
if (operand.name.empty())
continue;
const char *code = R"(
- unsigned variadicOperandSize = (this->getNumOperands() - {0}) / {1};
- unsigned offset = {2} + variadicOperandSize * {3};
+ int variadicOperandSize = (this->getNumOperands() - {0}) / {1};
+ int offset = {2} + variadicOperandSize * {3};
return )";
auto sizeAndOffset =
formatv(code, numNormalOperands, numVariadicOperands,
}
void OpEmitter::genNamedResultGetters() {
- const unsigned numResults = op.getNumResults();
- const unsigned numVariadicResults = op.getNumVariadicResults();
- const unsigned numNormalResults = numResults - numVariadicResults;
+ const int numResults = op.getNumResults();
+ const int numVariadicResults = op.getNumVariadicResults();
+ const int numNormalResults = numResults - numVariadicResults;
// Special case for ops without variadic results: the i-th value is for the
// i-th result defined in the op.
// result.
if (numVariadicResults <= 1) {
bool emittedVariadicResult = false;
- for (unsigned i = 0; i != numResults; ++i) {
+ for (int i = 0; i != numResults; ++i) {
const auto &result = op.getResult(i);
if (result.name.empty())
continue;
"specification over their sizes");
}
- unsigned emittedNormalResults = 0;
- unsigned emittedVariadicResults = 0;
+ int emittedNormalResults = 0;
+ int emittedVariadicResults = 0;
- for (unsigned i = 0; i != numResults; ++i) {
+ for (int i = 0; i != numResults; ++i) {
const auto &result = op.getResult(i);
if (result.name.empty())
continue;
const char *code = R"(
- unsigned variadicResultSize = (this->getNumResults() - {0}) / {1};
- unsigned offset = {2} + variadicResultSize * {3};
+ int variadicResultSize = (this->getNumResults() - {0}) / {1};
+ int offset = {2} + variadicResultSize * {3};
return )";
auto sizeAndOffset = formatv(code, numNormalResults, numVariadicResults,
emittedNormalResults, emittedVariadicResults);
// Emit parameters for all return types
if (!useOperandType && !useAttrType) {
- for (unsigned i = 0; i != numResults; ++i) {
+ for (int i = 0; i != numResults; ++i) {
const auto &result = op.getResult(i);
std::string resultName = result.name;
if (resultName.empty())
// Push all result types to the result
if (numResults > 0) {
if (!useOperandType && !useAttrType) {
- for (unsigned i = 0; i < numResults; ++i) {
+ for (int i = 0; i < numResults; ++i) {
const auto &result = op.getResult(i);
m.body() << " " << builderOpState;
if (result.isVariadic()) {
formatv("{0}{1}->getType()", getArgumentName(op, 0), index).str();
}
m.body() << " " << builderOpState << "->addTypes({" << resultType;
- for (unsigned i = 1; i != numResults; ++i)
+ for (int i = 1; i != numResults; ++i)
m.body() << ", " << resultType;
m.body() << "});\n\n";
}
}
// Push all operands to the result
- for (unsigned i = 0; i < numOperands; ++i) {
+ for (int i = 0; i < numOperands; ++i) {
const auto &operand = op.getOperand(i);
m.body() << " " << builderOpState;
if (operand.isVariadic()) {
}
}
- unsigned numResults = op.getNumResults();
- unsigned numVariadicResults = op.getNumVariadicResults();
- unsigned numNonVariadicResults = numResults - numVariadicResults;
+ int numResults = op.getNumResults();
+ int numVariadicResults = op.getNumVariadicResults();
+ int numNonVariadicResults = numResults - numVariadicResults;
- unsigned numOperands = op.getNumOperands();
- unsigned numVariadicOperands = op.getNumVariadicOperands();
- unsigned numNonVariadicOperands = numOperands - numVariadicOperands;
+ int numOperands = op.getNumOperands();
+ int numVariadicOperands = op.getNumVariadicOperands();
+ int numNonVariadicOperands = numOperands - numVariadicOperands;
// Generate default builders that requires all result type, operands, and
// attributes as parameters.
}
};
- for (unsigned i = 0, e = op.getNumOperands(); i < e; ++i) {
+ for (int i = 0, e = op.getNumOperands(); i < e; ++i) {
verifyValue(op.getOperand(i), i, /*isOperand=*/true);
}
- for (unsigned i = 0, e = op.getNumResults(); i < e; ++i) {
+ for (int i = 0, e = op.getNumResults(); i < e; ++i) {
verifyValue(op.getResult(i), i, /*isOperand=*/false);
}
}
void OpEmitter::genTraits() {
- unsigned numResults = op.getNumResults();
- unsigned numVariadicResults = op.getNumVariadicResults();
+ int numResults = op.getNumResults();
+ int numVariadicResults = op.getNumVariadicResults();
// Add return size trait.
if (numVariadicResults != 0) {
}
// Add variadic size trait and normal op traits.
- unsigned numOperands = op.getNumOperands();
- unsigned numVariadicOperands = op.getNumVariadicOperands();
+ int numOperands = op.getNumOperands();
+ int numVariadicOperands = op.getNumVariadicOperands();
// Add operand size trait.
if (numVariadicOperands != 0) {
PrintFatalError(loc, "only support up to 4-entity constraints now");
}
SmallVector<std::string, 4> names;
- unsigned i = 0;
- for (unsigned e = entities.size(); i < e; ++i)
+ int i = 0;
+ for (int e = entities.size(); i < e; ++i)
names.push_back(resolveSymbol(entities[i]));
for (; i < 4; ++i)
names.push_back("<unused>");
void PatternEmitter::emitRewriteMethod() {
const Operator &rootOp = pattern.getSourceRootOp();
int numExpectedResults = rootOp.getNumResults();
- unsigned numProvidedResults = pattern.getNumResults();
+ int numProvidedResults = pattern.getNumResults();
if (numProvidedResults < numExpectedResults)
PrintFatalError(
// Collect the replacement value for each result
llvm::SmallVector<std::string, 2> resultValues;
- for (unsigned i = 0; i < numProvidedResults; ++i) {
+ for (int i = 0; i < numProvidedResults; ++i) {
DagNode resultTree = pattern.getResultPattern(i);
resultValues.push_back(handleRewritePattern(resultTree, i, 0));
// Keep track of bound symbols at the top-level DAG nodes
PrintFatalError(loc, "unsupported NativeCodeCall argument numbers: " +
Twine(tree.getNumArgs()));
}
- for (unsigned i = 0, e = tree.getNumArgs(); i != e; ++i) {
+ for (int i = 0, e = tree.getNumArgs(); i != e; ++i) {
attrs[i] = handleOpArgument(tree.getArgAsLeaf(i), tree.getArgName(i));
}
return tgfmt(fmt, &rewriteCtx, attrs[0], attrs[1], attrs[2], attrs[3],
// First go through all the child nodes who are nested DAG constructs to
// create ops for them, so that we can use the results in the current node.
// This happens in a recursive manner.
- for (unsigned i = 0, e = resultOp.getNumOperands(); i != e; ++i) {
+ for (int i = 0, e = resultOp.getNumOperands(); i != e; ++i) {
if (auto child = tree.getArgAsNestedDag(i)) {
childNodeNames[i] = handleRewritePattern(child, i, depth + 1);
// Keep track of bound symbols at the middle-level DAG nodes