@@ -52,7 +52,7 @@ struct LlvmFAddToNeuraFAdd : public OpRewritePattern<mlir::LLVM::FAddOp> {
5252 if (!mlir::isa<FloatType>(result_type))
5353 return failure ();
5454
55- // Optional predicate: default to 'none'
55+ // Sets optional predicate: default to 'none'.
5656 rewriter.replaceOpWithNewOp <neura::FAddOp>(op, result_type, lhs, rhs);
5757 return success ();
5858 }
@@ -72,7 +72,7 @@ struct LlvmFSubToNeuraFSub : public OpRewritePattern<mlir::LLVM::FSubOp> {
7272 return failure ();
7373 }
7474
75- // Optional predicate: default to 'none'.
75+ // Sets optional predicate: default to 'none'.
7676 rewriter.replaceOpWithNewOp <neura::FSubOp>(op, result_type, lhs, rhs,
7777 Value ());
7878 return success ();
@@ -291,13 +291,13 @@ struct LlvmConstantToNeuraConstant : public OpRewritePattern<LLVM::ConstantOp> {
291291 PatternRewriter &rewriter) const override {
292292 auto attr = op.getValue ();
293293
294- // Creates operation state manually
294+ // Creates operation state manually.
295295 OperationState state (op.getLoc (), neura::ConstantOp::getOperationName ());
296296 state.addAttribute (" value" , attr);
297297 state.addAttribute (" predicate" , rewriter.getBoolAttr (true ));
298298 state.addTypes (op.getType ());
299299
300- // Creates the operation and replace
300+ // Creates the operation and replaces.
301301 Operation *newOp = rewriter.create (state);
302302 rewriter.replaceOp (op, newOp->getResults ());
303303 return success ();
@@ -312,9 +312,9 @@ struct LlvmAllocaToNeuraAlloca : public OpRewritePattern<LLVM::AllocaOp> {
312312 Value size = op.getArraySize ();
313313 Type resultType = op.getType ();
314314
315- // Convert the size to neura.data<i32, i1> if it's not already
316- // For simplicity, we'll assume the size is already in the right format
317- // In practice, you might need to handle type conversion here
315+ // Converts the size to neura.data<i32, i1> if it's not already.
316+ // Assumes the size is already in the right format.
317+ // Handles type conversion here.
318318
319319 rewriter.replaceOpWithNewOp <neura::AllocaOp>(op, resultType, size);
320320 return success ();
@@ -373,20 +373,20 @@ struct LlvmFuncToNeuraFunc : public OpRewritePattern<LLVM::LLVMFuncOp> {
373373 return failure ();
374374 }
375375
376- // Convert LLVMFunctionType to FunctionType
376+ // Converts LLVMFunctionType to FunctionType.
377377 auto llvmFuncType = op.getFunctionType ();
378378 auto funcType = rewriter.getFunctionType (
379379 llvmFuncType.getParams (),
380380 llvmFuncType.getReturnType ()
381381 );
382382
383- // Create the new func.func operation using OperationState to have full control
383+ // Creates the new func.func operation using OperationState to have full control.
384384 OperationState state (op.getLoc (), func::FuncOp::getOperationName ());
385385 state.addAttribute (" sym_name" , rewriter.getStringAttr (op.getName ()));
386386 state.addAttribute (" function_type" , TypeAttr::get (funcType));
387387
388- // Copy ALL attributes from the original llvm.func exactly as they are
389- // Skip function type and name attributes as they are handled separately
388+ // Copies ALL attributes from the original llvm.func exactly as they are.
389+ // Skips function type and name attributes as they are handled separately.
390390 SmallVector<NamedAttribute> attrs;
391391 for (auto attr : op->getAttrs ()) {
392392 if (attr.getName () == " function_type" || attr.getName () == " sym_name" ) {
@@ -396,15 +396,15 @@ struct LlvmFuncToNeuraFunc : public OpRewritePattern<LLVM::LLVMFuncOp> {
396396 }
397397 state.addAttributes (attrs);
398398
399- // Add the function body region
399+ // Adds the function body region.
400400 state.addRegion ();
401401
402402 auto newFunc = cast<func::FuncOp>(rewriter.create (state));
403403
404- // Move the function body
404+ // Moves the function body.
405405 rewriter.inlineRegionBefore (op.getBody (), newFunc.getBody (), newFunc.getBody ().end ());
406406
407- // Replace the old function
407+ // Replaces the old function.
408408 rewriter.replaceOp (op, newFunc);
409409 return success ();
410410 }
@@ -415,7 +415,7 @@ struct LlvmCallToFuncCall : public OpRewritePattern<LLVM::CallOp> {
415415
416416 LogicalResult matchAndRewrite (LLVM::CallOp op,
417417 PatternRewriter &rewriter) const override {
418- // Get the callee name
418+ // Gets the callee name.
419419 auto callee = op.getCallee ();
420420 if (!callee) {
421421 return failure ();
@@ -427,22 +427,22 @@ struct LlvmCallToFuncCall : public OpRewritePattern<LLVM::CallOp> {
427427 return failure ();
428428 }
429429
430- // Look for a func.func with the same name
430+ // Looks for a func.func with the same name.
431431 func::FuncOp funcOp = module .lookupSymbol <func::FuncOp>(callee.value ());
432432 if (!funcOp) {
433433 return failure ();
434434 }
435435
436- // Get the result types from the function signature
436+ // Gets the result types from the function signature.
437437 auto resultTypes = funcOp.getFunctionType ().getResults ();
438438
439- // Convert the call to func.call
439+ // Converts the call to func.call.
440440 auto newCall = rewriter.create <func::CallOp>(
441441 op.getLoc (), resultTypes, callee.value (), op.getArgOperands ()
442442 );
443443
444- // Replace the old call with the new one
445- // Handle both cases: calls with results and calls without results
444+ // Replaces the old call with the new one.
445+ // Handles both cases: calls with results and calls without results.
446446 if (op.getNumResults () == 0 ) {
447447 rewriter.eraseOp (op);
448448 } else {
@@ -499,13 +499,13 @@ struct LowerLlvmToNeuraPass
499499
500500 ModuleOp module_op = getOperation ();
501501
502- // function-level conversions
502+ // Performs function-level conversions.
503503 if (failed (applyPatternsGreedily (module_op, frozen))) {
504504 signalPassFailure ();
505505 return ;
506506 }
507507
508- // operation-level conversions
508+ // Performs operation-level conversions.
509509 // Applies to every region inside the module (regardless of func type,
510510 // e.g., mlir func or llvm func).
511511 module_op.walk ([&](FunctionOpInterface func) {
0 commit comments