]>
git.saurik.com Git - apple/javascriptcore.git/blob - ftl/FTLOutput.cpp
2 * Copyright (C) 2013 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 "FTLOutput.h"
31 namespace JSC
{ namespace FTL
{
33 Output::Output(LContext context
)
34 : IntrinsicRepository(context
)
37 , m_builder(llvm
->CreateBuilderInContext(m_context
))
45 llvm
->DisposeBuilder(m_builder
);
48 void Output::initialize(LModule
module, LValue function
, AbstractHeapRepository
& heaps
)
50 IntrinsicRepository::initialize(module);
51 m_function
= function
;
55 LBasicBlock
Output::appendTo(LBasicBlock block
, LBasicBlock nextBlock
)
58 return insertNewBlocksBefore(nextBlock
);
61 void Output::appendTo(LBasicBlock block
)
65 llvm
->PositionBuilderAtEnd(m_builder
, block
);
68 LBasicBlock
Output::newBlock(const char* name
)
71 return appendBasicBlock(m_context
, m_function
, name
);
72 return insertBasicBlock(m_context
, m_nextBlock
, name
);
75 LValue
Output::sensibleDoubleToInt(LValue value
)
77 RELEASE_ASSERT(isX86());
79 x86SSE2CvtTSD2SIIntrinsic(),
81 insertElement(getUndef(vectorType(doubleType
, 2)), value
, int32Zero
),
82 doubleZero
, int32One
));
85 LValue
Output::load(TypedPointer pointer
, LType refType
)
87 LValue result
= get(intToPtr(pointer
.value(), refType
));
88 pointer
.heap().decorateInstruction(result
, *m_heaps
);
92 void Output::store(LValue value
, TypedPointer pointer
, LType refType
)
94 LValue result
= set(value
, intToPtr(pointer
.value(), refType
));
95 pointer
.heap().decorateInstruction(result
, *m_heaps
);
98 LValue
Output::baseIndex(LValue base
, LValue index
, Scale scale
, ptrdiff_t offset
)
100 LValue accumulatedOffset
;
104 accumulatedOffset
= index
;
107 accumulatedOffset
= shl(index
, intPtrOne
);
110 accumulatedOffset
= shl(index
, intPtrTwo
);
114 accumulatedOffset
= shl(index
, intPtrThree
);
119 accumulatedOffset
= add(accumulatedOffset
, constIntPtr(offset
));
121 return add(base
, accumulatedOffset
);
124 void Output::branch(LValue condition
, LBasicBlock taken
, Weight takenWeight
, LBasicBlock notTaken
, Weight notTakenWeight
)
126 LValue branch
= buildCondBr(m_builder
, condition
, taken
, notTaken
);
128 if (!takenWeight
|| !notTakenWeight
)
131 double total
= takenWeight
.value() + notTakenWeight
.value();
136 m_context
, branchWeights
,
137 constInt32(takenWeight
.scaleToTotal(total
)),
138 constInt32(notTakenWeight
.scaleToTotal(total
))));
141 void Output::crashNonTerminal()
143 call(intToPtr(constIntPtr(abort
), pointerType(functionType(voidType
))));
146 } } // namespace JSC::FTL
148 #endif // ENABLE(FTL_JIT)