[llvm] r259349 - WebAssembly NFC: simplify control flow
JF Bastien via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 1 02:46:16 PST 2016
Author: jfb
Date: Mon Feb 1 04:46:16 2016
New Revision: 259349
URL: http://llvm.org/viewvc/llvm-project?rev=259349&view=rev
Log:
WebAssembly NFC: simplify control flow
This should now be easier to read.
Modified:
llvm/trunk/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp?rev=259349&r1=259348&r2=259349&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp Mon Feb 1 04:46:16 2016
@@ -104,6 +104,63 @@ static bool ReplaceDominatedUses(Machine
return Changed;
}
+static bool optimizeStore(MachineBasicBlock &MBB, MachineInstr &MI,
+ const MachineRegisterInfo &MRI,
+ MachineDominatorTree &MDT) {
+ const auto &Stored = MI.getOperand(WebAssembly::StoreValueOperandNo);
+ switch (Stored.getType()) {
+ case MachineOperand::MO_Register: {
+ unsigned ToReg = MI.getOperand(0).getReg();
+ unsigned FromReg = Stored.getReg();
+ return ReplaceDominatedUses(MBB, MI, FromReg, ToReg, MRI, MDT);
+ }
+ case MachineOperand::MO_FrameIndex:
+ // TODO: optimize.
+ return false;
+ default:
+ report_fatal_error("Store results: store not consuming reg or frame index");
+ }
+}
+
+static bool optimizeCall(MachineBasicBlock &MBB, MachineInstr &MI,
+ const MachineRegisterInfo &MRI,
+ MachineDominatorTree &MDT,
+ const WebAssemblyTargetLowering &TLI,
+ const TargetLibraryInfo &LibInfo) {
+ MachineOperand &Op1 = MI.getOperand(1);
+ if (!Op1.isSymbol())
+ return false;
+
+ StringRef Name(Op1.getSymbolName());
+ bool callReturnsInput = Name == TLI.getLibcallName(RTLIB::MEMCPY) ||
+ Name == TLI.getLibcallName(RTLIB::MEMMOVE) ||
+ Name == TLI.getLibcallName(RTLIB::MEMSET);
+ if (!callReturnsInput)
+ return false;
+
+ LibFunc::Func Func;
+ if (!LibInfo.getLibFunc(Name, Func))
+ return false;
+
+ const auto &Op2 = MI.getOperand(2);
+ switch (Op2.getType()) {
+ case MachineOperand::MO_Register: {
+ unsigned FromReg = Op2.getReg();
+ unsigned ToReg = MI.getOperand(0).getReg();
+ if (MRI.getRegClass(FromReg) != MRI.getRegClass(ToReg))
+ report_fatal_error("Store results: call to builtin function with wrong "
+ "signature, from/to mismatch");
+ return ReplaceDominatedUses(MBB, MI, FromReg, ToReg, MRI, MDT);
+ }
+ case MachineOperand::MO_FrameIndex:
+ // TODO: optimize.
+ return false;
+ default:
+ report_fatal_error("Store results: call to builtin function with wrong "
+ "signature, not consuming reg or frame index");
+ }
+}
+
bool WebAssemblyStoreResults::runOnMachineFunction(MachineFunction &MF) {
DEBUG({
dbgs() << "********** Store Results **********\n"
@@ -114,7 +171,7 @@ bool WebAssemblyStoreResults::runOnMachi
MachineDominatorTree &MDT = getAnalysis<MachineDominatorTree>();
const WebAssemblyTargetLowering &TLI =
*MF.getSubtarget<WebAssemblySubtarget>().getTargetLowering();
- auto &LibInfo = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
+ const auto &LibInfo = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
bool Changed = false;
assert(MRI.isSSA() && "StoreResults depends on SSA form");
@@ -133,50 +190,13 @@ bool WebAssemblyStoreResults::runOnMachi
case WebAssembly::STORE_F32:
case WebAssembly::STORE_F64:
case WebAssembly::STORE_I32:
- case WebAssembly::STORE_I64: {
- const auto &Stored = MI.getOperand(WebAssembly::StoreValueOperandNo);
- if (Stored.isReg()) {
- unsigned ToReg = MI.getOperand(0).getReg();
- unsigned FromReg = Stored.getReg();
- Changed |= ReplaceDominatedUses(MBB, MI, FromReg, ToReg, MRI, MDT);
- } else if (Stored.isFI()) {
- break;
- } else {
- report_fatal_error(
- "Store results: store not consuming reg or frame index");
- }
+ case WebAssembly::STORE_I64:
+ Changed |= optimizeStore(MBB, MI, MRI, MDT);
break;
- }
case WebAssembly::CALL_I32:
- case WebAssembly::CALL_I64: {
- MachineOperand &Op1 = MI.getOperand(1);
- if (Op1.isSymbol()) {
- StringRef Name(Op1.getSymbolName());
- if (Name == TLI.getLibcallName(RTLIB::MEMCPY) ||
- Name == TLI.getLibcallName(RTLIB::MEMMOVE) ||
- Name == TLI.getLibcallName(RTLIB::MEMSET)) {
- LibFunc::Func Func;
- if (LibInfo.getLibFunc(Name, Func)) {
- const auto &Op2 = MI.getOperand(2);
- if (Op2.isReg()) {
- unsigned FromReg = Op2.getReg();
- unsigned ToReg = MI.getOperand(0).getReg();
- if (MRI.getRegClass(FromReg) != MRI.getRegClass(ToReg))
- report_fatal_error("Store results: call to builtin function "
- "with wrong signature, from/to mismatch");
- Changed |=
- ReplaceDominatedUses(MBB, MI, FromReg, ToReg, MRI, MDT);
- } else if (Op2.isFI()) {
- break;
- } else {
- report_fatal_error("Store results: call to builtin function "
- "with wrong signature, not consuming reg or "
- "frame index");
- }
- }
- }
- }
- }
+ case WebAssembly::CALL_I64:
+ Changed |= optimizeCall(MBB, MI, MRI, MDT, TLI, LibInfo);
+ break;
}
}
More information about the llvm-commits
mailing list