diff --git a/compiler/src/iree/compiler/Codegen/Common/BufferizationAnalysis.cpp b/compiler/src/iree/compiler/Codegen/Common/BufferizationAnalysis.cpp index baa7825fac66..9eebf12617f5 100644 --- a/compiler/src/iree/compiler/Codegen/Common/BufferizationAnalysis.cpp +++ b/compiler/src/iree/compiler/Codegen/Common/BufferizationAnalysis.cpp @@ -460,42 +460,6 @@ static void hasDestructiveUpdatePattern(Value source, BufferizationPlan &plan) { } } -/// Ties together operands for operand fusion as exists today by reusing buffer -/// for the result for one of the inputs to do in-place update. Ideally we dont -/// need to do this if the fusion just happens at vector level. To be removed -/// when that is worked out and can be load-bearing. Conditions checked here are -/// 1) the result does not use the value of the `outs` buffer. -/// 2) the input has a single use (this op) and has the same indexing map as the -/// result. -/// 3) the input equivalence set does not have an interface binding, i.e. it is -/// not using a buffer from the dispatch ABI. -static void tieOperandsForOperandFusion(linalg::LinalgOp linalgOp, - BufferizationPlan &plan) { - for (auto [index, result] : llvm::enumerate(linalgOp.getDpsInitsMutable())) { - if (linalgOp.payloadUsesValueFromOperand(&result)) { - continue; - } - for (OpOperand *input : linalgOp.getDpsInputOperands()) { - auto tensorType = - llvm::dyn_cast(input->get().getType()); - if (!tensorType) - continue; - Type inputElementType = tensorType.getElementType(); - Type resultElementType = - llvm::cast(result.get().getType()).getElementType(); - if (input->get().hasOneUse() && (inputElementType == resultElementType) && - linalgOp.getMatchingIndexingMap(input) == - linalgOp.getMatchingIndexingMap(&result) && - !getEquivalentOpOfType( - input->get(), plan) && - !isFromReadOnlyTensor(input->get(), plan)) { - plan.unionSets(linalgOp->getResult(index), input->get()); - break; - } - } - } -} - void BufferizationPlan::unionSets(Value v1, Value v2) { if (!canSetsBeMerged(v1, v2, *this)) { return; diff --git a/compiler/src/iree/compiler/Codegen/Common/FlattenMemRefSubspanPass.cpp b/compiler/src/iree/compiler/Codegen/Common/FlattenMemRefSubspanPass.cpp index 0fd4129aaa77..94b51981cbab 100644 --- a/compiler/src/iree/compiler/Codegen/Common/FlattenMemRefSubspanPass.cpp +++ b/compiler/src/iree/compiler/Codegen/Common/FlattenMemRefSubspanPass.cpp @@ -705,23 +705,6 @@ struct FoldMemRefReshape final : public OpConversionPattern { }; }; -/// Returns the number of bytes of the given `type`. Returns std::nullopt if -/// cannot deduce. -/// -/// Note that this should be kept consistent with how the byte offset was -/// calculated in the subspan ops! -std::optional getNumBytes(Type type) { - if (type.isIntOrFloat()) - return IREE::Util::getRoundedElementByteWidth(type); - if (auto vectorType = llvm::dyn_cast(type)) { - auto elementBytes = getNumBytes(vectorType.getElementType()); - if (!elementBytes) - return std::nullopt; - return elementBytes.value() * vectorType.getNumElements(); - } - return std::nullopt; -} - /// Erase alignment hints. struct RemoveAssumeAlignOp : public OpRewritePattern { diff --git a/compiler/src/iree/compiler/Codegen/Common/FoldAffineMinInDistributedLoops.cpp b/compiler/src/iree/compiler/Codegen/Common/FoldAffineMinInDistributedLoops.cpp index ce744b4b17da..1aeca7aa3e22 100644 --- a/compiler/src/iree/compiler/Codegen/Common/FoldAffineMinInDistributedLoops.cpp +++ b/compiler/src/iree/compiler/Codegen/Common/FoldAffineMinInDistributedLoops.cpp @@ -36,16 +36,6 @@ namespace mlir { namespace iree_compiler { -/// Gets the given `attrOrValue` as a Value by creating constant ops for -/// attributes. -static Value getAsValue(OpFoldResult attrOrValue, OpBuilder &builder, - Location loc) { - if (Value val = attrOrValue.dyn_cast()) - return val; - auto attr = llvm::cast(attrOrValue.get()); - return builder.create(loc, attr.getInt()); -} - #ifndef NDEBUG inline raw_ostream &operator<<(raw_ostream &os, const LoopTilingAndDistributionInfo &info) { diff --git a/compiler/src/iree/compiler/Codegen/Common/GPU/GPUTensorAlloc.cpp b/compiler/src/iree/compiler/Codegen/Common/GPU/GPUTensorAlloc.cpp index ea243ffaa6e7..a7d2eb88d02c 100644 --- a/compiler/src/iree/compiler/Codegen/Common/GPU/GPUTensorAlloc.cpp +++ b/compiler/src/iree/compiler/Codegen/Common/GPU/GPUTensorAlloc.cpp @@ -80,20 +80,6 @@ static bool transposeOpFilter(Operation *op) { return opInfo.isTranspose(); } -/// Returns true if the index map represents a transpose that benefits from -/// shared mem. -static bool isSharedMemTranspose(AffineMap indexMap) { - if (!indexMap.isEmpty() && indexMap.isPermutation()) { - // Ensure that the fasted moving dimension (the last one) is permuted, - // Otherwise shared memory promotion will not benefit the operation. - if (indexMap.getDimPosition(indexMap.getNumDims() - 1) != - indexMap.getNumDims() - 1) { - return true; - } - } - return false; -} - namespace { /// Swaps bufferization.alloc_tensor with the copied linalg op result when the /// linalg op does not use the output initial value during calculation. diff --git a/compiler/src/iree/compiler/Codegen/Common/GenericVectorization.cpp b/compiler/src/iree/compiler/Codegen/Common/GenericVectorization.cpp index a50130c3c966..01025907d1a8 100644 --- a/compiler/src/iree/compiler/Codegen/Common/GenericVectorization.cpp +++ b/compiler/src/iree/compiler/Codegen/Common/GenericVectorization.cpp @@ -25,49 +25,6 @@ namespace mlir { namespace iree_compiler { namespace { -/// Returns the op that contains lowering config. Checks whether the provided op -/// contains the lowering config and returns it. Otherwise, tries to find the -/// lowering config across the function. If there are multiple ops with the same -/// lowering configs, returns the first one found. Returns failure if there are -/// multiple op with different lowering config. -static FailureOr getRootOp(Operation *op) { - // Check for self first. - if (iree_compiler::getLoweringConfig(op)) { - return op; - } - - // Get the function op. - auto funcOp = dyn_cast(op); - if (!funcOp) { - funcOp = op->getParentOfType(); - } - - assert(funcOp && "Missing funcOp"); - - Operation *rootOp = nullptr; - mlir::iree_compiler::IREE::Codegen::LoweringConfigAttr rootLoweringConfig; - auto result = funcOp.walk([&](Operation *op) -> WalkResult { - auto loweringConfig = iree_compiler::getLoweringConfig(op); - if (!loweringConfig) { - return WalkResult::advance(); - } - if (rootLoweringConfig) { - if (rootLoweringConfig != loweringConfig) { - return WalkResult::interrupt(); - } - } else { - rootOp = op; - rootLoweringConfig = loweringConfig; - } - return WalkResult::advance(); - }); - - if (!rootOp || result.wasInterrupted()) { - return failure(); - } - return rootOp; -} - /// Tries to infer the vector sizes from an IR using ValueBounds analysis. /// Returns failure if vector sizes can't be inferred. static FailureOr> diff --git a/compiler/src/iree/compiler/Codegen/Common/IREEComprehensiveBufferizePass.cpp b/compiler/src/iree/compiler/Codegen/Common/IREEComprehensiveBufferizePass.cpp index 6a97ab04af7e..e934114ed9db 100644 --- a/compiler/src/iree/compiler/Codegen/Common/IREEComprehensiveBufferizePass.cpp +++ b/compiler/src/iree/compiler/Codegen/Common/IREEComprehensiveBufferizePass.cpp @@ -92,8 +92,6 @@ class IREEComprehensiveBufferizePass }; } // namespace -static bool isaTensor(Type t) { return llvm::isa(t); }; - // Default allocation functions. static FailureOr defaultAllocationFn(OpBuilder &builder, Location loc, MemRefType allocationType, diff --git a/compiler/src/iree/compiler/Codegen/Common/RemoveTrivialLoops.cpp b/compiler/src/iree/compiler/Codegen/Common/RemoveTrivialLoops.cpp index 1f4ac2d4f114..7a673d56b8d8 100644 --- a/compiler/src/iree/compiler/Codegen/Common/RemoveTrivialLoops.cpp +++ b/compiler/src/iree/compiler/Codegen/Common/RemoveTrivialLoops.cpp @@ -91,18 +91,6 @@ getWorkgroupRange(Value processorValue, SmallVectorImpl & /*dims*/, return std::nullopt; } -/// Return true if the given tiled loop is distributed to workgroups. -static bool isWorkgroupLoop(const LoopTilingAndDistributionInfo &info) { - auto forOp = cast(info.loop); - Operation *lbOp = forOp.getLowerBound().getDefiningOp(); - if (isa(lbOp)) - return true; - auto applyOp = dyn_cast(lbOp); - return applyOp && llvm::any_of(applyOp.getMapOperands(), [](Value operand) { - return operand.getDefiningOp(); - }); -} - static LogicalResult removeOneTripTiledLoops(func::FuncOp funcOp, ArrayRef workgroupSize, ArrayRef numWorkgroups) { diff --git a/compiler/src/iree/compiler/Codegen/Common/TileAndDistributeToWorkgroupsPass.cpp b/compiler/src/iree/compiler/Codegen/Common/TileAndDistributeToWorkgroupsPass.cpp index e4ddea0bad9e..9bd2f4dcac73 100644 --- a/compiler/src/iree/compiler/Codegen/Common/TileAndDistributeToWorkgroupsPass.cpp +++ b/compiler/src/iree/compiler/Codegen/Common/TileAndDistributeToWorkgroupsPass.cpp @@ -120,26 +120,6 @@ getTileAndDistributeConfig(ArrayRef computeOps, return success(); } -/// Get the materialization information from a `tensor.pack` operation. -static FailureOr -getMaterializationInfo(tensor::PackOp packOp) { - IREE::LinalgExt::MaterializeEncodingInfo encodingInfo; - SmallVector mixedTileSizes = packOp.getMixedTiles(); - encodingInfo.innerTileSizes.reserve(mixedTileSizes.size()); - for (auto tileSize : mixedTileSizes) { - if (tileSize.is()) { - encodingInfo.innerTileSizes.push_back(ShapedType::kDynamic); - } else { - encodingInfo.innerTileSizes.push_back( - llvm::cast(tileSize.get()).getInt()); - } - } - encodingInfo.innerDimsPos = llvm::to_vector(packOp.getInnerDimsPos()); - encodingInfo.outerDimsPerm = llvm::to_vector(packOp.getOuterDimsPerm()); - encodingInfo.srcRank = packOp.getSourceRank(); - return encodingInfo; -} - //===---------------------------------------------------------------------===// // Patterns to lower operations that are used to compute the number of // workgroups. diff --git a/compiler/src/iree/compiler/Codegen/Interfaces/PartitionableLoopsInterface.cpp b/compiler/src/iree/compiler/Codegen/Interfaces/PartitionableLoopsInterface.cpp index 77724bf32bfd..56e54afca83b 100644 --- a/compiler/src/iree/compiler/Codegen/Interfaces/PartitionableLoopsInterface.cpp +++ b/compiler/src/iree/compiler/Codegen/Interfaces/PartitionableLoopsInterface.cpp @@ -51,14 +51,6 @@ getPartitionableLoopsImpl(linalg::LinalgOp linalgOp, return parallelLoops; } -static llvm::SmallVector -getIteratorTypesFromAttr(ArrayAttr iteratorTypesAttr) { - return llvm::map_to_vector(iteratorTypesAttr, [](Attribute attr) { - return utils::symbolizeIteratorType(llvm::cast(attr).getValue()) - .value(); - }); -} - /// External model implementation for all LinalgOps. template struct LinalgOpPartitionableLoops diff --git a/compiler/src/iree/compiler/Codegen/LLVMGPU/KernelConfig.cpp b/compiler/src/iree/compiler/Codegen/LLVMGPU/KernelConfig.cpp index c3b8d2c88154..220f04eb40b1 100644 --- a/compiler/src/iree/compiler/Codegen/LLVMGPU/KernelConfig.cpp +++ b/compiler/src/iree/compiler/Codegen/LLVMGPU/KernelConfig.cpp @@ -681,25 +681,6 @@ static LogicalResult setRootDefaultConfig(func::FuncOp entryPoint, passPipeline, workgroupSize); } -/// Return the size of the given dimension in the linalg op. -// TODO: this should be part of LinalgOp interface, the equivalent member -// function currently only support the case where all the dimensions are static -// while we want to support dynamic shapes. -static std::optional getLinalgDimSize(linalg::LinalgOp op, int64_t d) { - for (auto [mapIdx, map] : llvm::enumerate(op.getIndexingMapsArray())) { - for (auto [dimIdx, dim] : llvm::enumerate(map.getResults())) { - auto expr = dim.dyn_cast(); - if (expr && expr.getPosition() == d) { - auto type = llvm::cast(op->getOperand(mapIdx).getType()); - if (type.isDynamicDim(dimIdx)) - return std::nullopt; - return type.getDimSize(dimIdx); - } - } - } - return std::nullopt; -} - /// Set configuration for transform dialect based strategies. static LogicalResult setTransformDialectConfig(func::FuncOp entryPoint, Operation *op, diff --git a/compiler/src/iree/compiler/Codegen/LLVMGPU/Utils/LLVMGPULayoutAnalysisAndDistribution.cpp b/compiler/src/iree/compiler/Codegen/LLVMGPU/Utils/LLVMGPULayoutAnalysisAndDistribution.cpp index 6320d45dce40..058def07f48c 100644 --- a/compiler/src/iree/compiler/Codegen/LLVMGPU/Utils/LLVMGPULayoutAnalysisAndDistribution.cpp +++ b/compiler/src/iree/compiler/Codegen/LLVMGPU/Utils/LLVMGPULayoutAnalysisAndDistribution.cpp @@ -756,15 +756,6 @@ static int isSingleLaneIdReduced(std::array &order) { return count == 1; } -static int getVecSizes(std::array &order, const Layout &layout) { - int size = 1; - for (int i = 0; i < 4; i++) { - if (isVectorId(i)) - size *= layout.shape[i]; - } - return size; -} - using bodyType = std::function &)>; /// This function iterates over the dimensions of a given column/row order diff --git a/compiler/src/iree/compiler/Codegen/TransformStrategies/CPU/Common.cpp b/compiler/src/iree/compiler/Codegen/TransformStrategies/CPU/Common.cpp index 2bd0a9a1ec47..d90454b106f0 100644 --- a/compiler/src/iree/compiler/Codegen/TransformStrategies/CPU/Common.cpp +++ b/compiler/src/iree/compiler/Codegen/TransformStrategies/CPU/Common.cpp @@ -138,23 +138,6 @@ std::pair mlir::iree_compiler::cpu::buildCommonTrailingStrategy( // user-friendliness. //===----------------------------------------------------------------------===// -/// Placeholder to encode fixed reductions that should take finer-grained -/// precedence over other heuristics. In the future, this could be lifted to -/// e.g. `cpuModel` or higher up in some transform dialect database summary of -/// "known good things". -static FailureOr applyKnownGoodReductionConfigurations( - const transform_ext::MatchedReductionCaptures &captures, - const CPUModel &cpuModel) { - int64_t reductionSize = captures.reductionOpSizes.back(); - if (cpuModel.model == CPUModel::kDefaultCPU) { - if (captures.reductionOutputElementalTypeBitWidth == 32) { - if (reductionSize == 32) - return ReductionConfig{/*vectorSize=*/32}; - } - } - return failure(); -} - static ReductionConfig getReductionConfig(const transform_ext::MatchedReductionCaptures &captures, const CPUModel &cpuModel) { diff --git a/compiler/src/iree/compiler/Codegen/TransformStrategies/Common/Common.cpp b/compiler/src/iree/compiler/Codegen/TransformStrategies/Common/Common.cpp index 080601bf8652..42031186d447 100644 --- a/compiler/src/iree/compiler/Codegen/TransformStrategies/Common/Common.cpp +++ b/compiler/src/iree/compiler/Codegen/TransformStrategies/Common/Common.cpp @@ -390,41 +390,6 @@ struct ReductionSplitResult { }; } // namespace -/// Builds transform IR requesting to bubble up the "expand_shape" operation -/// produced as parent of reduction splitting if necessary for fusion of the -/// leading elementwise operation. -// TODO: consider passing a problem-specific struct to control information. -static ReductionSplitResult -createBubbleExpand(ImplicitLocOpBuilder &b, Value variantH, - SplitReductionOp splitReductionTransformOp, - bool hasLeadingEltwise, bool hasTrailingEltwise) { - ReductionSplitResult result; - if (!hasLeadingEltwise) { - result.splitFillH = splitReductionTransformOp.getFillOp(); - result.splitLinalgH = splitReductionTransformOp.getSplitLinalgOp(); - result.combinerH = splitReductionTransformOp.getCombiningLinalgOp(); - return result; - } - - auto funcH = b.create(variantH, func::FuncOp::getOperationName()); - b.create(funcH, [](OpBuilder &b, Location loc) { - b.create< - iree_compiler::IREE::transform_dialect::ApplyBubbleExpandPatternsOp>( - loc); - }); - std::tie(result.originalFillH, result.splitFillH) = - matchAndUnpack<2>(b, variantH, linalg::FillOp::getOperationName()); - if (hasTrailingEltwise) { - std::tie(result.leadingEltwiseH, result.splitLinalgH, result.combinerH, - result.trailingEltwiseH) = - matchAndUnpack<4>(b, variantH, linalg::GenericOp::getOperationName()); - } else { - std::tie(result.leadingEltwiseH, result.splitLinalgH, result.combinerH) = - matchAndUnpack<3>(b, variantH, linalg::GenericOp::getOperationName()); - } - return result; -} - /// Build transform IR to split the reduction into a parallel and combiner part. /// Then tile the parallel part and map it to `tileSize` threads, each reducing /// on `vectorSize` elements. diff --git a/compiler/src/iree/compiler/Dialect/Flow/IR/FlowOpFolders.cpp b/compiler/src/iree/compiler/Dialect/Flow/IR/FlowOpFolders.cpp index 9a2dcd232a53..d79e9a4ea5e6 100644 --- a/compiler/src/iree/compiler/Dialect/Flow/IR/FlowOpFolders.cpp +++ b/compiler/src/iree/compiler/Dialect/Flow/IR/FlowOpFolders.cpp @@ -132,23 +132,6 @@ struct ReplaceOpIfTensorOperandEmpty : public OpRewritePattern { } }; -// Turns a tensor type that may have one or more dynamic dimensions into a -// static type with dynamic dimensions replaced with 0. -// Example: tensor -> tensor<0x0x1xf32> -static Type makeZeroElementsStaticTensorType(Type type) { - auto tensorType = llvm::cast(type); - if (tensorType.hasStaticShape()) - return type; - SmallVector dims; - dims.resize(tensorType.getRank()); - for (int64_t i = 0; i < tensorType.getRank(); ++i) { - int64_t dim = tensorType.getDimSize(i); - dims[i] = dim == ShapedType::kDynamic ? 0 : dim; - } - return RankedTensorType::get(dims, tensorType.getElementType(), - tensorType.getEncoding()); -} - // Returns a new set of dynamic dimensions for a shape carrying op when a type // is being changed. This attempts to reuse the existing dimension values if // they are available and will drop/insert new ones as required. diff --git a/compiler/src/iree/compiler/Dialect/Flow/Transforms/FormDispatchRegions.cpp b/compiler/src/iree/compiler/Dialect/Flow/Transforms/FormDispatchRegions.cpp index ea00c12bb53a..cdbbe083ee95 100644 --- a/compiler/src/iree/compiler/Dialect/Flow/Transforms/FormDispatchRegions.cpp +++ b/compiler/src/iree/compiler/Dialect/Flow/Transforms/FormDispatchRegions.cpp @@ -158,15 +158,6 @@ static void appendToFusionGroup(Operation *op, ArrayRef newGroups) { fusionGroups.append(newGroups.begin(), newGroups.end()); op->setAttr(kFusionGroupsAttr, Builder(op).getI64ArrayAttr(fusionGroups)); } -/// Returns true if the given `op` is in the `targetGroup` fusion group. -static bool isInFusionGroup(Operation *op, unsigned targetGroup) { - if (ArrayAttr opGroupAttr = op->getAttrOfType(kFusionGroupsAttr)) { - return llvm::any_of(opGroupAttr, [&targetGroup](Attribute attr) { - return llvm::cast(attr).getInt() == targetGroup; - }); - } - return false; -} /// Removes the fusion groups attribute. static void removeFusionGroupsAttribute(Operation *op) { op->removeAttr(kFusionGroupsAttr); diff --git a/compiler/src/iree/compiler/Dialect/HAL/IR/HALOps.cpp b/compiler/src/iree/compiler/Dialect/HAL/IR/HALOps.cpp index 018cc77051ad..77c212516f6a 100644 --- a/compiler/src/iree/compiler/Dialect/HAL/IR/HALOps.cpp +++ b/compiler/src/iree/compiler/Dialect/HAL/IR/HALOps.cpp @@ -194,66 +194,6 @@ static void printTargetConditionRegion(OpAsmPrinter &p, Operation *op, /*printBlockTerminators=*/true); } -//===----------------------------------------------------------------------===// -// custom($targets, $objects, $target_regions) -//===----------------------------------------------------------------------===// - -static ParseResult parseConditionalTargetRegions( - OpAsmParser &parser, ArrayAttr &targetsAttr, ArrayAttr &objectsAttr, - SmallVectorImpl> &targetRegions) { - auto builder = parser.getBuilder(); - SmallVector targetAttrs; - SmallVector objectsAttrs; - do { - IREE::HAL::ExecutableTargetAttr targetAttr; - if (failed(parser.parseAttribute(targetAttr))) - return failure(); - targetAttrs.push_back(targetAttr); - std::unique_ptr targetRegion = std::make_unique(); - if (succeeded(parser.parseOptionalKeyword("if"))) { - if (failed(parseTargetConditionRegion(parser, *targetRegion))) - return failure(); - } - targetRegions.emplace_back(std::move(targetRegion)); - if (failed(parser.parseEqual())) - return failure(); - ArrayAttr targetObjectsAttr; - if (failed(parser.parseAttribute(targetObjectsAttr))) - return failure(); - objectsAttrs.push_back(targetObjectsAttr); - } while (succeeded(parser.parseOptionalComma())); - targetsAttr = builder.getArrayAttr(targetAttrs); - objectsAttr = builder.getArrayAttr(objectsAttrs); - return success(); -} - -static void -printConditionalTargetRegions(OpAsmPrinter &p, Operation *op, - ArrayAttr targetsAttr, ArrayAttr objectsAttr, - MutableArrayRef targetRegions) { - p.increaseIndent(); - p.printNewline(); - llvm::interleave( - llvm::zip_equal(targetsAttr.getAsRange(), - objectsAttr.getAsRange(), targetRegions), - [&](auto it) { - auto [targetAttr, targetObjectsAttr, targetRegion] = it; - p.printAttribute(targetAttr); - if (!targetRegion.empty()) { - p << " if"; - printTargetConditionRegion(p, op, targetRegion); - } - p << " = "; - p.printAttribute(targetObjectsAttr); - }, - [&]() { - p << ","; - p.printNewline(); - }); - p.decreaseIndent(); - p.printNewline(); -} - //===----------------------------------------------------------------------===// // custom($body) //===----------------------------------------------------------------------===// diff --git a/compiler/src/iree/compiler/Dialect/Stream/Analysis/ResourceHazards.cpp b/compiler/src/iree/compiler/Dialect/Stream/Analysis/ResourceHazards.cpp index 4a3383eca9f1..84776afffb84 100644 --- a/compiler/src/iree/compiler/Dialect/Stream/Analysis/ResourceHazards.cpp +++ b/compiler/src/iree/compiler/Dialect/Stream/Analysis/ResourceHazards.cpp @@ -33,22 +33,9 @@ namespace Stream { // TODO(#6972): move to StreamTypes.h. -static bool doesRead(ResourceAccessBitfield access) { - return bitEnumContainsAny(access, ResourceAccessBitfield::Read); -} -static bool doesWrite(ResourceAccessBitfield access) { - return bitEnumContainsAny(access, ResourceAccessBitfield::Write); -} static bool isReadOnly(ResourceAccessBitfield access) { return access == ResourceAccessBitfield::Read; } -static bool isWriteOnly(ResourceAccessBitfield access) { - return access == ResourceAccessBitfield::Write; -} -static bool isReadWrite(ResourceAccessBitfield access) { - return bitEnumContainsAny(access, ResourceAccessBitfield::Read | - ResourceAccessBitfield::Write); -} static bool doesRangeOverlap(AsyncAccessRange &lhs, AsyncAccessRange &rhs) { if (lhs.resource != rhs.resource) diff --git a/compiler/src/iree/compiler/Dialect/Stream/IR/StreamOps.cpp b/compiler/src/iree/compiler/Dialect/Stream/IR/StreamOps.cpp index a2a46acb7d40..09b68476c8bd 100644 --- a/compiler/src/iree/compiler/Dialect/Stream/IR/StreamOps.cpp +++ b/compiler/src/iree/compiler/Dialect/Stream/IR/StreamOps.cpp @@ -80,25 +80,6 @@ verifyDispatchWorkload(Operation *op, IREE::Stream::ExecutableExportOp exportOp, return success(); } -// Verifies that |dynamicDims| contains the appropriate number of dims for all -// of the dynamic dimensions in |values|. -static LogicalResult verifyOpDynamicDims(Operation *op, ValueRange values, - ValueRange dynamicDims) { - unsigned requiredCount = 0; - for (auto value : values) { - if (auto shapedType = llvm::dyn_cast(value.getType())) { - requiredCount += shapedType.getNumDynamicDims(); - } - } - if (dynamicDims.size() != requiredCount) { - return op->emitOpError() - << "value set has " << requiredCount - << " dynamic dimensions but only " << dynamicDims.size() - << " dimension values are attached"; - } - return success(); -} - // Verifies that |dynamicDims| contains the appropriate number of dims for all // the dynamic dimensions in |type|. static LogicalResult verifyOpDynamicDims(Operation *op, TypeRange types, diff --git a/compiler/src/iree/compiler/Dialect/Stream/Transforms/ElideAsyncCopies.cpp b/compiler/src/iree/compiler/Dialect/Stream/Transforms/ElideAsyncCopies.cpp index 40f75b7c05e5..756d6cfb577e 100644 --- a/compiler/src/iree/compiler/Dialect/Stream/Transforms/ElideAsyncCopies.cpp +++ b/compiler/src/iree/compiler/Dialect/Stream/Transforms/ElideAsyncCopies.cpp @@ -432,17 +432,6 @@ static bool isSafeToElideCloneOp(IREE::Stream::AsyncCloneOp cloneOp, return false; } -// Tries to elide |cloneOp| by replacing all uses with its source if safe. -// Returns true if the op was elided. -static bool tryElideCloneOp(IREE::Stream::AsyncCloneOp cloneOp, - LastUseAnalysis &analysis) { - if (!isSafeToElideCloneOp(cloneOp, analysis)) - return false; - cloneOp.replaceAllUsesWith(cloneOp.getSource()); - cloneOp.erase(); - return true; -} - // Tries to elide copies nested within |region| when safe. // Returns true if any ops were elided. static bool tryElideAsyncCopiesInRegion(Region ®ion, diff --git a/compiler/src/iree/compiler/Dialect/Stream/Transforms/LayoutSlices.cpp b/compiler/src/iree/compiler/Dialect/Stream/Transforms/LayoutSlices.cpp index 87c38d0146ba..7d2dc6281848 100644 --- a/compiler/src/iree/compiler/Dialect/Stream/Transforms/LayoutSlices.cpp +++ b/compiler/src/iree/compiler/Dialect/Stream/Transforms/LayoutSlices.cpp @@ -35,35 +35,6 @@ namespace { using Slice = IREE::Stream::ResourcePackOp::Slice; -// Packs slices back-to-back with no aliasing. Useful when debugging to remove -// the aliasing that makes data breakpoints useless. -// -// Slice packed offset SSA values will be updated and start at the given -// |baseOffset|. Returns |baseOffset| + the total size of the allocation -// aligned to the requirements of |resourceConfig|. -static Value -packSlicesWithNoAliasing(IREE::Stream::ResourcePackOp packOp, Value baseOffset, - ArrayRef slices, - IREE::Stream::ResourceConfigAttr resourceConfig, - IndexSet &indexSet, OpBuilder &builder) { - auto loc = packOp.getLoc(); - int64_t offsetAlignment = resourceConfig.getMinBufferOffsetAlignment(); - int64_t rangeAlignment = resourceConfig.getMinBufferRangeAlignment(); - - Value offset = baseOffset; - for (auto &slice : slices) { - auto sliceSize = builder.createOrFold( - loc, slice.dynamicSize, rangeAlignment); - slice.packedOffset.replaceAllUsesWith(offset); - auto valueToAlign = - builder.createOrFold(loc, offset, sliceSize); - offset = builder.createOrFold(loc, valueToAlign, - offsetAlignment); - } - - return builder.createOrFold(loc, offset, rangeAlignment); -} - // Packs a set of statically-sized slices by greedy strip packing. // // This is the same algorithm used in tflite here: diff --git a/compiler/src/iree/compiler/Dialect/Stream/Transforms/PropagateTimepoints.cpp b/compiler/src/iree/compiler/Dialect/Stream/Transforms/PropagateTimepoints.cpp index ea26f8408f37..e449748fab71 100644 --- a/compiler/src/iree/compiler/Dialect/Stream/Transforms/PropagateTimepoints.cpp +++ b/compiler/src/iree/compiler/Dialect/Stream/Transforms/PropagateTimepoints.cpp @@ -527,8 +527,6 @@ static void expandCondBranchOp(mlir::cf::CondBranchOp op, op.erase(); } -static ValueRange asValueRange(ArrayRef values) { return values; } - static void expandSwitchOp(mlir::cf::SwitchOp op, IRMapping &resourceTimepointMap) { if (!usesResources(op)) diff --git a/compiler/src/iree/compiler/Dialect/Stream/Transforms/VerifyLowerings.cpp b/compiler/src/iree/compiler/Dialect/Stream/Transforms/VerifyLowerings.cpp index 99ad8a236d71..f2da9a705841 100644 --- a/compiler/src/iree/compiler/Dialect/Stream/Transforms/VerifyLowerings.cpp +++ b/compiler/src/iree/compiler/Dialect/Stream/Transforms/VerifyLowerings.cpp @@ -236,16 +236,6 @@ static void markStreamAsyncOpsIllegal(Verifier &verifier) { }); } -static void markStreamCmdOpsIllegal(Verifier &verifier) { - verifier.addOpVerifier( - [](Operation *op) -> std::optional { - if (op->hasTrait()) { - return Verifier::Legality::ILLEGAL; - } - return std::nullopt; - }); -} - //===----------------------------------------------------------------------===// // -iree-stream-verify-input //===----------------------------------------------------------------------===// diff --git a/compiler/src/iree/compiler/Dialect/VM/Conversion/VMToEmitC/ConvertVMToEmitC.cpp b/compiler/src/iree/compiler/Dialect/VM/Conversion/VMToEmitC/ConvertVMToEmitC.cpp index 113e12e366bb..26d406567e7b 100644 --- a/compiler/src/iree/compiler/Dialect/VM/Conversion/VMToEmitC/ConvertVMToEmitC.cpp +++ b/compiler/src/iree/compiler/Dialect/VM/Conversion/VMToEmitC/ConvertVMToEmitC.cpp @@ -213,30 +213,6 @@ removeBlockArguments(IREE::VM::ModuleOp moduleOp, return success(); } -FailureOr calculateNumSpans(IREE::VM::CallVariadicOp &callOp) { - auto isVariadic = [](APInt segmentSize) { - return segmentSize.getSExtValue() != -1; - }; - - DenseIntElementsAttr segmentSizes = callOp.getSegmentSizes(); - size_t numSegments = segmentSizes.size(); - size_t numVariadicSegments = llvm::count_if(segmentSizes, isVariadic); - - if (numVariadicSegments != 1) { - callOp.emitError() << "only exactly one variadic segment supported"; - return failure(); - } - - auto lastSegmentSize = *(segmentSizes.begin() + (numSegments - 1)); - - if (!isVariadic(lastSegmentSize)) { - callOp.emitError() << "expected the last segment to be variadic"; - return failure(); - } - - return lastSegmentSize.getSExtValue(); -} - std::optional buildFunctionName(IREE::VM::ModuleOp &moduleOp, IREE::VM::ImportOp &importOp) { auto callingConvention = makeImportCallingConventionString(importOp); diff --git a/compiler/src/iree/compiler/Dialect/VM/Target/Bytecode/BytecodeModuleTarget.cpp b/compiler/src/iree/compiler/Dialect/VM/Target/Bytecode/BytecodeModuleTarget.cpp index 5bce5ee34ce2..824bc45731ef 100644 --- a/compiler/src/iree/compiler/Dialect/VM/Target/Bytecode/BytecodeModuleTarget.cpp +++ b/compiler/src/iree/compiler/Dialect/VM/Target/Bytecode/BytecodeModuleTarget.cpp @@ -262,19 +262,6 @@ makeFunctionSignatureDef(IREE::VM::FuncOp funcOp, cconv.value(), attrsRef, fbb); } -// Returns a serialized function signature. -static iree_vm_FunctionSignatureDef_ref_t -makeInternalFunctionSignatureDef(IREE::VM::FuncOp funcOp, - llvm::DenseMap &typeTable, - FlatbufferBuilder &fbb) { - // Generate the signature calling convention string based on types. - auto cconv = makeCallingConventionString(funcOp); - if (!cconv.has_value()) - return {}; - return createFunctionSignatureDef(funcOp.getFunctionType(), typeTable, - cconv.value(), /*attrsRef=*/0, fbb); -} - // Walks |rootOp| to find all VM features required by it and its children. static iree_vm_FeatureBits_enum_t findRequiredFeatures(Operation *rootOp) { iree_vm_FeatureBits_enum_t result = 0; diff --git a/compiler/src/iree/compiler/InputConversion/StableHLO/Preprocessing/StableHLOToStableHLO.cpp b/compiler/src/iree/compiler/InputConversion/StableHLO/Preprocessing/StableHLOToStableHLO.cpp index 601c4e35f651..7fcfb04f3e06 100644 --- a/compiler/src/iree/compiler/InputConversion/StableHLO/Preprocessing/StableHLOToStableHLO.cpp +++ b/compiler/src/iree/compiler/InputConversion/StableHLO/Preprocessing/StableHLOToStableHLO.cpp @@ -46,12 +46,6 @@ DenseIntElementsAttr make1DElementsAttr(OpBuilder &b, return DenseIntElementsAttr::get(type, integers); } -DenseIntElementsAttr make1DElementsAttr(OpBuilder &b, int64_t start, - int64_t num) { - return make1DElementsAttr( - b, llvm::to_vector(llvm::seq(start, start + num))); -} - Value getF32Const(ImplicitLocOpBuilder b, ArrayRef shapes, ArrayRef values) { RankedTensorType ty = RankedTensorType::get(shapes, b.getF32Type()); diff --git a/runtime/src/iree/hal/drivers/vulkan/descriptor_set_arena.cc b/runtime/src/iree/hal/drivers/vulkan/descriptor_set_arena.cc index 528f1292410d..cb54de909164 100644 --- a/runtime/src/iree/hal/drivers/vulkan/descriptor_set_arena.cc +++ b/runtime/src/iree/hal/drivers/vulkan/descriptor_set_arena.cc @@ -85,22 +85,6 @@ static void PopulateDescriptorSetWriteInfos( *out_infos = write_infos.data(); } -static VkDescriptorSetAllocateInfo PopulateDescriptorSetsAllocateInfo( - const DescriptorPool& descriptor_pool, - iree_hal_descriptor_set_layout_t* set_layout) { - VkDescriptorSetAllocateInfo allocate_info; - allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; - allocate_info.pNext = nullptr; - allocate_info.descriptorPool = descriptor_pool.handle; - - VkDescriptorSetLayout set_layout_handle = - iree_hal_vulkan_native_descriptor_set_layout_handle(set_layout); - allocate_info.descriptorSetCount = 1; - allocate_info.pSetLayouts = &set_layout_handle; - - return allocate_info; -} - } // namespace DescriptorSetArena::DescriptorSetArena( diff --git a/runtime/src/iree/modules/hal/inline/module.c b/runtime/src/iree/modules/hal/inline/module.c index 6f9a21a72472..2284a5c2310f 100644 --- a/runtime/src/iree/modules/hal/inline/module.c +++ b/runtime/src/iree/modules/hal/inline/module.c @@ -203,13 +203,6 @@ static iree_status_t IREE_API_PTR iree_hal_inline_module_notify( // Utilities //===----------------------------------------------------------------------===// -// Casts a VM value to a C host size. -static iree_host_size_t iree_hal_cast_host_size(int64_t value) { - // TODO(benvanik): make this return status and check for overflow if host - // size is 32-bits. - return (iree_host_size_t)value; -} - // Casts a VM value to a HAL device size. static iree_device_size_t iree_hal_cast_device_size(int64_t value) { // TODO(benvanik): make this return status and check for overflow if device diff --git a/runtime/src/iree/modules/hal/loader/module.c b/runtime/src/iree/modules/hal/loader/module.c index c775fd886174..01264213ea32 100644 --- a/runtime/src/iree/modules/hal/loader/module.c +++ b/runtime/src/iree/modules/hal/loader/module.c @@ -93,13 +93,6 @@ static iree_host_size_t iree_hal_cast_host_size(int64_t value) { return (iree_host_size_t)value; } -// Casts a VM value to a HAL device size. -static iree_device_size_t iree_hal_cast_device_size(int64_t value) { - // TODO(benvanik): make this return status and check for overflow if device - // size is 32-bits. - return (iree_device_size_t)value; -} - //===----------------------------------------------------------------------===// // Shared argument shims //===----------------------------------------------------------------------===// diff --git a/runtime/src/iree/task/topology_cpuinfo.c b/runtime/src/iree/task/topology_cpuinfo.c index e0cec1224789..a0a42ab9f2c4 100644 --- a/runtime/src/iree/task/topology_cpuinfo.c +++ b/runtime/src/iree/task/topology_cpuinfo.c @@ -323,12 +323,6 @@ iree_status_t iree_task_topology_initialize_from_logical_cpu_set( typedef bool (*iree_task_topology_core_filter_t)( const struct cpuinfo_core* core, uintptr_t user_data); -// Matches all cores. -static bool iree_task_topology_core_filter_all(const struct cpuinfo_core* core, - uintptr_t user_data) { - return true; -} - // Matches all cores that have the provided cluster ID. static bool iree_task_topology_core_filter_by_cluster_id( const struct cpuinfo_core* core, uintptr_t user_data) { diff --git a/runtime/src/iree/tooling/numpy_io_test.cc b/runtime/src/iree/tooling/numpy_io_test.cc index b7f883779dab..554f870ee00c 100644 --- a/runtime/src/iree/tooling/numpy_io_test.cc +++ b/runtime/src/iree/tooling/numpy_io_test.cc @@ -19,11 +19,6 @@ using iree::testing::status::IsOk; using iree::testing::status::StatusIs; using ::testing::ElementsAreArray; -std::ostream& operator<<(std::ostream& os, const Status& x) { - os << x.ToString(); - return os; -} - class NumpyIOTest : public ::testing::Test { protected: virtual void SetUp() { diff --git a/runtime/src/iree/tooling/trace_replay.c b/runtime/src/iree/tooling/trace_replay.c index 6f2c8496bc8a..06ed094f1d63 100644 --- a/runtime/src/iree/tooling/trace_replay.c +++ b/runtime/src/iree/tooling/trace_replay.c @@ -370,25 +370,12 @@ static uint32_t iree_tree_replay_pseudorandom_uint32(uint32_t* state) { return *state; } -// Returns a random uint8_t in the range of [0, UCHAR_MAX]. -static uint8_t iree_trace_replay_pseudorandom_uint8(uint32_t* state) { - // return the second-least-signicant out of the 4 bytes of state. it avoids - // some mild issues with the least-significant and most-significant bytes. - return iree_tree_replay_pseudorandom_uint32(state) >> 8; -} - // Returns a random uint32_t in the range [0, range). static inline uint32_t iree_trace_replay_pseudorandom_range(uint32_t* state, uint32_t range) { return iree_tree_replay_pseudorandom_uint32(state) % range; } -// Returns a random double in the range of [0, 1.0). -static double iree_trace_replay_pseudorandom_double(uint32_t* state) { - const double inv_modulus = 1.0 / IREE_PRNG_MODULUS; - return iree_tree_replay_pseudorandom_uint32(state) * inv_modulus; -} - // Get minimum and maximum for integer-valued uniform distribution. static void iree_trace_replay_get_min_max_for_element_type( iree_hal_element_type_t element_type, int32_t* min, int32_t* max) { diff --git a/tools/iree-e2e-matmul-test.c b/tools/iree-e2e-matmul-test.c index 692615ebd131..503f4a36020e 100644 --- a/tools/iree-e2e-matmul-test.c +++ b/tools/iree-e2e-matmul-test.c @@ -112,26 +112,6 @@ static inline iree_e2e_test_value_t iree_e2e_test_value_make_i32( return result; } -// TODO(#5542): check the value type before accessing the union. -static inline int32_t iree_e2e_test_value_get_i32( - iree_e2e_test_value_t* value) { - return value->i32; -} - -static inline iree_e2e_test_value_t iree_e2e_test_value_make_i64( - int64_t value) { - iree_e2e_test_value_t result; - result.type = IREE_E2E_TEST_VALUE_TYPE_I64; - result.i64 = value; - return result; -} - -// TODO(#5542): check the value type before accessing the union. -static inline int64_t iree_e2e_test_value_get_i64( - iree_e2e_test_value_t* value) { - return value->i64; -} - static inline iree_e2e_test_value_t iree_e2e_test_value_make_f16( uint16_t value) { iree_e2e_test_value_t result; @@ -155,35 +135,6 @@ static inline iree_e2e_test_value_t iree_e2e_test_value_make_f32(float value) { return result; } -// TODO(#5542): check the value type before accessing the union. -static inline float iree_e2e_test_value_get_f32(iree_e2e_test_value_t* value) { - return value->f32; -} - -// TODO(#5542): check the value type before accessing the union. -static inline uint16_t iree_e2e_test_value_get_f16( - iree_e2e_test_value_t* value) { - return value->f16_u16; -} - -// TODO(#5542): check the value type before accessing the union. -static inline uint16_t iree_e2e_test_value_get_bf16( - iree_e2e_test_value_t* value) { - return value->bf16_u16; -} - -static inline iree_e2e_test_value_t iree_e2e_test_value_make_f64(double value) { - iree_e2e_test_value_t result; - result.type = IREE_E2E_TEST_VALUE_TYPE_F64; - result.f64 = value; - return result; -} - -// TODO(#5542): check the value type before accessing the union. -static inline double iree_e2e_test_value_get_f64(iree_e2e_test_value_t* value) { - return value->f64; -} - /***************************************************************************** * * Part 1: @@ -289,22 +240,6 @@ static iree_status_t copy_device_buffer_view_to_host( return status; } -// Performs a deep copy of host-local |src| into a device-local |dst|. -// Allocates |dst|. -static iree_status_t copy_host_buffer_view_to_device( - iree_hal_device_t* device, iree_hal_allocator_t* hal_allocator, - iree_hal_buffer_view_t* src, iree_hal_buffer_view_t** dst) { - iree_hal_buffer_mapping_t src_mapping; - IREE_RETURN_IF_ERROR(map_host_local_row_major_data( - src, IREE_HAL_MEMORY_ACCESS_READ, &src_mapping)); - iree_const_byte_span_t const_src_bytes = iree_make_const_byte_span( - src_mapping.contents.data, src_mapping.contents.data_length); - IREE_RETURN_IF_ERROR(allocate_device_buffer_view_like( - device, hal_allocator, src, const_src_bytes, dst)); - IREE_RETURN_IF_ERROR(iree_hal_buffer_unmap_range(&src_mapping)); - return iree_ok_status(); -} - // Performs a deep copy of device-local |src| into a device-local |dst|. // Allocates |dst|. static iree_status_t copy_device_buffer_view_to_device( @@ -349,32 +284,6 @@ static iree_status_t copy_device_buffer_views_to_host( return iree_ok_status(); } -// Helper to write an int value to a single buffer element. -static void write_int_element(iree_hal_element_type_t element_type, int value, - void* dst) { -#define WRITE_INT_ELEMENT_CASE(ETYPE, CTYPE) \ - case IREE_HAL_ELEMENT_TYPE_##ETYPE: \ - *(CTYPE*)dst = (CTYPE)value; \ - break; - - switch (element_type) { - WRITE_INT_ELEMENT_CASE(INT_8, int8_t) - WRITE_INT_ELEMENT_CASE(INT_32, int32_t) - WRITE_INT_ELEMENT_CASE(FLOAT_32, float) - case IREE_HAL_ELEMENT_TYPE_FLOAT_16: - *(uint16_t*)dst = iree_math_f32_to_f16((float)value); - break; - case IREE_HAL_ELEMENT_TYPE_BFLOAT_16: - *(uint16_t*)dst = iree_math_f32_to_bf16((float)value); - break; - default: - IREE_ASSERT(false, "unhandled element type"); - break; - } - -#undef WRITE_INT_ELEMENT_CASE -} - /***************************************************************************** * * Part 2: @@ -388,30 +297,6 @@ static void write_int_element(iree_hal_element_type_t element_type, int value, * particular test program is entrenched here. * *****************************************************************************/ -// Write an int32_t element to a mapped row-major matrix buffer. -static void write_int_to_matrix_element(int32_t value, iree_hal_dim_t m_size, - iree_hal_dim_t n_size, - iree_hal_element_type_t result_type, - void* data, iree_hal_dim_t m, - iree_hal_dim_t n) { - iree_host_size_t index = n + m * n_size; - (void)m_size; - if (iree_hal_element_type_is_integer(result_type, 32)) { - ((int32_t*)data)[index] = value; - return; - } else if (result_type == IREE_HAL_ELEMENT_TYPE_FLOAT_16) { - ((uint16_t*)data)[index] = iree_math_f32_to_f16((float)value); - return; - } else if (result_type == IREE_HAL_ELEMENT_TYPE_BFLOAT_16) { - ((uint16_t*)data)[index] = iree_math_f32_to_bf16((float)value); - return; - } else if (result_type == IREE_HAL_ELEMENT_TYPE_FLOAT_32) { - ((float*)data)[index] = value; - return; - } - IREE_CHECK_OK(iree_make_status(IREE_STATUS_INVALID_ARGUMENT, - "unhandled matmul result type")); -} // Reads an element from a mapped row-major matrix buffer. static iree_e2e_test_value_t read_matrix_element(