]>
git.saurik.com Git - apple/javascriptcore.git/blob - ftl/FTLLocation.cpp
2 * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "FTLLocation.h"
31 #include "FTLSaveRestore.h"
32 #include "RegisterSet.h"
33 #include <wtf/CommaPrinter.h>
34 #include <wtf/DataLog.h>
35 #include <wtf/ListDump.h>
37 namespace JSC
{ namespace FTL
{
39 Location
Location::forStackmaps(const StackMaps
* stackmaps
, const StackMaps::Location
& location
)
41 switch (location
.kind
) {
42 case StackMaps::Location::Unprocessed
:
43 RELEASE_ASSERT_NOT_REACHED();
46 case StackMaps::Location::Register
:
47 case StackMaps::Location::Direct
:
48 return forRegister(location
.dwarfReg
, location
.offset
);
50 case StackMaps::Location::Indirect
:
51 return forIndirect(location
.dwarfReg
, location
.offset
);
53 case StackMaps::Location::Constant
:
54 return forConstant(location
.offset
);
56 case StackMaps::Location::ConstantIndex
:
58 return forConstant(stackmaps
->constants
[location
.offset
].integer
);
61 RELEASE_ASSERT_NOT_REACHED();
66 void Location::dump(PrintStream
& out
) const
68 out
.print("(", kind());
70 out
.print(", ", dwarfReg());
72 out
.print(", ", offset());
74 out
.print(", ", addend());
76 out
.print(", ", constant());
80 bool Location::involvesGPR() const
82 return isGPR() || kind() == Indirect
;
85 bool Location::isGPR() const
87 return kind() == Register
&& dwarfReg().reg().isGPR();
90 GPRReg
Location::gpr() const
92 return dwarfReg().reg().gpr();
95 bool Location::isFPR() const
97 return kind() == Register
&& dwarfReg().reg().isFPR();
100 FPRReg
Location::fpr() const
102 return dwarfReg().reg().fpr();
105 void Location::restoreInto(MacroAssembler
& jit
, char* savedRegisters
, GPRReg result
, unsigned numFramesToPop
) const
107 if (involvesGPR() && RegisterSet::stackRegisters().get(gpr())) {
108 // Make the result GPR contain the appropriate stack register.
109 if (numFramesToPop
) {
110 jit
.move(MacroAssembler::framePointerRegister
, result
);
112 for (unsigned i
= numFramesToPop
- 1; i
--;)
113 jit
.loadPtr(result
, result
);
115 if (gpr() == MacroAssembler::framePointerRegister
)
116 jit
.loadPtr(result
, result
);
118 jit
.addPtr(MacroAssembler::TrustedImmPtr(sizeof(void*) * 2), result
);
120 jit
.move(gpr(), result
);
124 if (RegisterSet::stackRegisters().get(gpr())) {
125 // Already restored into result.
127 jit
.load64(savedRegisters
+ offsetOfGPR(gpr()), result
);
130 jit
.add64(MacroAssembler::TrustedImm32(addend()), result
);
135 jit
.load64(savedRegisters
+ offsetOfFPR(fpr()), result
);
142 // LLVM used some register that we don't know about!
143 dataLog("Unrecognized location: ", *this, "\n");
144 RELEASE_ASSERT_NOT_REACHED();
148 if (RegisterSet::stackRegisters().get(gpr())) {
149 // The stack register is already recovered into result.
150 jit
.load64(MacroAssembler::Address(result
, offset()), result
);
154 jit
.load64(savedRegisters
+ offsetOfGPR(gpr()), result
);
155 jit
.load64(MacroAssembler::Address(result
, offset()), result
);
159 jit
.move(MacroAssembler::TrustedImm64(constant()), result
);
163 // Should never see this - it's an enumeration entry on LLVM's side that means that
164 // it hasn't processed this location.
165 RELEASE_ASSERT_NOT_REACHED();
169 RELEASE_ASSERT_NOT_REACHED();
172 GPRReg
Location::directGPR() const
174 RELEASE_ASSERT(!addend());
178 } } // namespace JSC::FTL
182 using namespace JSC::FTL
;
184 void printInternal(PrintStream
& out
, JSC::FTL::Location::Kind kind
)
187 case Location::Unprocessed
:
188 out
.print("Unprocessed");
190 case Location::Register
:
191 out
.print("Register");
193 case Location::Indirect
:
194 out
.print("Indirect");
196 case Location::Constant
:
197 out
.print("Constant");
200 RELEASE_ASSERT_NOT_REACHED();
205 #endif // ENABLE(FTL_JIT)