[PATCH] D44150: [WebAssembly] Move WasmSignatureDenseMapInfo to header for reuse. NFC
Nicholas Wilson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 6 06:26:08 PST 2018
ncw created this revision.
ncw added reviewers: sbc100, ruiu.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, dschuff, jfb.
I want to use a DenseMap<WasmSignature> in another file in LLD
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D44150
Files:
wasm/Writer.cpp
wasm/WriterUtils.h
Index: wasm/WriterUtils.h
===================================================================
--- wasm/WriterUtils.h
+++ wasm/WriterUtils.h
@@ -11,13 +11,16 @@
#define LLD_WASM_WRITERUTILS_H
#include "lld/Common/LLVM.h"
+#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Object/Wasm.h"
#include "llvm/Support/raw_ostream.h"
using llvm::raw_ostream;
-// Needed for WasmSignatureDenseMapInfo
+namespace llvm {
+
+// Needed for DenseMapInfo<wasm::WasmSignature>
inline bool operator==(const llvm::wasm::WasmSignature &LHS,
const llvm::wasm::WasmSignature &RHS) {
return LHS.ReturnType == RHS.ReturnType && LHS.ParamTypes == RHS.ParamTypes;
@@ -39,6 +42,32 @@
return !(LHS == RHS);
}
+// Traits for using WasmSignature in a DenseMap.
+template<> struct DenseMapInfo<wasm::WasmSignature> {
+ static wasm::WasmSignature getEmptyKey() {
+ wasm::WasmSignature Sig;
+ Sig.ReturnType = 1;
+ return Sig;
+ }
+ static wasm::WasmSignature getTombstoneKey() {
+ wasm::WasmSignature Sig;
+ Sig.ReturnType = 2;
+ return Sig;
+ }
+ static unsigned getHashValue(const wasm::WasmSignature &Sig) {
+ unsigned H = hash_value(Sig.ReturnType);
+ for (int32_t Param : Sig.ParamTypes)
+ H = hash_combine(H, Param);
+ return H;
+ }
+ static bool isEqual(const wasm::WasmSignature &LHS,
+ const wasm::WasmSignature &RHS) {
+ return LHS == RHS;
+ }
+};
+
+} // end namespace llvm
+
namespace lld {
namespace wasm {
Index: wasm/Writer.cpp
===================================================================
--- wasm/Writer.cpp
+++ wasm/Writer.cpp
@@ -40,29 +40,6 @@
namespace {
-// Traits for using WasmSignature in a DenseMap.
-struct WasmSignatureDenseMapInfo {
- static WasmSignature getEmptyKey() {
- WasmSignature Sig;
- Sig.ReturnType = 1;
- return Sig;
- }
- static WasmSignature getTombstoneKey() {
- WasmSignature Sig;
- Sig.ReturnType = 2;
- return Sig;
- }
- static unsigned getHashValue(const WasmSignature &Sig) {
- unsigned H = hash_value(Sig.ReturnType);
- for (int32_t Param : Sig.ParamTypes)
- H = hash_combine(H, Param);
- return H;
- }
- static bool isEqual(const WasmSignature &LHS, const WasmSignature &RHS) {
- return LHS == RHS;
- }
-};
-
// An init entry to be written to either the synthetic init func or the
// linking metadata.
struct WasmInitEntry {
@@ -119,7 +96,7 @@
uint32_t NumMemoryPages = 0;
std::vector<const WasmSignature *> Types;
- DenseMap<WasmSignature, int32_t, WasmSignatureDenseMapInfo> TypeIndices;
+ DenseMap<WasmSignature, int32_t> TypeIndices;
std::vector<const Symbol *> ImportedSymbols;
unsigned NumImportedFunctions = 0;
unsigned NumImportedGlobals = 0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44150.137187.patch
Type: text/x-patch
Size: 2787 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180306/f1fc9a70/attachment.bin>
More information about the llvm-commits
mailing list