[llvm] r252975 - [WebAssembly] Introduce a new pseudo-operand for unused expression results.
Dan Gohman via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 12 16:21:05 PST 2015
Author: djg
Date: Thu Nov 12 18:21:05 2015
New Revision: 252975
URL: http://llvm.org/viewvc/llvm-project?rev=252975&view=rev
Log:
[WebAssembly] Introduce a new pseudo-operand for unused expression results.
Modified:
llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
llvm/trunk/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp
llvm/trunk/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h
llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegNumbering.cpp
llvm/trunk/test/CodeGen/WebAssembly/unused-argument.ll
Modified: llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp?rev=252975&r1=252974&r2=252975&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp Thu Nov 12 18:21:05 2015
@@ -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::WebAssemblyInstP
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(c
"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::printOperan
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())
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp?rev=252975&r1=252974&r2=252975&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp Thu Nov 12 18:21:05 2015
@@ -104,7 +104,9 @@ std::string WebAssemblyAsmPrinter::regTo
if (TargetRegisterInfo::isPhysicalRegister(RegNo))
return WebAssemblyInstPrinter::getRegisterName(RegNo);
- return utostr(MFI->getWAReg(RegNo));
+ unsigned WAReg = MFI->getWAReg(RegNo);
+ assert(WAReg != WebAssemblyFunctionInfo::UnusedReg);
+ return utostr(WAReg);
}
const char *WebAssemblyAsmPrinter::toString(MVT VT) const {
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp?rev=252975&r1=252974&r2=252975&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp Thu Nov 12 18:21:05 2015
@@ -17,3 +17,9 @@
using namespace llvm;
WebAssemblyFunctionInfo::~WebAssemblyFunctionInfo() {}
+
+void WebAssemblyFunctionInfo::initWARegs() {
+ assert(WARegs.empty());
+ unsigned Reg = UnusedReg;
+ WARegs.resize(MF.getRegInfo().getNumVirtRegs(), Reg);
+}
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h?rev=252975&r1=252974&r2=252975&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h Thu Nov 12 18:21:05 2015
@@ -43,11 +43,11 @@ public:
void addResult(MVT VT) { Results.push_back(VT); }
const std::vector<MVT> &getResults() const { return Results; }
- void initWARegs() {
- assert(WARegs.empty());
- WARegs.resize(MF.getRegInfo().getNumVirtRegs(), -1u);
- }
+ static const unsigned UnusedReg = -1u;
+
+ void initWARegs();
void setWAReg(unsigned VReg, unsigned WAReg) {
+ assert(WAReg != UnusedReg);
WARegs[TargetRegisterInfo::virtReg2Index(VReg)] = WAReg;
}
unsigned getWAReg(unsigned VReg) const {
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegNumbering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegNumbering.cpp?rev=252975&r1=252974&r2=252975&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegNumbering.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegNumbering.cpp Thu Nov 12 18:21:05 2015
@@ -90,7 +90,7 @@ bool WebAssemblyRegNumbering::runOnMachi
// Skip unused registers.
if (MRI.use_empty(VReg))
continue;
- if (MFI.getWAReg(VReg) == -1u)
+ if (MFI.getWAReg(VReg) == WebAssemblyFunctionInfo::UnusedReg)
MFI.setWAReg(VReg, NumArgRegs + CurReg++);
}
Modified: llvm/trunk/test/CodeGen/WebAssembly/unused-argument.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/unused-argument.ll?rev=252975&r1=252974&r2=252975&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/unused-argument.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/unused-argument.ll Thu Nov 12 18:21:05 2015
@@ -24,3 +24,12 @@ define i32 @unused_first(i32 %x, i32 %y)
define i32 @unused_second(i32 %x, i32 %y) {
ret i32 %x
}
+
+; CHECK-LABEL: call_something:
+; CHECK-NEXT: call return_something, $discard{{$}}
+; CHECK-NEXT: return{{$}}
+declare i32 @return_something()
+define void @call_something() {
+ call i32 @return_something()
+ ret void
+}
More information about the llvm-commits
mailing list