This is an archive of the discontinued LLVM Phabricator instance.

[ExecutionEngine] Support TargetExtType in Interpreter
ClosedPublic

Authored by wenju on Apr 13 2023, 6:19 PM.

Details

Summary

When llvm Interpreter is used to execute bitcode, it shall be able to handle TargetExtType.

Diff Detail

Event Timeline

wenju created this revision.Apr 13 2023, 6:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 13 2023, 6:19 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
wenju requested review of this revision.Apr 13 2023, 6:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 13 2023, 6:19 PM

Sorry for the delay in reviewing this patch.

I'm not an expert in the JIT code, so I'm not completely certain that this code covers all the bases (in particular, it's somewhat unclear to me if this is handling globals correctly).

You should be able to add a test for this code along the lines of test/ExecutionEngine/test-interp-aggregate.ll, that would at least make sure that load/store, global variables, ConstantTargetNone, and poison value initializers work correctly. That would definitely make me more comfortable re the global variable support.

wenju updated this revision to Diff 528733.Jun 6 2023, 12:52 AM

add load/store/constant lit test for changes in ExecutionEngine.cpp

wenju added a comment.Jun 6 2023, 1:28 AM

I don't have a test case of global variable with target extension type.

poison value initializers

doe this mean something like "store target("spirv.Event") poison, ptr %event, align 8"?

An alterative approach to this patch is to lower target extension type to its layout type before executing interpreter. I'm proposing this patch as I think it might worth adding natively support of target extension type to interpreter. I don't know if this support will be useful for someone else. There could be cases that target extension type exists in bitcode input of an interpreter.

I don't have a test case of global variable with target extension type.

A simple @global = target("spirv.Event") zeroinitializer should suffice, combined with a load or store of that global. The point is to make sure that the interpreter can handle a global variable having a target extension type without crashing.

poison value initializers

doe this mean something like "store target("spirv.Event") poison, ptr %event, align 8"?

Yes.

An alterative approach to this patch is to lower target extension type to its layout type before executing interpreter. I'm proposing this patch as I think it might worth adding natively support of target extension type to interpreter. I don't know if this support will be useful for someone else. There could be cases that target extension type exists in bitcode input of an interpreter.

That's another approach I considered, but I think this approach works a little better. Although you did remind me that there should be a comment somewhere justifying that it is safe to treat the target extension type as its layout type, since the only thing the interpreter is doing is zero-initializing or copying the bits around, and never otherwise inspecting or touching them.

wenju updated this revision to Diff 529119.Jun 6 2023, 6:38 PM

add test of global and poison value, add comment of 'It is safe to treat TargetExtType as its layout type'

jcranmer-intel accepted this revision.Jun 7 2023, 2:07 PM

Thanks, LGTM.

This revision is now accepted and ready to land.Jun 7 2023, 2:07 PM
wenju added a comment.Jun 7 2023, 6:19 PM

@jcranmer-intel thank you for the review

This revision was automatically updated to reflect the committed changes.