Skip to content

[MC] Optimize loops in MC. #98114

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

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions llvm/lib/MC/MCParser/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6116,8 +6116,8 @@ bool AsmParser::parseMSInlineAsm(
const char *AsmStart = ASMString.begin();
const char *AsmEnd = ASMString.end();
array_pod_sort(AsmStrRewrites.begin(), AsmStrRewrites.end(), rewritesSort);
for (auto it = AsmStrRewrites.begin(); it != AsmStrRewrites.end(); ++it) {
const AsmRewrite &AR = *it;
for (auto I = AsmStrRewrites.begin(), E = AsmStrRewrites.end(); I != E; ++I) {
const AsmRewrite &AR = *I;
// Check if this has already been covered by another rewrite...
if (AR.Done)
continue;
Expand Down Expand Up @@ -6160,7 +6160,7 @@ bool AsmParser::parseMSInlineAsm(
SMLoc OffsetLoc = SMLoc::getFromPointer(AR.IntelExp.OffsetName.data());
size_t OffsetLen = OffsetName.size();
auto rewrite_it = std::find_if(
it, AsmStrRewrites.end(), [&](const AsmRewrite &FusingAR) {
I, AsmStrRewrites.end(), [&](const AsmRewrite &FusingAR) {
return FusingAR.Loc == OffsetLoc && FusingAR.Len == OffsetLen &&
(FusingAR.Kind == AOK_Input ||
FusingAR.Kind == AOK_CallInput);
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/MC/MCParser/MasmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7474,8 +7474,8 @@ bool MasmParser::parseMSInlineAsm(
const char *AsmStart = ASMString.begin();
const char *AsmEnd = ASMString.end();
array_pod_sort(AsmStrRewrites.begin(), AsmStrRewrites.end(), rewritesSort);
for (auto it = AsmStrRewrites.begin(); it != AsmStrRewrites.end(); ++it) {
const AsmRewrite &AR = *it;
for (auto I = AsmStrRewrites.begin(), E = AsmStrRewrites.end(); I != E; ++I) {
const AsmRewrite &AR = *I;
// Check if this has already been covered by another rewrite...
if (AR.Done)
continue;
Expand Down Expand Up @@ -7518,7 +7518,7 @@ bool MasmParser::parseMSInlineAsm(
SMLoc OffsetLoc = SMLoc::getFromPointer(AR.IntelExp.OffsetName.data());
size_t OffsetLen = OffsetName.size();
auto rewrite_it = std::find_if(
it, AsmStrRewrites.end(), [&](const AsmRewrite &FusingAR) {
I, AsmStrRewrites.end(), [&](const AsmRewrite &FusingAR) {
return FusingAR.Loc == OffsetLoc && FusingAR.Len == OffsetLen &&
(FusingAR.Kind == AOK_Input ||
FusingAR.Kind == AOK_CallInput);
Expand Down
19 changes: 8 additions & 11 deletions llvm/lib/MC/XCOFFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1385,23 +1385,21 @@ void XCOFFObjectWriter::addExceptionEntry(
unsigned XCOFFObjectWriter::getExceptionSectionSize() {
unsigned EntryNum = 0;

for (auto it = ExceptionSection.ExceptionTable.begin();
it != ExceptionSection.ExceptionTable.end(); ++it)
for (const auto &TableEntry : ExceptionSection.ExceptionTable)
// The size() gets +1 to account for the initial entry containing the
// symbol table index.
EntryNum += it->second.Entries.size() + 1;
EntryNum += TableEntry.second.Entries.size() + 1;

return EntryNum * (is64Bit() ? XCOFF::ExceptionSectionEntrySize64
: XCOFF::ExceptionSectionEntrySize32);
}

unsigned XCOFFObjectWriter::getExceptionOffset(const MCSymbol *Symbol) {
unsigned EntryNum = 0;
for (auto it = ExceptionSection.ExceptionTable.begin();
it != ExceptionSection.ExceptionTable.end(); ++it) {
if (Symbol == it->second.FunctionSymbol)
for (const auto &TableEntry : ExceptionSection.ExceptionTable) {
if (Symbol == TableEntry.second.FunctionSymbol)
break;
EntryNum += it->second.Entries.size() + 1;
EntryNum += TableEntry.second.Entries.size() + 1;
}
return EntryNum * (is64Bit() ? XCOFF::ExceptionSectionEntrySize64
: XCOFF::ExceptionSectionEntrySize32);
Expand Down Expand Up @@ -1667,17 +1665,16 @@ void XCOFFObjectWriter::writeSectionForDwarfSectionEntry(
void XCOFFObjectWriter::writeSectionForExceptionSectionEntry(
const MCAssembler &Asm, ExceptionSectionEntry &ExceptionEntry,
uint64_t &CurrentAddressLocation) {
for (auto it = ExceptionEntry.ExceptionTable.begin();
it != ExceptionEntry.ExceptionTable.end(); it++) {
for (const auto &TableEntry : ExceptionEntry.ExceptionTable) {
// For every symbol that has exception entries, you must start the entries
// with an initial symbol table index entry
W.write<uint32_t>(SymbolIndexMap[it->second.FunctionSymbol]);
W.write<uint32_t>(SymbolIndexMap[TableEntry.second.FunctionSymbol]);
if (is64Bit()) {
// 4-byte padding on 64-bit.
W.OS.write_zeros(4);
}
W.OS.write_zeros(2);
for (auto &TrapEntry : it->second.Entries) {
for (auto &TrapEntry : TableEntry.second.Entries) {
writeWord(TrapEntry.TrapAddress);
W.write<uint8_t>(TrapEntry.Lang);
W.write<uint8_t>(TrapEntry.Reason);
Expand Down
Loading