Various llvm backend bugfixes
[hiphop-php.git] / hphp / runtime / vm / jit / type-source.h
blob62837c298bdc069ab0d2ac4c47fb68e4fb11a9f5
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 #ifndef incl_HPHP_JIT_TYPE_SOURCE_H_
18 #define incl_HPHP_JIT_TYPE_SOURCE_H_
20 #include "hphp/runtime/vm/jit/containers.h"
21 #include "hphp/util/assertions.h"
23 #include <string>
25 namespace HPHP { namespace jit {
27 struct IRInstruction;
28 struct SSATmp;
31 * The source of a local's type. Either the current value or a guard.
33 * Used for guard relaxation, as we're constraining a value, local, or stack
34 * slot, and we need to know what guards that type came from.
36 struct TypeSource {
37 enum class Kind : uint8_t {
38 Value,
39 Guard,
42 static TypeSource makeValue(SSATmp* value) {
43 assert(value);
44 TypeSource src;
45 src.value = value;
46 src.kind = Kind::Value;
47 return src;
50 static TypeSource makeGuard(const IRInstruction* guard) {
51 assert(guard);
52 TypeSource src;
53 src.guard = guard;
54 src.kind = Kind::Guard;
55 return src;
58 bool isGuard() const { return kind == Kind::Guard; }
59 bool isValue() const { return kind == Kind::Value; }
61 bool operator==(const TypeSource& rhs) const {
62 return kind == rhs.kind && value == rhs.value;
64 bool operator!=(const TypeSource& rhs) const {
65 return !operator==(rhs);
67 bool operator<(const TypeSource& rhs) const;
69 std::string toString() const;
71 // Members.
72 union {
73 SSATmp* value{nullptr};
74 const IRInstruction* guard;
77 Kind kind;
80 typedef jit::flat_set<TypeSource> TypeSourceSet;
82 std::string show(const TypeSource&);
83 std::string show(const TypeSourceSet&);
87 #endif