1/*
2 * Copyright (C) 2015-2019 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 "AirSpecial.h"
31
32namespace JSC { namespace B3 { namespace Air {
33
34// Use this special for constructing a C call. Arg 0 is of course a Special arg that refers to the
35// CCallSpecial object. Arg 1 is the callee, and it can be an ImmPtr, a register, or an address. The
36// next three args - arg 2, arg 3, and arg 4 - hold the return value GPRs and FPR. The remaining args
37// are just the set of argument registers used by this call. For arguments that go to the stack, you
38// have to do the grunt work of doing those stack stores. In fact, the only reason why we specify the
39// argument registers as arguments to a call is so that the liveness analysis can see that they get
40// used here. It would be wrong to automagically report all argument registers as being used because
41// if we had a call that didn't pass them, then they'd appear to be live until some clobber point or
42// the prologue, whichever happened sooner.
43
44class CCallSpecial : public Special {
45public:
46 CCallSpecial();
47 ~CCallSpecial();
48
49 // You cannot use this register to pass arguments. It just so happens that this register is not
50 // used for arguments in the C calling convention. By the way, this is the only thing that causes
51 // this special to be specific to C calls.
52 static constexpr GPRReg scratchRegister = GPRInfo::nonPreservedNonArgumentGPR0;
53
54protected:
55 void forEachArg(Inst&, const ScopedLambda<Inst::EachArgCallback>&) final;
56 bool isValid(Inst&) final;
57 bool admitsStack(Inst&, unsigned argIndex) final;
58 bool admitsExtendedOffsetAddr(Inst&, unsigned) final;
59 void reportUsedRegisters(Inst&, const RegisterSet&) final;
60 CCallHelpers::Jump generate(Inst&, CCallHelpers&, GenerationContext&) final;
61 RegisterSet extraEarlyClobberedRegs(Inst&) final;
62 RegisterSet extraClobberedRegs(Inst&) final;
63
64 void dumpImpl(PrintStream&) const final;
65 void deepDumpImpl(PrintStream&) const final;
66
67private:
68 static constexpr unsigned specialArgOffset = 0;
69 static constexpr unsigned numSpecialArgs = 1;
70 static constexpr unsigned calleeArgOffset = numSpecialArgs;
71 static constexpr unsigned numCalleeArgs = 1;
72 static constexpr unsigned returnGPArgOffset = numSpecialArgs + numCalleeArgs;
73 static constexpr unsigned numReturnGPArgs = 2;
74 static constexpr unsigned returnFPArgOffset = numSpecialArgs + numCalleeArgs + numReturnGPArgs;
75 static constexpr unsigned numReturnFPArgs = 1;
76 static constexpr unsigned argArgOffset =
77 numSpecialArgs + numCalleeArgs + numReturnGPArgs + numReturnFPArgs;
78
79 RegisterSet m_clobberedRegs;
80 RegisterSet m_emptyRegs;
81};
82
83} } } // namespace JSC::B3::Air
84
85#endif // ENABLE(B3_JIT)
86