Commit c129d64d authored by Kevin Modzelewski's avatar Kevin Modzelewski

Cache the number of vregs in the frame info

since we need to look at this at every deinitFrame.  calculateNumUserVisibleVRegs()
was showing up in the profile.

This might be less important under pgo (which is currently broken), but seems
like a good thing to try anyway.
parent 332880da
......@@ -165,19 +165,24 @@ template <typename Builder> static llvm::Value* getVRegsGep(Builder& builder, ll
return builder.CreateConstInBoundsGEP2_32(v, 0, 4);
}
template <typename Builder> static llvm::Value* getStmtGep(Builder& builder, llvm::Value* v) {
static_assert(offsetof(FrameInfo, stmt) == 56, "");
template <typename Builder> static llvm::Value* getNumVRegsGep(Builder& builder, llvm::Value* v) {
static_assert(offsetof(FrameInfo, num_vregs) == 56, "");
return builder.CreateConstInBoundsGEP2_32(v, 0, 5);
}
template <typename Builder> static llvm::Value* getGlobalsGep(Builder& builder, llvm::Value* v) {
static_assert(offsetof(FrameInfo, globals) == 64, "");
template <typename Builder> static llvm::Value* getStmtGep(Builder& builder, llvm::Value* v) {
static_assert(offsetof(FrameInfo, stmt) == 64, "");
return builder.CreateConstInBoundsGEP2_32(v, 0, 6);
}
template <typename Builder> static llvm::Value* getGlobalsGep(Builder& builder, llvm::Value* v) {
static_assert(offsetof(FrameInfo, globals) == 72, "");
return builder.CreateConstInBoundsGEP2_32(v, 0, 7);
}
template <typename Builder> static llvm::Value* getMDGep(Builder& builder, llvm::Value* v) {
static_assert(offsetof(FrameInfo, md) == 64 + 16, "");
return builder.CreateConstInBoundsGEP2_32(v, 0, 8);
static_assert(offsetof(FrameInfo, md) == 72 + 16, "");
return builder.CreateConstInBoundsGEP2_32(v, 0, 9);
}
void IRGenState::setupFrameInfoVar(llvm::Value* passed_closure, llvm::Value* passed_globals,
......@@ -283,6 +288,7 @@ void IRGenState::setupFrameInfoVar(llvm::Value* passed_closure, llvm::Value* pas
builder.CreateStore(passed_globals, getGlobalsGep(builder, al));
// set frame_info.vregs
builder.CreateStore(vregs, getVRegsGep(builder, al));
builder.CreateStore(getConstantInt(num_user_visible_vregs, g.i32), getNumVRegsGep(builder, al));
builder.CreateStore(embedRelocatablePtr(getMD(), g.llvm_functionmetadata_type_ptr), getMDGep(builder, al));
this->frame_info = al;
......
......@@ -962,6 +962,8 @@ struct FrameInfo {
// uninitialized. When one wants to access any of the values, you need to check if exc.type
// is NULL, and if so crawl up the stack looking for the first frame with a non-null exc.type
// and copy that.
//
// Note: Adding / moving any fields here requires updating the "getXxxGEP()" functions in irgenerator.cpp
ExcInfo exc;
// This field is always initialized:
......@@ -971,6 +973,8 @@ struct FrameInfo {
BORROWED(BoxedClosure*) passed_closure;
Box** vregs;
int num_vregs;
AST_stmt* stmt; // current statement
// This is either a module or a dict
BORROWED(Box*) globals;
......@@ -980,7 +984,17 @@ struct FrameInfo {
Box* updateBoxedLocals();
FrameInfo(ExcInfo exc) : exc(exc), boxedLocals(NULL), frame_obj(0), passed_closure(0), vregs(0), stmt(0), globals(0), back(0), md(0) {}
FrameInfo(ExcInfo exc)
: exc(exc),
boxedLocals(NULL),
frame_obj(0),
passed_closure(0),
vregs(0),
num_vregs(INT_MAX),
stmt(0),
globals(0),
back(0),
md(0) {}
};
// callattr() takes a number of flags and arguments, and for performance we pack them into a single register:
......
......@@ -230,7 +230,7 @@ extern "C" void deinitFrame(FrameInfo* frame_info) {
Py_CLEAR(frame_info->frame_obj);
}
if (frame_info->vregs) {
int num_user_visible_vregs = frame_info->md->calculateNumUserVisibleVRegs();
int num_user_visible_vregs = frame_info->num_vregs;
for (int i = 0; i < num_user_visible_vregs; i++) {
Py_XDECREF(frame_info->vregs[i]);
}
......@@ -248,7 +248,7 @@ int frameinfo_traverse(FrameInfo* frame_info, visitproc visit, void* arg) noexce
Py_VISIT(frame_info->frame_obj);
if (frame_info->vregs) {
int num_user_visible_vregs = frame_info->md->calculateNumUserVisibleVRegs();
int num_user_visible_vregs = frame_info->num_vregs;
for (int i = 0; i < num_user_visible_vregs; i++) {
Py_VISIT(frame_info->vregs[i]);
}
......
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