On 9 August 2010 22:39, Lally Singh <lally.singh at gmail.com>
wrote:> If I've got some code that I can compile using clang, that depends
> on a certain endianness, can I generate bitcode that will have the
> code operate correctly, even if run on machines of the the opposite
> endianness? If not, what're we talking about in specific work
that'd
> be needed?
Hi Lally,
IR has a target data layout to specify the endianness:
http://llvm.org/docs/LangRef.html#datalayout
But that's more like information for the back end to generate correct
code, assuming you'll run the codegen passes on multiple IR files and
want to keep them in the same data layout.
Some things that strike me as a problem are the constants (if you have
written it in the reverse order already), or if you're mixing little
and big endian code without explicitly telling the codegen passes (via
data layout).
Another thing you need to make sure is if this is code or data
endianness. You might have little endian code accessing big endian
data or even parts of your data big while the rest is little (some
embedded systems have those bad habits). I'm not sure LLVM can cope
with mixed endianness in the same target, but it should be just a
matter of fixing the data layout for the general simple case.
Hope that helps,
--renato