-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[MC] Reorder TARGETInstrTable to shrink MCInstrDesc::ImplicitOffset #171199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -959,13 +959,19 @@ void InstrInfoEmitter::run(raw_ostream &OS) { | |
|
|
||
| OS << "struct " << TargetName << "InstrTable {\n"; | ||
| OS << " MCInstrDesc Insts[" << NumberedInstructions.size() << "];\n"; | ||
| OS << " static_assert(alignof(MCInstrDesc) >= alignof(MCPhysReg), " | ||
| "\"Unwanted padding between Insts and ImplicitOps\");\n"; | ||
| OS << " MCPhysReg ImplicitOps[" << std::max(ImplicitListSize, 1U) | ||
| << "];\n"; | ||
| // Emit enough padding to make ImplicitOps plus Padding add up to the size | ||
| // of a whole number of MCOperandInfo structs. This allows us to index into | ||
| // the OperandInfo array starting from the end of the Insts array, by | ||
| // biasing the indices by the OpInfoBase value calculated below. | ||
| OS << " char Padding[sizeof(MCOperandInfo) - sizeof ImplicitOps % " | ||
| "sizeof(MCOperandInfo)];\n"; | ||
| OS << " static_assert(alignof(MCInstrDesc) >= alignof(MCOperandInfo), " | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this assertion still correct/relevant?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. It's not completely obvious, but I think this is still required, otherwise there's no way we could index into the OperandInfo array starting from the end of the Insts array. |
||
| "\"Unwanted padding between Insts and OperandInfo\");\n"; | ||
| OS << " MCOperandInfo OperandInfo[" << OperandInfoSize << "];\n"; | ||
| OS << " static_assert(alignof(MCOperandInfo) >= alignof(MCPhysReg), " | ||
| "\"Unwanted padding between OperandInfo and ImplicitOps\");\n"; | ||
| OS << " MCPhysReg ImplicitOps[" << std::max(ImplicitListSize, 1U) | ||
| << "];\n"; | ||
| OS << "};"; | ||
| } | ||
|
|
||
|
|
@@ -991,9 +997,12 @@ void InstrInfoEmitter::run(raw_ostream &OS) { | |
|
|
||
| // Emit all of the MCInstrDesc records in reverse ENUM ordering. | ||
| Timer.startTimer("Emit InstrDesc records"); | ||
| OS << "static_assert(sizeof(MCOperandInfo) % sizeof(MCPhysReg) == 0);\n"; | ||
| OS << "static constexpr unsigned " << TargetName << "ImpOpBase = sizeof " | ||
| << TargetName << "InstrTable::OperandInfo / (sizeof(MCPhysReg));\n\n"; | ||
| OS << "static_assert((sizeof " << TargetName | ||
| << "InstrTable::ImplicitOps + sizeof " << TargetName | ||
| << "InstrTable::Padding) % sizeof(MCOperandInfo) == 0);\n"; | ||
| OS << "static constexpr unsigned " << TargetName << "OpInfoBase = (sizeof " | ||
| << TargetName << "InstrTable::ImplicitOps + sizeof " << TargetName | ||
| << "InstrTable::Padding) / sizeof(MCOperandInfo);\n\n"; | ||
|
|
||
| OS << "extern const " << TargetName << "InstrTable " << TargetName | ||
| << "Descs = {\n {\n"; | ||
|
|
@@ -1013,12 +1022,6 @@ void InstrInfoEmitter::run(raw_ostream &OS) { | |
|
|
||
| OS << " }, {\n"; | ||
|
|
||
| // Emit all of the operand info records. | ||
| Timer.startTimer("Emit operand info"); | ||
| EmitOperandInfo(OS, OperandInfoList); | ||
|
|
||
| OS << " }, {\n"; | ||
|
|
||
| // Emit all of the instruction's implicit uses and defs. | ||
| Timer.startTimer("Emit uses/defs"); | ||
| for (auto &List : ImplicitLists) { | ||
|
|
@@ -1028,6 +1031,17 @@ void InstrInfoEmitter::run(raw_ostream &OS) { | |
| OS << '\n'; | ||
| } | ||
|
|
||
| OS << " }, {\n"; | ||
|
|
||
| // Emit the padding. | ||
| OS << " 0\n"; | ||
|
|
||
| OS << " }, {\n"; | ||
|
|
||
| // Emit all of the operand info records. | ||
| Timer.startTimer("Emit operand info"); | ||
| EmitOperandInfo(OS, OperandInfoList); | ||
|
|
||
| OS << " }\n};\n\n"; | ||
|
|
||
| // Emit the array of instruction names. | ||
|
|
@@ -1291,11 +1305,11 @@ void InstrInfoEmitter::emitRecord( | |
|
|
||
| // Emit the operand info offset. | ||
| OperandInfoTy OperandInfo = GetOperandInfo(Inst); | ||
| OS << OperandInfoMap.find(OperandInfo)->second << ",\t"; | ||
| OS << Target.getName() << "OpInfoBase + " | ||
| << OperandInfoMap.find(OperandInfo)->second << ",\t"; | ||
|
|
||
| // Emit implicit operand base. | ||
| OS << Target.getName() << "ImpOpBase + " << EmittedLists[ImplicitOps] | ||
| << ",\t0"; | ||
| OS << EmittedLists[ImplicitOps] << ",\t0"; | ||
|
|
||
| // Emit all of the target independent flags... | ||
| if (Inst.isPreISelOpcode) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is mostly inherited from the existing code, but there seems to be a mix of
sizeofwithout brackets and with brackets. Perhaps we can tidy them all up?(This also applies to many of the lines below.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's how C works - you only need parentheses for sizeof a type, not for sizeof a variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I know syntactically it's OK -- but would it be more consistent to use brackets for them all? (Feel free to ignore me, I know this is just a nit.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. My personal preference is not to add the parens where they're not required.