================
@@ -50,26 +51,97 @@ struct LibOptPass : public impl::LibOptBase<LibOptPass> {
// Raw libopt option string forwarded by the frontend. This will later
control
// which optimizations the pass enables.
std::string optimizationOptions;
-
- /// Tracks current module.
- ModuleOp theModule;
};
} // namespace
mlir::LogicalResult LibOptPass::initializeOptions(
llvm::StringRef options,
- llvm::function_ref<mlir::LogicalResult(const llvm::Twine &)> errorHandler)
{
- (void)errorHandler;
+ llvm::function_ref<mlir::LogicalResult(const llvm::Twine &)>) {
optimizationOptions = options.str();
// TODO(cir): Parse options to select the active transformations for the
// pass.
return mlir::success();
}
+static void rewriteStdFindToMemchr(StdFindOp findOp,
+ mlir::SymbolTableCollection &symbolTables) {
+ auto iterTy = mlir::dyn_cast<cir::PointerType>(findOp.getResult().getType());
+ if (!iterTy || iterTy.getAddrSpace())
+ return;
+ auto elemTy = mlir::dyn_cast<cir::IntType>(iterTy.getPointee());
+ if (!elemTy || elemTy.getWidth() != 8)
+ return;
+
+ auto patternPtrTy =
+ mlir::dyn_cast<cir::PointerType>(findOp.getPattern().getType());
+ if (!patternPtrTy || patternPtrTy.getPointee() != elemTy)
+ return;
+
+ // No builtin state rides on both the raised call and the enclosing function.
+ auto enclosing = findOp->getParentOfType<cir::FuncOp>();
+ if (isNoBuiltin(findOp, "memchr") ||
+ (enclosing && noBuiltinListDisables(enclosing, "memchr"))) {
+ return;
+ }
+
+ // An enum or atomic element also lowers to a byte wide integer.
+ auto callee = symbolTables.lookupNearestSymbolFrom<cir::FuncOp>(
+ findOp, findOp.getOriginalFnAttr());
+ auto funcIdentity = mlir::dyn_cast_if_present<cir::FuncIdentityAttr>(
+ callee ? callee.getFuncInfoAttr() : mlir::Attribute());
+ if (!funcIdentity || funcIdentity.getKind() != cir::KnownFuncKind::StdFind ||
+ !funcIdentity.getNarrowCharParams()) {
+ return;
+ }
+
+ // cir.libc.memchr fixes the value and length widths at 32 and 64 bits.
+ // TODO(cir): gate on the target size type and libcall availability.
+ auto moduleOp = findOp->getParentOfType<mlir::ModuleOp>();
+ auto tripleAttr = moduleOp ? moduleOp->getAttrOfType<mlir::StringAttr>(
+ cir::CIRDialect::getTripleAttrName())
+ : nullptr;
+ if (!tripleAttr)
+ return;
+ llvm::Triple triple(tripleAttr.getValue().str());
+
+ // size_t is not 64 bits on the 32 bit archs, the ILP32 on 64 ABIs, and
+ // the PS3, so the length argument would have the wrong width there.
+ bool sizeTypeMismatch = !triple.isArch64Bit() || triple.isX32() ||
----------------
SharmaRithik wrote:
I just updated the PR, and did it exactly this way and cir.size_type_width
records it now. For handling other sizes/widths need cir.libc.memchr changed
first. and its length operand is fixed to u64 (maybe I can look into this
deeper)
https://github.com/llvm/llvm-project/pull/212355
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits