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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « include/llvm/MC/MCNaClExpander.h ('k') | lib/MC/MCParser/NaClAsmParser.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- MCNaClExpander.cpp ---------------------------------------*- C++ -*-===// 1 //===- MCNaClExpander.cpp ---------------------------------------*- C++ -*-===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This file implements the MCNaClExpander class. This is a base 10 // This file implements the MCNaClExpander class. This is a base
11 // class that encapsulates the expansion logic for MCInsts, and holds 11 // class that encapsulates the expansion logic for MCInsts, and holds
12 // state such as available scratch registers. 12 // state such as available scratch registers.
13 // 13 //
14 //===----------------------------------------------------------------------===// 14 //===----------------------------------------------------------------------===//
15 15
16 #include "llvm/MC/MCNaClExpander.h" 16 #include "llvm/MC/MCNaClExpander.h"
17 #include "llvm/MC/MCInst.h" 17 #include "llvm/MC/MCInst.h"
18 #include "llvm/MC/MCInstrInfo.h" 18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCRegisterInfo.h" 19 #include "llvm/MC/MCRegisterInfo.h"
20 20
21 namespace llvm { 21 namespace llvm {
22 22
23 void MCNaClExpander::Error(const MCInst &Inst, const char msg[]) { 23 void MCNaClExpander::Error(const MCInst &Inst, const char msg[]) {
24 Ctx.FatalError(Inst.getLoc(), msg); 24 Ctx.FatalError(Inst.getLoc(), msg);
25 } 25 }
26 26
27 void MCNaClExpander::pushScratchReg(unsigned Reg) { 27 bool MCNaClExpander::addScratchReg(unsigned Reg) {
28 if (!isValidScratchRegister(Reg))
29 return true;
28 ScratchRegs.push_back(Reg); 30 ScratchRegs.push_back(Reg);
31 return false;
29 } 32 }
30 33
31 unsigned MCNaClExpander::popScratchReg() { 34 void MCNaClExpander::invalidateScratchRegs(const MCInst &Inst) {
32 assert(!ScratchRegs.empty() && 35 // TODO(dschuff): There are arch-specific special cases where this fails,
33 "Trying to pop an empty scratch register stack"); 36 // e.g. xchg/cmpxchg
37 const MCInstrDesc &Desc = InstInfo->get(Inst.getOpcode());
38 for (auto I = ScratchRegs.begin(), E = ScratchRegs.end(); I != E; ++I) {
39 if (Desc.hasDefOfPhysReg(Inst, *I, *RegInfo))
40 I = ScratchRegs.erase(I);
41 }
42 }
34 43
35 unsigned Reg = ScratchRegs.back(); 44 void MCNaClExpander::clearScratchRegs() {
36 ScratchRegs.pop_back(); 45 ScratchRegs.clear();
37 return Reg;
38 } 46 }
39 47
40 unsigned MCNaClExpander::getScratchReg(int index) { 48 unsigned MCNaClExpander::getScratchReg(int index) {
41 int len = numScratchRegs(); 49 assert(index >= 0 && static_cast<unsigned>(index) < numScratchRegs());
42 return ScratchRegs[len - index - 1]; 50 return ScratchRegs[numScratchRegs() - index - 1];
43 } 51 }
44 52
45 unsigned MCNaClExpander::numScratchRegs() const { return ScratchRegs.size(); } 53 unsigned MCNaClExpander::numScratchRegs() const { return ScratchRegs.size(); }
46 54
47 bool MCNaClExpander::isPseudo(const MCInst &Inst) const { 55 bool MCNaClExpander::isPseudo(const MCInst &Inst) const {
48 return InstInfo->get(Inst.getOpcode()).isPseudo(); 56 return InstInfo->get(Inst.getOpcode()).isPseudo();
49 } 57 }
50 58
51 bool MCNaClExpander::mayAffectControlFlow(const MCInst &Inst) const { 59 bool MCNaClExpander::mayAffectControlFlow(const MCInst &Inst) const {
52 return InstInfo->get(Inst.getOpcode()).mayAffectControlFlow(Inst, *RegInfo); 60 return InstInfo->get(Inst.getOpcode()).mayAffectControlFlow(Inst, *RegInfo);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 void MCNaClExpander::replaceDefinitions(MCInst &Inst, unsigned RegOld, 107 void MCNaClExpander::replaceDefinitions(MCInst &Inst, unsigned RegOld,
100 unsigned RegNew) const { 108 unsigned RegNew) const {
101 const MCInstrDesc &Desc = InstInfo->get(Inst.getOpcode()); 109 const MCInstrDesc &Desc = InstInfo->get(Inst.getOpcode());
102 for (int i = 0; i < Desc.NumDefs; ++i) { 110 for (int i = 0; i < Desc.NumDefs; ++i) {
103 MCOperand &Op = Inst.getOperand(i); 111 MCOperand &Op = Inst.getOperand(i);
104 if (Op.isReg() && Op.getReg() == RegOld) 112 if (Op.isReg() && Op.getReg() == RegOld)
105 Op.setReg(RegNew); 113 Op.setReg(RegNew);
106 } 114 }
107 } 115 }
108 } 116 }
OLDNEW
« 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