Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,11 @@ MCSymbol *WebAssemblyAsmPrinter::getOrCreateWasmSymbol(StringRef Name) {
// Clang-provided symbols.
if (Name == "__stack_pointer" || Name == "__tls_base" ||
Name == "__memory_base" || Name == "__table_base" ||
Name == "__tls_size" || Name == "__tls_align") {
Name == "__tls_size" || Name == "__tls_align" ||
Name == "__stack_chk_guard") {
bool Mutable =
Name == "__stack_pointer" || Name == "__tls_base";
Name == "__stack_pointer" || Name == "__tls_base" ||
Name == "__stack_chk_guard";
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL);
WasmSym->setGlobalType(wasm::WasmGlobalType{
uint8_t(Subtarget.hasAddr64() ? wasm::WASM_TYPE_I64
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3695,3 +3695,7 @@ WebAssemblyTargetLowering::PerformDAGCombine(SDNode *N,
return performMulCombine(N, DCI);
}
}

bool WebAssemblyTargetLowering::useLoadStackGuardNode(const Module &M) const {
return true;
}
2 changes: 2 additions & 0 deletions llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class WebAssemblyTargetLowering final : public TargetLowering {
MVT getPointerTy(const DataLayout &DL, uint32_t AS = 0) const override;
MVT getPointerMemTy(const DataLayout &DL, uint32_t AS = 0) const override;

bool useLoadStackGuardNode(const Module &M) const override;

private:
/// Keep a pointer to the WebAssemblySubtarget around so that we can make the
/// right decision when generating code for different targets.
Expand Down
21 changes: 20 additions & 1 deletion llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ WebAssemblyInstrInfo::WebAssemblyInstrInfo(const WebAssemblySubtarget &STI)
: WebAssemblyGenInstrInfo(STI, RI, WebAssembly::ADJCALLSTACKDOWN,
WebAssembly::ADJCALLSTACKUP,
WebAssembly::CATCHRET),
RI(STI.getTargetTriple()) {}
Subtarget(STI), RI(STI.getTargetTriple()) {}

bool WebAssemblyInstrInfo::isReMaterializableImpl(
const MachineInstr &MI) const {
Expand Down Expand Up @@ -233,3 +233,22 @@ bool WebAssemblyInstrInfo::isExplicitTargetIndexDef(const MachineInstr &MI,
}
return false;
}

bool WebAssemblyInstrInfo::expandPostRAPseudo(MachineInstr &MI) const {
if(MI.getOpcode() == TargetOpcode::LOAD_STACK_GUARD) {
MachineFunction *MF = MI.getParent()->getParent();
const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo();
const char *BaseName = MF->createExternalSymbolName("__stack_chk_guard");

MachineInstrBuilder MIB = BuildMI(*MF, MI.getDebugLoc(),
TII->get(Subtarget.hasAddr64()
? WebAssembly::GLOBAL_GET_I64
: WebAssembly::GLOBAL_GET_I32))
.addDef(MI.getOperand(0).getReg())
.addExternalSymbol(BaseName);
MI.getParent()->insert(MI.getIterator(), MIB.getInstr());
MI.eraseFromParent();
return true;
}
return false;
}
3 changes: 3 additions & 0 deletions llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace llvm {
class WebAssemblySubtarget;

class WebAssemblyInstrInfo final : public WebAssemblyGenInstrInfo {
const WebAssemblySubtarget &Subtarget;
const WebAssemblyRegisterInfo RI;

public:
Expand Down Expand Up @@ -67,6 +68,8 @@ class WebAssemblyInstrInfo final : public WebAssemblyGenInstrInfo {

bool isExplicitTargetIndexDef(const MachineInstr &MI, int &Index,
int64_t &Offset) const override;

bool expandPostRAPseudo(MachineInstr &MI) const override;
};

} // end namespace llvm
Expand Down