X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=lib%2FCodeGen%2FAsmPrinter%2FAsmPrinter.cpp;h=32bcd6b8158104de8f550af356abda25feea6ff5;hp=c2fd91830f5245908c84a4f232edb95bddc7bc2a;hb=5bf8ade9d043d8739b8bfa90e7d7c64ebfe11ef1;hpb=05c3ddfa4ee09387aa50db8d1013707caf8ef8ae diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index c2fd91830f5..32bcd6b8158 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -173,7 +173,7 @@ bool AsmPrinter::doInitialization(Module &M) { const_cast(getObjFileLowering()) .Initialize(OutContext, TM); - OutStreamer.InitSections(); + OutStreamer.InitSections(false); Mang = new Mangler(TM.getSubtargetImpl()->getDataLayout()); @@ -222,14 +222,12 @@ bool AsmPrinter::doInitialization(Module &M) { } if (MAI->doesSupportDebugInformation()) { - if (Triple(TM.getTargetTriple()).isKnownWindowsMSVCEnvironment()) { + if (Triple(TM.getTargetTriple()).isKnownWindowsMSVCEnvironment()) Handlers.push_back(HandlerInfo(new WinCodeViewLineTables(this), DbgTimerName, CodeViewLineTablesGroupName)); - } else { - DD = new DwarfDebug(this, &M); - Handlers.push_back(HandlerInfo(DD, DbgTimerName, DWARFGroupName)); - } + DD = new DwarfDebug(this, &M); + Handlers.push_back(HandlerInfo(DD, DbgTimerName, DWARFGroupName)); } EHStreamer *ES = nullptr; @@ -244,7 +242,12 @@ bool AsmPrinter::doInitialization(Module &M) { ES = new ARMException(this); break; case ExceptionHandling::WinEH: - ES = new Win64Exception(this); + switch (MAI->getWinEHEncodingType()) { + default: llvm_unreachable("unsupported unwinding information encoding"); + case WinEH::EncodingType::Itanium: + ES = new Win64Exception(this); + break; + } break; } if (ES) @@ -609,24 +612,26 @@ static void emitKill(const MachineInstr *MI, AsmPrinter &AP) { /// of DBG_VALUE, returning true if it was able to do so. A false return /// means the target will need to handle MI in EmitInstruction. static bool emitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP) { - // This code handles only the 3-operand target-independent form. - if (MI->getNumOperands() != 3) + // This code handles only the 4-operand target-independent form. + if (MI->getNumOperands() != 4) return false; SmallString<128> Str; raw_svector_ostream OS(Str); OS << "DEBUG_VALUE: "; - DIVariable V(MI->getOperand(2).getMetadata()); + DIVariable V = MI->getDebugVariable(); if (V.getContext().isSubprogram()) { StringRef Name = DISubprogram(V.getContext()).getDisplayName(); if (!Name.empty()) OS << Name << ":"; } OS << V.getName(); - if (V.isVariablePiece()) - OS << " [piece offset=" << V.getPieceOffset() - << " size="<getDebugExpression(); + if (Expr.isVariablePiece()) + OS << " [piece offset=" << Expr.getPieceOffset() + << " size=" << Expr.getPieceSize() << "]"; OS << " <- "; // The second operand is only an offset if it's an immediate. @@ -726,12 +731,10 @@ void AsmPrinter::EmitFunctionBody() { // Print out code for the function. bool HasAnyRealCode = false; - const MachineInstr *LastMI = nullptr; for (auto &MBB : *MF) { // Print a label for the basic block. EmitBasicBlockStart(MBB); for (auto &MI : MBB) { - LastMI = &MI; // Print the assembly for the instruction. if (!MI.isPosition() && !MI.isImplicitDef() && !MI.isKill() && @@ -792,24 +795,18 @@ void AsmPrinter::EmitFunctionBody() { EmitBasicBlockEnd(MBB); } - // If the last instruction was a prolog label, then we have a situation where - // we emitted a prolog but no function body. This results in the ending prolog - // label equaling the end of function label and an invalid "row" in the - // FDE. We need to emit a noop in this situation so that the FDE's rows are - // valid. - bool RequiresNoop = LastMI && LastMI->isCFIInstruction(); - // If the function is empty and the object file uses .subsections_via_symbols, // then we need to emit *something* to the function body to prevent the // labels from collapsing together. Just emit a noop. - if ((MAI->hasSubsectionsViaSymbols() && !HasAnyRealCode) || RequiresNoop) { + if ((MAI->hasSubsectionsViaSymbols() && !HasAnyRealCode)) { MCInst Noop; TM.getSubtargetImpl()->getInstrInfo()->getNoopForMachoTarget(Noop); - if (Noop.getOpcode()) { - OutStreamer.AddComment("avoids zero-length function"); + OutStreamer.AddComment("avoids zero-length function"); + + // Targets can opt-out of emitting the noop here by leaving the opcode + // unspecified. + if (Noop.getOpcode()) OutStreamer.EmitInstruction(Noop, getSubtargetInfo()); - } else // Target not mc-ized yet. - OutStreamer.EmitRawText(StringRef("\tnop\n")); } const Function *F = MF->getFunction(); @@ -882,16 +879,17 @@ bool AsmPrinter::doFinalization(Module &M) { bool IsThumb = (Arch == Triple::thumb || Arch == Triple::thumbeb); MCInst TrapInst; TM.getSubtargetImpl()->getInstrInfo()->getTrap(TrapInst); + unsigned LogAlignment = llvm::Log2_64(JITI->entryByteAlignment()); + + // Emit the right section for these functions. + OutStreamer.SwitchSection(OutContext.getObjectFileInfo()->getTextSection()); for (const auto &KV : JITI->getTables()) { uint64_t Count = 0; for (const auto &FunPair : KV.second) { // Emit the function labels to make this be a function entry point. MCSymbol *FunSym = OutContext.GetOrCreateSymbol(FunPair.second->getName()); - OutStreamer.EmitSymbolAttribute(FunSym, MCSA_Global); - // FIXME: JumpTableInstrInfo should store information about the required - // alignment of table entries and the size of the padding instruction. - EmitAlignment(3); + EmitAlignment(LogAlignment); if (IsThumb) OutStreamer.EmitThumbFunc(FunSym); if (MAI->hasDotTypeDotSizeDirective()) @@ -913,10 +911,9 @@ bool AsmPrinter::doFinalization(Module &M) { } // Emit enough padding instructions to fill up to the next power of two. - // This assumes that the trap instruction takes 8 bytes or fewer. uint64_t Remaining = NextPowerOf2(Count) - Count; for (uint64_t C = 0; C < Remaining; ++C) { - EmitAlignment(3); + EmitAlignment(LogAlignment); OutStreamer.EmitInstruction(TrapInst, getSubtargetInfo()); } @@ -963,24 +960,21 @@ bool AsmPrinter::doFinalization(Module &M) { } } - if (MAI->hasSetDirective()) { - OutStreamer.AddBlankLine(); - for (const auto &Alias : M.aliases()) { - MCSymbol *Name = getSymbol(&Alias); + OutStreamer.AddBlankLine(); + for (const auto &Alias : M.aliases()) { + MCSymbol *Name = getSymbol(&Alias); - if (Alias.hasExternalLinkage() || !MAI->getWeakRefDirective()) - OutStreamer.EmitSymbolAttribute(Name, MCSA_Global); - else if (Alias.hasWeakLinkage() || Alias.hasLinkOnceLinkage()) - OutStreamer.EmitSymbolAttribute(Name, MCSA_WeakReference); - else - assert(Alias.hasLocalLinkage() && "Invalid alias linkage"); + if (Alias.hasExternalLinkage() || !MAI->getWeakRefDirective()) + OutStreamer.EmitSymbolAttribute(Name, MCSA_Global); + else if (Alias.hasWeakLinkage() || Alias.hasLinkOnceLinkage()) + OutStreamer.EmitSymbolAttribute(Name, MCSA_WeakReference); + else + assert(Alias.hasLocalLinkage() && "Invalid alias linkage"); - EmitVisibility(Name, Alias.getVisibility()); + EmitVisibility(Name, Alias.getVisibility()); - // Emit the directives as assignments aka .set: - OutStreamer.EmitAssignment(Name, - lowerConstant(Alias.getAliasee(), *this)); - } + // Emit the directives as assignments aka .set: + OutStreamer.EmitAssignment(Name, lowerConstant(Alias.getAliasee(), *this)); } GCModuleInfo *MI = getAnalysisIfAvailable(); @@ -1164,11 +1158,10 @@ void AsmPrinter::EmitJumpTableInfo() { // If this jump table was deleted, ignore it. if (JTBBs.empty()) continue; - // For the EK_LabelDifference32 entry, if the target supports .set, emit a - // .set directive for each unique entry. This reduces the number of - // relocations the assembler will generate for the jump table. + // For the EK_LabelDifference32 entry, if using .set avoids a relocation, + /// emit a .set directive for each unique entry. if (MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference32 && - MAI->hasSetDirective()) { + MAI->doesSetDirectiveSuppressesReloc()) { SmallPtrSet EmittedSets; const TargetLowering *TLI = TM.getSubtargetImpl()->getTargetLowering(); const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr(MF,JTI,OutContext); @@ -1241,27 +1234,22 @@ void AsmPrinter::EmitJumpTableEntry(const MachineJumpTableInfo *MJTI, } case MachineJumpTableInfo::EK_LabelDifference32: { - // EK_LabelDifference32 - Each entry is the address of the block minus - // the address of the jump table. This is used for PIC jump tables where - // gprel32 is not supported. e.g.: + // Each entry is the address of the block minus the address of the jump + // table. This is used for PIC jump tables where gprel32 is not supported. + // e.g.: // .word LBB123 - LJTI1_2 - // If the .set directive is supported, this is emitted as: + // If the .set directive avoids relocations, this is emitted as: // .set L4_5_set_123, LBB123 - LJTI1_2 // .word L4_5_set_123 - - // If we have emitted set directives for the jump table entries, print - // them rather than the entries themselves. If we're emitting PIC, then - // emit the table entries as differences between two text section labels. - if (MAI->hasSetDirective()) { - // If we used .set, reference the .set's symbol. + if (MAI->doesSetDirectiveSuppressesReloc()) { Value = MCSymbolRefExpr::Create(GetJTSetSymbol(UID, MBB->getNumber()), OutContext); break; } - // Otherwise, use the difference as the jump table entry. Value = MCSymbolRefExpr::Create(MBB->getSymbol(), OutContext); - const MCExpr *JTI = MCSymbolRefExpr::Create(GetJTISymbol(UID), OutContext); - Value = MCBinaryExpr::CreateSub(Value, JTI, OutContext); + const TargetLowering *TLI = TM.getSubtargetImpl()->getTargetLowering(); + const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr(MF, UID, OutContext); + Value = MCBinaryExpr::CreateSub(Value, Base, OutContext); break; } } @@ -1442,9 +1430,9 @@ void AsmPrinter::EmitInt32(int Value) const { OutStreamer.EmitIntValue(Value, 4); } -/// EmitLabelDifference - Emit something like ".long Hi-Lo" where the size -/// in bytes of the directive is specified by Size and Hi/Lo specify the -/// labels. This implicitly uses .set if it is available. +/// Emit something like ".long Hi-Lo" where the size in bytes of the directive +/// is specified by Size and Hi/Lo specify the labels. This implicitly uses +/// .set if it avoids relocations. void AsmPrinter::EmitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) const { // Get the Hi-Lo expression. @@ -1453,7 +1441,7 @@ void AsmPrinter::EmitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo, MCSymbolRefExpr::Create(Lo, OutContext), OutContext); - if (!MAI->hasSetDirective()) { + if (!MAI->doesSetDirectiveSuppressesReloc()) { OutStreamer.EmitValue(Diff, Size); return; } @@ -1464,36 +1452,6 @@ void AsmPrinter::EmitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo, OutStreamer.EmitSymbolValue(SetLabel, Size); } -/// EmitLabelOffsetDifference - Emit something like ".long Hi+Offset-Lo" -/// where the size in bytes of the directive is specified by Size and Hi/Lo -/// specify the labels. This implicitly uses .set if it is available. -void AsmPrinter::EmitLabelOffsetDifference(const MCSymbol *Hi, uint64_t Offset, - const MCSymbol *Lo, - unsigned Size) const { - - // Emit Hi+Offset - Lo - // Get the Hi+Offset expression. - const MCExpr *Plus = - MCBinaryExpr::CreateAdd(MCSymbolRefExpr::Create(Hi, OutContext), - MCConstantExpr::Create(Offset, OutContext), - OutContext); - - // Get the Hi+Offset-Lo expression. - const MCExpr *Diff = - MCBinaryExpr::CreateSub(Plus, - MCSymbolRefExpr::Create(Lo, OutContext), - OutContext); - - if (!MAI->hasSetDirective()) - OutStreamer.EmitValue(Diff, Size); - else { - // Otherwise, emit with .set (aka assignment). - MCSymbol *SetLabel = GetTempSymbol("set", SetCounter++); - OutStreamer.EmitAssignment(SetLabel, Diff); - OutStreamer.EmitSymbolValue(SetLabel, Size); - } -} - /// EmitLabelPlusOffset - Emit something like ".long Label+Offset" /// where the size in bytes of the directive is specified by Size and Label /// specifies the label. This implicitly uses .set if it is available.