Commit 03aedad4 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #653 from tjhance/dont-guard-builtin

Don't guard types sometimes
parents fc8b1d26 ede5b9a9
...@@ -218,6 +218,8 @@ public: ...@@ -218,6 +218,8 @@ public:
template <typename Src, typename Dst> inline RewriterVar* getAttrCast(int offset, Location loc = Location::any()); template <typename Src, typename Dst> inline RewriterVar* getAttrCast(int offset, Location loc = Location::any());
bool isConstant() { return is_constant; }
private: private:
Rewriter* rewriter; Rewriter* rewriter;
......
...@@ -683,7 +683,7 @@ BoxedDict* Box::getDict() { ...@@ -683,7 +683,7 @@ BoxedDict* Box::getDict() {
static StatCounter box_getattr_slowpath("slowpath_box_getattr"); static StatCounter box_getattr_slowpath("slowpath_box_getattr");
Box* Box::getattr(llvm::StringRef attr, GetattrRewriteArgs* rewrite_args) { Box* Box::getattr(llvm::StringRef attr, GetattrRewriteArgs* rewrite_args) {
if (rewrite_args) if (rewrite_args && !rewrite_args->obj_cls_guarded)
rewrite_args->obj->addAttrGuard(offsetof(Box, cls), (intptr_t)cls); rewrite_args->obj->addAttrGuard(offsetof(Box, cls), (intptr_t)cls);
#if 0 #if 0
...@@ -733,7 +733,10 @@ Box* Box::getattr(llvm::StringRef attr, GetattrRewriteArgs* rewrite_args) { ...@@ -733,7 +733,10 @@ Box* Box::getattr(llvm::StringRef attr, GetattrRewriteArgs* rewrite_args) {
REWRITE_ABORTED(""); REWRITE_ABORTED("");
rewrite_args = NULL; rewrite_args = NULL;
} else { } else {
rewrite_args->obj->addAttrGuard(cls->attrs_offset + offsetof(HCAttrs, hcls), (intptr_t)hcls); if (!(rewrite_args->obj->isConstant() && cls == type_cls
&& static_cast<BoxedClass*>(this)->is_constant)) {
rewrite_args->obj->addAttrGuard(cls->attrs_offset + offsetof(HCAttrs, hcls), (intptr_t)hcls);
}
if (hcls->type == HiddenClass::SINGLETON) if (hcls->type == HiddenClass::SINGLETON)
hcls->addDependence(rewrite_args->rewriter); hcls->addDependence(rewrite_args->rewriter);
} }
...@@ -985,6 +988,9 @@ Box* typeLookup(BoxedClass* cls, llvm::StringRef attr, GetattrRewriteArgs* rewri ...@@ -985,6 +988,9 @@ Box* typeLookup(BoxedClass* cls, llvm::StringRef attr, GetattrRewriteArgs* rewri
assert(rewrite_args->obj == obj_saved); assert(rewrite_args->obj == obj_saved);
} else { } else {
rewrite_args->obj = rewrite_args->rewriter->loadConst((intptr_t)base, Location::any()); rewrite_args->obj = rewrite_args->rewriter->loadConst((intptr_t)base, Location::any());
if (static_cast<BoxedClass*>(base)->is_constant) {
rewrite_args->obj_cls_guarded = true;
}
} }
val = base->getattr(attr, rewrite_args); val = base->getattr(attr, rewrite_args);
assert(rewrite_args->out_success); assert(rewrite_args->out_success);
...@@ -5042,6 +5048,7 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) { ...@@ -5042,6 +5048,7 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) {
if (rewriter.get()) { if (rewriter.get()) {
RewriterVar* builtins = rewriter->loadConst((intptr_t)builtins_module, Location::any()); RewriterVar* builtins = rewriter->loadConst((intptr_t)builtins_module, Location::any());
GetattrRewriteArgs rewrite_args(rewriter.get(), builtins, rewriter->getReturnDestination()); GetattrRewriteArgs rewrite_args(rewriter.get(), builtins, rewriter->getReturnDestination());
rewrite_args.obj_cls_guarded = true; // always builtin module
rtn = builtins_module->getattr(name->s(), &rewrite_args); rtn = builtins_module->getattr(name->s(), &rewrite_args);
if (!rtn || !rewrite_args.out_success) { if (!rtn || !rewrite_args.out_success) {
......
...@@ -28,6 +28,7 @@ struct GetattrRewriteArgs { ...@@ -28,6 +28,7 @@ struct GetattrRewriteArgs {
RewriterVar* out_rtn; RewriterVar* out_rtn;
bool obj_hcls_guarded; bool obj_hcls_guarded;
bool obj_cls_guarded;
GetattrRewriteArgs(Rewriter* rewriter, RewriterVar* obj, Location destination) GetattrRewriteArgs(Rewriter* rewriter, RewriterVar* obj, Location destination)
: rewriter(rewriter), : rewriter(rewriter),
...@@ -35,7 +36,8 @@ struct GetattrRewriteArgs { ...@@ -35,7 +36,8 @@ struct GetattrRewriteArgs {
destination(destination), destination(destination),
out_success(false), out_success(false),
out_rtn(NULL), out_rtn(NULL),
obj_hcls_guarded(false) {} obj_hcls_guarded(false),
obj_cls_guarded(false) {}
}; };
struct SetattrRewriteArgs { struct SetattrRewriteArgs {
......
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