summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-01-03 19:21:54 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-01-03 19:21:54 +0000
commit8e0f67dcec577760e3bdc36f0377c6f43e1894d8 (patch)
tree3bc672a832234d85f97627203e2158d92c6debbf /include
parent5124fef085c067e0f41e797ae03963154e3bb4e7 (diff)
downloadllvm-8e0f67dcec577760e3bdc36f0377c6f43e1894d8.tar.gz
llvm-8e0f67dcec577760e3bdc36f0377c6f43e1894d8.tar.bz2
llvm-8e0f67dcec577760e3bdc36f0377c6f43e1894d8.tar.xz
Make the llvm mangler depend only on DataLayout.
Before this patch any program that wanted to know the final symbol name of a GlobalValue had to link with Target. This patch implements a compromise solution where the mangler uses DataLayout. This way, any tool that already links with Target (llc, clang) gets the exact behavior as before and new IR files can be mangled without linking with Target. With this patch the mangler is constructed with just a DataLayout and DataLayout is extended to include the information the Mangler needs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198438 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/IR/DataLayout.h53
-rw-r--r--include/llvm/MC/MCAsmInfo.h32
-rw-r--r--include/llvm/Target/Mangler.h6
-rw-r--r--include/llvm/Target/TargetLoweringObjectFile.h3
4 files changed, 58 insertions, 36 deletions
diff --git a/include/llvm/IR/DataLayout.h b/include/llvm/IR/DataLayout.h
index a1776fbf9b..520d4ede18 100644
--- a/include/llvm/IR/DataLayout.h
+++ b/include/llvm/IR/DataLayout.h
@@ -34,6 +34,7 @@ class Type;
class IntegerType;
class StructType;
class StructLayout;
+class Triple;
class GlobalVariable;
class LLVMContext;
template<typename T>
@@ -99,6 +100,15 @@ private:
bool LittleEndian; ///< Defaults to false
unsigned StackNaturalAlign; ///< Stack natural alignment
+ enum ManglingModeT {
+ MM_None,
+ MM_ELF,
+ MM_MachO,
+ MM_COFF,
+ MM_Mips
+ };
+ ManglingModeT ManglingMode;
+
SmallVector<unsigned char, 8> LegalIntWidths; ///< Legal Integers.
/// Alignments - Where the primitive type alignment data is stored.
@@ -174,6 +184,7 @@ public:
ImmutablePass(ID),
LittleEndian(DL.isLittleEndian()),
StackNaturalAlign(DL.StackNaturalAlign),
+ ManglingMode(DL.ManglingMode),
LegalIntWidths(DL.LegalIntWidths),
Alignments(DL.Alignments),
Pointers(DL.Pointers),
@@ -222,6 +233,48 @@ public:
return (StackNaturalAlign != 0) && (Align > StackNaturalAlign);
}
+ bool hasMicrosoftFastStdCallMangling() const {
+ return ManglingMode == MM_COFF;
+ }
+
+ bool hasLinkerPrivateGlobalPrefix() const {
+ return ManglingMode == MM_MachO;
+ }
+
+ const char *getLinkerPrivateGlobalPrefix() const {
+ if (ManglingMode == MM_MachO)
+ return "l";
+ return getPrivateGlobalPrefix();
+ }
+
+ char getGlobalPrefix() const {
+ switch (ManglingMode) {
+ case MM_None:
+ case MM_ELF:
+ case MM_Mips:
+ return '\0';
+ case MM_MachO:
+ case MM_COFF:
+ return '_';
+ }
+ }
+
+ const char *getPrivateGlobalPrefix() const {
+ switch (ManglingMode) {
+ case MM_None:
+ return "";
+ case MM_ELF:
+ return ".L";
+ case MM_Mips:
+ return "$";
+ case MM_MachO:
+ case MM_COFF:
+ return "L";
+ }
+ }
+
+ static const char *getManglingComponent(const Triple &T);
+
/// fitsInLegalInteger - This function returns true if the specified type fits
/// in a native integer type supported by the CPU. For example, if the CPU
/// only supports i32 as a native integer type, then i27 fits in a legal
diff --git a/include/llvm/MC/MCAsmInfo.h b/include/llvm/MC/MCAsmInfo.h
index 5bd42e90f5..a46c300bf2 100644
--- a/include/llvm/MC/MCAsmInfo.h
+++ b/include/llvm/MC/MCAsmInfo.h
@@ -115,22 +115,11 @@ namespace llvm {
/// LabelSuffix - This is appended to emitted labels.
const char *DebugLabelSuffix; // Defaults to ":"
- /// If this is set to anything other than '\0', it is prepended
- /// onto all global symbols. This is often used for '_'.
- char GlobalPrefix; // Defaults to '\0'
-
/// This prefix is used for globals like constant pool entries that are
/// completely private to the .s file and should not have names in the .o
/// file.
const char *PrivateGlobalPrefix; // Defaults to "L"
- /// This prefix is used for symbols that should be passed through the
- /// assembler but be removed by the linker. This is 'l' on Darwin,
- /// currently used for some ObjC metadata.
- /// The default of "" meast that for this system a plain private symbol
- /// should be used.
- const char *LinkerPrivateGlobalPrefix; // Defaults to "".
-
/// InlineAsmStart/End - If these are nonempty, they contain a directive to
/// emit before and after an inline assembly statement.
const char *InlineAsmStart; // Defaults to "#APP\n"
@@ -200,11 +189,6 @@ namespace llvm {
/// which doesn't support the '.bss' directive only.
bool UsesELFSectionDirectiveForBSS; // Defaults to false.
- /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
- /// style mangling for functions with X86_StdCall/X86_FastCall calling
- /// convention.
- bool HasMicrosoftFastStdCallMangling; // Defaults to false.
-
bool NeedsDwarfSectionOffsetDirective;
//===--- Alignment Information ----------------------------------------===//
@@ -393,10 +377,6 @@ namespace llvm {
return UsesELFSectionDirectiveForBSS;
}
- bool hasMicrosoftFastStdCallMangling() const {
- return HasMicrosoftFastStdCallMangling;
- }
-
bool needsDwarfSectionOffsetDirective() const {
return NeedsDwarfSectionOffsetDirective;
}
@@ -436,21 +416,9 @@ namespace llvm {
const char *getDebugLabelSuffix() const {
return DebugLabelSuffix;
}
-
- char getGlobalPrefix() const {
- return GlobalPrefix;
- }
const char *getPrivateGlobalPrefix() const {
return PrivateGlobalPrefix;
}
- bool hasLinkerPrivateGlobalPrefix() const {
- return LinkerPrivateGlobalPrefix[0] != '\0';
- }
- const char *getLinkerPrivateGlobalPrefix() const {
- if (hasLinkerPrivateGlobalPrefix())
- return LinkerPrivateGlobalPrefix;
- return getPrivateGlobalPrefix();
- }
const char *getInlineAsmStart() const {
return InlineAsmStart;
}
diff --git a/include/llvm/Target/Mangler.h b/include/llvm/Target/Mangler.h
index 3a8f32646f..78ce264b5e 100644
--- a/include/llvm/Target/Mangler.h
+++ b/include/llvm/Target/Mangler.h
@@ -18,10 +18,10 @@
namespace llvm {
+class DataLayout;
class GlobalValue;
class MCContext;
template <typename T> class SmallVectorImpl;
-class TargetMachine;
class Twine;
class Mangler {
@@ -33,7 +33,7 @@ public:
};
private:
- const TargetMachine *TM;
+ const DataLayout *DL;
/// AnonGlobalIDs - We need to give global values the same name every time
/// they are mangled. This keeps track of the number we give to anonymous
@@ -46,7 +46,7 @@ private:
unsigned NextAnonGlobalID;
public:
- Mangler(const TargetMachine *TM) : TM(TM), NextAnonGlobalID(1) {}
+ Mangler(const DataLayout *DL) : DL(DL), NextAnonGlobalID(1) {}
/// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
/// and the specified global variable's name. If the global variable doesn't
diff --git a/include/llvm/Target/TargetLoweringObjectFile.h b/include/llvm/Target/TargetLoweringObjectFile.h
index c289c9c77a..f389e1966c 100644
--- a/include/llvm/Target/TargetLoweringObjectFile.h
+++ b/include/llvm/Target/TargetLoweringObjectFile.h
@@ -34,6 +34,7 @@ namespace llvm {
class TargetLoweringObjectFile : public MCObjectFileInfo {
MCContext *Ctx;
+ const DataLayout *DL;
TargetLoweringObjectFile(
const TargetLoweringObjectFile&) LLVM_DELETED_FUNCTION;
@@ -42,7 +43,7 @@ class TargetLoweringObjectFile : public MCObjectFileInfo {
public:
MCContext &getContext() const { return *Ctx; }
- TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(0) {}
+ TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(0), DL(0) {}
virtual ~TargetLoweringObjectFile();