Repository navigation
Implement new vector opcodes - #6458
Conversation
gita-omr
commented
Apr 5, 2022
- introduce VectorOperations enum(vadd and vfma for now)
- the set of vector opcodes is a product of vector operations and vector types
- vector opcodes are generated at runtime and stored in IlOpCode class
- all OMR tables contain entries for vector operations following non-vector opcodes
0efb51a to
9c866ca
Compare
|
Fixed line endings in a new file. |
|
Jenkins build all |
9c866ca to
933294d
Compare
|
Fixed mistake in extra parameter in TR_ASSERT. |
|
Jenkins build all |
933294d to
e2aa009
Compare
- introduce VectorOperations enum(vadd and vfma for now) - the set of vector opcodes is a product of vector operations and vector types - vector opcodes are generated at runtime and stored in IlOpCode class - all OMR tables contain entries for vector operations following non-vector opcodes
e2aa009 to
24c4aa8
Compare
|
@0xdaryl could you please review and approve the common part? @jdmpapin @Leonardo2718 @mstoodle @vijaysun-omr : fyi Please kindly provide your comments by the end of the week so that we can target mid next week (Arpil 13) for the merge? |
|
|
||
| TR::Register* | ||
| OMR::X86::I386::TreeEvaluator::vfmaEvaluator(TR::Node *node, TR::CodeGenerator *cg) | ||
| { |
There was a problem hiding this comment.
Is there a reason to define these implementations specific to ia32/amd64? As far as I know, intel vfma instructions should work on 32-bit as well.
There was a problem hiding this comment.
I think I just follow an example of vdsqrt. In which class should I define vfma so that it works for both? @BradleyWood
There was a problem hiding this comment.
I was just referring to commoning it in compiler/x/codegen/OMRTreeEvaluator
There was a problem hiding this comment.
I think the evaluator needs to be defined in both inOMR::X86::AMD64::TreeEvaluator and in OMR::X86::I386::TreeEvaluator classes to avoid linkage errors. Currently they are both unimplemented. I think it's better to do the commoning when they are actually implemented. This PR is just an example how to add a new vector opcode.
| if (OMR::ILOpCode::isVectorOpCode(opcode) && OMR::ILOpCode::getVectorOperation(opcode) == OMR::vadd) | ||
| { | ||
| arithmetic = BinaryArithmeticAdd; | ||
| break; |
There was a problem hiding this comment.
Perhaps this can be a switch statement to discourage large chains of if statements in the future.
| TR::DataType et = ot.getVectorElementType(); | ||
|
|
||
| if (et == TR::Int8 || et == TR::Int16 || et == TR::Int32 || et == TR::Int64 || et == TR::Float || et == TR::Double) | ||
| return true; |
There was a problem hiding this comment.
Isn't this all the data types? You can simplify:
return ot.getVectorLength() == TR::VectorLength128; // all types supported for vadd128
There was a problem hiding this comment.
Indeed these are all the types. I did not notice it while moving existing code.
|
|
||
| if (opcode.isVectorOpCode() && opcode.getVectorOperation() == OMR::vadd) | ||
| { | ||
| TR::DataType ot = opcode.getVectorResultDataType(); |
There was a problem hiding this comment.
Shouldn't length and opcode.getVectorResultDataType() be equal? Also, for the old vector opcodes, the vector length is assumed to be 128, so do we really need that argument?
There was a problem hiding this comment.
Good points. I was thinking of removing that argument when we remove all old style opcodes. But maybe you are right, we can remove it now.
|
|
||
| TR::DataType et = ot.getVectorElementType(); | ||
|
|
||
| if (et == TR::Int8 || et == TR::Int16 || et == TR::Int32 || et == TR::Int64 || et == TR::Float || et == TR::Double) |
There was a problem hiding this comment.
The same comment as in https://github.com/eclipse/omr/pull/6458/files#r843332926. It appears that all element types are listed here.
There was a problem hiding this comment.
Right, I just copied the old code. I will simplify.
1dcf105 to
3592e50
Compare
| return false; | ||
| } | ||
|
|
||
| if (opcode.isVectorOpCode() && opcode.getVectorOperation() == OMR::vadd) |
There was a problem hiding this comment.
I am thinking on how we make this part more extensible? i.e, when we start adding support for other vector operations as well. If the opcode is Vector Opcode, it might be better if we use switch case similar to how it is used for old vector types. That would make adding new types easier and cleaner.
There was a problem hiding this comment.
When we remove all old vector opcodes we will have only one switch. Maybe better to leave it till then?
There was a problem hiding this comment.
And if (opcode.isVectorOpCode()) will soon be gone as well since all vector opcodes will return true.
There was a problem hiding this comment.
Are we planning to replace old opcode with new opcodes together in future or incrementally?
If we are planning together then we can leave it till then but in case of incrementally adding them (For example, OMR::vsub, OMR::vmul , etc), we will have to stick them to above if condition right?
There was a problem hiding this comment.
Actually, just looked at it more careful. It will not cause any nested switches, so sure, I will change to a single case switch to set a good example :)
There was a problem hiding this comment.
Changed to a switch on all platforms.
|
Just wanted to bring to the attention of the reviewers that it's important to make sure that all the tables that rely on the number of opcodes or their order need to be checked. I think I found all such places but please let me know if you can think of anything else. |
3592e50 to
27833a4
Compare
|
|
||
| if (ot.getVectorLength() != TR::VectorLength128) return false; | ||
|
|
||
| swtich (opcode.getVectorOperation()) |
| class TreeEvaluatorFunctionPointerTable | ||
| { | ||
| private: | ||
| static TR_TreeEvaluatorFunctionPointer table[]; |
There was a problem hiding this comment.
Since you are wrapping this table with another class, perhaps now is the time to drop the TR_ prefix from its name.
There was a problem hiding this comment.
TR_TreeEvaluatorFunctionPointer was and still is defined in another file, outside of any class, as:
typedef TR::Register *(* TR_TreeEvaluatorFunctionPointer)(TR::Node *node, TR::CodeGenerator *codeGen);
I am not sure yet what would be the best place for it...
There was a problem hiding this comment.
I think I found a better place: just before the class that uses it is defined.
| // to avoid any race conditions, initialize all vector names once, | ||
| // as soon as first one is requested | ||
| static bool staticallyInitialized = initVectorNames(); | ||
| static bool staticallyInitialized = initVectorNames(); |
There was a problem hiding this comment.
Remove extra indent space (unless there's a reason for it that's not apparent to me).
| public: | ||
|
|
||
| // The class is capable of storing "hidden" vector opcodes and provides an interface | ||
| // for creating and quiering them |
| // The class is capable of storing "hidden" vector opcodes and provides an interface | ||
| // for creating and quiering them | ||
| // Vector operations that return a non-vector type(e.g. reduction) or for which result | ||
| // and source types are different(e.g. conversion) will be handled later |
There was a problem hiding this comment.
Can you add a space before the ( in the above two lines please?
| */ | ||
| static ILOpCode createVectorOpCode(VectorOperation operation, DataType resultVectorType) | ||
| { | ||
| static_assert(NumAllIlOps < ((long long)1 << (sizeof(TR::ILOpCodes)*8)), "Number of scalar and vector opcodes does not fit into TR::ILOpCodes\n"); |
There was a problem hiding this comment.
Is there a reason to use long long here instead of the more conventional uint64_t throughout the code base?
There was a problem hiding this comment.
No, good point. Will change.
| */ | ||
| static VectorOperation getVectorOperation(ILOpCode op) | ||
| { | ||
| TR_ASSERT_FATAL(isVectorOpCode(op), "getVectOroperation() can only be called on vector opcode\n"); |
| case TR::iadd: return ILOpCode::createVectorOpCode(OMR::vadd, TR::DataType::createVectorType(TR::Int32, vectorLength)).getOpCodeValue(); | ||
| case TR::ladd: return ILOpCode::createVectorOpCode(OMR::vadd, TR::DataType::createVectorType(TR::Int64, vectorLength)).getOpCodeValue(); | ||
| case TR::fadd: return ILOpCode::createVectorOpCode(OMR::vadd, TR::DataType::createVectorType(TR::Float, vectorLength)).getOpCodeValue(); | ||
| case TR::dadd: return ILOpCode::createVectorOpCode(OMR::vadd, TR::DataType::createVectorType(TR::Double, vectorLength)).getOpCodeValue(); |
There was a problem hiding this comment.
Since there is already a local opcode set to the scalar opcode (L1353-1354), I think this can be simplified (and generate less code) as:
case TR::badd:
case TR::sadd:
case TR::iadd:
case TR::ladd:
case TR::fadd:
case TR::dadd:
return ILOpCode::createVectorOpCode(OMR::vadd, TR::DataType::createVectorType(opcode.getDataType(), vectorLength)).getOpCodeValue();
There was a problem hiding this comment.
yes, that will be better. Will change
| static_assert(TR::NumIlOps == | ||
| (sizeof(simplifierOpts) / sizeof(simplifierOpts[0])), | ||
| "simplifierOpts is not the correct size"); | ||
| extern const SimplifierPtrTable simplifierOpts; |
There was a problem hiding this comment.
I think this name should be made consistent with the CodeGenerator TreeEvaluatorFunctionPointerTable you created earlier (i.e., expand the Ptr)
There was a problem hiding this comment.
Right, I just added "Table" to the old name. Will make them consistent.
| typedef TR::Node* (* ValuePropagationPtr)(OMR::ValuePropagation *, TR::Node *); | ||
| extern const ValuePropagationPtr constraintHandlers[]; | ||
|
|
||
| class ValuePropagationPtrTable |
There was a problem hiding this comment.
I think this name should be made consistent with the CodeGenerator TreeEvaluatorFunctionPointerTable you created earlier (i.e., expand the Ptr)
There was a problem hiding this comment.
Similar to the Simplifier I just added "Table" to the existing name. I will make them consistent.
27833a4 to
65ed745
Compare
- new opcodes will have length encoded in them and old ones assume 128
6168f31 to
4e75d72
Compare
|
Jenkins build all |
| TR::DataType et = ot.getVectorElementType(); | ||
|
|
||
| if (self()->comp()->target().cpu.isAtLeast(OMR_PROCESSOR_PPC_P8) && | ||
| opcode.getVectorOperation() == OMR::vadd && dt == TR::Int64) |
There was a problem hiding this comment.
I think this is supposed to check et against TR::Int64?
There was a problem hiding this comment.
Good find! Currently, they are the same and dt will be removed when we remove all old (typeless) vector opcodes. But let me change just for clarity.
4e75d72 to
a6ccacf
Compare
|
Addressed latest comments. |
|
I looked over the P sections of the code and they looked good to me. |
|
Jenkins build all |
|
Last call for review comments. This will be merged later this evening unless there are any new concerns raised. |
|
Jenkins build zos |