[PATCH] D115893: [WebAssembly] Support clang -fwasm-exceptions for bitcode

2021-12-16 Thread Derek Schuff via Phabricator via cfe-commits
dschuff added inline comments.



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp:37
 
-// Emscripten's asm.js-style exception handling
-cl::opt
-WasmEnableEmEH("enable-emscripten-cxx-exceptions",
-   cl::desc("WebAssembly Emscripten-style exception handling"),
-   cl::init(false));
-
-// Emscripten's asm.js-style setjmp/longjmp handling
-cl::opt WasmEnableEmSjLj(
-"enable-emscripten-sjlj",
-cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"),
-cl::init(false));
-
-// Exception handling using wasm EH instructions
-cl::opt WasmEnableEH("wasm-enable-eh",
-   cl::desc("WebAssembly exception handling"),
-   cl::init(false));
-
-// setjmp/longjmp handling using wasm EH instrutions
-cl::opt WasmEnableSjLj("wasm-enable-sjlj",
- cl::desc("WebAssembly setjmp/longjmp handling"),
- cl::init(false));
+extern cl::opt WasmEnableEmEH;   // asm.js-style EH
+extern cl::opt WasmEnableEmSjLj; // asm.js-style SjLJ

aheejin wrote:
> dschuff wrote:
> > We could put these declarations in WebAssemblyUtilities.h; then they 
> > wouldn't have to be duplicated here and in WebAssemblyMCAsmInfo.cpp
> Done. But as a result they are not within `WebAssembly` namespace, which I 
> think is actually better because we have been cluttering the `llvm` namespace 
> so far. And I needed to attach `WebAssembly::` to all the usages of these 
> variables in other places. In this file I just used `using WebAssembly::***`, 
> because there are too many usages of these options.
 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115893/new/

https://reviews.llvm.org/D115893

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115893: [WebAssembly] Support clang -fwasm-exceptions for bitcode

2021-12-16 Thread Heejin Ahn via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4625b848793f: [WebAssembly] Support clang -fwasm-exceptions 
for bitcode (authored by aheejin).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115893/new/

https://reviews.llvm.org/D115893

Files:
  clang/test/CodeGen/WebAssembly/wasm-eh.ll
  llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h
  llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Index: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -14,6 +14,7 @@
 #include "WebAssemblyTargetMachine.h"
 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
 #include "TargetInfo/WebAssemblyTargetInfo.h"
+#include "Utils/WebAssemblyUtilities.h"
 #include "WebAssembly.h"
 #include "WebAssemblyMachineFunctionInfo.h"
 #include "WebAssemblyTargetObjectFile.h"
@@ -24,6 +25,7 @@
 #include "llvm/CodeGen/RegAllocRegistry.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/IR/Function.h"
+#include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Transforms/Scalar.h"
@@ -33,28 +35,6 @@
 
 #define DEBUG_TYPE "wasm"
 
-// Emscripten's asm.js-style exception handling
-cl::opt
-WasmEnableEmEH("enable-emscripten-cxx-exceptions",
-   cl::desc("WebAssembly Emscripten-style exception handling"),
-   cl::init(false));
-
-// Emscripten's asm.js-style setjmp/longjmp handling
-cl::opt WasmEnableEmSjLj(
-"enable-emscripten-sjlj",
-cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"),
-cl::init(false));
-
-// Exception handling using wasm EH instructions
-cl::opt WasmEnableEH("wasm-enable-eh",
-   cl::desc("WebAssembly exception handling"),
-   cl::init(false));
-
-// setjmp/longjmp handling using wasm EH instrutions
-cl::opt WasmEnableSjLj("wasm-enable-sjlj",
- cl::desc("WebAssembly setjmp/longjmp handling"),
- cl::init(false));
-
 // A command-line option to keep implicit locals
 // for the purpose of testing with lit/llc ONLY.
 // This produces output which is not valid WebAssembly, and is not supported
@@ -368,7 +348,23 @@
   return nullptr; // No reg alloc
 }
 
-static void basicCheckForEHAndSjLj(const TargetMachine *TM) {
+using WebAssembly::WasmEnableEH;
+using WebAssembly::WasmEnableEmEH;
+using WebAssembly::WasmEnableEmSjLj;
+using WebAssembly::WasmEnableSjLj;
+
+static void basicCheckForEHAndSjLj(TargetMachine *TM) {
+  // Before checking, we make sure TargetOptions.ExceptionModel is the same as
+  // MCAsmInfo.ExceptionsType. Normally these have to be the same, because clang
+  // stores the exception model info in LangOptions, which is later transferred
+  // to TargetOptions and MCAsmInfo. But when clang compiles bitcode directly,
+  // clang's LangOptions is not used and thus the exception model info is not
+  // correctly transferred to TargetOptions and MCAsmInfo, so we make sure we
+  // have the correct exception model in in WebAssemblyMCAsmInfo constructor.
+  // But in this case TargetOptions is still not updated, so we make sure they
+  // are the same.
+  TM->Options.ExceptionModel = TM->getMCAsmInfo()->getExceptionHandlingType();
+
   // Basic Correctness checking related to -exception-model
   if (TM->Options.ExceptionModel != ExceptionHandling::None &&
   TM->Options.ExceptionModel != ExceptionHandling::Wasm)
Index: llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
@@ -40,9 +40,6 @@
" instruction output for test purposes only."),
   cl::init(false));
 
-extern cl::opt WasmEnableEmEH;
-extern cl::opt WasmEnableEmSjLj;
-
 static void removeRegisterOperands(const MachineInstr *MI, MCInst );
 
 MCSymbol *
@@ -112,7 +109,8 @@
 
   bool InvokeDetected = false;
   auto *WasmSym = Printer.getMCSymbolForFunction(
-  F, WasmEnableEmEH || WasmEnableEmSjLj, Signature.get(), InvokeDetected);
+  F, WebAssembly::WasmEnableEmEH || WebAssembly::WasmEnableEmSjLj,
+  Signature.get(), InvokeDetected);
   WasmSym->setSignature(Signature.get());
   

[PATCH] D115893: [WebAssembly] Support clang -fwasm-exceptions for bitcode

2021-12-16 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin updated this revision to Diff 395025.
aheejin added a comment.

Remove an unnecessary include


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115893/new/

https://reviews.llvm.org/D115893

Files:
  clang/test/CodeGen/WebAssembly/wasm-eh.ll
  llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h
  llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Index: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -14,6 +14,7 @@
 #include "WebAssemblyTargetMachine.h"
 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
 #include "TargetInfo/WebAssemblyTargetInfo.h"
+#include "Utils/WebAssemblyUtilities.h"
 #include "WebAssembly.h"
 #include "WebAssemblyMachineFunctionInfo.h"
 #include "WebAssemblyTargetObjectFile.h"
@@ -24,6 +25,7 @@
 #include "llvm/CodeGen/RegAllocRegistry.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/IR/Function.h"
+#include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Transforms/Scalar.h"
@@ -33,28 +35,6 @@
 
 #define DEBUG_TYPE "wasm"
 
-// Emscripten's asm.js-style exception handling
-cl::opt
-WasmEnableEmEH("enable-emscripten-cxx-exceptions",
-   cl::desc("WebAssembly Emscripten-style exception handling"),
-   cl::init(false));
-
-// Emscripten's asm.js-style setjmp/longjmp handling
-cl::opt WasmEnableEmSjLj(
-"enable-emscripten-sjlj",
-cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"),
-cl::init(false));
-
-// Exception handling using wasm EH instructions
-cl::opt WasmEnableEH("wasm-enable-eh",
-   cl::desc("WebAssembly exception handling"),
-   cl::init(false));
-
-// setjmp/longjmp handling using wasm EH instrutions
-cl::opt WasmEnableSjLj("wasm-enable-sjlj",
- cl::desc("WebAssembly setjmp/longjmp handling"),
- cl::init(false));
-
 // A command-line option to keep implicit locals
 // for the purpose of testing with lit/llc ONLY.
 // This produces output which is not valid WebAssembly, and is not supported
@@ -368,7 +348,23 @@
   return nullptr; // No reg alloc
 }
 
-static void basicCheckForEHAndSjLj(const TargetMachine *TM) {
+using WebAssembly::WasmEnableEH;
+using WebAssembly::WasmEnableEmEH;
+using WebAssembly::WasmEnableEmSjLj;
+using WebAssembly::WasmEnableSjLj;
+
+static void basicCheckForEHAndSjLj(TargetMachine *TM) {
+  // Before checking, we make sure TargetOptions.ExceptionModel is the same as
+  // MCAsmInfo.ExceptionsType. Normally these have to be the same, because clang
+  // stores the exception model info in LangOptions, which is later transferred
+  // to TargetOptions and MCAsmInfo. But when clang compiles bitcode directly,
+  // clang's LangOptions is not used and thus the exception model info is not
+  // correctly transferred to TargetOptions and MCAsmInfo, so we make sure we
+  // have the correct exception model in in WebAssemblyMCAsmInfo constructor.
+  // But in this case TargetOptions is still not updated, so we make sure they
+  // are the same.
+  TM->Options.ExceptionModel = TM->getMCAsmInfo()->getExceptionHandlingType();
+
   // Basic Correctness checking related to -exception-model
   if (TM->Options.ExceptionModel != ExceptionHandling::None &&
   TM->Options.ExceptionModel != ExceptionHandling::Wasm)
Index: llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
@@ -40,9 +40,6 @@
" instruction output for test purposes only."),
   cl::init(false));
 
-extern cl::opt WasmEnableEmEH;
-extern cl::opt WasmEnableEmSjLj;
-
 static void removeRegisterOperands(const MachineInstr *MI, MCInst );
 
 MCSymbol *
@@ -112,7 +109,8 @@
 
   bool InvokeDetected = false;
   auto *WasmSym = Printer.getMCSymbolForFunction(
-  F, WasmEnableEmEH || WasmEnableEmSjLj, Signature.get(), InvokeDetected);
+  F, WebAssembly::WasmEnableEmEH || WebAssembly::WasmEnableEmSjLj,
+  Signature.get(), InvokeDetected);
   WasmSym->setSignature(Signature.get());
   Printer.addSignature(std::move(Signature));
   WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp

[PATCH] D115893: [WebAssembly] Support clang -fwasm-exceptions for bitcode

2021-12-16 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin added inline comments.



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp:37
 
-// Emscripten's asm.js-style exception handling
-cl::opt
-WasmEnableEmEH("enable-emscripten-cxx-exceptions",
-   cl::desc("WebAssembly Emscripten-style exception handling"),
-   cl::init(false));
-
-// Emscripten's asm.js-style setjmp/longjmp handling
-cl::opt WasmEnableEmSjLj(
-"enable-emscripten-sjlj",
-cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"),
-cl::init(false));
-
-// Exception handling using wasm EH instructions
-cl::opt WasmEnableEH("wasm-enable-eh",
-   cl::desc("WebAssembly exception handling"),
-   cl::init(false));
-
-// setjmp/longjmp handling using wasm EH instrutions
-cl::opt WasmEnableSjLj("wasm-enable-sjlj",
- cl::desc("WebAssembly setjmp/longjmp handling"),
- cl::init(false));
+extern cl::opt WasmEnableEmEH;   // asm.js-style EH
+extern cl::opt WasmEnableEmSjLj; // asm.js-style SjLJ

dschuff wrote:
> We could put these declarations in WebAssemblyUtilities.h; then they wouldn't 
> have to be duplicated here and in WebAssemblyMCAsmInfo.cpp
Done. But as a result they are not within `WebAssembly` namespace, which I 
think is actually better because we have been cluttering the `llvm` namespace 
so far. And I needed to attach `WebAssembly::` to all the usages of these 
variables in other places. In this file I just used `using WebAssembly::***`, 
because there are too many usages of these options.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115893/new/

https://reviews.llvm.org/D115893

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115893: [WebAssembly] Support clang -fwasm-exceptions for bitcode

2021-12-16 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin updated this revision to Diff 395024.
aheejin marked 2 inline comments as done.
aheejin added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115893/new/

https://reviews.llvm.org/D115893

Files:
  clang/test/CodeGen/WebAssembly/wasm-eh.ll
  llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h
  llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Index: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -14,6 +14,7 @@
 #include "WebAssemblyTargetMachine.h"
 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
 #include "TargetInfo/WebAssemblyTargetInfo.h"
+#include "Utils/WebAssemblyUtilities.h"
 #include "WebAssembly.h"
 #include "WebAssemblyMachineFunctionInfo.h"
 #include "WebAssemblyTargetObjectFile.h"
@@ -24,6 +25,7 @@
 #include "llvm/CodeGen/RegAllocRegistry.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/IR/Function.h"
+#include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Transforms/Scalar.h"
@@ -33,28 +35,6 @@
 
 #define DEBUG_TYPE "wasm"
 
-// Emscripten's asm.js-style exception handling
-cl::opt
-WasmEnableEmEH("enable-emscripten-cxx-exceptions",
-   cl::desc("WebAssembly Emscripten-style exception handling"),
-   cl::init(false));
-
-// Emscripten's asm.js-style setjmp/longjmp handling
-cl::opt WasmEnableEmSjLj(
-"enable-emscripten-sjlj",
-cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"),
-cl::init(false));
-
-// Exception handling using wasm EH instructions
-cl::opt WasmEnableEH("wasm-enable-eh",
-   cl::desc("WebAssembly exception handling"),
-   cl::init(false));
-
-// setjmp/longjmp handling using wasm EH instrutions
-cl::opt WasmEnableSjLj("wasm-enable-sjlj",
- cl::desc("WebAssembly setjmp/longjmp handling"),
- cl::init(false));
-
 // A command-line option to keep implicit locals
 // for the purpose of testing with lit/llc ONLY.
 // This produces output which is not valid WebAssembly, and is not supported
@@ -368,7 +348,23 @@
   return nullptr; // No reg alloc
 }
 
-static void basicCheckForEHAndSjLj(const TargetMachine *TM) {
+using WebAssembly::WasmEnableEH;
+using WebAssembly::WasmEnableEmEH;
+using WebAssembly::WasmEnableEmSjLj;
+using WebAssembly::WasmEnableSjLj;
+
+static void basicCheckForEHAndSjLj(TargetMachine *TM) {
+  // Before checking, we make sure TargetOptions.ExceptionModel is the same as
+  // MCAsmInfo.ExceptionsType. Normally these have to be the same, because clang
+  // stores the exception model info in LangOptions, which is later transferred
+  // to TargetOptions and MCAsmInfo. But when clang compiles bitcode directly,
+  // clang's LangOptions is not used and thus the exception model info is not
+  // correctly transferred to TargetOptions and MCAsmInfo, so we make sure we
+  // have the correct exception model in in WebAssemblyMCAsmInfo constructor.
+  // But in this case TargetOptions is still not updated, so we make sure they
+  // are the same.
+  TM->Options.ExceptionModel = TM->getMCAsmInfo()->getExceptionHandlingType();
+
   // Basic Correctness checking related to -exception-model
   if (TM->Options.ExceptionModel != ExceptionHandling::None &&
   TM->Options.ExceptionModel != ExceptionHandling::Wasm)
Index: llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
@@ -40,9 +40,6 @@
" instruction output for test purposes only."),
   cl::init(false));
 
-extern cl::opt WasmEnableEmEH;
-extern cl::opt WasmEnableEmSjLj;
-
 static void removeRegisterOperands(const MachineInstr *MI, MCInst );
 
 MCSymbol *
@@ -112,7 +109,8 @@
 
   bool InvokeDetected = false;
   auto *WasmSym = Printer.getMCSymbolForFunction(
-  F, WasmEnableEmEH || WasmEnableEmSjLj, Signature.get(), InvokeDetected);
+  F, WebAssembly::WasmEnableEmEH || WebAssembly::WasmEnableEmSjLj,
+  Signature.get(), InvokeDetected);
   WasmSym->setSignature(Signature.get());
   Printer.addSignature(std::move(Signature));
   WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
Index: 

[PATCH] D115893: [WebAssembly] Support clang -fwasm-exceptions for bitcode

2021-12-16 Thread Derek Schuff via Phabricator via cfe-commits
dschuff accepted this revision.
dschuff added inline comments.
This revision is now accepted and ready to land.



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp:37
 
-// Emscripten's asm.js-style exception handling
-cl::opt
-WasmEnableEmEH("enable-emscripten-cxx-exceptions",
-   cl::desc("WebAssembly Emscripten-style exception handling"),
-   cl::init(false));
-
-// Emscripten's asm.js-style setjmp/longjmp handling
-cl::opt WasmEnableEmSjLj(
-"enable-emscripten-sjlj",
-cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"),
-cl::init(false));
-
-// Exception handling using wasm EH instructions
-cl::opt WasmEnableEH("wasm-enable-eh",
-   cl::desc("WebAssembly exception handling"),
-   cl::init(false));
-
-// setjmp/longjmp handling using wasm EH instrutions
-cl::opt WasmEnableSjLj("wasm-enable-sjlj",
- cl::desc("WebAssembly setjmp/longjmp handling"),
- cl::init(false));
+extern cl::opt WasmEnableEmEH;   // asm.js-style EH
+extern cl::opt WasmEnableEmSjLj; // asm.js-style SjLJ

We could put these declarations in WebAssemblyUtilities.h; then they wouldn't 
have to be duplicated here and in WebAssemblyMCAsmInfo.cpp



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp:357
+  // Before checking, we make sure TargetOptions.ExceptionModel is the same as
+  // MCAsmInfo.ExceptionsType. Normally when these have to be the same, because
+  // clang stores the exception model info in LangOptions, which is later




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115893/new/

https://reviews.llvm.org/D115893

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115893: [WebAssembly] Support clang -fwasm-exceptions for bitcode

2021-12-16 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin updated this revision to Diff 394951.
aheejin added a comment.

Revert a function name change


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115893/new/

https://reviews.llvm.org/D115893

Files:
  clang/test/CodeGen/WebAssembly/wasm-eh.ll
  llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Index: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -24,6 +24,7 @@
 #include "llvm/CodeGen/RegAllocRegistry.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/IR/Function.h"
+#include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Transforms/Scalar.h"
@@ -33,27 +34,10 @@
 
 #define DEBUG_TYPE "wasm"
 
-// Emscripten's asm.js-style exception handling
-cl::opt
-WasmEnableEmEH("enable-emscripten-cxx-exceptions",
-   cl::desc("WebAssembly Emscripten-style exception handling"),
-   cl::init(false));
-
-// Emscripten's asm.js-style setjmp/longjmp handling
-cl::opt WasmEnableEmSjLj(
-"enable-emscripten-sjlj",
-cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"),
-cl::init(false));
-
-// Exception handling using wasm EH instructions
-cl::opt WasmEnableEH("wasm-enable-eh",
-   cl::desc("WebAssembly exception handling"),
-   cl::init(false));
-
-// setjmp/longjmp handling using wasm EH instrutions
-cl::opt WasmEnableSjLj("wasm-enable-sjlj",
- cl::desc("WebAssembly setjmp/longjmp handling"),
- cl::init(false));
+extern cl::opt WasmEnableEmEH;   // asm.js-style EH
+extern cl::opt WasmEnableEmSjLj; // asm.js-style SjLJ
+extern cl::opt WasmEnableEH; // EH using Wasm EH instructions
+extern cl::opt WasmEnableSjLj;   // SjLj using Wasm EH instructions
 
 // A command-line option to keep implicit locals
 // for the purpose of testing with lit/llc ONLY.
@@ -368,7 +352,18 @@
   return nullptr; // No reg alloc
 }
 
-static void basicCheckForEHAndSjLj(const TargetMachine *TM) {
+static void basicCheckForEHAndSjLj(TargetMachine *TM) {
+  // Before checking, we make sure TargetOptions.ExceptionModel is the same as
+  // MCAsmInfo.ExceptionsType. Normally when these have to be the same, because
+  // clang stores the exception model info in LangOptions, which is later
+  // transferred to TargetOptions and MCAsmInfo. But when clang compiles bitcode
+  // directly, clang's LangOptions is not used and thus the exception model info
+  // is not correctly transferred to TargetOptions and MCAsmInfo, so we make
+  // sure we have the correct exception model in in WebAssemblyMCAsmInfo
+  // constructor. But in this case TargetOptions is still not updated, so we
+  // make sure they are the same.
+  TM->Options.ExceptionModel = TM->getMCAsmInfo()->getExceptionHandlingType();
+
   // Basic Correctness checking related to -exception-model
   if (TM->Options.ExceptionModel != ExceptionHandling::None &&
   TM->Options.ExceptionModel != ExceptionHandling::Wasm)
Index: llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp
===
--- llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp
+++ llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp
@@ -18,6 +18,29 @@
 #include "llvm/MC/MCContext.h"
 using namespace llvm;
 
+// Exception handling & setjmp-longjmp handling related options. These are
+// defined here to be shared between WebAssembly and its subdirectories.
+
+// Emscripten's asm.js-style exception handling
+cl::opt
+WasmEnableEmEH("enable-emscripten-cxx-exceptions",
+   cl::desc("WebAssembly Emscripten-style exception handling"),
+   cl::init(false));
+// Emscripten's asm.js-style setjmp/longjmp handling
+cl::opt WasmEnableEmSjLj(
+"enable-emscripten-sjlj",
+cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"),
+cl::init(false));
+// Exception handling using wasm EH instructions
+cl::opt WasmEnableEH("wasm-enable-eh",
+   cl::desc("WebAssembly exception handling"),
+   cl::init(false));
+// setjmp/longjmp handling using wasm EH instrutions
+cl::opt WasmEnableSjLj("wasm-enable-sjlj",
+ cl::desc("WebAssembly setjmp/longjmp handling"),
+ cl::init(false));
+
+// Function names in libc++abi and libunwind
 const char *const WebAssembly::CxaBeginCatchFn = "__cxa_begin_catch";
 const char *const WebAssembly::CxaRethrowFn = "__cxa_rethrow";
 const char *const 

[PATCH] D115893: [WebAssembly] Support clang -fwasm-exceptions for bitcode

2021-12-16 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin created this revision.
aheejin added a reviewer: dschuff.
Herald added subscribers: wingo, ecnelises, pengfei, sunfish, hiraditya, 
jgravelle-google, sbc100.
aheejin requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This supports bitcode compilation using `clang -fwasm-exceptions`.

---

The current situation:

Currently the backend requires two options for Wasm EH:
`-wasm-enable-eh` and `-exception-model=wasm`. Wasm SjLj requires two
options as well: `-wasm-enable-sjlj` and `-exception-model=wasm`. When
using Wasm EH via Emscripten, you only need to pass `-fwasm-exceptions`,
and these options will be added within the clang driver. This
description will focus on the case of Wasm EH going forward, but Wasm
SjLj's case is similar.

When you pass `-fwasm-exceptions` to emcc and clang driver, the clang
driver adds these options to the command line that calls the clang
frontend (`clang -cc1`): `-mllvm -wasm-enable-eh` and
`-exception-model=wasm`. `-wasm-enable-eh` is prefixed with `-mllvm`, so
it is passed as is to the backend. But `-exception-model` is parsed and
processed within the clang frontend and stored in `LangOptions` class
backend via `LangOptions` class. This info is later transferred to
`TargetOptions` class, and then eventually passed to `MCAsmInfo` class.
All LLVM code queries this `MCAsmInfo` to get the exception model. (
(e.g., here)

---

Problem:

The problem is the whole `LangOptions` processing is bypassed when
compiling bitcode, so the information transfer of `LangOptions` ->
`TargetOptions` -> `MCAsmInfo` does not happen. They are all set to
`ExceptionHandling::None`, which is the default value.

---

What other targets do, and why we can't do the same:

Other targets support bitcode compilation by the clang driver, but they
can do that by using different triples. For example, X86 target supports
multiple triples, each of which has its own subclass of `MCAsmInfo`, so
it can hardcode the appropriate exception model within those subclasses'
constructors. But we don't have separate triples for each exception
mode: none, emscripten, ans wasm.

---

What this CL does:

If we can figure out whether `-wasm-enable-eh` is passed to the backend,
we can programatically set the exception model from the backend, rather
than requiring it to be passed.

So we check `WasmEnableEH` and `WasmEnableSjLj` variables, which are
`cl::opt` for `-wasm-enable-eh` and `-wasm-enable-sjlj`, in
`WebAssemblyMCAsmInfo` constructor, and if either of them is set, we set
`MCAsmInfo.ExceptionType` to Wasm. `TargetOptions` cannot be updated
there, so we make sure they are the same later.

Fixes https://github.com/emscripten-core/emscripten/issues/15712.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115893

Files:
  clang/test/CodeGen/WebAssembly/wasm-eh.ll
  llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Index: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -24,6 +24,7 @@
 #include "llvm/CodeGen/RegAllocRegistry.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/IR/Function.h"
+#include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Transforms/Scalar.h"
@@ -33,27 +34,10 @@
 
 #define DEBUG_TYPE "wasm"
 
-// Emscripten's asm.js-style exception handling
-cl::opt
-WasmEnableEmEH("enable-emscripten-cxx-exceptions",
-   cl::desc("WebAssembly Emscripten-style exception handling"),
-   cl::init(false));
-
-// Emscripten's asm.js-style setjmp/longjmp handling
-cl::opt WasmEnableEmSjLj(
-"enable-emscripten-sjlj",
-cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"),
-cl::init(false));
-
-// Exception handling using wasm EH instructions
-cl::opt WasmEnableEH("wasm-enable-eh",
-   cl::desc("WebAssembly exception handling"),
-   cl::init(false));
-
-// setjmp/longjmp handling using wasm EH instrutions
-cl::opt WasmEnableSjLj("wasm-enable-sjlj",
- cl::desc("WebAssembly setjmp/longjmp handling"),
- cl::init(false));
+extern cl::opt WasmEnableEmEH;   // asm.js-style EH
+extern cl::opt WasmEnableEmSjLj; // asm.js-style SjLJ
+extern cl::opt WasmEnableEH; // EH using Wasm EH instructions
+extern cl::opt WasmEnableSjLj;   // SjLj using Wasm EH instructions
 
 // A command-line option to keep implicit locals
 // for the purpose of testing with lit/llc ONLY.
@@ -368,7 +352,18 @@
   return nullptr; // No reg alloc
 }
 
-static void basicCheckForEHAndSjLj(const