================
@@ -50,26 +51,133 @@ 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;
+
+  // LibOpt runs before LoweringPrepare, so a global initializer is still a
+  // cir.global here. Anything else is not a shape CIRGen produces.
+  auto enclosing = findOp->getParentOfType<cir::FuncOp>();
+  auto enclosingGlobal = findOp->getParentOfType<cir::GlobalOp>();
+  if (!enclosing && !enclosingGlobal)
+    return;
+
+  // No builtin state rides on the raised call and on the enclosing function.
+  // A global initializer has no function to carry the list.
+  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()) {
----------------
SharmaRithik wrote:

Ah! That is a good catch. I reproduced both examples and confirmed that char8_t 
is excluded while unsigned char is rewritten. I also verified that both 
searches return the same position for every 8 bit char8_t value. I will include 
char8_t in the call site check and add a positive test.

https://github.com/llvm/llvm-project/pull/212355
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to