1/*
2 * Copyright (C) 2015-2017 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#if ENABLE(B3_JIT)
29
30#include "AirArg.h"
31#include "AirSpecial.h"
32#include "B3ValueRep.h"
33
34namespace JSC { namespace B3 {
35
36namespace Air { class Code; }
37
38// This is a base class for specials that have stackmaps. Note that it can find the Stackmap by
39// asking for the Inst's origin. Hence, these objects don't need to even hold a reference to the
40// Stackmap.
41
42class StackmapSpecial : public Air::Special {
43public:
44 StackmapSpecial();
45 virtual ~StackmapSpecial();
46
47 enum RoleMode : int8_t {
48 SameAsRep,
49 ForceLateUseUnlessRecoverable,
50 ForceLateUse
51 };
52
53protected:
54 void reportUsedRegisters(Air::Inst&, const RegisterSet&) final;
55 RegisterSet extraEarlyClobberedRegs(Air::Inst&) final;
56 RegisterSet extraClobberedRegs(Air::Inst&) final;
57
58 // Note that this does not override generate() or dumpImpl()/deepDumpImpl(). We have many
59 // subclasses that implement that.
60 void forEachArgImpl(
61 unsigned numIgnoredB3Args, unsigned numIgnoredAirArgs,
62 Air::Inst&, RoleMode, Optional<unsigned> firstRecoverableIndex,
63 const ScopedLambda<Air::Inst::EachArgCallback>&, Optional<Width> optionalDefArgWidth);
64
65 bool isValidImpl(
66 unsigned numIgnoredB3Args, unsigned numIgnoredAirArgs,
67 Air::Inst&);
68 bool admitsStackImpl(
69 unsigned numIgnoredB3Args, unsigned numIgnoredAirArgs,
70 Air::Inst&, unsigned argIndex);
71
72 // Appends the reps for the Inst's args, starting with numIgnoredArgs, to the given vector.
73 Vector<ValueRep> repsImpl(
74 Air::GenerationContext&, unsigned numIgnoredB3Args, unsigned numIgnoredAirArgs, Air::Inst&);
75
76 static bool isArgValidForValue(const Air::Arg&, Value*);
77 static bool isArgValidForRep(Air::Code&, const Air::Arg&, const ValueRep&);
78 static ValueRep repForArg(Air::Code&, const Air::Arg&);
79};
80
81} } // namespace JSC::B3
82
83namespace WTF {
84
85void printInternal(PrintStream&, JSC::B3::StackmapSpecial::RoleMode);
86
87} // namespace WTF
88
89#endif // ENABLE(B3_JIT)
90