diff options
author | Dan Gohman <dan433584@gmail.com> | 2015-11-13 00:21:05 +0000 |
---|---|---|
committer | Dan Gohman <dan433584@gmail.com> | 2015-11-13 00:21:05 +0000 |
commit | 058fce5435464631a40cd8e92e347296c49eb46a (patch) | |
tree | f805bc42d5b206e2864c87625d010aa1189b70e2 /llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp | |
parent | cbc56baae6bf7cd948a4fe101290b849797b5dad (diff) | |
download | bcm5719-llvm-058fce5435464631a40cd8e92e347296c49eb46a.tar.gz bcm5719-llvm-058fce5435464631a40cd8e92e347296c49eb46a.zip |
[WebAssembly] Introduce a new pseudo-operand for unused expression results.
llvm-svn: 252975
Diffstat (limited to 'llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp b/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp index cc77f56dce3..d3c4861e1d6 100644 --- a/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp +++ b/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp @@ -14,6 +14,7 @@ #include "InstPrinter/WebAssemblyInstPrinter.h" #include "WebAssembly.h" +#include "WebAssemblyMachineFunctionInfo.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" #include "llvm/MC/MCInstrInfo.h" @@ -36,6 +37,7 @@ WebAssemblyInstPrinter::WebAssemblyInstPrinter(const MCAsmInfo &MAI, void WebAssemblyInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { + assert(RegNo != WebAssemblyFunctionInfo::UnusedReg); // FIXME: Revisit whether we actually print the get_local explicitly. OS << "(get_local " << RegNo << ")"; } @@ -60,9 +62,14 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, raw_ostream &OS, "Instructions with multiple result values not implemented"); // FIXME: Revisit whether we actually print the set_local explicitly. - if (NumDefs != 0) - OS << "\n" - "\t" "set_local " << MI->getOperand(0).getReg() << ", $pop"; + if (NumDefs != 0) { + unsigned WAReg = MI->getOperand(0).getReg(); + // Only print the set_local if the register is used. + // TODO: Revisit this once the spec explains what should happen here. + if (WAReg != WebAssemblyFunctionInfo::UnusedReg) + OS << "\n" + "\t" "set_local " << WAReg << ", $pop"; + } } static std::string toString(const APFloat &FP) { @@ -86,10 +93,14 @@ void WebAssemblyInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) { const MCOperand &Op = MI->getOperand(OpNo); if (Op.isReg()) { - if (OpNo < MII.get(MI->getOpcode()).getNumDefs()) - O << "$push"; - else + if (OpNo >= MII.get(MI->getOpcode()).getNumDefs()) printRegName(O, Op.getReg()); + else { + if (Op.getReg() != WebAssemblyFunctionInfo::UnusedReg) + O << "$push"; + else + O << "$discard"; + } } else if (Op.isImm()) O << Op.getImm(); else if (Op.isFPImm()) |