CTSRD-CHERI / clang

DO NOT USE. Use llvm-project instead
Other
9 stars 8 forks source link

In purecap ABI by value structs are passed as series of i64 arguments #153

Closed arichardson closed 4 years ago

arichardson commented 7 years ago

In the hybrid ABI it uses memcpy and passes a pointer starting at >= 64 bytes. See test/CodeGen/cheri-byval-argument.c

Not sure this is a problem, but it generates tons of code instead of calling memcpy.

davidchisnall commented 7 years ago

I think that's normal. The back end will either lower it to a memcpy call or to a sequence of loads and stores, depending on which makes more sense.

arichardson commented 7 years ago

It ends up generated functions with a huge amount of variables and lots of loads and stores if we have an array of e.g. 2048 bytes (see the output generated by https://github.com/CTSRD-CHERI/clang/blob/master/test/CodeGen/cheri-byval-argument.c). I think the threshold between expanding and using memcpy should be the same (or only slightly higher) between n64 and purecap ABI.

davidchisnall commented 7 years ago

The threshold is set in the back end. I agree that we should be generating a memcpy call for these, but the current threshold is 16 stores, so I'm not quite sure how we are getting 64 bytes not becoming a memcpy call.

davidchisnall commented 7 years ago

Hmm, it looks as if this is actually a problem with the calling convention. For MIPS, we're passing the struct indirectly (via a pointer), in the pure-cap ABI we're passing it all in registers (in the IR - most of which then gets lowered to stack arguments). I think this is part of the change made by @kgudka regarding byval arguments.

arichardson commented 7 years ago

It seems to be using 8 * capability registers size in bits as the threshold.

arichardson commented 4 years ago

Should be fixed.