Skip to content

Conversation

SahilPatidar
Copy link
Contributor

Reimplement value printing on top of ORC MemoryAccess. The previous
implementation only supported in-process evaluation; with this new
design it now works in both in-process and out-of-process modes.

The implementation introduces a ValueBuffer hierarchy (Builtin, Array,
Pointer) for capturing evaluated values, a ReaderDispatcher for reading
values from MemoryAccess, and a ValueToString printer for converting
buffers back to strings.

@SahilPatidar
Copy link
Contributor Author

@vgvassilev This is still a draft — some parts are not implemented yet (e.g. record and function types), but I shared it so you can see the idea and check if the approach looks feasible.

@SahilPatidar
Copy link
Contributor Author

And also I need a way to detect whether the interpreter is running in-process or out-of-process.

return Str;
case clang::BuiltinType::Short:
SS << V.getShort();
SS << B.as<short>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we have to cast the data when we know its type? If that's needed for out-of-process where the host and target architectures do not match, we should probably somehow do it in a separate facility because getX is much faster on matching architectures.

Copy link
Contributor Author

@SahilPatidar SahilPatidar Sep 6, 2025

Choose a reason for hiding this comment

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

Since I’m not using our existing Value, I introduced a universal buffer for built-in types (including strings).

class BuiltinValueBuffer : public ValueBuffer {
public:
  std::vector<uint8_t> raw;
 
  BuiltinValueBuffer(QualType _Ty) : ValueBuffer(K_Builtin) { Ty = _Ty; }
  
  template <typename T> T as() const {
    T v{};
    // assert(raw.size() >= sizeof(T) && "Buffer too small for type!");
    memcpy(&v, raw.data(), sizeof(T));
    return v;
  }
  static bool classof(const ValueBuffer *B) { return B->isBuiltin(); }
};

I use ValueBuffer to read memory directly into a buffer sized for the type, and at print time we cast the raw data back to the correct type.
If we use a Value-kind structure, we need to read memory, cast it, and set the value at read time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’m working on a new design inspired by clang::APValue, intended to replace Value so it can support both execution environments:https://gist.github.com/SahilPatidar/9ba885fb29aebc68b6cf788b8937a204

Copy link

github-actions bot commented Sep 8, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff origin/main HEAD --extensions cpp,h -- compiler-rt/lib/orc/send_value.cpp clang/include/clang/Interpreter/Interpreter.h clang/include/clang/Interpreter/Value.h clang/lib/Interpreter/Interpreter.cpp clang/lib/Interpreter/InterpreterValuePrinter.cpp clang/lib/Interpreter/Value.cpp

⚠️
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing origin/main to the base branch/commit you want to compare against.
⚠️

View the diff from clang-format here.
diff --git a/compiler-rt/lib/orc/send_value.cpp b/compiler-rt/lib/orc/send_value.cpp
index 31834439e..c106358a0 100644
--- a/compiler-rt/lib/orc/send_value.cpp
+++ b/compiler-rt/lib/orc/send_value.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "common.h"
+#include "debug.h"
 #include "jit_dispatch.h"
 #include "wrapper_function_utils.h"
-#include "debug.h"
 
 using namespace orc_rt;
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants