Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Unified Diff: lib/MC/MCNaClExpander.cpp

Issue 1274223003: Auto-sandboxing: Switch to automatic scratch register invalidation (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: add flag to tests Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/llvm/MC/MCNaClExpander.h ('k') | lib/MC/MCParser/NaClAsmParser.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/MC/MCNaClExpander.cpp
diff --git a/lib/MC/MCNaClExpander.cpp b/lib/MC/MCNaClExpander.cpp
index 64a56cc45f07c29bc0207a4b831253494ffea5b3..90a073170a1b59b10f207a77388894e2a33323d8 100644
--- a/lib/MC/MCNaClExpander.cpp
+++ b/lib/MC/MCNaClExpander.cpp
@@ -24,22 +24,30 @@ void MCNaClExpander::Error(const MCInst &Inst, const char msg[]) {
Ctx.FatalError(Inst.getLoc(), msg);
}
-void MCNaClExpander::pushScratchReg(unsigned Reg) {
+bool MCNaClExpander::addScratchReg(unsigned Reg) {
+ if (!isValidScratchRegister(Reg))
+ return true;
ScratchRegs.push_back(Reg);
+ return false;
}
-unsigned MCNaClExpander::popScratchReg() {
- assert(!ScratchRegs.empty() &&
- "Trying to pop an empty scratch register stack");
+void MCNaClExpander::invalidateScratchRegs(const MCInst &Inst) {
+ // TODO(dschuff): There are arch-specific special cases where this fails,
+ // e.g. xchg/cmpxchg
+ const MCInstrDesc &Desc = InstInfo->get(Inst.getOpcode());
+ for (auto I = ScratchRegs.begin(), E = ScratchRegs.end(); I != E; ++I) {
+ if (Desc.hasDefOfPhysReg(Inst, *I, *RegInfo))
+ I = ScratchRegs.erase(I);
+ }
+}
- unsigned Reg = ScratchRegs.back();
- ScratchRegs.pop_back();
- return Reg;
+void MCNaClExpander::clearScratchRegs() {
+ ScratchRegs.clear();
}
unsigned MCNaClExpander::getScratchReg(int index) {
- int len = numScratchRegs();
- return ScratchRegs[len - index - 1];
+ assert(index >= 0 && static_cast<unsigned>(index) < numScratchRegs());
+ return ScratchRegs[numScratchRegs() - index - 1];
}
unsigned MCNaClExpander::numScratchRegs() const { return ScratchRegs.size(); }
« no previous file with comments | « include/llvm/MC/MCNaClExpander.h ('k') | lib/MC/MCParser/NaClAsmParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698