use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef in project graal by oracle.
the class LLVMGenerator method buildStatepointInvoke.
LLVMValueRef buildStatepointInvoke(LLVMValueRef callee, boolean nativeABI, LLVMBasicBlockRef successor, LLVMBasicBlockRef handler, long statepointId, LLVMValueRef... args) {
LLVMBasicBlockRef successorBlock;
LLVMBasicBlockRef handlerBlock;
if (!nativeABI) {
successorBlock = builder.appendBasicBlock(currentBlock.toString() + "_invoke_successor");
handlerBlock = builder.appendBasicBlock(currentBlock.toString() + "_invoke_handler");
splitBlockEndMap.put(currentBlock, successorBlock);
} else {
successorBlock = successor;
handlerBlock = handler;
}
LLVMValueRef result = builder.buildInvoke(callee, successorBlock, handlerBlock, args);
builder.setCallSiteAttribute(result, Attribute.StatepointID, Long.toString(statepointId));
if (!nativeABI) {
builder.positionAtEnd(handlerBlock);
builder.buildLandingPad();
for (SpecialRegister reg : SpecialRegister.registers()) {
setHandlerSpecialRegisterValue(reg, getSpecialRegisterValue(reg));
}
builder.buildBranch(handler);
builder.positionAtEnd(successorBlock);
int numReturnValues = LLVMIRBuilder.countElementTypes(typeOf(result));
for (SpecialRegister reg : SpecialRegister.registers()) {
assert reg.index < numReturnValues;
setSpecialRegisterValue(reg, builder.buildExtractValue(result, reg.index));
}
result = numReturnValues > SpecialRegister.count() ? builder.buildExtractValue(result, SpecialRegister.count()) : result;
builder.buildBranch(successor);
}
return result;
}
use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef in project graal by oracle.
the class NodeLLVMBuilder method emitForeignCall.
@Override
public void emitForeignCall(ForeignCall i) {
ForeignCallLinkage linkage = gen.getForeignCalls().lookupForeignCall(i.getDescriptor());
LIRFrameState state = state(i);
Value[] args = i.operands(this);
Value result = null;
if (i instanceof ForeignCallNode) {
result = gen.emitForeignCall(linkage, state, args);
} else if (i instanceof ForeignCallWithExceptionNode) {
ForeignCallWithExceptionNode foreignCallWithExceptionNode = (ForeignCallWithExceptionNode) i;
LLVMBasicBlockRef successor = gen.getBlock(foreignCallWithExceptionNode.next());
LLVMBasicBlockRef handler = gen.getBlock(foreignCallWithExceptionNode.exceptionEdge());
result = gen.emitForeignCall(linkage, state, successor, handler, args);
} else {
throw shouldNotReachHere();
}
if (result != null) {
setResult(i.asNode(), result);
}
}
use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef in project graal by oracle.
the class NodeLLVMBuilder method visitEndNode.
@Override
public void visitEndNode(AbstractEndNode i) {
LLVMBasicBlockRef nextBlock = gen.getBlock(i.merge());
builder.buildBranch(nextBlock);
}
use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef in project graal by oracle.
the class NodeLLVMBuilder method emitIf.
/* Control flow nodes */
@Override
public void emitIf(IfNode i) {
LLVMValueRef condition = emitCondition(i.condition());
LLVMBasicBlockRef thenBlock = gen.getBlock(i.trueSuccessor());
LLVMBasicBlockRef elseBlock = gen.getBlock(i.falseSuccessor());
LLVMValueRef instr = builder.buildIf(condition, thenBlock, elseBlock);
int trueProbability = expandProbability(i.getTrueSuccessorProbability());
int falseProbability = expandProbability(1 - i.getTrueSuccessorProbability());
LLVMValueRef branchWeights = builder.branchWeights(builder.constantInt(trueProbability), builder.constantInt(falseProbability));
builder.setMetadata(instr, "prof", branchWeights);
}
use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef in project graal by oracle.
the class NodeLLVMBuilder method emitSwitch.
@Override
public void emitSwitch(SwitchNode switchNode) {
if (switchNode instanceof TypeSwitchNode) {
emitTypeSwitch((TypeSwitchNode) switchNode);
return;
}
int numCases = switchNode.keyCount();
LLVMValueRef[] values = new LLVMValueRef[numCases];
LLVMBasicBlockRef[] blocks = new LLVMBasicBlockRef[numCases];
LLVMValueRef[] weights = new LLVMValueRef[numCases + 1];
int defaultProbability = expandProbability(switchNode.probability(switchNode.defaultSuccessor()));
weights[0] = builder.constantInt(defaultProbability);
for (int i = 0; i < numCases; ++i) {
JavaConstant key = (JavaConstant) switchNode.keyAt(i);
values[i] = builder.constantInt(key.asInt());
blocks[i] = gen.getBlock(switchNode.keySuccessor(i));
int keyProbability = expandProbability(switchNode.probability(switchNode.keySuccessor(i)));
weights[i + 1] = builder.constantInt(keyProbability);
}
LLVMValueRef switchInstr = builder.buildSwitch(llvmOperand(switchNode.value()), gen.getBlock(switchNode.defaultSuccessor()), values, blocks);
LLVMValueRef branchWeights = builder.branchWeights(weights);
builder.setMetadata(switchInstr, "prof", branchWeights);
}
Aggregations