use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef in project graal by oracle.
the class LLVMGenerator method buildExplicitSelect.
/*
* Select has to be manually created sometimes because of a bug in LLVM 8 and below which makes
* it incompatible with statepoint emission in rare cases.
*/
private LLVMValueRef buildExplicitSelect(LLVMValueRef condition, LLVMValueRef trueVal, LLVMValueRef falseVal) {
LLVMBasicBlockRef trueBlock = builder.appendBasicBlock(currentBlock.toString() + "_select_true");
LLVMBasicBlockRef falseBlock = builder.appendBasicBlock(currentBlock.toString() + "_select_false");
LLVMBasicBlockRef mergeBlock = builder.appendBasicBlock(currentBlock.toString() + "_select_end");
splitBlockEndMap.put(currentBlock, mergeBlock);
assert LLVMIRBuilder.compatibleTypes(typeOf(trueVal), typeOf(falseVal));
builder.buildIf(condition, trueBlock, falseBlock);
builder.positionAtEnd(trueBlock);
builder.buildBranch(mergeBlock);
builder.positionAtEnd(falseBlock);
builder.buildBranch(mergeBlock);
builder.positionAtEnd(mergeBlock);
LLVMValueRef[] incomingValues = new LLVMValueRef[] { trueVal, falseVal };
LLVMBasicBlockRef[] incomingBlocks = new LLVMBasicBlockRef[] { trueBlock, falseBlock };
return builder.buildPhi(typeOf(trueVal), incomingValues, incomingBlocks);
}
use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef in project graal by oracle.
the class NodeLLVMBuilder method doBlock.
@Override
public void doBlock(Block block, StructuredGraph graph, BlockMap<List<Node>> blockMap) {
assert !processedBlocks.contains(block) : "Block already processed " + block;
assert verifyPredecessors(block);
gen.beginBlock(block);
if (block == graph.getLastSchedule().getCFG().getStartBlock()) {
assert block.getPredecessorCount() == 0;
long startPatchpointID = LLVMGenerator.nextPatchpointId.getAndIncrement();
builder.buildStackmap(builder.constantLong(startPatchpointID));
gen.getCompilationResult().recordInfopoint(NumUtil.safeToInt(startPatchpointID), null, InfopointReason.METHOD_START);
for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
int offset = (gen.isEntryPoint() ? 0 : SpecialRegister.count());
LLVMValueRef paramValue = builder.getFunctionParam(param.index() + offset);
setResult(param, paramValue);
}
for (SpecialRegister reg : SpecialRegister.registers()) {
gen.setInitialSpecialRegisterValue(reg, gen.isEntryPoint() ? builder.constantNull(builder.wordType()) : builder.getFunctionParam(reg.getIndex()));
}
gen.getDebugInfoPrinter().printFunction(graph, this);
} else {
assert block.getPredecessorCount() > 0;
// create phi-in value array
AbstractBeginNode begin = block.getBeginNode();
if (begin instanceof AbstractMergeNode) {
AbstractMergeNode merge = (AbstractMergeNode) begin;
for (SpecialRegister reg : SpecialRegister.registers()) {
List<LLVMValueRef> forwardPredValues = new ArrayList<>();
List<LLVMBasicBlockRef> forwardBlocks = new ArrayList<>();
for (Block predecessor : block.getPredecessors()) {
if (processedBlocks.contains(predecessor)) {
forwardPredValues.add(block.isExceptionEntry() ? gen.getHandlerSpecialRegisterValue(reg, predecessor) : gen.getSpecialRegisterValue(reg, predecessor));
forwardBlocks.add(gen.getBlockEnd(predecessor));
}
}
LLVMValueRef registerPhi = builder.buildPhi(builder.wordType(), forwardPredValues.toArray(new LLVMValueRef[0]), forwardBlocks.toArray(new LLVMBasicBlockRef[0]));
gen.setInitialSpecialRegisterValue(reg, registerPhi);
}
for (ValuePhiNode phiNode : merge.valuePhis()) {
List<LLVMValueRef> forwardPhis = new ArrayList<>();
List<LLVMBasicBlockRef> forwardBlocks = new ArrayList<>();
LLVMTypeRef phiType = getLLVMType(phiNode);
boolean hasBackwardIncomingEdges = false;
for (Block predecessor : block.getPredecessors()) {
if (processedBlocks.contains(predecessor)) {
ValueNode phiValue = phiNode.valueAt((AbstractEndNode) predecessor.getEndNode());
LLVMValueRef value;
if (operand(phiValue) instanceof LLVMPendingSpecialRegisterRead) {
/*
* The pending read may need to perform instructions to load the
* value, so we put them at the end of the predecessor block
*/
Block currentBlock = (Block) gen.getCurrentBlock();
gen.editBlock(predecessor);
value = llvmOperand(phiValue);
gen.resumeBlock(currentBlock);
} else {
value = llvmOperand(phiValue);
}
LLVMBasicBlockRef parentBlock = gen.getBlockEnd(predecessor);
forwardPhis.add(value);
forwardBlocks.add(parentBlock);
} else {
hasBackwardIncomingEdges = true;
}
}
LLVMValueRef[] incomingValues = forwardPhis.toArray(new LLVMValueRef[0]);
LLVMBasicBlockRef[] incomingBlocks = forwardBlocks.toArray(new LLVMBasicBlockRef[0]);
LLVMValueRef phi = builder.buildPhi(phiType, incomingValues, incomingBlocks);
if (hasBackwardIncomingEdges) {
backwardsPhi.put(phiNode, phi);
}
setResult(phiNode, phi);
}
} else {
assert block.getPredecessorCount() == 1;
Block predecessor = block.getFirstPredecessor();
for (SpecialRegister reg : SpecialRegister.registers()) {
gen.setInitialSpecialRegisterValue(reg, block.isExceptionEntry() ? gen.getHandlerSpecialRegisterValue(reg, predecessor) : gen.getSpecialRegisterValue(reg, predecessor));
}
}
}
gen.getDebugInfoPrinter().printBlock(block);
for (Node node : blockMap.get(block)) {
if (node instanceof ValueNode) {
/*
* There can be cases in which the result of an instruction is already set before by
* other instructions.
*/
if (!valueMap.containsKey(node)) {
ValueNode valueNode = (ValueNode) node;
try {
gen.getDebugInfoPrinter().printNode(valueNode);
emitNode(valueNode);
} catch (GraalError e) {
throw GraalGraphError.transformAndAddContext(e, valueNode);
} catch (Throwable e) {
throw new GraalGraphError(e).addContext(valueNode);
}
}
}
}
if (builder.blockTerminator(gen.getBlockEnd(block)) == null) {
NodeIterable<Node> successors = block.getEndNode().successors();
assert successors.count() == block.getSuccessorCount();
if (block.getSuccessorCount() != 1) {
/*
* If we have more than one successor, we cannot just use the first one. Since
* successors are unordered, this would be a random choice.
*/
throw new GraalError("Block without BlockEndOp: " + block.getEndNode());
}
builder.buildBranch(gen.getBlock(block.getFirstSuccessor()));
}
processedBlocks.add(block);
}
use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef in project graal by oracle.
the class NodeLLVMBuilder method visitLoopEnd.
@Override
public void visitLoopEnd(LoopEndNode i) {
LLVMBasicBlockRef[] basicBlocks = new LLVMBasicBlockRef[] { gen.getBlockEnd((Block) gen.getCurrentBlock()) };
assert gen.getCurrentBlock().getSuccessorCount() == 1;
for (SpecialRegister reg : SpecialRegister.registers()) {
Block successor = ((Block) gen.getCurrentBlock()).getFirstSuccessor();
LLVMValueRef phi = gen.getInitialSpecialRegisterValue(reg, successor);
assert LLVM.LLVMGetInstructionOpcode(phi) == LLVM.LLVMPHI;
builder.addIncoming(phi, new LLVMValueRef[] { gen.getSpecialRegisterValue(reg) }, basicBlocks);
}
for (ValuePhiNode phiNode : i.merge().valuePhis()) {
LLVMValueRef phi = backwardsPhi.get(phiNode);
LLVMValueRef value = llvmOperand(phiNode.valueAt(i));
LLVMValueRef[] values = new LLVMValueRef[] { value };
builder.addIncoming(phi, values, basicBlocks);
}
}
use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef in project graal by oracle.
the class NodeLLVMBuilder method emitCallInstruction.
private LLVMValueRef emitCallInstruction(Invoke invoke, boolean nativeABI, LLVMValueRef callee, long patchpointId, LLVMValueRef... args) {
LLVMValueRef call;
if (invoke instanceof InvokeWithExceptionNode) {
InvokeWithExceptionNode invokeWithExceptionNode = (InvokeWithExceptionNode) invoke;
LLVMBasicBlockRef successor = gen.getBlock(invokeWithExceptionNode.next());
LLVMBasicBlockRef handler = gen.getBlock(invokeWithExceptionNode.exceptionEdge());
call = gen.buildStatepointInvoke(callee, nativeABI, successor, handler, patchpointId, args);
} else {
call = gen.buildStatepointCall(callee, nativeABI, patchpointId, args);
}
return call;
}
use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef in project graal by oracle.
the class LLVMHelperFunctions method buildCompressFunction.
private LLVMValueRef buildCompressFunction(boolean nonNull, int shift) {
String funcName = COMPRESS_FUNCTION_BASE_NAME + (nonNull ? "_nonNull" : "") + "_" + shift;
LLVMValueRef func = builder.addFunction(funcName, builder.functionType(builder.objectType(true), builder.objectType(false), builder.wordType()));
LLVMIRBuilder.setLinkage(func, LinkageType.LinkOnce);
builder.setFunctionAttribute(func, Attribute.AlwaysInline);
builder.setFunctionAttribute(func, Attribute.GCLeafFunction);
LLVMBasicBlockRef block = builder.appendBasicBlock(func, "main");
builder.positionAtEnd(block);
LLVMValueRef uncompressed = builder.buildPtrToInt(LLVMIRBuilder.getParam(func, 0));
LLVMValueRef heapBase = LLVMIRBuilder.getParam(func, 1);
LLVMValueRef compressed = builder.buildSub(uncompressed, heapBase);
if (!nonNull) {
LLVMValueRef isNull = builder.buildIsNull(uncompressed);
compressed = builder.buildSelect(isNull, uncompressed, compressed);
}
if (shift != 0) {
compressed = builder.buildShr(compressed, builder.constantInt(shift));
}
compressed = builder.buildLLVMIntToPtr(compressed, builder.objectType(true));
builder.buildRet(compressed);
return func;
}
Aggregations