augustoasilva commented on a change in pull request #11193:
URL: https://github.com/apache/arrow/pull/11193#discussion_r734101093



##########
File path: cpp/src/gandiva/gandiva_object_cache.h
##########
@@ -0,0 +1,84 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#if defined(_MSC_VER)
+#pragma warning(push)
+#pragma warning(disable : 4244)
+#pragma warning(disable : 4141)
+#pragma warning(disable : 4146)
+#pragma warning(disable : 4267)
+#pragma warning(disable : 4624)
+#endif
+
+#include <llvm/ExecutionEngine/ObjectCache.h>
+#include <llvm/Support/MemoryBuffer.h>
+
+#include <chrono>
+
+#include "expression_cache_key.h"
+#include "gandiva/cache.h"
+
+namespace gandiva {
+/// Class that enables the LLVM to use a custom rule to deal with the object 
code.
+class GandivaObjectCache : public llvm::ObjectCache {
+ public:
+  explicit GandivaObjectCache(
+      std::shared_ptr<Cache<ExpressionCacheKey, 
std::shared_ptr<llvm::MemoryBuffer>>>& cache,
+      ExpressionCacheKey key) : cache_key_(key) {
+    cache_ = cache;
+    // Start measuring code gen time
+    begin_time_ = std::chrono::high_resolution_clock::now();
+  }
+
+  ~GandivaObjectCache() {}
+
+  void notifyObjectCompiled(const llvm::Module* M, llvm::MemoryBufferRef Obj) {
+    // Stop measuring time and  calculate the elapsed time to compile the 
object code
+    auto end_time = std::chrono::high_resolution_clock::now();
+    auto elapsed_time =
+        std::chrono::duration_cast<std::chrono::milliseconds>(end_time - 
begin_time_)
+            .count();
+
+    std::unique_ptr<llvm::MemoryBuffer> obj_buffer =
+        llvm::MemoryBuffer::getMemBufferCopy(Obj.getBuffer(), 
Obj.getBufferIdentifier());
+    std::shared_ptr<llvm::MemoryBuffer> obj_code = std::move(obj_buffer);
+
+    ValueCacheObject<std::shared_ptr<llvm::MemoryBuffer>> value_cache(
+        obj_code, elapsed_time, obj_code->getBufferSize());
+
+    cache_->PutObjectCode(cache_key_, value_cache);
+  }
+
+  std::unique_ptr<llvm::MemoryBuffer> getObject(const llvm::Module* M) {
+    std::shared_ptr<llvm::MemoryBuffer> cached_obj =
+        cache_->GetObjectCode(cache_key_);

Review comment:
       Added the logs on the above scenarios that you asked.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to