From bd4df643ba56621fad1662112e07dba19548b74b Mon Sep 17 00:00:00 2001 From: Mikhail Aksenov Date: Thu, 13 Jul 2023 09:01:55 +0000 Subject: [PATCH 1/5] Change bug report URL --- llvm/CMakeLists.txt | 2 +- llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 4534e655f47c..e1e01a023f92 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -326,7 +326,7 @@ option(LLVM_TOOL_LLVM_DRIVER_BUILD "Enables building the llvm multicall tool" OF set(PACKAGE_NAME LLVM) set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") -set(PACKAGE_BUGREPORT "https://github.com/llvm/llvm-project/issues/") +set(PACKAGE_BUGREPORT "https://github.com/NilFoundation/zkllvm-circifier/issues/") set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING "Default URL where bug reports are to be submitted.") diff --git a/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn b/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn index 393744f2d6c5..dd8746253db7 100644 --- a/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn @@ -123,7 +123,7 @@ write_cmake_config("config") { "LLVM_TARGET_TRIPLE_ENV=", "LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO=1", "LLVM_WINDOWS_PREFER_FORWARD_SLASH=", - "PACKAGE_BUGREPORT=https://github.com/llvm/llvm-project/issues/", + "PACKAGE_BUGREPORT=https://github.com/NilFoundation/zkllvm-circifier/issues/", "PACKAGE_NAME=LLVM", "PACKAGE_STRING=LLVM ${llvm_version}git", "PACKAGE_VERSION=${llvm_version}git", From 3f8f30724f94651e1cd1602a8547d03d0d6c762b Mon Sep 17 00:00:00 2001 From: Mikhail Aksenov Date: Thu, 13 Jul 2023 09:02:39 +0000 Subject: [PATCH 2/5] Support constant vectors of field elements --- clang/lib/CodeGen/CGExprConstant.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index afc06bc72c0c..a46b49a609ac 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -2129,7 +2129,11 @@ llvm::Constant *ConstantEmitter::tryEmitPrivate(const APValue &Value, Inits[I] = llvm::ConstantInt::get(CGM.getLLVMContext(), Elt.getInt()); else if (Elt.isFloat()) Inits[I] = llvm::ConstantFP::get(CGM.getLLVMContext(), Elt.getFloat()); - else + else if (Elt.isField()) { + const llvm::FieldElem &Field = Elt.getField(); + auto FieldType = llvm::GaloisFieldType::get(CGM.getLLVMContext(), Field.getKind()); + Inits[I] = llvm::ConstantField::get(FieldType, Field); + } else llvm_unreachable("unsupported vector element type"); } return llvm::ConstantVector::get(Inits); From f52648497591f6b786cffa4e49b4e319288acfa5 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 14 Jul 2023 12:21:07 +0000 Subject: [PATCH 3/5] Bit composition builtins added. #61 --- clang/include/clang/Basic/BuiltinsAssigner.def | 3 +++ clang/lib/CodeGen/CGBuiltin.cpp | 15 +++++++++++++++ llvm/include/llvm/IR/IntrinsicsAssigner.td | 3 +++ 3 files changed, 21 insertions(+) diff --git a/clang/include/clang/Basic/BuiltinsAssigner.def b/clang/include/clang/Basic/BuiltinsAssigner.def index 480f937a751b..88be6d1b988d 100644 --- a/clang/include/clang/Basic/BuiltinsAssigner.def +++ b/clang/include/clang/Basic/BuiltinsAssigner.def @@ -50,5 +50,8 @@ BUILTIN(__builtin_assigner_vesta_curve_init, "e2g7g7", "n") BUILTIN(__builtin_assigner_bls12381_curve_init, "e3g3g3", "n") BUILTIN(__builtin_assigner_curve25519_curve_init, "e4g5g5", "n") +BUILTIN(__builtin_assigner_bit_decomposition64, "E64g1g1", "n") +BUILTIN(__builtin_assigner_bit_composition128, "g1E64g1E64g1", "n") + #undef BUILTIN #undef TARGET_BUILTIN diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 1c3b3fe3a782..5de8c3ddb042 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -19908,6 +19908,21 @@ Value *CodeGenFunction::EmitAssignerBuiltinExpr(unsigned int BuiltinID, OverloadTypes = {Curve, BaseField}; break; } + case assigner::BI__builtin_assigner_bit_composition128: { + ID = Intrinsic::assigner_bit_composition128; + auto ElemTy = llvm::GaloisFieldType::get(context, + llvm::GALOIS_FIELD_PALLAS_BASE); + + OverloadTypes = {ElemTy, llvm::FixedVectorType::get(ElemTy, 64)}; + break; + } + case assigner::BI__builtin_assigner_bit_decomposition64: { + ID = Intrinsic::assigner_bit_decomposition64; + auto ElemTy = llvm::GaloisFieldType::get(context, + llvm::GALOIS_FIELD_PALLAS_BASE); + OverloadTypes = {llvm::FixedVectorType::get(ElemTy, 64), ElemTy}; + break; + } } assert(ID != Intrinsic::not_intrinsic); diff --git a/llvm/include/llvm/IR/IntrinsicsAssigner.td b/llvm/include/llvm/IR/IntrinsicsAssigner.td index cc6a7943b5fd..cbaf40f4ff88 100644 --- a/llvm/include/llvm/IR/IntrinsicsAssigner.td +++ b/llvm/include/llvm/IR/IntrinsicsAssigner.td @@ -21,3 +21,6 @@ def int_assigner_zkml_pooling: Intrinsic<[llvm_ptrptr_ty], [llvm_ptrptr_t def int_assigner_zkml_ReLU: Intrinsic<[llvm_float_ty], [llvm_float_ty]>; def int_assigner_zkml_batch_norm: Intrinsic<[llvm_ptrptr_ty], [llvm_ptrptr_ty]>; def int_assigner_curve_init: Intrinsic<[llvm_any_ty], [llvm_any_ty, LLVMMatchType<1>]>; + +def int_assigner_bit_decomposition64: Intrinsic<[llvm_anyvector_ty], [llvm_any_ty]>; +def int_assigner_bit_composition128: Intrinsic<[llvm_any_ty], [llvm_anyvector_ty, LLVMMatchType<1>]>; From c67458ea4d9f80a9bf61a37ccbef9b60ed11575a Mon Sep 17 00:00:00 2001 From: root Date: Sun, 16 Jul 2023 16:56:16 +0000 Subject: [PATCH 4/5] Bit decomposition builtin updated. Input parameter changed from field element to std::uint64_t.#61 --- clang/include/clang/Basic/BuiltinsAssigner.def | 2 +- clang/lib/CodeGen/CGBuiltin.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsAssigner.def b/clang/include/clang/Basic/BuiltinsAssigner.def index 88be6d1b988d..1d8d2f29f538 100644 --- a/clang/include/clang/Basic/BuiltinsAssigner.def +++ b/clang/include/clang/Basic/BuiltinsAssigner.def @@ -50,7 +50,7 @@ BUILTIN(__builtin_assigner_vesta_curve_init, "e2g7g7", "n") BUILTIN(__builtin_assigner_bls12381_curve_init, "e3g3g3", "n") BUILTIN(__builtin_assigner_curve25519_curve_init, "e4g5g5", "n") -BUILTIN(__builtin_assigner_bit_decomposition64, "E64g1g1", "n") +BUILTIN(__builtin_assigner_bit_decomposition64, "E64g1ULLi", "n") BUILTIN(__builtin_assigner_bit_composition128, "g1E64g1E64g1", "n") #undef BUILTIN diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 5de8c3ddb042..2a0dc181e6d8 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -19920,7 +19920,8 @@ Value *CodeGenFunction::EmitAssignerBuiltinExpr(unsigned int BuiltinID, ID = Intrinsic::assigner_bit_decomposition64; auto ElemTy = llvm::GaloisFieldType::get(context, llvm::GALOIS_FIELD_PALLAS_BASE); - OverloadTypes = {llvm::FixedVectorType::get(ElemTy, 64), ElemTy}; + auto IntType = llvm::IntegerType::get(context, 64); + OverloadTypes = {llvm::FixedVectorType::get(ElemTy, 64), IntType}; break; } } From 27b2740c7b463ccc295c37fa83910ac675feae03 Mon Sep 17 00:00:00 2001 From: Mikhail Aksenov Date: Thu, 20 Jul 2023 14:18:43 +0000 Subject: [PATCH 5/5] Enable instruction printing in release mode --- llvm/include/llvm/IR/Value.h | 2 -- llvm/lib/IR/Value.cpp | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/llvm/include/llvm/IR/Value.h b/llvm/include/llvm/IR/Value.h index d0cd83bec89d..cabcae877c66 100644 --- a/llvm/include/llvm/IR/Value.h +++ b/llvm/include/llvm/IR/Value.h @@ -290,9 +290,7 @@ class Value { /// \note It is an error to call V->takeName(V). void takeName(Value *V); -#ifndef NDEBUG std::string getNameOrAsOperand() const; -#endif /// Change all uses of this to point to a new Value. /// diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index fa22065dcf36..9bf9ae5b3a6d 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -439,7 +439,6 @@ void Value::takeName(Value *V) { ST->reinsertValue(this); } -#ifndef NDEBUG std::string Value::getNameOrAsOperand() const { if (!getName().empty()) return std::string(getName()); @@ -449,7 +448,6 @@ std::string Value::getNameOrAsOperand() const { printAsOperand(OS, false); return OS.str(); } -#endif void Value::assertModuleIsMaterializedImpl() const { #ifndef NDEBUG @@ -818,7 +816,7 @@ bool Value::canBeFreed() const { // which is why we need the explicit opt in on a per collector basis. if (!F->hasGC()) return true; - + const auto &GCName = F->getGC(); if (GCName == "statepoint-example") { auto *PT = cast(this->getType());