diff options
author | Dan Gohman <dan433584@gmail.com> | 2017-02-24 23:46:05 +0000 |
---|---|---|
committer | Dan Gohman <dan433584@gmail.com> | 2017-02-24 23:46:05 +0000 |
commit | 82607f56bd25d8c260e6d9cf8267371ea5e410c7 (patch) | |
tree | 06d5be4a6612484abe16501586fbb8cf981f48fd /llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp | |
parent | 8d543e2741c1fac6b002fb87e47dfc0b8ee0c212 (diff) | |
download | llvm-82607f56bd25d8c260e6d9cf8267371ea5e410c7.zip llvm-82607f56bd25d8c260e6d9cf8267371ea5e410c7.tar.gz llvm-82607f56bd25d8c260e6d9cf8267371ea5e410c7.tar.bz2 |
[WebAssembly] Add support for using a wasm global for the stack pointer.
This replaces the __stack_pointer variable which was allocated in linear
memory.
llvm-svn: 296201
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp index 32ee09e..57d4547 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp @@ -30,6 +30,7 @@ #include "llvm/CodeGen/MachineBlockFrequencyInfo.h" #include "llvm/CodeGen/MachineDominators.h" #include "llvm/CodeGen/MachineInstrBuilder.h" +#include "llvm/CodeGen/MachineModuleInfoImpls.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/Passes.h" #include "llvm/Support/Debug.h" @@ -152,7 +153,7 @@ static void QueryCallee(const MachineInstr &MI, unsigned CalleeOpNo, bool &Read, } // Determine whether MI reads memory, writes memory, has side effects, -// and/or uses the __stack_pointer value. +// and/or uses the stack pointer value. static void Query(const MachineInstr &MI, AliasAnalysis &AA, bool &Read, bool &Write, bool &Effects, bool &StackPointer) { assert(!MI.isPosition()); @@ -169,15 +170,28 @@ static void Query(const MachineInstr &MI, AliasAnalysis &AA, bool &Read, if (MI.mayStore()) { Write = true; - // Check for stores to __stack_pointer. - for (auto MMO : MI.memoperands()) { - const MachinePointerInfo &MPI = MMO->getPointerInfo(); - if (MPI.V.is<const PseudoSourceValue *>()) { - auto PSV = MPI.V.get<const PseudoSourceValue *>(); - if (const ExternalSymbolPseudoSourceValue *EPSV = - dyn_cast<ExternalSymbolPseudoSourceValue>(PSV)) - if (StringRef(EPSV->getSymbol()) == "__stack_pointer") - StackPointer = true; + const MachineFunction &MF = *MI.getParent()->getParent(); + if (MF.getSubtarget<WebAssemblySubtarget>() + .getTargetTriple().isOSBinFormatELF()) { + // Check for stores to __stack_pointer. + for (auto MMO : MI.memoperands()) { + const MachinePointerInfo &MPI = MMO->getPointerInfo(); + if (MPI.V.is<const PseudoSourceValue *>()) { + auto PSV = MPI.V.get<const PseudoSourceValue *>(); + if (const ExternalSymbolPseudoSourceValue *EPSV = + dyn_cast<ExternalSymbolPseudoSourceValue>(PSV)) + if (StringRef(EPSV->getSymbol()) == "__stack_pointer") + StackPointer = true; + } + } + } else { + // Check for sets of the stack pointer. + const MachineModuleInfoWasm &MMIW = + MF.getMMI().getObjFileInfo<MachineModuleInfoWasm>(); + if ((MI.getOpcode() == WebAssembly::SET_LOCAL_I32 || + MI.getOpcode() == WebAssembly::SET_LOCAL_I64) && + MI.getOperand(0).getImm() == MMIW.getStackPointerGlobal()) { + StackPointer = true; } } } else if (MI.hasOrderedMemoryRef()) { |