This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] IntegralComplexToBoolean casts
AcceptedPublic

Authored by tbaeder on Apr 15 2023, 5:23 AM.

Details

Summary

I wanted to avoid adding too many opcodes for bitint, complex, vector, etc. types so I implemented this by just emitting more ops.

Diff Detail

Event Timeline

tbaeder created this revision.Apr 15 2023, 5:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2023, 5:23 AM
tbaeder requested review of this revision.Apr 15 2023, 5:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2023, 5:23 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tbaeder added inline comments.Apr 15 2023, 5:25 AM
clang/lib/AST/Interp/ByteCodeExprGen.cpp
1165

Since complex types are arrays with two elements, we can't dereference them like normal. This change just ignore the dereference.

I was wondering if it would be better to add an opcode to dereference it so we have [real, imag] on the stack and then callers that operate on such complex rvalues can pop(); pop(); to get the values.

aaron.ballman accepted this revision.Apr 17 2023, 5:27 AM

LGTM aside from a minor cleanup.

clang/lib/AST/Interp/ByteCodeExprGen.cpp
1165

I was wondering if it would be better to add an opcode to dereference it so we have [real, imag] on the stack and then callers that operate on such complex rvalues can pop(); pop(); to get the values.

That might be worthwhile as an optimization, but I suppose we can wait to see how often complex is used in constant expressions before deciding what to do there?

clang/lib/AST/Interp/ByteCodeExprGen.h
272–275

This form does the assertion for you.

This revision is now accepted and ready to land.Apr 17 2023, 5:27 AM