Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
12 changes: 7 additions & 5 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ IncludeCategories:
Priority: 0 # Needs to be set to 1 when we change priorities soon.
- Regex: '^("|<)llzk-c/.*("|>)$' # LLZK C API headers
Priority: 1 # Set to priority 1 and onwards in preparation for putting LLZK headers in priority 1
- Regex: '^<mlir/.*>$' # MLIR headers
- Regex: '^<pcl/.*>$' # PCL headers
Priority: 2
- Regex: '^<mlir-c/.*>$' # MLIR C API headers
- Regex: '^<mlir/.*>$' # MLIR headers
Priority: 3
- Regex: '^<llvm/.*>$' # LLVM headers
- Regex: '^<mlir-c/.*>$' # MLIR C API headers
Priority: 4
- Regex: '^<.*(\.h)?>$' # Standard library headers
- Regex: '^<llvm/.*>$' # LLVM headers
Priority: 5
- Regex: '^.*$' # Everything else
- Regex: '^<.*(\.h)?>$' # Standard library headers
Priority: 6
- Regex: '^.*$' # Everything else
Priority: 7
SortIncludes: true
InsertNewlineAtEOF: true
---
Expand Down
2 changes: 2 additions & 0 deletions changelogs/unreleased/shankara__llzk-to-pcl-pass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
added:
- Added a pass to convert llzk to pcl
6 changes: 6 additions & 0 deletions include/llzk/Transforms/LLZKTransformationPasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#pragma once

#include "llzk/Pass/PassBase.h"
#include "llzk/Transforms/Parsers.h"

#include <llvm/ADT/APInt.h>
#include <llvm/Support/CommandLine.h>

namespace llzk {

Expand All @@ -31,6 +35,8 @@ std::unique_ptr<mlir::Pass> createInlineStructsPass();

std::unique_ptr<mlir::Pass> createR1CSLoweringPass();

std::unique_ptr<mlir::Pass> createPCLLoweringPass();

void registerTransformationPassPipelines();

void registerInliningExtensions(mlir::DialectRegistry &registry);
Expand Down
13 changes: 13 additions & 0 deletions include/llzk/Transforms/LLZKTransformationPasses.td
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,17 @@ def R1CSLoweringPass : LLZKPass<"llzk-r1cs-lowering"> {
let constructor = "llzk::createR1CSLoweringPass()";
}

def PCLLoweringPass : LLZKPass<"llzk-to-pcl"> {
let summary = "Rewrites constraints to be compatible with PCL constraints "
"used by Picus";
let description = [{
Transforms LLZK constraints into an equivalent set of constraints expressed in the pcl-mlir dialect.
}];
let constructor = "llzk::createPCLLoweringPass()";
let options = [Option<"prime", "prime", "::llvm::APInt",
"llvm::APInt(31, 2130706433)", // KoalaBear in decimal
"Prime field that the constraints operate over. This "
"is required by PCL">];
}

#endif // LLZK_TRANSFORMATION_PASSES_TD
62 changes: 62 additions & 0 deletions include/llzk/Transforms/Parsers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//===-- Parsers.h -----------------------------------------------*- C++ -*-===//
//
// Command line parsers for LLZK transformation passes.
//
// Part of the LLZK Project, under the Apache License v2.0.
// See LICENSE.txt for license information.
// Copyright 2025 Veridise Inc.
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

#include <llvm/ADT/APInt.h>
#include <llvm/ADT/StringExtras.h>
#include <llvm/Support/CommandLine.h>

// Custom command line parsers
namespace llvm {
namespace cl {

// Parser for APInt
template <> class parser<APInt> : public basic_parser<APInt> {
public:
parser(Option &O) : basic_parser(O) {}

bool parse(Option &O, StringRef, StringRef Arg, APInt &Val) {
if (Arg.empty()) {
return O.error("empty integer literal");
}
// Decimal-only: allocate a safe width then shrink.
unsigned bits = std::max(1u, 4u * (unsigned)Arg.size());
APInt tmp(bits, Arg, 10);
unsigned active = tmp.getActiveBits();
if (active == 0) {
active = 1;
}
Val = tmp.zextOrTrunc(active);
return false;
}

// Prints how the passed option differs from the default one specified in the pass
// For example, if V = 17 and Default = 11 then it should print
// [OptionName] 17 (bits=5) (default: 11 (bits=4))
void printOptionDiff(
const Option &O, const APInt &V, OptionValue<APInt> Default, size_t GlobalWidth
) const {
std::string Cur = llvm::toString(V, 10, false);
Cur += " (bits=" + std::to_string(V.getBitWidth()) + ")";

std::string Def = "<unspecified>";
if (Default.hasValue()) {
const APInt &D = Default.getValue();
Def = llvm::toString(D, 10, false);
Def += " (bits=" + std::to_string(D.getBitWidth()) + ")";
}

printOptionName(O, GlobalWidth);
llvm::outs() << Cur << " (default: " << Def << ")\n";
}
};

} // namespace cl
} // namespace llvm
3 changes: 2 additions & 1 deletion lib/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ target_link_libraries(
LLVMHeaders MLIRHeaders
PRIVATE
LLZKDialect
R1CSDialect)
R1CSDialect
$<$<BOOL:${LLZK_WITH_PCL_BOOL}>:PCL::PCLDialect>)
add_dependencies(LLZKTransforms LLZKDialect LLZKDialectHeaders)
llzk_target_add_mlir_link_settings(LLZKTransforms)

Expand Down
Loading
Loading