-
Notifications
You must be signed in to change notification settings - Fork 15k
[clang-repl] Reimplement value printing using MemoryAccess to support in-process and out-of-process #156649
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
base: main
Are you sure you want to change the base?
Conversation
@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. |
And also I need a way to detect whether the interpreter is running in-process or out-of-process. |
… in-process and out-of-process
return Str; | ||
case clang::BuiltinType::Short: | ||
SS << V.getShort(); | ||
SS << B.as<short>(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
33a530c
to
a5d7d9e
Compare
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
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;
|
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.