llvm.org GIT mirror llvm / 8e0f67d
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 Rafael Espindola 6 years ago
38 changed file(s) with 208 addition(s) and 111 deletion(s). Raw diff Collapse all Expand all
11591159 ``a::``
11601160 This specifies the alignment for an aggregate type of a given bit
11611161 ````.
1162 ``m:``
1163 If prerest, specifies that llvm names are mangled in the output. The
1164 options are
1165 * ``e``: ELF mangling: Private symbols get a ``.L`` prefix.
1166 * ``m``: Mips mangling: Private symbols get a ``$`` prefix.
1167 * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other
1168 symbols get a ``_`` prefix.
1169 * ``c``: COFF prefix: Similar to Mach-O, but stdcall and fastcall
1170 functions also get a sufiix based on the frame size.
11621171 ``n::...``
11631172 This specifies a set of native integer widths for the target CPU in
11641173 bits. For example, it might contain ``n32`` for 32-bit PowerPC,
3333 class IntegerType;
3434 class StructType;
3535 class StructLayout;
36 class Triple;
3637 class GlobalVariable;
3738 class LLVMContext;
3839 template
9899 bool LittleEndian; ///< Defaults to false
99100 unsigned StackNaturalAlign; ///< Stack natural alignment
100101
102 enum ManglingModeT {
103 MM_None,
104 MM_ELF,
105 MM_MachO,
106 MM_COFF,
107 MM_Mips
108 };
109 ManglingModeT ManglingMode;
110
101111 SmallVector LegalIntWidths; ///< Legal Integers.
102112
103113 /// Alignments - Where the primitive type alignment data is stored.
173183 ImmutablePass(ID),
174184 LittleEndian(DL.isLittleEndian()),
175185 StackNaturalAlign(DL.StackNaturalAlign),
186 ManglingMode(DL.ManglingMode),
176187 LegalIntWidths(DL.LegalIntWidths),
177188 Alignments(DL.Alignments),
178189 Pointers(DL.Pointers),
220231 bool exceedsNaturalStackAlignment(unsigned Align) const {
221232 return (StackNaturalAlign != 0) && (Align > StackNaturalAlign);
222233 }
234
235 bool hasMicrosoftFastStdCallMangling() const {
236 return ManglingMode == MM_COFF;
237 }
238
239 bool hasLinkerPrivateGlobalPrefix() const {
240 return ManglingMode == MM_MachO;
241 }
242
243 const char *getLinkerPrivateGlobalPrefix() const {
244 if (ManglingMode == MM_MachO)
245 return "l";
246 return getPrivateGlobalPrefix();
247 }
248
249 char getGlobalPrefix() const {
250 switch (ManglingMode) {
251 case MM_None:
252 case MM_ELF:
253 case MM_Mips:
254 return '\0';
255 case MM_MachO:
256 case MM_COFF:
257 return '_';
258 }
259 }
260
261 const char *getPrivateGlobalPrefix() const {
262 switch (ManglingMode) {
263 case MM_None:
264 return "";
265 case MM_ELF:
266 return ".L";
267 case MM_Mips:
268 return "$";
269 case MM_MachO:
270 case MM_COFF:
271 return "L";
272 }
273 }
274
275 static const char *getManglingComponent(const Triple &T);
223276
224277 /// fitsInLegalInteger - This function returns true if the specified type fits
225278 /// in a native integer type supported by the CPU. For example, if the CPU
114114 /// LabelSuffix - This is appended to emitted labels.
115115 const char *DebugLabelSuffix; // Defaults to ":"
116116
117 /// If this is set to anything other than '\0', it is prepended
118 /// onto all global symbols. This is often used for '_'.
119 char GlobalPrefix; // Defaults to '\0'
120
121117 /// This prefix is used for globals like constant pool entries that are
122118 /// completely private to the .s file and should not have names in the .o
123119 /// file.
124120 const char *PrivateGlobalPrefix; // Defaults to "L"
125
126 /// This prefix is used for symbols that should be passed through the
127 /// assembler but be removed by the linker. This is 'l' on Darwin,
128 /// currently used for some ObjC metadata.
129 /// The default of "" meast that for this system a plain private symbol
130 /// should be used.
131 const char *LinkerPrivateGlobalPrefix; // Defaults to "".
132121
133122 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
134123 /// emit before and after an inline assembly statement.
199188 /// which doesn't support the '.bss' directive only.
200189 bool UsesELFSectionDirectiveForBSS; // Defaults to false.
201190
202 /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
203 /// style mangling for functions with X86_StdCall/X86_FastCall calling
204 /// convention.
205 bool HasMicrosoftFastStdCallMangling; // Defaults to false.
206
207191 bool NeedsDwarfSectionOffsetDirective;
208192
209193 //===--- Alignment Information ----------------------------------------===//
392376 return UsesELFSectionDirectiveForBSS;
393377 }
394378
395 bool hasMicrosoftFastStdCallMangling() const {
396 return HasMicrosoftFastStdCallMangling;
397 }
398
399379 bool needsDwarfSectionOffsetDirective() const {
400380 return NeedsDwarfSectionOffsetDirective;
401381 }
435415 const char *getDebugLabelSuffix() const {
436416 return DebugLabelSuffix;
437417 }
438
439 char getGlobalPrefix() const {
440 return GlobalPrefix;
441 }
442418 const char *getPrivateGlobalPrefix() const {
443419 return PrivateGlobalPrefix;
444 }
445 bool hasLinkerPrivateGlobalPrefix() const {
446 return LinkerPrivateGlobalPrefix[0] != '\0';
447 }
448 const char *getLinkerPrivateGlobalPrefix() const {
449 if (hasLinkerPrivateGlobalPrefix())
450 return LinkerPrivateGlobalPrefix;
451 return getPrivateGlobalPrefix();
452420 }
453421 const char *getInlineAsmStart() const {
454422 return InlineAsmStart;
1717
1818 namespace llvm {
1919
20 class DataLayout;
2021 class GlobalValue;
2122 class MCContext;
2223 template class SmallVectorImpl;
23 class TargetMachine;
2424 class Twine;
2525
2626 class Mangler {
3232 };
3333
3434 private:
35 const TargetMachine *TM;
35 const DataLayout *DL;
3636
3737 /// AnonGlobalIDs - We need to give global values the same name every time
3838 /// they are mangled. This keeps track of the number we give to anonymous
4545 unsigned NextAnonGlobalID;
4646
4747 public:
48 Mangler(const TargetMachine *TM) : TM(TM), NextAnonGlobalID(1) {}
48 Mangler(const DataLayout *DL) : DL(DL), NextAnonGlobalID(1) {}
4949
5050 /// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
5151 /// and the specified global variable's name. If the global variable doesn't
3333
3434 class TargetLoweringObjectFile : public MCObjectFileInfo {
3535 MCContext *Ctx;
36 const DataLayout *DL;
3637
3738 TargetLoweringObjectFile(
3839 const TargetLoweringObjectFile&) LLVM_DELETED_FUNCTION;
4142 public:
4243 MCContext &getContext() const { return *Ctx; }
4344
44 TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(0) {}
45 TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(0), DL(0) {}
4546
4647 virtual ~TargetLoweringObjectFile();
4748
164164
165165 OutStreamer.InitStreamer();
166166
167 Mang = new Mangler(&TM);
167 Mang = new Mangler(TM.getDataLayout());
168168
169169 // Allow the target to emit any magic that it wants at the start of the file.
170170 EmitStartOfAsmFile(M);
11051105 /// by the current function to the current output stream.
11061106 ///
11071107 void AsmPrinter::EmitJumpTableInfo() {
1108 const DataLayout *DL = MF->getTarget().getDataLayout();
11081109 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
11091110 if (MJTI == 0) return;
11101111 if (MJTI->getEntryKind() == MachineJumpTableInfo::EK_Inline) return;
11701171 // before each jump table. The first label is never referenced, but tells
11711172 // the assembler and linker the extents of the jump table object. The
11721173 // second label is actually referenced by the code.
1173 if (JTInDiffSection && MAI->hasLinkerPrivateGlobalPrefix())
1174 if (JTInDiffSection && DL->hasLinkerPrivateGlobalPrefix())
11741175 // FIXME: This doesn't have to have any specific name, just any randomly
11751176 // named and numbered 'l' label would work. Simplify GetJTISymbol.
11761177 OutStreamer.EmitLabel(GetJTISymbol(JTI, true));
19921993 /// GetTempSymbol - Return the MCSymbol corresponding to the assembler
19931994 /// temporary label with the specified stem and unique ID.
19941995 MCSymbol *AsmPrinter::GetTempSymbol(StringRef Name, unsigned ID) const {
1995 return OutContext.GetOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) +
1996 const DataLayout *DL = TM.getDataLayout();
1997 return OutContext.GetOrCreateSymbol(Twine(DL->getPrivateGlobalPrefix()) +
19961998 Name + Twine(ID));
19971999 }
19982000
19992001 /// GetTempSymbol - Return an assembler temporary label with the specified
20002002 /// stem.
20012003 MCSymbol *AsmPrinter::GetTempSymbol(StringRef Name) const {
2002 return OutContext.GetOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix())+
2004 const DataLayout *DL = TM.getDataLayout();
2005 return OutContext.GetOrCreateSymbol(Twine(DL->getPrivateGlobalPrefix())+
20032006 Name);
20042007 }
20052008
20142017
20152018 /// GetCPISymbol - Return the symbol for the specified constant pool entry.
20162019 MCSymbol *AsmPrinter::GetCPISymbol(unsigned CPID) const {
2020 const DataLayout *DL = TM.getDataLayout();
20172021 return OutContext.GetOrCreateSymbol
2018 (Twine(MAI->getPrivateGlobalPrefix()) + "CPI" + Twine(getFunctionNumber())
2022 (Twine(DL->getPrivateGlobalPrefix()) + "CPI" + Twine(getFunctionNumber())
20192023 + "_" + Twine(CPID));
20202024 }
20212025
20272031 /// GetJTSetSymbol - Return the symbol for the specified jump table .set
20282032 /// FIXME: privatize to AsmPrinter.
20292033 MCSymbol *AsmPrinter::GetJTSetSymbol(unsigned UID, unsigned MBBID) const {
2034 const DataLayout *DL = TM.getDataLayout();
20302035 return OutContext.GetOrCreateSymbol
2031 (Twine(MAI->getPrivateGlobalPrefix()) + Twine(getFunctionNumber()) + "_" +
2036 (Twine(DL->getPrivateGlobalPrefix()) + Twine(getFunctionNumber()) + "_" +
20322037 Twine(UID) + "_set_" + Twine(MBBID));
20332038 }
20342039
1818 #include "llvm/CodeGen/MachineBasicBlock.h"
1919 #include "llvm/CodeGen/MachineModuleInfo.h"
2020 #include "llvm/IR/Constants.h"
21 #include "llvm/IR/DataLayout.h"
2122 #include "llvm/IR/InlineAsm.h"
2223 #include "llvm/IR/LLVMContext.h"
2324 #include "llvm/IR/Module.h"
490491 /// for their own strange codes.
491492 void AsmPrinter::PrintSpecial(const MachineInstr *MI, raw_ostream &OS,
492493 const char *Code) const {
494 const DataLayout *DL = TM.getDataLayout();
493495 if (!strcmp(Code, "private")) {
494 OS << MAI->getPrivateGlobalPrefix();
496 OS << DL->getPrivateGlobalPrefix();
495497 } else if (!strcmp(Code, "comment")) {
496498 OS << MAI->getCommentString();
497499 } else if (!strcmp(Code, "uid")) {
5151 if (!CachedMCSymbol) {
5252 const MachineFunction *MF = getParent();
5353 MCContext &Ctx = MF->getContext();
54 const char *Prefix = Ctx.getAsmInfo()->getPrivateGlobalPrefix();
54 const TargetMachine &TM = MF->getTarget();
55 const char *Prefix = TM.getDataLayout()->getPrivateGlobalPrefix();
5556 CachedMCSymbol = Ctx.GetOrCreateSymbol(Twine(Prefix) + "BB" +
5657 Twine(MF->getFunctionNumber()) +
5758 "_" + Twine(getNumber()));
446446 /// normal 'L' label is returned.
447447 MCSymbol *MachineFunction::getJTISymbol(unsigned JTI, MCContext &Ctx,
448448 bool isLinkerPrivate) const {
449 const DataLayout *DL = getTarget().getDataLayout();
449450 assert(JumpTableInfo && "No jump tables");
450451 assert(JTI < JumpTableInfo->getJumpTables().size() && "Invalid JTI!");
451 const MCAsmInfo &MAI = *getTarget().getMCAsmInfo();
452
453 const char *Prefix = isLinkerPrivate ? MAI.getLinkerPrivateGlobalPrefix() :
454 MAI.getPrivateGlobalPrefix();
452
453 const char *Prefix = isLinkerPrivate ? DL->getLinkerPrivateGlobalPrefix() :
454 DL->getPrivateGlobalPrefix();
455455 SmallString<60> Name;
456456 raw_svector_ostream(Name)
457457 << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
461461 /// getPICBaseSymbol - Return a function-local symbol to represent the PIC
462462 /// base.
463463 MCSymbol *MachineFunction::getPICBaseSymbol() const {
464 const MCAsmInfo &MAI = *Target.getMCAsmInfo();
465 return Ctx.GetOrCreateSymbol(Twine(MAI.getPrivateGlobalPrefix())+
464 const DataLayout *DL = getTarget().getDataLayout();
465 return Ctx.GetOrCreateSymbol(Twine(DL->getPrivateGlobalPrefix())+
466466 Twine(getFunctionNumber())+"$pb");
467467 }
468468
231231 }
232232
233233 uint64_t MCJIT::getExistingSymbolAddress(const std::string &Name) {
234 Mangler Mang(TM);
234 Mangler Mang(TM->getDataLayout());
235235 SmallString<128> FullName;
236236 Mang.getNameWithPrefix(FullName, Name);
237237 return Dyld.getSymbolLoadAddress(FullName);
322322 //
323323 // This is the accessor for the target address, so make sure to check the
324324 // load address of the symbol, not the local address.
325 Mangler Mang(TM);
325 Mangler Mang(TM->getDataLayout());
326326 SmallString<128> Name;
327327 Mang.getNameWithPrefix(Name, F);
328328 return (void*)Dyld.getSymbolLoadAddress(Name);
1818 #include "llvm/IR/DataLayout.h"
1919 #include "llvm/ADT/DenseMap.h"
2020 #include "llvm/ADT/STLExtras.h"
21 #include "llvm/ADT/Triple.h"
2122 #include "llvm/IR/Constants.h"
2223 #include "llvm/IR/DerivedTypes.h"
2324 #include "llvm/IR/Module.h"
150151 //===----------------------------------------------------------------------===//
151152 // DataLayout Class Implementation
152153 //===----------------------------------------------------------------------===//
154
155 const char *DataLayout::getManglingComponent(const Triple &T) {
156 if (T.isOSBinFormatMachO())
157 return "-m:o";
158 if (T.isOSBinFormatELF() || T.isArch64Bit())
159 return "-m:e";
160 assert(T.isOSBinFormatCOFF());
161 return "-m:c";
162 }
153163
154164 static const LayoutAlignElem DefaultAlignments[] = {
155165 { INTEGER_ALIGN, 1, 1, 1 }, // i1
172182 LayoutMap = 0;
173183 LittleEndian = false;
174184 StackNaturalAlign = 0;
185 ManglingMode = MM_None;
175186
176187 // Default alignments
177188 for (int I = 0, N = array_lengthof(DefaultAlignments); I < N; ++I) {
304315 StackNaturalAlign = inBytes(getInt(Tok));
305316 break;
306317 }
318 case 'm':
319 assert(Tok.empty());
320 assert(Rest.size() == 1);
321 switch(Rest[0]) {
322 default:
323 llvm_unreachable("Unknown mangling in datalayout string");
324 case 'e':
325 ManglingMode = MM_ELF;
326 break;
327 case 'o':
328 ManglingMode = MM_MachO;
329 break;
330 case 'm':
331 ManglingMode = MM_Mips;
332 break;
333 case 'c':
334 ManglingMode = MM_COFF;
335 break;
336 }
337 break;
307338 default:
308339 llvm_unreachable("Unknown specifier in datalayout string");
309340 break;
480511 raw_string_ostream OS(Result);
481512
482513 OS << (LittleEndian ? "e" : "E");
514
515 switch (ManglingMode) {
516 case MM_None:
517 break;
518 case MM_ELF:
519 OS << "-m:e";
520 break;
521 case MM_MachO:
522 OS << "-m:o";
523 break;
524 case MM_COFF:
525 OS << "-m:c";
526 break;
527 case MM_Mips:
528 OS << "-m:m";
529 break;
530 }
531
483532 SmallVector addrSpaces;
484533 // Lets get all of the known address spaces and sort them
485534 // into increasing order so that we can emit the string
386386 passes.add(createVerifierPass());
387387
388388 // mark which symbols can not be internalized
389 Mangler Mangler(TargetMach);
389 Mangler Mangler(TargetMach->getDataLayout());
390390 std::vector MustPreserveList;
391391 SmallPtrSet AsmUsed;
392392 std::vector Libcalls;
4343 LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t)
4444 : _module(m), _target(t),
4545 _context(_target->getMCAsmInfo(), _target->getRegisterInfo(), &ObjFileInfo),
46 _mangler(t) {
46 _mangler(t->getDataLayout()) {
4747 ObjFileInfo.InitMCObjectFileInfo(t->getTargetTriple(),
4848 t->getRelocationModel(), t->getCodeModel(),
4949 _context);
4040 CommentString = "#";
4141 LabelSuffix = ":";
4242 DebugLabelSuffix = ":";
43 GlobalPrefix = '\0';
4443 PrivateGlobalPrefix = "L";
45 LinkerPrivateGlobalPrefix = "";
4644 InlineAsmStart = "APP";
4745 InlineAsmEnd = "NO_APP";
4846 Code16Directive = ".code16";
8684 ExceptionsType = ExceptionHandling::None;
8785 DwarfUsesRelocationsAcrossSections = true;
8886 DwarfRegNumForCFI = false;
89 HasMicrosoftFastStdCallMangling = false;
9087 NeedsDwarfSectionOffsetDirective = false;
9188 UseParensForSymbolVariant = false;
9289 }
1717 void MCAsmInfoCOFF::anchor() { }
1818
1919 MCAsmInfoCOFF::MCAsmInfoCOFF() {
20 GlobalPrefix = '_';
2120 // MingW 4.5 and later support .comm with log2 alignment, but .lcomm uses byte
2221 // alignment.
2322 COMMDirectiveAlignmentIsInBytes = false;
3433 // Set up DWARF directives
3534 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
3635 SupportsDebugInformation = true;
37 HasMicrosoftFastStdCallMangling = true;
3836 NeedsDwarfSectionOffsetDirective = true;
3937 }
4038
2222 MCAsmInfoDarwin::MCAsmInfoDarwin() {
2323 // Common settings for all Darwin targets.
2424 // Syntax:
25 GlobalPrefix = '_';
26 LinkerPrivateGlobalPrefix = "l";
2725 HasSingleParameterDotFile = false;
2826 HasSubsectionsViaSymbols = true;
2927
3333 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
3434 Subtarget(TT, CPU, FS),
3535 InstrInfo(Subtarget),
36 DL("e-i64:64-i128:128-n32:64-S128"),
36 DL("e-m:e-i64:64-i128:128-n32:64-S128"),
3737 TLInfo(*this),
3838 TSInfo(*this),
3939 FrameLowering(Subtarget) {
222222
223223 MCSymbol *ARMAsmPrinter::
224224 GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const {
225 const DataLayout *DL = TM.getDataLayout();
225226 SmallString<60> Name;
226 raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "JTI"
227 raw_svector_ostream(Name) << DL->getPrivateGlobalPrefix() << "JTI"
227228 << getFunctionNumber() << '_' << uid << '_' << uid2;
228229 return OutContext.GetOrCreateSymbol(Name.str());
229230 }
230231
231232
232233 MCSymbol *ARMAsmPrinter::GetARMSJLJEHLabel() const {
234 const DataLayout *DL = TM.getDataLayout();
233235 SmallString<60> Name;
234 raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "SJLJEH"
236 raw_svector_ostream(Name) << DL->getPrivateGlobalPrefix() << "SJLJEH"
235237 << getFunctionNumber();
236238 return OutContext.GetOrCreateSymbol(Name.str());
237239 }
801803
802804 void ARMAsmPrinter::
803805 EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
806 const DataLayout *DL = TM.getDataLayout();
804807 int Size = TM.getDataLayout()->getTypeAllocSize(MCPV->getType());
805808
806809 ARMConstantPoolValue *ACPV = static_cast(MCPV);
809812 if (ACPV->isLSDA()) {
810813 SmallString<128> Str;
811814 raw_svector_ostream OS(Str);
812 OS << MAI->getPrivateGlobalPrefix() << "_LSDA_" << getFunctionNumber();
815 OS << DL->getPrivateGlobalPrefix() << "_LSDA_" << getFunctionNumber();
813816 MCSym = OutContext.GetOrCreateSymbol(OS.str());
814817 } else if (ACPV->isBlockAddress()) {
815818 const BlockAddress *BA =
837840 OutContext);
838841
839842 if (ACPV->getPCAdjustment()) {
840 MCSymbol *PCLabel = getPICLabel(MAI->getPrivateGlobalPrefix(),
843 MCSymbol *PCLabel = getPICLabel(DL->getPrivateGlobalPrefix(),
841844 getFunctionNumber(),
842845 ACPV->getLabelId(),
843846 OutContext);
11161119 #include "ARMGenMCPseudoLowering.inc"
11171120
11181121 void ARMAsmPrinter::EmitInstruction(const MachineInstr *MI) {
1122 const DataLayout *DL = TM.getDataLayout();
1123
11191124 // If we just ended a constant pool, mark it as such.
11201125 if (InConstantPool && MI->getOpcode() != ARM::CONSTPOOL_ENTRY) {
11211126 OutStreamer.EmitDataRegion(MCDR_DataRegionEnd);
12531258 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
12541259 const MCExpr *GVSymExpr = MCSymbolRefExpr::Create(GVSym, OutContext);
12551260
1256 MCSymbol *LabelSym = getPICLabel(MAI->getPrivateGlobalPrefix(),
1261 MCSymbol *LabelSym = getPICLabel(DL->getPrivateGlobalPrefix(),
12571262 getFunctionNumber(),
12581263 MI->getOperand(2).getImm(), OutContext);
12591264 const MCExpr *LabelSymExpr= MCSymbolRefExpr::Create(LabelSym, OutContext);
12861291 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
12871292 const MCExpr *GVSymExpr = MCSymbolRefExpr::Create(GVSym, OutContext);
12881293
1289 MCSymbol *LabelSym = getPICLabel(MAI->getPrivateGlobalPrefix(),
1294 MCSymbol *LabelSym = getPICLabel(DL->getPrivateGlobalPrefix(),
12901295 getFunctionNumber(),
12911296 MI->getOperand(3).getImm(), OutContext);
12921297 const MCExpr *LabelSymExpr= MCSymbolRefExpr::Create(LabelSym, OutContext);
13121317 // This adds the address of LPC0 to r0.
13131318
13141319 // Emit the label.
1315 OutStreamer.EmitLabel(getPICLabel(MAI->getPrivateGlobalPrefix(),
1320 OutStreamer.EmitLabel(getPICLabel(DL->getPrivateGlobalPrefix(),
13161321 getFunctionNumber(), MI->getOperand(2).getImm(),
13171322 OutContext));
13181323
13331338 // This adds the address of LPC0 to r0.
13341339
13351340 // Emit the label.
1336 OutStreamer.EmitLabel(getPICLabel(MAI->getPrivateGlobalPrefix(),
1341 OutStreamer.EmitLabel(getPICLabel(DL->getPrivateGlobalPrefix(),
13371342 getFunctionNumber(), MI->getOperand(2).getImm(),
13381343 OutContext));
13391344
13641369 // a PC-relative address at the ldr instruction.
13651370
13661371 // Emit the label.
1367 OutStreamer.EmitLabel(getPICLabel(MAI->getPrivateGlobalPrefix(),
1372 OutStreamer.EmitLabel(getPICLabel(DL->getPrivateGlobalPrefix(),
13681373 getFunctionNumber(), MI->getOperand(2).getImm(),
13691374 OutContext));
13701375
6969 void ARMTargetMachine::anchor() { }
7070
7171 static std::string computeDataLayout(ARMSubtarget &ST) {
72 // Little endian. Pointers are 32 bits and aligned to 32 bits.
73 std::string Ret = "e-p:32:32";
72 // Little endian.
73 std::string Ret = "e";
74
75 Ret += DataLayout::getManglingComponent(ST.getTargetTriple());
76
77 // Pointers are 32 bits and aligned to 32 bits.
78 Ret += "-p:32:32";
7479
7580 // On thumb, i16,i18 and i1 have natural aligment requirements, but we try to
7681 // align to 32.
7070 CodeModel::Model CM,
7171 CodeGenOpt::Level OL)
7272 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
73 DL("e-p:32:32-i1:32-i64:64-a:0-n32") ,
73 DL("e-m:e-p:32:32-i1:32-i64:64-a:0-n32") ,
7474 Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this),
7575 TSInfo(*this),
7676 FrameLowering(Subtarget),
1616 #include "llvm/CodeGen/AsmPrinter.h"
1717 #include "llvm/CodeGen/MachineBasicBlock.h"
1818 #include "llvm/CodeGen/MachineInstr.h"
19 #include "llvm/IR/DataLayout.h"
1920 #include "llvm/MC/MCAsmInfo.h"
2021 #include "llvm/MC/MCContext.h"
2122 #include "llvm/MC/MCExpr.h"
2324 #include "llvm/Support/ErrorHandling.h"
2425 #include "llvm/Support/raw_ostream.h"
2526 #include "llvm/Target/Mangler.h"
27 #include "llvm/Target/TargetMachine.h"
2628 using namespace llvm;
2729
2830 MCSymbol *MSP430MCInstLower::
4749
4850 MCSymbol *MSP430MCInstLower::
4951 GetJumpTableSymbol(const MachineOperand &MO) const {
52 const DataLayout *DL = Printer.TM.getDataLayout();
5053 SmallString<256> Name;
51 raw_svector_ostream(Name) << Printer.MAI->getPrivateGlobalPrefix() << "JTI"
54 raw_svector_ostream(Name) << DL->getPrivateGlobalPrefix() << "JTI"
5255 << Printer.getFunctionNumber() << '_'
5356 << MO.getIndex();
5457
6366
6467 MCSymbol *MSP430MCInstLower::
6568 GetConstantPoolIndexSymbol(const MachineOperand &MO) const {
69 const DataLayout *DL = Printer.TM.getDataLayout();
6670 SmallString<256> Name;
67 raw_svector_ostream(Name) << Printer.MAI->getPrivateGlobalPrefix() << "CPI"
71 raw_svector_ostream(Name) << DL->getPrivateGlobalPrefix() << "CPI"
6872 << Printer.getFunctionNumber() << '_'
6973 << MO.getIndex();
7074
3333 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
3434 Subtarget(TT, CPU, FS),
3535 // FIXME: Check DataLayout string.
36 DL("e-p:16:16-i32:16:32-n8:16"),
36 DL("e-m:e-p:16:16-i32:16:32-n8:16"),
3737 InstrInfo(*this), TLInfo(*this), TSInfo(*this),
3838 FrameLowering(Subtarget) {
3939 initAsmInfo();
1616 #include "llvm/IR/DataLayout.h"
1717 #include "llvm/IR/DerivedTypes.h"
1818 #include "llvm/IR/Function.h"
19 #include "llvm/MC/MCAsmInfo.h"
2019 #include "llvm/MC/MCContext.h"
21 #include "llvm/Target/TargetMachine.h"
2220 #include "llvm/Support/raw_ostream.h"
2321 using namespace llvm;
2422
3028 SmallString<256> TmpData;
3129 StringRef Name = GVName.toStringRef(TmpData);
3230 assert(!Name.empty() && "getNameWithPrefix requires non-empty name");
33
34 const MCAsmInfo *MAI = TM->getMCAsmInfo();
35
31
3632 // If the global name is not led with \1, add the appropriate prefixes.
3733 if (Name[0] == '\1') {
3834 Name = Name.substr(1);
3935 } else {
4036 if (PrefixTy == Mangler::Private) {
41 const char *Prefix = MAI->getPrivateGlobalPrefix();
37 const char *Prefix = DL->getPrivateGlobalPrefix();
4238 OutName.append(Prefix, Prefix+strlen(Prefix));
4339 } else if (PrefixTy == Mangler::LinkerPrivate) {
44 const char *Prefix = MAI->getLinkerPrivateGlobalPrefix();
40 const char *Prefix = DL->getLinkerPrivateGlobalPrefix();
4541 OutName.append(Prefix, Prefix+strlen(Prefix));
4642 }
4743
48
49 char Prefix = MAI->getGlobalPrefix();
44 char Prefix = DL->getGlobalPrefix();
5045 if (Prefix != '\0')
5146 OutName.push_back(Prefix);
5247 }
10499 // Must mangle the global into a unique ID.
105100 getNameWithPrefix(OutName, "__unnamed_" + Twine(ID), PrefixTy);
106101 }
107
102
108103 // If we are supposed to add a microsoft-style suffix for stdcall/fastcall,
109104 // add it.
110 if (TM->getMCAsmInfo()->hasMicrosoftFastStdCallMangling()) {
105 if (DL->hasMicrosoftFastStdCallMangling()) {
111106 if (const Function *F = dyn_cast(GV)) {
112107 CallingConv::ID CC = F->getCallingConv();
113108
127122 // "Pure" variadic functions do not receive @0 suffix.
128123 (!FT->isVarArg() || FT->getNumParams() == 0 ||
129124 (FT->getNumParams() == 1 && F->hasStructRetAttr())))
130 AddFastCallStdCallSuffix(OutName, F, *TM->getDataLayout());
125 AddFastCallStdCallSuffix(OutName, F, *DL);
131126 }
132127 }
133128 }
494494
495495 void MipsAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
496496 raw_ostream &O) {
497 const DataLayout *DL = TM.getDataLayout();
497498 const MachineOperand &MO = MI->getOperand(opNum);
498499 bool closeP = false;
499500
542543 }
543544
544545 case MachineOperand::MO_ConstantPoolIndex:
545 O << MAI->getPrivateGlobalPrefix() << "CPI"
546 O << DL->getPrivateGlobalPrefix() << "CPI"
546547 << getFunctionNumber() << "_" << MO.getIndex();
547548 if (MO.getOffset())
548549 O << "+" << MO.getOffset();
5353 else
5454 Ret += "E";
5555
56 Ret += "-m:m";
57
5658 // Pointers are 32 bit on some ABIs.
5759 if (!ST.isABI_N64())
5860 Ret += "-p:32:32";
894894 const_cast(getObjFileLowering())
895895 .Initialize(OutContext, TM);
896896
897 Mang = new Mangler(&TM);
897 Mang = new Mangler(TM.getDataLayout());
898898
899899 // Emit header before any dwarf directives are emitted below.
900900 emitHeader(M, OS1);
138138
139139 void PPCAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
140140 raw_ostream &O) {
141 const DataLayout *DL = TM.getDataLayout();
141142 const MachineOperand &MO = MI->getOperand(OpNo);
142143
143144 switch (MO.getType()) {
157158 O << *MO.getMBB()->getSymbol();
158159 return;
159160 case MachineOperand::MO_ConstantPoolIndex:
160 O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
161 O << DL->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
161162 << '_' << MO.getIndex();
162163 return;
163164 case MachineOperand::MO_BlockAddress:
280281 /// exists for it. If not, create one. Then return a symbol that references
281282 /// the TOC entry.
282283 MCSymbol *PPCAsmPrinter::lookUpOrCreateTOCEntry(MCSymbol *Sym) {
283
284 const DataLayout *DL = TM.getDataLayout();
284285 MCSymbol *&TOCEntry = TOC[Sym];
285286
286287 // To avoid name clash check if the name already exists.
287288 while (TOCEntry == 0) {
288 if (OutContext.LookupSymbol(Twine(MAI->getPrivateGlobalPrefix()) +
289 if (OutContext.LookupSymbol(Twine(DL->getPrivateGlobalPrefix()) +
289290 "C" + Twine(TOCLabelID++)) == 0) {
290291 TOCEntry = GetTempSymbol("C", TOCLabelID);
291292 }
1818 #include "llvm/CodeGen/AsmPrinter.h"
1919 #include "llvm/CodeGen/MachineFunction.h"
2020 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
21 #include "llvm/IR/DataLayout.h"
2122 #include "llvm/IR/GlobalValue.h"
2223 #include "llvm/MC/MCAsmInfo.h"
2324 #include "llvm/MC/MCExpr.h"
2425 #include "llvm/MC/MCInst.h"
2526 #include "llvm/Target/Mangler.h"
27 #include "llvm/Target/TargetMachine.h"
2628 using namespace llvm;
2729
2830 static MachineModuleInfoMachO &getMachOMMI(AsmPrinter &AP) {
3133
3234
3335 static MCSymbol *GetSymbolFromOperand(const MachineOperand &MO, AsmPrinter &AP){
36 const DataLayout *DL = AP.TM.getDataLayout();
3437 MCContext &Ctx = AP.OutContext;
3538
3639 SmallString<128> Name;
4144 Suffix = "$non_lazy_ptr";
4245
4346 if (!Suffix.empty())
44 Name += AP.MAI->getPrivateGlobalPrefix();
47 Name += DL->getPrivateGlobalPrefix();
4548
4649 unsigned PrefixLen = Name.size();
4750
3838
3939 // PPC is big endian.
4040 std::string Ret = "E";
41
42 Ret += DataLayout::getManglingComponent(T);
4143
4244 // PPC32 has 32 bit pointers. The PS3 (OS Lv2) is a PPC64 machine with 32 bit
4345 // pointers.
218218
219219 void SparcAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
220220 raw_ostream &O) {
221 const DataLayout *DL = TM.getDataLayout();
221222 const MachineOperand &MO = MI->getOperand (opNum);
222223 unsigned TF = MO.getTargetFlags();
223224 #ifndef NDEBUG
317318 O << MO.getSymbolName();
318319 break;
319320 case MachineOperand::MO_ConstantPoolIndex:
320 O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
321 O << DL->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
321322 << MO.getIndex();
322323 break;
323324 default:
2424
2525 static std::string computeDataLayout(const SparcSubtarget &ST) {
2626 // Sparc is big endian.
27 std::string Ret = "E";
27 std::string Ret = "E-m:e";
2828
2929 // Some ABIs have 32bit pointers.
3030 if (!ST.is64Bit())
2929 // Make sure that global data has at least 16 bits of alignment by default,
3030 // so that we can refer to it using LARL. We don't have any special
3131 // requirements for stack variables though.
32 DL("E-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64"),
32 DL("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64"),
3333 InstrInfo(*this), TLInfo(*this), TSInfo(*this),
3434 FrameLowering(*this, Subtarget) {
3535 initAsmInfo();
4040 void TargetLoweringObjectFile::Initialize(MCContext &ctx,
4141 const TargetMachine &TM) {
4242 Ctx = &ctx;
43 DL = TM.getDataLayout();
4344 InitMCObjectFileInfo(TM.getTargetTriple(),
4445 TM.getRelocationModel(), TM.getCodeModel(), *Ctx);
4546 }
113114 assert(!GV->hasLinkerPrivateLinkage());
114115 assert(!GV->hasLinkerPrivateWeakLinkage());
115116
116 const MCAsmInfo *MAI = Ctx->getAsmInfo();
117117 SmallString<60> NameStr;
118 NameStr += MAI->getPrivateGlobalPrefix();
118 NameStr += DL->getPrivateGlobalPrefix();
119119 M.getNameWithPrefix(NameStr, GV);
120120 NameStr.append(Suffix.begin(), Suffix.end());
121121 return Ctx->GetOrCreateSymbol(NameStr.str());
130130 void X86MCAsmInfoMicrosoft::anchor() { }
131131
132132 X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) {
133 if (Triple.getArch() == Triple::x86_64) {
134 GlobalPrefix = '\0';
133 if (Triple.getArch() == Triple::x86_64)
135134 PrivateGlobalPrefix = ".L";
136 HasMicrosoftFastStdCallMangling = false;
137 }
138135
139136 AssemblerDialect = AsmWriterFlavor;
140137
146143 void X86MCAsmInfoGNUCOFF::anchor() { }
147144
148145 X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) {
149 if (Triple.getArch() == Triple::x86_64) {
150 GlobalPrefix = '\0';
146 if (Triple.getArch() == Triple::x86_64)
151147 PrivateGlobalPrefix = ".L";
152 HasMicrosoftFastStdCallMangling = false;
153 }
154148
155149 AssemblerDialect = AsmWriterFlavor;
156150
6969 /// operand to an MCSymbol.
7070 MCSymbol *X86MCInstLower::
7171 GetSymbolFromOperand(const MachineOperand &MO) const {
72 const DataLayout *DL = TM.getDataLayout();
7273 assert((MO.isGlobal() || MO.isSymbol() || MO.isMBB()) && "Isn't a symbol reference");
7374
7475 SmallString<128> Name;
9091 }
9192
9293 if (!Suffix.empty())
93 Name += MAI.getPrivateGlobalPrefix();
94 Name += DL->getPrivateGlobalPrefix();
9495
9596 unsigned PrefixLen = Name.size();
9697
3333 // X86 is little endian
3434 std::string Ret = "e";
3535
36 Ret += DataLayout::getManglingComponent(ST.getTargetTriple());
3637 // X86 and x32 have 32 bit pointers.
3738 if (ST.isTarget64BitILP32() || !ST.is64Bit())
3839 Ret += "-p:32:32";
203203
204204 void XCoreAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
205205 raw_ostream &O) {
206 const DataLayout *DL = TM.getDataLayout();
206207 const MachineOperand &MO = MI->getOperand(opNum);
207208 switch (MO.getType()) {
208209 case MachineOperand::MO_Register:
218219 O << *getSymbol(MO.getGlobal());
219220 break;
220221 case MachineOperand::MO_ConstantPoolIndex:
221 O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
222 O << DL->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
222223 << '_' << MO.getIndex();
223224 break;
224225 case MachineOperand::MO_BlockAddress:
2626 CodeGenOpt::Level OL)
2727 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
2828 Subtarget(TT, CPU, FS),
29 DL("e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i64:32-f64:32-a:0:32-n32"),
29 DL("e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i64:32-f64:32-a:0:32-n32"),
3030 InstrInfo(),
3131 FrameLowering(Subtarget),
3232 TLInfo(*this),