[WebAssembly] Reapply r252858, with svn add for the new file.
[oota-llvm.git] / lib / Target / WebAssembly / WebAssemblyTargetMachine.cpp
index 18e2e5057db55a9556fc70f2757fc7c6a159815f..5aae71084744b10fbeab020fcadf49959d113545 100644 (file)
@@ -50,6 +50,12 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine(
                                : "e-p:32:32-i64:64-n32:64-S128",
                         TT, CPU, FS, Options, RM, CM, OL),
       TLOF(make_unique<WebAssemblyTargetObjectFile>()) {
+  // WebAssembly type-checks expressions, but a noreturn function with a return
+  // type that doesn't match the context will cause a check failure. So we lower
+  // LLVM 'unreachable' to ISD::TRAP and then lower that to WebAssembly's
+  // 'unreachable' expression which is meant for that case.
+  this->Options.TrapUnreachable = true;
+
   initAsmInfo();
 
   // We need a reducible CFG, so disable some optimizations which tend to
@@ -169,4 +175,5 @@ void WebAssemblyPassConfig::addPreSched2() {}
 
 void WebAssemblyPassConfig::addPreEmitPass() {
   addPass(createWebAssemblyCFGStackify());
+  addPass(createWebAssemblyRegNumbering());
 }