summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/WebAssembly
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Target/WebAssembly')
-rw-r--r--llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp53
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp9
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h1
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp9
4 files changed, 17 insertions, 55 deletions
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
index 2c97aadd7f9..3b800858063 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
@@ -42,23 +42,8 @@ private:
WebAssemblyWasmObjectWriter::WebAssemblyWasmObjectWriter(bool Is64Bit)
: MCWasmObjectTargetWriter(Is64Bit) {}
-// Test whether the given expression computes a function address.
-static bool isFunctionExpr(const MCExpr *Expr) {
- if (auto SyExp = dyn_cast<MCSymbolRefExpr>(Expr))
- return cast<MCSymbolWasm>(SyExp->getSymbol()).isFunction();
-
- if (auto BinOp = dyn_cast<MCBinaryExpr>(Expr))
- return isFunctionExpr(BinOp->getLHS()) != isFunctionExpr(BinOp->getRHS());
-
- if (auto UnOp = dyn_cast<MCUnaryExpr>(Expr))
- return isFunctionExpr(UnOp->getSubExpr());
-
- return false;
-}
-
-static bool isFunctionType(const MCValue &Target) {
- const MCSymbolRefExpr *RefA = Target.getSymA();
- return RefA && RefA->getKind() == MCSymbolRefExpr::VK_WebAssembly_TYPEINDEX;
+static bool isFunctionSignatureRef(const MCSymbolRefExpr *Ref) {
+ return Ref->getKind() == MCSymbolRefExpr::VK_WebAssembly_TYPEINDEX;
}
static const MCSection *getFixupSection(const MCExpr *Expr) {
@@ -80,41 +65,33 @@ static const MCSection *getFixupSection(const MCExpr *Expr) {
return nullptr;
}
-static bool isGlobalType(const MCValue &Target) {
- const MCSymbolRefExpr *RefA = Target.getSymA();
- return RefA && RefA->getKind() == MCSymbolRefExpr::VK_WebAssembly_GLOBAL;
-}
-
-static bool isEventType(const MCValue &Target) {
- const MCSymbolRefExpr *RefA = Target.getSymA();
- return RefA && RefA->getKind() == MCSymbolRefExpr::VK_WebAssembly_EVENT;
-}
-
unsigned WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target,
const MCFixup &Fixup) const {
- // WebAssembly functions are not allocated in the data address space. To
- // resolve a pointer to a function, we must use a special relocation type.
- bool IsFunction = isFunctionExpr(Fixup.getValue());
+ const MCSymbolRefExpr *RefA = Target.getSymA();
+ assert(RefA);
+ auto& SymA = cast<MCSymbolWasm>(RefA->getSymbol());
switch (unsigned(Fixup.getKind())) {
case WebAssembly::fixup_code_sleb128_i32:
- if (IsFunction)
+ if (SymA.isFunction())
return wasm::R_WASM_TABLE_INDEX_SLEB;
return wasm::R_WASM_MEMORY_ADDR_SLEB;
case WebAssembly::fixup_code_sleb128_i64:
llvm_unreachable("fixup_sleb128_i64 not implemented yet");
case WebAssembly::fixup_code_uleb128_i32:
- if (isGlobalType(Target))
+ if (SymA.isFunction()) {
+ if (isFunctionSignatureRef(RefA))
+ return wasm::R_WASM_TYPE_INDEX_LEB;
+ else
+ return wasm::R_WASM_FUNCTION_INDEX_LEB;
+ }
+ if (SymA.isGlobal())
return wasm::R_WASM_GLOBAL_INDEX_LEB;
- if (isFunctionType(Target))
- return wasm::R_WASM_TYPE_INDEX_LEB;
- if (IsFunction)
- return wasm::R_WASM_FUNCTION_INDEX_LEB;
- if (isEventType(Target))
+ if (SymA.isEvent())
return wasm::R_WASM_EVENT_INDEX_LEB;
return wasm::R_WASM_MEMORY_ADDR_LEB;
case FK_Data_4:
- if (IsFunction)
+ if (SymA.isFunction())
return wasm::R_WASM_TABLE_INDEX_I32;
if (auto Section = static_cast<const MCSectionWasm *>(
getFixupSection(Fixup.getValue()))) {
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index 18ec2c273ec..b0a80b0ca79 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -332,15 +332,6 @@ void WebAssemblyAsmPrinter::EmitInstruction(const MachineInstr *MI) {
}
}
-const MCExpr *WebAssemblyAsmPrinter::lowerConstant(const Constant *CV) {
- if (const auto *GV = dyn_cast<GlobalValue>(CV))
- if (GV->getValueType()->isFunctionTy()) {
- return MCSymbolRefExpr::create(
- getSymbol(GV), MCSymbolRefExpr::VK_WebAssembly_FUNCTION, OutContext);
- }
- return AsmPrinter::lowerConstant(CV);
-}
-
bool WebAssemblyAsmPrinter::PrintAsmOperand(const MachineInstr *MI,
unsigned OpNo, unsigned AsmVariant,
const char *ExtraCode,
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h
index c4300cf7916..579cc9a493e 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h
@@ -63,7 +63,6 @@ public:
void EmitConstantPool() override;
void EmitFunctionBodyStart() override;
void EmitInstruction(const MachineInstr *MI) override;
- const MCExpr *lowerConstant(const Constant *CV) override;
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
unsigned AsmVariant, const char *ExtraCode,
raw_ostream &OS) override;
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
index 054fe5496d5..e357842b3e9 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
@@ -122,13 +122,8 @@ MCOperand WebAssemblyMCInstLower::lowerSymbolOperand(MCSymbol *Sym,
int64_t Offset,
bool IsFunc, bool IsGlob,
bool IsEvent) const {
- MCSymbolRefExpr::VariantKind VK =
- IsFunc ? MCSymbolRefExpr::VK_WebAssembly_FUNCTION
- : IsGlob ? MCSymbolRefExpr::VK_WebAssembly_GLOBAL
- : IsEvent ? MCSymbolRefExpr::VK_WebAssembly_EVENT
- : MCSymbolRefExpr::VK_None;
-
- const MCExpr *Expr = MCSymbolRefExpr::create(Sym, VK, Ctx);
+ const MCExpr *Expr =
+ MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, Ctx);
if (Offset != 0) {
if (IsFunc)
OpenPOWER on IntegriCloud