[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[omr-dev] Is this correct IL codegen?
|
Hi,
I am trying to create an api that lets me:
a) Allocate local stack space (alloca)
b) Load/store values from the allocated space
There is some C scaffolding here but the operation should be obvious -
I would like to know if this is correct?
Many thanks
Regards
Dibyendu
// Create local array (alloca equivalent)
JIT_SymbolRef JIT_CreateLocalByteArray(JIT_ILInjectorRef ilinjector,
uint32_t size) {
auto injector = unwrap_ilinjector(ilinjector);
return wrap_symbolref(injector->symRefTab()->createLocalPrimArray(
size, injector->methodSymbol(),
8 /*apparently 8 means Java bytearray! */));
}
// Convert symbol ref to address
JIT_NodeRef JIT_LoadAddress(JIT_ILInjectorRef ilinjector,
JIT_SymbolRef symbol) {
auto symref = unwrap_symbolref(symbol);
return wrap_node(TR::Node::createWithSymRef(TR::loadaddr, 0, symref));
}
// Load value from base[index]
JIT_NodeRef JIT_ArrayLoad(JIT_ILInjectorRef ilinjector, JIT_NodeRef basenode,
JIT_NodeRef indexnode, JIT_Type dt) {
auto injector = unwrap_ilinjector(ilinjector);
auto base = unwrap_node(basenode);
auto index = unwrap_node(indexnode);
auto type = TR::DataType((TR::DataTypes)dt);
TR::SymbolReference *symRef =
injector->symRefTab()->findOrCreateArrayShadowSymbolRef(type, base);
TR::Node *load = TR::Node::createWithSymRef(
TR::ILOpCode::indirectLoadOpCode(type), 1, index, 0, symRef);
return wrap_node(load);
}
// Store base[index] = value
void JIT_ArrayStore(JIT_ILInjectorRef ilinjector, JIT_NodeRef basenode,
JIT_NodeRef indexnode, JIT_NodeRef valuenode) {
auto injector = unwrap_ilinjector(ilinjector);
auto base = unwrap_node(basenode);
auto index = unwrap_node(indexnode);
auto value = unwrap_node(valuenode);
auto type = value->getDataType();
TR::SymbolReference *symRef =
injector->symRefTab()->findOrCreateArrayShadowSymbolRef(type, base);
TR::ILOpCodes storeOp = injector->comp()->il.opCodeForIndirectStore(type);
TR::Node *store = TR::Node::createWithSymRef(
storeOp, 2, index, value, 0, symRef);
injector->genTreeTop(store);
}