Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support private funcs in wrap-generic #1310

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/Transforms/Secretize/WrapGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ struct WrapWithGeneric : public OpRewritePattern<func::FuncOp> {

SmallVector<Type, 4> newInputs;
for (unsigned i = 0; i < op.getNumArguments(); i++) {
auto argTy = op.getArgument(i).getType();
auto argTy = op.getArgumentTypes()[i];
if (op.getArgAttr(i, secret::SecretDialect::kArgSecretAttrName) !=
nullptr) {
hasSecrets = true;
op.removeArgAttr(i, secret::SecretDialect::kArgSecretAttrName);

auto newTy = secret::SecretType::get(argTy);
op.getArgument(i).setType(newTy); // Updates the block argument type.
if (!op.isDeclaration())
op.getArgument(i).setType(newTy); // Updates the block argument type.
newInputs.push_back(newTy);
} else {
newInputs.push_back(argTy);
Expand All @@ -49,10 +50,14 @@ struct WrapWithGeneric : public OpRewritePattern<func::FuncOp> {
op.setFunctionType(
FunctionType::get(getContext(), {newInputs}, {newOutputs}));

// Externally defined functions have no body
if (op.isDeclaration()) {
return success();
}
// Create a new block where we will insert the new secret.generic and move
// the function ops into.
Block &opEntryBlock = op.getRegion().front();
auto newBlock = rewriter.createBlock(
auto *newBlock = rewriter.createBlock(
&opEntryBlock, opEntryBlock.getArgumentTypes(),
SmallVector<Location>(opEntryBlock.getNumArguments(), op.getLoc()));

Expand Down
18 changes: 18 additions & 0 deletions tests/Transforms/secretize/func_call.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: heir-opt -wrap-generic %s | FileCheck %s

module {
// CHECK: private @some_func(i1) -> i1
func.func private @some_func(i1) -> i1

// CHECK: private @some_func2(!secret.secret<i1>) -> !secret.secret<i1>
func.func private @some_func2(i1 {secret.secret}) -> i1
Comment on lines +7 to +8
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the purpose of this func for the testcase?


// CHECK: @main(%[[arg:.*]]: !secret.secret<i1>)
// CHECK-COUNT-1: secret.generic
// CHECK-NOT: secret.generic
// CHECK: return
func.func @main(%a: i1 {secret.secret}) -> i1 {
%0 = func.call @some_func(%a) : (i1) -> i1
return %0 : i1
}
}
Loading