aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sehr <sehr@chromium.org>2012-11-29 13:55:21 -0800
committerDavid Sehr <sehr@chromium.org>2012-11-29 13:55:21 -0800
commita3724044c4d473461d8df8f904292ca54c2d6acf (patch)
tree37c3c3567e05771fe554888e4f0b57b248c75e2b
parent5cad50ae8e489ad5f323c88a2995662e0d90ea9a (diff)
Add isOSNaCl, and add Asm subclasses for NaCl
Removes some of the FIXME cruft that suggest we should use subclassing. BUG= Review URL: https://codereview.chromium.org/11316230
-rw-r--r--include/llvm/ADT/Triple.h5
-rw-r--r--lib/Target/ARM/ARMSubtarget.h4
-rw-r--r--lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp35
-rw-r--r--lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp2
-rw-r--r--lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp38
-rw-r--r--lib/Target/Mips/MipsSubtarget.h6
-rw-r--r--lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp70
-rw-r--r--lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp2
-rw-r--r--lib/Target/X86/X86Subtarget.h4
9 files changed, 106 insertions, 60 deletions
diff --git a/include/llvm/ADT/Triple.h b/include/llvm/ADT/Triple.h
index a9e67cafba..f317c190b0 100644
--- a/include/llvm/ADT/Triple.h
+++ b/include/llvm/ADT/Triple.h
@@ -310,6 +310,11 @@ public:
return getOS() == Triple::Win32 || isOSCygMing();
}
+ /// \brief isOSNaCl - Is this the Native Client OS.
+ bool isOSNaCl() const {
+ return getOS() == Triple::NativeClient;
+ }
+
/// \brief Tests whether the OS uses the ELF binary format.
bool isOSBinFormatELF() const {
return !isOSDarwin() && !isOSWindows();
diff --git a/lib/Target/ARM/ARMSubtarget.h b/lib/Target/ARM/ARMSubtarget.h
index e99d1d4a48..f07ad350a2 100644
--- a/lib/Target/ARM/ARMSubtarget.h
+++ b/lib/Target/ARM/ARMSubtarget.h
@@ -256,9 +256,7 @@ protected:
bool isTargetIOS() const { return TargetTriple.getOS() == Triple::IOS; }
bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
- bool isTargetNaCl() const {
- return TargetTriple.getOS() == Triple::NativeClient;
- }
+ bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); } // @LOCALMOD
bool isTargetELF() const { return !isTargetDarwin(); }
bool isAPCS_ABI() const { return TargetABI == ARM_ABI_APCS; }
diff --git a/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp b/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
index 6380d09ad8..27c1bc76fd 100644
--- a/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
+++ b/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
@@ -632,20 +632,37 @@ public:
uint8_t _OSABI)
: ARMAsmBackend(T, TT), OSABI(_OSABI) { }
+ void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
+ uint64_t Value) const;
+
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
return createARMELFObjectWriter(OS, OSABI);
}
};
+// FIXME: Raise this to share code between Darwin and ELF.
+void ELFARMAsmBackend::applyFixup(const MCFixup &Fixup, char *Data,
+ unsigned DataSize, uint64_t Value) const {
+ unsigned NumBytes = 4; // FIXME: 2 for Thumb
+ Value = adjustFixupValue(Fixup, Value);
+ if (!Value) return; // Doesn't change encoding.
+
+ unsigned Offset = Fixup.getOffset();
+
+ // For each byte of the fragment that the fixup touches, mask in the bits from
+ // the fixup value. The Value has been "split up" into the appropriate
+ // bitfields above.
+ for (unsigned i = 0; i != NumBytes; ++i)
+ Data[Offset + i] |= uint8_t((Value >> (i * 8)) & 0xff);
+}
+
// @LOCALMOD-BEGIN
class NaClARMAsmBackend : public ELFARMAsmBackend {
- public:
- NaClARMAsmBackend(const Target &T, const StringRef TT,
- uint8_t OSABI)
- : ELFARMAsmBackend(T, TT, OSABI) { }
- unsigned getBundleSize() const {
- return 16;
- }
+public:
+ NaClARMAsmBackend(const Target &T, const StringRef TT, uint8_t _OSABI)
+ : ELFARMAsmBackend(T, TT, _OSABI) { }
+
+ unsigned getBundleSize() const { return 16; }
bool CustomExpandInst(const MCInst &Inst, MCStreamer &Out) const {
return CustomExpandInstNaClARM(Inst, Out);
@@ -705,7 +722,9 @@ MCAsmBackend *llvm::createARMAsmBackend(const Target &T, StringRef TT, StringRef
assert(0 && "Windows not supported on ARM");
uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(Triple(TT).getOS());
- if (TheTriple.getOS() == llvm::Triple::NativeClient)
+ // @LOCALMOD-END
+ if (TheTriple.isOSNaCl())
return new NaClARMAsmBackend(T, TT, OSABI);
+ // @LOCALMOD-END
return new ELFARMAsmBackend(T, TT, OSABI);
}
diff --git a/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp b/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
index ffbb115098..bb40b4b0de 100644
--- a/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
+++ b/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
@@ -156,7 +156,7 @@ static MCAsmInfo *createARMMCAsmInfo(const Target &T, StringRef TT) {
// @LOCALMOD-BEGIN
ARMELFMCAsmInfo *MAI = new ARMELFMCAsmInfo();
- if (TheTriple.getOS() == Triple::NativeClient) {
+ if (TheTriple.isOSNaCl()) {
// NativeClient uses Dwarf exception handling
MAI->setExceptionsType(ExceptionHandling::DwarfCFI);
// Initial state of the frame ARM:SP points to cfa
diff --git a/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp b/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
index 2e5092c13c..f7e88b98f8 100644
--- a/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
+++ b/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
@@ -248,29 +248,36 @@ public:
OW->Write32(0);
return true;
}
+}; // class MipsAsmBackend
+
+// @LOCALMOD-BEGIN
+class NaClMipsAsmBackend : public MipsAsmBackend {
+public:
+ NaClMipsAsmBackend(const Target &T, bool _is64Bit)
+ : MipsAsmBackend(T, Triple::NativeClient, /* IsLittle */ true, _is64Bit) {}
- // @LOCALMOD-BEGIN
- // FIXME! NaCl should INHERIT from MipsAsmBackend, not add to it.
unsigned getBundleSize() const {
- return (OSType == Triple::NativeClient) ? 16 : 0;
+ return 16;
}
bool CustomExpandInst(const MCInst &Inst, MCStreamer &Out) const {
- if (OSType == Triple::NativeClient) {
- return CustomExpandInstNaClMips(Inst, Out);
- }
- return false;
+ return CustomExpandInstNaClMips(Inst, Out);
}
- // @LOCALMOD-END
-}; // class MipsAsmBackend
+}; // class NaClMipsAsmBackend
+// @LOCALMOD-END
} // namespace
// MCAsmBackend
MCAsmBackend *llvm::createMipsAsmBackendEL32(const Target &T, StringRef TT,
StringRef CPU) {
- return new MipsAsmBackend(T, Triple(TT).getOS(),
- /*IsLittle*/true, /*Is64Bit*/false);
+ // @LOCALMOD-BEGIN
+ if (Triple(TT).isOSNaCl())
+ return new NaClMipsAsmBackend(T, /*Is64Bit*/false);
+ else
+ return new MipsAsmBackend(T, Triple(TT).getOS(),
+ /*IsLittle*/true, /*Is64Bit*/false);
+ // @LOCALMOD-END
}
MCAsmBackend *llvm::createMipsAsmBackendEB32(const Target &T, StringRef TT,
@@ -281,8 +288,13 @@ MCAsmBackend *llvm::createMipsAsmBackendEB32(const Target &T, StringRef TT,
MCAsmBackend *llvm::createMipsAsmBackendEL64(const Target &T, StringRef TT,
StringRef CPU) {
- return new MipsAsmBackend(T, Triple(TT).getOS(),
- /*IsLittle*/true, /*Is64Bit*/true);
+ // @LOCALMOD-BEGIN
+ if (Triple(TT).isOSNaCl())
+ return new NaClMipsAsmBackend(T, /*Is64Bit*/true);
+ else
+ return new MipsAsmBackend(T, Triple(TT).getOS(),
+ /*IsLittle*/true, /*Is64Bit*/true);
+ // @LOCALMOD-END
}
MCAsmBackend *llvm::createMipsAsmBackendEB64(const Target &T, StringRef TT,
diff --git a/lib/Target/Mips/MipsSubtarget.h b/lib/Target/Mips/MipsSubtarget.h
index 0ea85bb3c1..f8fd0490fa 100644
--- a/lib/Target/Mips/MipsSubtarget.h
+++ b/lib/Target/Mips/MipsSubtarget.h
@@ -157,11 +157,7 @@ public:
bool hasBitCount() const { return HasBitCount; }
bool hasFPIdx() const { return HasFPIdx; }
- // @LOCALMOD-BEGIN
- bool isTargetNaCl() const {
- return TargetTriple.getOS() == Triple::NativeClient;
- }
- // @LOCALMOD-END
+ bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); } // @LOCALMOD
};
} // End llvm namespace
diff --git a/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
index 2c91c8c566..c0bddc65c1 100644
--- a/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
+++ b/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
@@ -338,10 +338,8 @@ namespace {
class ELFX86AsmBackend : public X86AsmBackend {
public:
uint8_t OSABI;
- Triple::OSType OSType; // @LOCALMOD: kept OSTYPE vs upstream. FIXME: remove.
- ELFX86AsmBackend(const Target &T, uint8_t _OSABI, StringRef CPU,
- Triple::OSType _OSType)
- : X86AsmBackend(T, CPU), OSABI(_OSABI), OSType(_OSType) {
+ ELFX86AsmBackend(const Target &T, uint8_t _OSABI, StringRef CPU)
+ : X86AsmBackend(T, CPU), OSABI(_OSABI) {
HasReliableSymbolDifference = true;
}
@@ -350,27 +348,12 @@ public:
return ES.getFlags() & ELF::SHF_MERGE;
}
- // @LOCALMOD-BEGIN
- // FIXME! NaCl should inherit from ELFX86AsmBackend!
- unsigned getBundleSize() const {
- return OSType == Triple::NativeClient ? 32 : 0;
- }
-
- bool CustomExpandInst(const MCInst &Inst, MCStreamer &Out) const {
- if (OSType == Triple::NativeClient) {
- return CustomExpandInstNaClX86(Inst, Out);
- }
- return false;
- }
- // @LOCALMOD-END
-
};
class ELFX86_32AsmBackend : public ELFX86AsmBackend {
public:
- ELFX86_32AsmBackend(const Target &T, uint8_t OSABI, StringRef CPU,
- Triple::OSType OSType) // @LOCALMOD: kept OSType
- : ELFX86AsmBackend(T, OSABI, CPU, OSType) {}
+ ELFX86_32AsmBackend(const Target &T, uint8_t OSABI, StringRef CPU)
+ : ELFX86AsmBackend(T, OSABI, CPU) {}
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
return createX86ELFObjectWriter(OS, /*IsELF64*/ false, OSABI, ELF::EM_386);
@@ -379,15 +362,40 @@ public:
class ELFX86_64AsmBackend : public ELFX86AsmBackend {
public:
- ELFX86_64AsmBackend(const Target &T, uint8_t OSABI, StringRef CPU,
- Triple::OSType OSType) // @LOCALMOD: kept OSType
- : ELFX86AsmBackend(T, OSABI, CPU, OSType) {}
+ ELFX86_64AsmBackend(const Target &T, uint8_t OSABI, StringRef CPU)
+ : ELFX86AsmBackend(T, OSABI, CPU) {}
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
return createX86ELFObjectWriter(OS, /*IsELF64*/ true, OSABI, ELF::EM_X86_64);
}
};
+// @LOCALMOD-BEGIN
+class NaClX86_32AsmBackend : public ELFX86_32AsmBackend {
+public:
+ NaClX86_32AsmBackend(const Target &T, uint8_t OSABI, StringRef CPU)
+ : ELFX86_32AsmBackend(T, OSABI, CPU) {}
+
+ unsigned getBundleSize() const { return 32; }
+
+ bool CustomExpandInst(const MCInst &Inst, MCStreamer &Out) const {
+ return CustomExpandInstNaClX86(Inst, Out);
+ }
+};
+
+class NaClX86_64AsmBackend : public ELFX86_64AsmBackend {
+public:
+ NaClX86_64AsmBackend(const Target &T, uint8_t OSABI, StringRef CPU)
+ : ELFX86_64AsmBackend(T, OSABI, CPU) {}
+
+ unsigned getBundleSize() const { return 32; }
+
+ bool CustomExpandInst(const MCInst &Inst, MCStreamer &Out) const {
+ return CustomExpandInstNaClX86(Inst, Out);
+ }
+};
+// @LOCALMOD-END
+
class WindowsX86AsmBackend : public X86AsmBackend {
bool Is64Bit;
@@ -479,7 +487,12 @@ MCAsmBackend *llvm::createX86_32AsmBackend(const Target &T, StringRef TT, String
return new WindowsX86AsmBackend(T, false, CPU);
uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TheTriple.getOS());
- return new ELFX86_32AsmBackend(T, OSABI, CPU, TheTriple.getOS());
+ // @LOCALMOD-BEGIN
+ if (TheTriple.isOSNaCl())
+ return new NaClX86_32AsmBackend(T, OSABI, CPU);
+ else
+ return new ELFX86_32AsmBackend(T, OSABI, CPU);
+ // @LOCALMOD-END
}
MCAsmBackend *llvm::createX86_64AsmBackend(const Target &T, StringRef TT, StringRef CPU) {
@@ -492,5 +505,10 @@ MCAsmBackend *llvm::createX86_64AsmBackend(const Target &T, StringRef TT, String
return new WindowsX86AsmBackend(T, true, CPU);
uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TheTriple.getOS());
- return new ELFX86_64AsmBackend(T, OSABI, CPU, TheTriple.getOS());
+ // @LOCALMOD-BEGIN
+ if (TheTriple.isOSNaCl())
+ return new NaClX86_64AsmBackend(T, OSABI, CPU);
+ else
+ return new ELFX86_64AsmBackend(T, OSABI, CPU);
+ // @LOCALMOD-END
}
diff --git a/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp b/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
index 7706b9308e..19951b3385 100644
--- a/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
+++ b/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
@@ -79,7 +79,7 @@ X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) {
// @LOCALMOD-BEGIN
if (T.getArch() == Triple::x86_64) {
- if (T.getOS() == Triple::NativeClient) {
+ if (T.isOSNaCl()) {
PointerSize = 4;
StackSlotSize = 8;
} else {
diff --git a/lib/Target/X86/X86Subtarget.h b/lib/Target/X86/X86Subtarget.h
index 0f8cab52f2..f86b947574 100644
--- a/lib/Target/X86/X86Subtarget.h
+++ b/lib/Target/X86/X86Subtarget.h
@@ -249,9 +249,7 @@ public:
TargetTriple.isOSBinFormatELF());
}
bool isTargetLinux() const { return TargetTriple.getOS() == Triple::Linux; }
- bool isTargetNaCl() const {
- return TargetTriple.getOS() == Triple::NativeClient;
- }
+ bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); } // @LOCALMOD
bool isTargetNaCl32() const { return isTargetNaCl() && !is64Bit(); }
bool isTargetNaCl64() const { return isTargetNaCl() && is64Bit(); }
bool isTargetWindows() const { return TargetTriple.getOS() == Triple::Win32; }