Skip to content

Commit e14338c

Browse files
committed
callattr runtimeCall: don't generate arg guards if we know that the classes can't change
1 parent 189c7ac commit e14338c

File tree

8 files changed

+36
-20
lines changed

8 files changed

+36
-20
lines changed

src/asm_writing/icinfo.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ ICInfo::ICInfo(void* start_addr, void* slowpath_rtn_addr, void* continue_addr, S
236236
retry_in(0),
237237
retry_backoff(1),
238238
times_rewritten(0),
239+
has_const_arg_classes(false),
239240
start_addr(start_addr),
240241
slowpath_rtn_addr(slowpath_rtn_addr),
241242
continue_addr(continue_addr) {

src/asm_writing/icinfo.h

+4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class ICInfo {
122122
TypeRecorder* const type_recorder;
123123
int retry_in, retry_backoff;
124124
int times_rewritten;
125+
bool has_const_arg_classes;
125126

126127
// for ICSlotRewrite:
127128
ICSlotInfo* pickEntryForRewrite(const char* debug_name);
@@ -149,6 +150,9 @@ class ICInfo {
149150
int percentBackedoff() const { return retry_backoff; }
150151
int timesRewritten() const { return times_rewritten; }
151152

153+
void setHasConstArgClasses(bool b = true) { has_const_arg_classes = b; }
154+
bool hasConstArgClasses() const { return has_const_arg_classes; }
155+
152156
friend class ICSlotRewrite;
153157
static void visitGCReferences(gc::GCVisitor* visitor);
154158

src/asm_writing/rewriter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1986,9 +1986,9 @@ Rewriter* Rewriter::createRewriter(void* rtn_addr, int num_args, const char* deb
19861986
// Horrible non-robust optimization: addresses below this address are probably in the binary (ex the interpreter),
19871987
// so don't do the more-expensive hash table lookup to find it.
19881988
if (rtn_addr > (void*)0x1000000) {
1989-
ic = getICInfo(rtn_addr);
1989+
ic = pyston::getICInfo(rtn_addr);
19901990
} else {
1991-
ASSERT(!getICInfo(rtn_addr), "%p", rtn_addr);
1991+
ASSERT(!pyston::getICInfo(rtn_addr), "%p", rtn_addr);
19921992
}
19931993

19941994
log_ic_attempts(debug_name);

src/asm_writing/rewriter.h

+2
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,8 @@ class Rewriter : public ICSlotRewrite::CommitHook, public gc::GCVisitable {
555555

556556
TypeRecorder* getTypeRecorder();
557557

558+
const ICInfo* getICInfo() { return rewrite->getICInfo(); }
559+
558560
const char* debugName() { return rewrite->debugName(); }
559561

560562
// Register that this rewrite will embed a reference to a particular gc object.

src/codegen/compvars.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,16 @@ static ConcreteCompilerVariable* _call(IREmitter& emitter, const OpInfo& info, l
584584
bool pass_keyword_names = (keyword_names != nullptr);
585585
assert(pass_keyword_names == (argspec.num_keywords > 0));
586586

587+
bool has_const_arg_classes = true;
587588
std::vector<BoxedClass*> guaranteed_classes;
588589
std::vector<ConcreteCompilerVariable*> converted_args;
589590
for (int i = 0; i < args.size(); i++) {
590591
assert(args[i]);
591592
converted_args.push_back(args[i]->makeConverted(emitter, args[i]->getBoxType()));
592-
guaranteed_classes.push_back(converted_args.back()->guaranteedClass());
593+
BoxedClass* guaranteed_class = converted_args.back()->guaranteedClass();
594+
guaranteed_classes.push_back(guaranteed_class);
595+
if (guaranteed_class == NULL)
596+
has_const_arg_classes = false;
593597
}
594598

595599
std::vector<llvm::Value*> llvm_args;
@@ -654,7 +658,8 @@ static ConcreteCompilerVariable* _call(IREmitter& emitter, const OpInfo& info, l
654658
if (do_patchpoint) {
655659
assert(func_addr);
656660

657-
ICSetupInfo* pp = createCallsiteIC(info.getTypeRecorder(), args.size(), info.getBJitICInfo());
661+
ICSetupInfo* pp
662+
= createCallsiteIC(info.getTypeRecorder(), args.size(), info.getBJitICInfo(), has_const_arg_classes);
658663

659664
llvm::Value* uncasted = emitter.createIC(pp, func_addr, llvm_args, info.unw_info, target_exception_style);
660665

src/codegen/patchpoints.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ int ICSetupInfo::totalSize() const {
4848
static std::vector<std::pair<PatchpointInfo*, void* /* addr of func to call */>> new_patchpoints;
4949

5050
ICSetupInfo* ICSetupInfo::initialize(bool has_return_value, int num_slots, int slot_size, ICType type,
51-
TypeRecorder* type_recorder) {
52-
ICSetupInfo* rtn = new ICSetupInfo(type, num_slots, slot_size, has_return_value, type_recorder);
51+
TypeRecorder* type_recorder, bool has_const_arg_classes) {
52+
ICSetupInfo* rtn
53+
= new ICSetupInfo(type, num_slots, slot_size, has_return_value, type_recorder, has_const_arg_classes);
5354

5455
// We use size == CALL_ONLY_SIZE to imply that the call isn't patchable
5556
assert(rtn->totalSize() > CALL_ONLY_SIZE);
@@ -258,6 +259,7 @@ void processStackmap(CompiledFunction* cf, StackMap* stackmap) {
258259
start_addr, initialization_info.slowpath_start, initialization_info.continue_addr,
259260
initialization_info.slowpath_rtn_addr, ic, StackInfo(scratch_size, scratch_rsp_offset),
260261
std::move(initialization_info.live_outs));
262+
icinfo->setHasConstArgClasses(ic->has_const_arg_classes);
261263

262264
assert(cf);
263265
// TODO: unsafe. hard to use a unique_ptr here though.
@@ -333,9 +335,9 @@ ICSetupInfo* createDelattrIC(TypeRecorder* type_recorder) {
333335
return ICSetupInfo::initialize(false, 1, 144, ICSetupInfo::Delattr, type_recorder);
334336
}
335337

336-
ICSetupInfo* createCallsiteIC(TypeRecorder* type_recorder, int num_args, ICInfo* bjit_ic_info) {
337-
return ICSetupInfo::initialize(true, numSlots(bjit_ic_info, 4), 640 + 48 * num_args, ICSetupInfo::Callsite,
338-
type_recorder);
338+
ICSetupInfo* createCallsiteIC(TypeRecorder* type_recorder, int num_args, ICInfo* bjit_ic_info, bool const_arg_classes) {
339+
return ICSetupInfo::initialize(true, const_arg_classes ? 1 : numSlots(bjit_ic_info, 4), 640 + 48 * num_args,
340+
ICSetupInfo::Callsite, type_recorder, const_arg_classes);
339341
}
340342

341343
ICSetupInfo* createGetGlobalIC(TypeRecorder* type_recorder) {

src/codegen/patchpoints.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,21 @@ class ICSetupInfo {
5959
};
6060

6161
private:
62-
ICSetupInfo(ICType type, int num_slots, int slot_size, bool has_return_value, TypeRecorder* type_recorder)
62+
ICSetupInfo(ICType type, int num_slots, int slot_size, bool has_return_value, TypeRecorder* type_recorder,
63+
bool has_const_arg_classes)
6364
: type(type),
6465
num_slots(num_slots),
6566
slot_size(slot_size),
6667
has_return_value(has_return_value),
68+
has_const_arg_classes(has_const_arg_classes),
6769
type_recorder(type_recorder) {}
6870

6971
public:
7072
const ICType type;
7173

7274
const int num_slots, slot_size;
7375
const bool has_return_value;
76+
const bool has_const_arg_classes;
7477
TypeRecorder* const type_recorder;
7578

7679
int totalSize() const;
@@ -91,7 +94,7 @@ class ICSetupInfo {
9194
}
9295

9396
static ICSetupInfo* initialize(bool has_return_value, int num_slots, int slot_size, ICType type,
94-
TypeRecorder* type_recorder);
97+
TypeRecorder* type_recorder, bool has_const_arg_classes = false);
9598
};
9699

97100
struct PatchpointInfo {
@@ -163,7 +166,8 @@ struct PatchpointInfo {
163166

164167
class ICInfo;
165168
ICSetupInfo* createGenericIC(TypeRecorder* type_recorder, bool has_return_value, int size);
166-
ICSetupInfo* createCallsiteIC(TypeRecorder* type_recorder, int num_args, ICInfo* bjit_ic_info);
169+
ICSetupInfo* createCallsiteIC(TypeRecorder* type_recorder, int num_args, ICInfo* bjit_ic_info,
170+
bool has_const_arg_classes);
167171
ICSetupInfo* createGetGlobalIC(TypeRecorder* type_recorder);
168172
ICSetupInfo* createGetattrIC(TypeRecorder* type_recorder, ICInfo* bjit_ic_info);
169173
ICSetupInfo* createSetattrIC(TypeRecorder* type_recorder, ICInfo* bjit_ic_info);

src/runtime/objmodel.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -3132,11 +3132,10 @@ Box* _callattrEntry(Box* obj, BoxedString* attr, CallattrFlags flags, Box* arg1,
31323132
}
31333133

31343134
if (rewriter.get()) {
3135-
// TODO feel weird about doing this; it either isn't necessary
3136-
// or this kind of thing is necessary in a lot more places
3137-
// rewriter->getArg(3).addGuard(npassed_args);
3138-
31393135
CallattrRewriteArgs rewrite_args(rewriter.get(), rewriter->getArg(0), rewriter->getReturnDestination());
3136+
if (rewriter->getICInfo()->hasConstArgClasses())
3137+
rewrite_args.args_guarded = true;
3138+
31403139
if (npassed_args >= 1)
31413140
rewrite_args.arg1 = rewriter->getArg(3);
31423141
if (npassed_args >= 2)
@@ -4427,11 +4426,10 @@ static Box* runtimeCallEntry(Box* obj, ArgPassSpec argspec, Box* arg1, Box* arg2
44274426
#endif
44284427

44294428
if (rewriter.get()) {
4430-
// TODO feel weird about doing this; it either isn't necessary
4431-
// or this kind of thing is necessary in a lot more places
4432-
// rewriter->getArg(1).addGuard(npassed_args);
4433-
44344429
CallRewriteArgs rewrite_args(rewriter.get(), rewriter->getArg(0), rewriter->getReturnDestination());
4430+
if (rewriter->getICInfo()->hasConstArgClasses())
4431+
rewrite_args.args_guarded = true;
4432+
44354433
if (npassed_args >= 1)
44364434
rewrite_args.arg1 = rewriter->getArg(2);
44374435
if (npassed_args >= 2)

0 commit comments

Comments
 (0)