[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [omr-dev] Is this correct IL codegen?
|
Hi - an update.
After doing some experimentation I have changed this to compute
(array[offset]) and use the computed address in the indirect
load/store instructions. It appears to work this way.
I would still like to understand if there is a way to explicitly
load/store using array[offset].
Additional questions:
1. When doing indirect store/load I assume that the address needs to
be properly aligned as per the value being accessed?
2. I assume that the load/store operation doesn't care if the address
is of a local array or a pointer address?
Thanks and Regards
Dibyendu
On 11 June 2018 at 00:10, Dibyendu Majumdar <mobile@xxxxxxxxxxxxxxx> wrote:
> I guess part of the question is whether indirect load/store IL
> supports array offsets of the form base[index] or do I need to compute
> the address?
>
> Thanks and Regards
> Dibyendu
>
> On 10 June 2018 at 23:21, Dibyendu Majumdar <mobile@xxxxxxxxxxxxxxx> wrote:
>> 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);
>> }