Commit 2f60cce3 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #788 from undingen/bjit_opt2

Small bjit improvements + fixes the build
parents bdf0764f dd7aa0d5
......@@ -668,8 +668,13 @@ RewriterVar* JitFragmentWriter::emitPPCall(void* func_addr, llvm::ArrayRef<Rewri
RewriterVar* result = createNewVar();
addAction([=]() { this->_emitPPCall(result, func_addr, args_vec, num_slots, slot_size); }, args,
ActionType::NORMAL);
if (type_recorder)
return call(false, (void*)recordType, imm(type_recorder), result);
if (type_recorder) {
RewriterVar* type_recorder_var = imm(type_recorder);
RewriterVar* obj_cls_var = result->getAttr(offsetof(Box, cls));
addAction([=]() { _emitRecordType(type_recorder_var, obj_cls_var); }, { type_recorder_var, obj_cls_var },
ActionType::NORMAL);
return result;
}
return result;
#else
assert(args_vec.size() < 7);
......@@ -868,6 +873,26 @@ void JitFragmentWriter::_emitPPCall(RewriterVar* result, void* func_addr, const
result->releaseIfNoUses();
}
void JitFragmentWriter::_emitRecordType(RewriterVar* type_recorder_var, RewriterVar* obj_cls_var) {
// This directly emits the instructions of the recordType() function.
assembler::Register obj_cls_reg = obj_cls_var->getInReg();
assembler::Register type_recorder_reg = type_recorder_var->getInReg(Location::any(), true, obj_cls_reg);
assembler::Indirect last_seen_count = assembler::Indirect(type_recorder_reg, offsetof(TypeRecorder, last_count));
assembler::Indirect last_seen_indirect = assembler::Indirect(type_recorder_reg, offsetof(TypeRecorder, last_seen));
assembler->cmp(last_seen_indirect, obj_cls_reg);
{
assembler::ForwardJump je(*assembler, assembler::COND_EQUAL);
assembler->mov(obj_cls_reg, last_seen_indirect);
assembler->movq(assembler::Immediate(0ul), last_seen_count);
}
assembler->incl(last_seen_count);
type_recorder_var->bumpUse();
obj_cls_var->bumpUse();
}
void JitFragmentWriter::_emitReturn(RewriterVar* return_val) {
return_val->getInReg(assembler::RDX, true);
assembler->mov(assembler::Immediate(0ul), assembler::RAX); // TODO: use xor
......
......@@ -296,6 +296,7 @@ private:
void _emitOSRPoint(RewriterVar* result, RewriterVar* node_var);
void _emitPPCall(RewriterVar* result, void* func_addr, const RewriterVar::SmallVector& args, int num_slots,
int slot_size);
void _emitRecordType(RewriterVar* type_recorder_var, RewriterVar* obj_cls_var);
void _emitReturn(RewriterVar* v);
void _emitSideExit(RewriterVar* var, RewriterVar* val_constant, CFGBlock* next_block, RewriterVar* false_path);
};
......
......@@ -63,6 +63,7 @@ SourceInfo::SourceInfo(BoxedModule* m, ScopingAnalysis* scoping, FutureFlags fut
std::vector<AST_stmt*> body, std::string fn)
: parent_module(m),
scoping(scoping),
scope_info(NULL),
future_flags(future_flags),
ast(ast),
cfg(NULL),
......
......@@ -127,7 +127,9 @@ Box* SourceInfo::getDocString() {
}
ScopeInfo* SourceInfo::getScopeInfo() {
return scoping->getScopeInfoForNode(ast);
if (!scope_info)
scope_info = scoping->getScopeInfoForNode(ast);
return scope_info;
}
LivenessAnalysis* SourceInfo::getLiveness() {
......
......@@ -299,7 +299,7 @@ private:
}
void checkAndPropagateCapiException(const UnwindInfo& unw_info, llvm::Value* returned_val, llvm::Value* exc_val,
bool double_check) {
bool double_check) override {
assert(!double_check); // need to call PyErr_Occurred
llvm::BasicBlock* normal_dest
......
......@@ -30,6 +30,9 @@ TypeRecorder* getTypeRecorderForNode(AST* node) {
}
Box* recordType(TypeRecorder* self, Box* obj) {
// The baseline JIT directly generates machine code for this function inside JitFragmentWriter::_emitRecordType.
// When changing this function one has to also change the bjit code.
BoxedClass* cls = obj->cls;
if (cls != self->last_seen) {
self->last_seen = cls;
......
......@@ -33,11 +33,10 @@ class TypeRecorder;
// The return value of this function is 'obj' for ease of use.
extern "C" Box* recordType(TypeRecorder* recorder, Box* obj);
class TypeRecorder {
private:
public:
BoxedClass* last_seen;
int64_t last_count;
public:
constexpr TypeRecorder() : last_seen(nullptr), last_count(0) {}
BoxedClass* predict();
......
......@@ -1188,8 +1188,8 @@ std::string getCurrentPythonLine() {
if (frame_iter.get()) {
std::ostringstream stream;
auto* cf = frame_iter->getCF();
auto source = cf->clfunc->source.get();
auto* clfunc = frame_iter->getCL();
auto source = clfunc->source.get();
auto current_stmt = frame_iter->getCurrentStatement();
......
......@@ -328,6 +328,7 @@ class SourceInfo {
public:
BoxedModule* parent_module;
ScopingAnalysis* scoping;
ScopeInfo* scope_info;
FutureFlags future_flags;
AST* ast;
CFG* cfg;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment