Switch-related cleanup
[hiphop-php.git] / hphp / runtime / vm / jit / annotation.cpp
blob324e90b17740889fc2cc540f2f8bc09eff841b55
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/runtime/vm/jit/annotation.h"
19 #include "hphp/runtime/vm/jit/normalized-instruction.h"
20 #include "hphp/runtime/vm/jit/translator.h"
21 #include "hphp/runtime/vm/jit/translator-inline.h"
22 #include "hphp/runtime/vm/repo.h"
23 #include "hphp/runtime/vm/repo-global-data.h"
25 namespace HPHP { namespace jit {
27 TRACE_SET_MOD(trans);
29 //////////////////////////////////////////////////////////////////////
31 namespace {
33 const StaticString s_empty("");
35 const Func* lookupDirectFunc(SrcKey const sk,
36 const StringData* fname,
37 const StringData* clsName,
38 bool staticCall) {
39 if (clsName && !clsName->isame(s_empty.get())) {
40 auto const cls = Unit::lookupClassOrUniqueClass(clsName);
41 bool magic = false;
42 auto const ctx = sk.func()->cls();
43 return lookupImmutableMethod(cls, fname, magic, staticCall, ctx);
45 auto const func = Unit::lookupFunc(fname);
46 if (func && func->isNameBindingImmutable(sk.unit())) {
47 return func;
49 return nullptr;
54 //////////////////////////////////////////////////////////////////////
56 void annotate(NormalizedInstruction* i) {
57 switch (i->op()) {
58 case Op::FCallD:
60 auto const fpi = i->func()->findFPI(i->source.offset());
61 auto const pushOp = i->m_unit->getOpcode(fpi->m_fpushOff);
62 auto const clsName = i->m_unit->lookupLitstrId(i->imm[1].u_SA);
63 auto const funcName = i->m_unit->lookupLitstrId(i->imm[2].u_SA);
64 auto const isStatic = pushOp == Op::FPushClsMethodD ||
65 pushOp == Op::FPushClsMethodF ||
66 pushOp == Op::FPushClsMethod;
69 * Currently we don't attempt any of this for FPushClsMethod
70 * because lookupImmutableMethod is only for situations that
71 * don't involve LSB.
73 auto const func =
74 pushOp == Op::FPushClsMethod
75 ? nullptr
76 : lookupDirectFunc(i->source, funcName, clsName, isStatic);
78 if (func) {
79 FTRACE(1, "found direct func ({}) for FCallD\n",
80 func->fullName()->data());
81 i->funcd = func;
84 break;
85 default:
86 break;
90 //////////////////////////////////////////////////////////////////////