[PATCH] D86088: Reduce the number of memory allocations when displaying a warning about clobbering reserved registers (NFC).
Momchil Velikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 7 09:05:15 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeb482afaf5bb: Reduce the number of memory allocations when displaying (authored by chill).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D86088/new/
https://reviews.llvm.org/D86088
Files:
llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Twine.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
@@ -547,22 +548,23 @@
EmitMSInlineAsmStr(AsmStr, MI, MMI, AP, LocCookie, OS);
// Emit warnings if we use reserved registers on the clobber list, as
- // that might give surprising results.
- std::vector<std::string> RestrRegs;
+ // that might lead to undefined behaviour.
+ SmallVector<Register, 8> RestrRegs;
+ const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
// Start with the first operand descriptor, and iterate over them.
for (unsigned I = InlineAsm::MIOp_FirstOperand, NumOps = MI->getNumOperands();
I < NumOps; ++I) {
const MachineOperand &MO = MI->getOperand(I);
- if (MO.isImm()) {
- unsigned Flags = MO.getImm();
- const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
- if (InlineAsm::getKind(Flags) == InlineAsm::Kind_Clobber &&
- !TRI->isAsmClobberable(*MF, MI->getOperand(I + 1).getReg())) {
- RestrRegs.push_back(TRI->getName(MI->getOperand(I + 1).getReg()));
- }
- // Skip to one before the next operand descriptor, if it exists.
- I += InlineAsm::getNumOperandRegisters(Flags);
+ if (!MO.isImm())
+ continue;
+ unsigned Flags = MO.getImm();
+ if (InlineAsm::getKind(Flags) == InlineAsm::Kind_Clobber) {
+ Register Reg = MI->getOperand(I + 1).getReg();
+ if (!TRI->isAsmClobberable(*MF, Reg))
+ RestrRegs.push_back(Reg);
}
+ // Skip to one before the next operand descriptor, if it exists.
+ I += InlineAsm::getNumOperandRegisters(Flags);
}
if (!RestrRegs.empty()) {
@@ -572,14 +574,15 @@
SrcMgr.getMemoryBuffer(BufNum)->getBuffer().begin());
std::string Msg = "inline asm clobber list contains reserved registers: ";
- for (auto I = RestrRegs.begin(), E = RestrRegs.end(); I != E; I++) {
+ for (auto I = RestrRegs.begin(), E = RestrRegs.end(); I != E; ++I) {
if(I != RestrRegs.begin())
Msg += ", ";
- Msg += *I;
+ Msg += TRI->getName(*I);
}
- std::string Note = "Reserved registers on the clobber list may not be "
- "preserved across the asm statement, and clobbering them may "
- "lead to undefined behaviour.";
+ const char *Note =
+ "Reserved registers on the clobber list may not be "
+ "preserved across the asm statement, and clobbering them may "
+ "lead to undefined behaviour.";
SrcMgr.PrintMessage(Loc, SourceMgr::DK_Warning, Msg);
SrcMgr.PrintMessage(Loc, SourceMgr::DK_Note, Note);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86088.290302.patch
Type: text/x-patch
Size: 3031 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200907/7ed7c043/attachment.bin>
More information about the llvm-commits
mailing list