Commit 3ab1408c authored by Marius Wachtler's avatar Marius Wachtler

Rewrite unaryops

parent 38e94b5f
......@@ -1373,8 +1373,22 @@ private:
ConcreteCompilerVariable* converted = operand->makeConverted(emitter, operand->getBoxType());
operand->decvref(emitter);
llvm::Value* rtn = emitter.createCall2(unw_info, g.funcs.unaryop, converted->getValue(),
getConstantInt(node->op_type, g.i32));
llvm::Value* rtn = NULL;
bool do_patchpoint = ENABLE_ICGENERICS;
if (do_patchpoint) {
ICSetupInfo* pp = createGenericIC(getEmptyOpInfo(unw_info).getTypeRecorder(), true, 256);
std::vector<llvm::Value*> llvm_args;
llvm_args.push_back(converted->getValue());
llvm_args.push_back(getConstantInt(node->op_type, g.i32));
llvm::Value* uncasted = emitter.createIC(pp, (void*)pyston::unaryop, llvm_args, unw_info);
rtn = emitter.getBuilder()->CreateIntToPtr(uncasted, g.llvm_value_type_ptr);
} else {
rtn = emitter.createCall2(unw_info, g.funcs.unaryop, converted->getValue(),
getConstantInt(node->op_type, g.i32));
}
converted->decvref(emitter);
return new ConcreteCompilerVariable(UNKNOWN, rtn, true);
......
......@@ -4378,12 +4378,23 @@ extern "C" Box* unaryop(Box* operand, int op_type) {
BoxedString* op_name = getOpName(op_type);
CallattrFlags callattr_flags{.cls_only = true, .null_on_nonexistent = true, .argspec = ArgPassSpec(0) };
Box* rtn = callattr(operand, op_name, callattr_flags, NULL, NULL, NULL, NULL, NULL);
std::unique_ptr<Rewriter> rewriter(
Rewriter::createRewriter(__builtin_extract_return_addr(__builtin_return_address(0)), 1, "unaryop"));
Box* rtn = NULL;
if (rewriter) {
CallRewriteArgs srewrite_args(rewriter.get(), rewriter->getArg(0), rewriter->getReturnDestination());
rtn = callattrInternal0(operand, op_name, CLASS_ONLY, &srewrite_args, ArgPassSpec(0));
if (srewrite_args.out_success && rtn)
rewriter->commitReturning(srewrite_args.out_rtn);
else
rewriter.reset();
} else
rtn = callattrInternal0(operand, op_name, CLASS_ONLY, NULL, ArgPassSpec(0));
if (rtn == NULL) {
raiseExcHelper(TypeError, "bad operand type for unary '%s': '%s'", op_name->c_str(), getTypeName(operand));
}
return rtn;
}
......
# run_args: -n
# statcheck: noninit_count('slowpath_unaryop') <= 10
# statcheck: noninit_count('slowpath_runtimecall') <= 10
for i in xrange(1000):
print -i
print ~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