diff options
Diffstat (limited to 'gnu/llvm/lib/CodeGen')
| -rw-r--r-- | gnu/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 234 | ||||
| -rw-r--r-- | gnu/llvm/lib/CodeGen/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | gnu/llvm/lib/CodeGen/PrologEpilogInserter.cpp | 252 | ||||
| -rw-r--r-- | gnu/llvm/lib/CodeGen/StackProtector.cpp | 79 | ||||
| -rw-r--r-- | gnu/llvm/lib/CodeGen/TargetLoweringBase.cpp | 78 | ||||
| -rw-r--r-- | gnu/llvm/lib/CodeGen/TargetPassConfig.cpp | 106 |
6 files changed, 490 insertions, 267 deletions
diff --git a/gnu/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/gnu/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 21bd72789cd..4174b81b0dd 100644 --- a/gnu/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/gnu/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -16,6 +16,7 @@ #include "CodeViewDebug.h" #include "DwarfDebug.h" #include "DwarfException.h" +#include "WinCFGuard.h" #include "WinException.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/APInt.h" @@ -30,7 +31,6 @@ #include "llvm/ADT/Twine.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/EHPersonalities.h" -#include "llvm/Analysis/ObjectUtils.h" #include "llvm/Analysis/OptimizationRemarkEmitter.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/BinaryFormat/ELF.h" @@ -39,6 +39,7 @@ #include "llvm/CodeGen/GCStrategy.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineConstantPool.h" +#include "llvm/CodeGen/MachineDominators.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunctionPass.h" @@ -54,7 +55,6 @@ #include "llvm/CodeGen/TargetFrameLowering.h" #include "llvm/CodeGen/TargetInstrInfo.h" #include "llvm/CodeGen/TargetLowering.h" -#include "llvm/CodeGen/TargetLoweringObjectFile.h" #include "llvm/CodeGen/TargetOpcodes.h" #include "llvm/CodeGen/TargetRegisterInfo.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" @@ -87,6 +87,7 @@ #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" #include "llvm/MC/MCSection.h" +#include "llvm/MC/MCSectionCOFF.h" #include "llvm/MC/MCSectionELF.h" #include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MCStreamer.h" @@ -107,6 +108,7 @@ #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Target/TargetLoweringObjectFile.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" #include <algorithm> @@ -130,6 +132,8 @@ static const char *const DbgTimerName = "emit"; static const char *const DbgTimerDescription = "Debug Info Emission"; static const char *const EHTimerName = "write_exception"; static const char *const EHTimerDescription = "DWARF Exception Writer"; +static const char *const CFGuardName = "Control Flow Guard"; +static const char *const CFGuardDescription = "Control Flow Guard Tables"; static const char *const CodeViewLineTablesGroupName = "linetables"; static const char *const CodeViewLineTablesGroupDescription = "CodeView Line Tables"; @@ -211,8 +215,10 @@ const DataLayout &AsmPrinter::getDataLayout() const { } // Do not use the cached DataLayout because some client use it without a Module -// (llvm-dsymutil, llvm-dwarfdump). -unsigned AsmPrinter::getPointerSize() const { return TM.getPointerSize(); } +// (dsymutil, llvm-dwarfdump). +unsigned AsmPrinter::getPointerSize() const { + return TM.getPointerSize(0); // FIXME: Default address space +} const MCSubtargetInfo &AsmPrinter::getSubtargetInfo() const { assert(MF && "getSubtargetInfo requires a valid MachineFunction!"); @@ -234,7 +240,6 @@ void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired<MachineModuleInfo>(); AU.addRequired<MachineOptimizationRemarkEmitterPass>(); AU.addRequired<GCModuleInfo>(); - AU.addRequired<MachineLoopInfo>(); } bool AsmPrinter::doInitialization(Module &M) { @@ -246,7 +251,7 @@ bool AsmPrinter::doInitialization(Module &M) { OutStreamer->InitSections(false); - // Emit the version-min deplyment target directive if needed. + // Emit the version-min deployment target directive if needed. // // FIXME: If we end up with a collection of these sorts of Darwin-specific // or ELF-specific things, it may make sense to have a platform helper class @@ -291,8 +296,7 @@ bool AsmPrinter::doInitialization(Module &M) { if (MAI->doesSupportDebugInformation()) { bool EmitCodeView = MMI->getModule()->getCodeViewFlag(); - if (EmitCodeView && (TM.getTargetTriple().isKnownWindowsMSVCEnvironment() || - TM.getTargetTriple().isWindowsItaniumEnvironment())) { + if (EmitCodeView && TM.getTargetTriple().isOSWindows()) { Handlers.push_back(HandlerInfo(new CodeViewDebug(this), DbgTimerName, DbgTimerDescription, CodeViewLineTablesGroupName, @@ -350,10 +354,20 @@ bool AsmPrinter::doInitialization(Module &M) { break; } break; + case ExceptionHandling::Wasm: + // TODO to prevent warning + break; } if (ES) Handlers.push_back(HandlerInfo(ES, EHTimerName, EHTimerDescription, DWARFGroupName, DWARFGroupDescription)); + + if (mdconst::extract_or_null<ConstantInt>( + MMI->getModule()->getModuleFlag("cfguard"))) + Handlers.push_back(HandlerInfo(new WinCFGuard(this), CFGuardName, + CFGuardDescription, DWARFGroupName, + DWARFGroupDescription)); + return false; } @@ -361,7 +375,7 @@ static bool canBeHidden(const GlobalValue *GV, const MCAsmInfo &MAI) { if (!MAI.hasWeakDefCanBeHiddenDirective()) return false; - return canBeOmittedFromSymbolTable(GV); + return GV->canBeOmittedFromSymbolTable(); } void AsmPrinter::EmitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const { @@ -416,7 +430,7 @@ MCSymbol *AsmPrinter::getSymbol(const GlobalValue *GV) const { /// EmitGlobalVariable - Emit the specified global variable to the .s file. void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) { - bool IsEmuTLSVar = TM.Options.EmulatedTLS && GV->isThreadLocal(); + bool IsEmuTLSVar = TM.useEmulatedTLS() && GV->isThreadLocal(); assert(!(IsEmuTLSVar && GV->hasCommonLinkage()) && "No emulated TLS variables in the common section"); @@ -898,6 +912,30 @@ static bool emitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP) { return true; } +/// This method handles the target-independent form of DBG_LABEL, returning +/// true if it was able to do so. A false return means the target will need +/// to handle MI in EmitInstruction. +static bool emitDebugLabelComment(const MachineInstr *MI, AsmPrinter &AP) { + if (MI->getNumOperands() != 1) + return false; + + SmallString<128> Str; + raw_svector_ostream OS(Str); + OS << "DEBUG_LABEL: "; + + const DILabel *V = MI->getDebugLabel(); + if (auto *SP = dyn_cast<DISubprogram>(V->getScope())) { + StringRef Name = SP->getName(); + if (!Name.empty()) + OS << Name << ":"; + } + OS << V->getName(); + + // NOTE: Want this comment at start of line, don't emit with AddComment. + AP.OutStreamer->emitRawComment(OS.str()); + return true; +} + AsmPrinter::CFIMoveType AsmPrinter::needsCFIMoves() const { if (MAI->getExceptionHandlingType() == ExceptionHandling::DwarfCFI && MF->getFunction().needsUnwindTableEntry()) @@ -952,7 +990,8 @@ void AsmPrinter::emitStackSizeSection(const MachineFunction &MF) { if (!MF.getTarget().Options.EmitStackSizeSection) return; - MCSection *StackSizeSection = getObjFileLowering().getStackSizesSection(); + MCSection *StackSizeSection = + getObjFileLowering().getStackSizesSection(*getCurrentSection()); if (!StackSizeSection) return; @@ -964,10 +1003,9 @@ void AsmPrinter::emitStackSizeSection(const MachineFunction &MF) { OutStreamer->PushSection(); OutStreamer->SwitchSection(StackSizeSection); - const MCSymbol *FunctionSymbol = getSymbol(&MF.getFunction()); + const MCSymbol *FunctionSymbol = getFunctionBegin(); uint64_t StackSize = FrameInfo.getStackSize(); - OutStreamer->EmitValue(MCSymbolRefExpr::create(FunctionSymbol, OutContext), - /* size = */ 8); + OutStreamer->EmitSymbolValue(FunctionSymbol, TM.getProgramPointerSize()); OutStreamer->EmitULEB128IntValue(StackSize); OutStreamer->PopSection(); @@ -996,6 +1034,24 @@ void AsmPrinter::EmitFunctionBody() { bool ShouldPrintDebugScopes = MMI->hasDebugInfo(); + if (isVerbose()) { + // Get MachineDominatorTree or compute it on the fly if it's unavailable + MDT = getAnalysisIfAvailable<MachineDominatorTree>(); + if (!MDT) { + OwnedMDT = make_unique<MachineDominatorTree>(); + OwnedMDT->getBase().recalculate(*MF); + MDT = OwnedMDT.get(); + } + + // Get MachineLoopInfo or compute it on the fly if it's unavailable + MLI = getAnalysisIfAvailable<MachineLoopInfo>(); + if (!MLI) { + OwnedMLI = make_unique<MachineLoopInfo>(); + OwnedMLI->getBase().analyze(MDT->getBase()); + MLI = OwnedMLI.get(); + } + } + // Print out code for the function. bool HasAnyRealCode = false; int NumInstsInFunction = 0; @@ -1005,7 +1061,7 @@ void AsmPrinter::EmitFunctionBody() { for (auto &MI : MBB) { // Print the assembly for the instruction. if (!MI.isPosition() && !MI.isImplicitDef() && !MI.isKill() && - !MI.isDebugValue()) { + !MI.isDebugInstr()) { HasAnyRealCode = true; ++NumInstsInFunction; } @@ -1044,6 +1100,12 @@ void AsmPrinter::EmitFunctionBody() { EmitInstruction(&MI); } break; + case TargetOpcode::DBG_LABEL: + if (isVerbose()) { + if (!emitDebugLabelComment(&MI, *this)) + EmitInstruction(&MI); + } + break; case TargetOpcode::IMPLICIT_DEF: if (isVerbose()) emitImplicitDef(&MI); break; @@ -1155,7 +1217,7 @@ void AsmPrinter::EmitFunctionBody() { OutStreamer->AddBlankLine(); } -/// \brief Compute the number of Global Variables that uses a Constant. +/// Compute the number of Global Variables that uses a Constant. static unsigned getNumGlobalVariableUses(const Constant *C) { if (!C) return 0; @@ -1170,7 +1232,7 @@ static unsigned getNumGlobalVariableUses(const Constant *C) { return NumUses; } -/// \brief Only consider global GOT equivalents if at least one user is a +/// Only consider global GOT equivalents if at least one user is a /// cstexpr inside an initializer of another global variables. Also, don't /// handle cstexpr inside instructions. During global variable emission, /// candidates are skipped and are emitted later in case at least one cstexpr @@ -1193,7 +1255,7 @@ static bool isGOTEquivalentCandidate(const GlobalVariable *GV, return NumGOTEquivUsers > 0; } -/// \brief Unnamed constant global variables solely contaning a pointer to +/// Unnamed constant global variables solely contaning a pointer to /// another globals variable is equivalent to a GOT table entry; it contains the /// the address of another symbol. Optimize it and replace accesses to these /// "GOT equivalents" by using the GOT entry for the final global instead. @@ -1214,7 +1276,7 @@ void AsmPrinter::computeGlobalGOTEquivs(Module &M) { } } -/// \brief Constant expressions using GOT equivalent globals may not be eligible +/// Constant expressions using GOT equivalent globals may not be eligible /// for PC relative GOT entry conversion, in such cases we need to emit such /// globals we previously omitted in EmitGlobalVariable. void AsmPrinter::emitGlobalGOTEquivs() { @@ -1312,7 +1374,7 @@ bool AsmPrinter::doFinalization(Module &M) { const TargetLoweringObjectFile &TLOF = getObjFileLowering(); - TLOF.emitModuleMetadata(*OutStreamer, M, TM); + TLOF.emitModuleMetadata(*OutStreamer, M); if (TM.getTargetTriple().isOSBinFormatELF()) { MachineModuleInfoELF &MMIELF = MMI->getObjFileInfo<MachineModuleInfoELF>(); @@ -1323,6 +1385,7 @@ bool AsmPrinter::doFinalization(Module &M) { OutStreamer->SwitchSection(TLOF.getDataSection()); const DataLayout &DL = M.getDataLayout(); + EmitAlignment(Log2_32(DL.getPointerSize())); for (const auto &Stub : Stubs) { OutStreamer->EmitLabel(Stub.first); OutStreamer->EmitSymbolValue(Stub.second.getPointer(), @@ -1421,6 +1484,61 @@ bool AsmPrinter::doFinalization(Module &M) { if (MCSection *S = MAI->getNonexecutableStackSection(OutContext)) OutStreamer->SwitchSection(S); + if (TM.getTargetTriple().isOSBinFormatCOFF()) { + // Emit /EXPORT: flags for each exported global as necessary. + const auto &TLOF = getObjFileLowering(); + std::string Flags; + + for (const GlobalValue &GV : M.global_values()) { + raw_string_ostream OS(Flags); + TLOF.emitLinkerFlagsForGlobal(OS, &GV); + OS.flush(); + if (!Flags.empty()) { + OutStreamer->SwitchSection(TLOF.getDrectveSection()); + OutStreamer->EmitBytes(Flags); + } + Flags.clear(); + } + + // Emit /INCLUDE: flags for each used global as necessary. + if (const auto *LU = M.getNamedGlobal("llvm.used")) { + assert(LU->hasInitializer() && + "expected llvm.used to have an initializer"); + assert(isa<ArrayType>(LU->getValueType()) && + "expected llvm.used to be an array type"); + if (const auto *A = cast<ConstantArray>(LU->getInitializer())) { + for (const Value *Op : A->operands()) { + const auto *GV = + cast<GlobalValue>(Op->stripPointerCastsNoFollowAliases()); + // Global symbols with internal or private linkage are not visible to + // the linker, and thus would cause an error when the linker tried to + // preserve the symbol due to the `/include:` directive. + if (GV->hasLocalLinkage()) + continue; + + raw_string_ostream OS(Flags); + TLOF.emitLinkerFlagsForUsed(OS, GV); + OS.flush(); + + if (!Flags.empty()) { + OutStreamer->SwitchSection(TLOF.getDrectveSection()); + OutStreamer->EmitBytes(Flags); + } + Flags.clear(); + } + } + } + } + + if (TM.Options.EmitAddrsig) { + // Emit address-significance attributes for all globals. + OutStreamer->EmitAddrsig(); + for (const GlobalValue &GV : M.global_values()) + if (!GV.isThreadLocal() && !GV.getName().startswith("llvm.") && + !GV.hasAtLeastLocalUnnamedAddr()) + OutStreamer->EmitAddrsigSym(getSymbol(&GV)); + } + // Allow the target to emit any magic that it wants at the end of the file, // after everything else has gone out. EmitEndOfAsmFile(M); @@ -1429,6 +1547,8 @@ bool AsmPrinter::doFinalization(Module &M) { OutStreamer->Finish(); OutStreamer->reset(); + OwnedMLI.reset(); + OwnedMDT.reset(); return false; } @@ -1447,14 +1567,14 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) { CurrentFnBegin = nullptr; CurExceptionSym = nullptr; bool NeedsLocalForSize = MAI->needsLocalForSize(); - if (needFuncLabelsForEHOrDebugInfo(MF, MMI) || NeedsLocalForSize) { + if (needFuncLabelsForEHOrDebugInfo(MF, MMI) || NeedsLocalForSize || + MF.getTarget().Options.EmitStackSizeSection) { CurrentFnBegin = createTempSymbol("func_begin"); if (NeedsLocalForSize) CurrentFnSymForSize = CurrentFnBegin; } ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE(); - LI = &getAnalysis<MachineLoopInfo>(); const TargetSubtargetInfo &STI = MF.getSubtarget(); EnablePrintSchedInfo = PrintSchedule.getNumOccurrences() @@ -1842,22 +1962,27 @@ void AsmPrinter::EmitModuleIdents(Module &M) { // Emission and print routines // -/// EmitInt8 - Emit a byte directive and value. +/// Emit a byte directive and value. /// -void AsmPrinter::EmitInt8(int Value) const { +void AsmPrinter::emitInt8(int Value) const { OutStreamer->EmitIntValue(Value, 1); } -/// EmitInt16 - Emit a short directive and value. -void AsmPrinter::EmitInt16(int Value) const { +/// Emit a short directive and value. +void AsmPrinter::emitInt16(int Value) const { OutStreamer->EmitIntValue(Value, 2); } -/// EmitInt32 - Emit a long directive and value. -void AsmPrinter::EmitInt32(int Value) const { +/// Emit a long directive and value. +void AsmPrinter::emitInt32(int Value) const { OutStreamer->EmitIntValue(Value, 4); } +/// Emit a long long directive and value. +void AsmPrinter::emitInt64(uint64_t Value) const { + OutStreamer->EmitIntValue(Value, 8); +} + /// 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. @@ -2096,6 +2221,7 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *C, uint64_t Offset = 0); static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP); +static void emitGlobalConstantFP(APFloat APF, Type *ET, AsmPrinter &AP); /// isRepeatedByteSequence - Determine whether the given value is /// composed of a repeated sequence of identical bytes and return the @@ -2173,13 +2299,15 @@ static void emitGlobalConstantDataSequential(const DataLayout &DL, ElementByteSize); } } else { + Type *ET = CDS->getElementType(); for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I) - emitGlobalConstantFP(cast<ConstantFP>(CDS->getElementAsConstant(I)), AP); + emitGlobalConstantFP(CDS->getElementAsAPFloat(I), ET, AP); } unsigned Size = DL.getTypeAllocSize(CDS->getType()); unsigned EmittedSize = DL.getTypeAllocSize(CDS->getType()->getElementType()) * CDS->getNumElements(); + assert(EmittedSize <= Size && "Size cannot be less than EmittedSize!"); if (unsigned Padding = Size - EmittedSize) AP.OutStreamer->EmitZeros(Padding); } @@ -2243,17 +2371,17 @@ static void emitGlobalConstantStruct(const DataLayout &DL, "Layout of constant struct may be incorrect!"); } -static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP) { - APInt API = CFP->getValueAPF().bitcastToAPInt(); +static void emitGlobalConstantFP(APFloat APF, Type *ET, AsmPrinter &AP) { + APInt API = APF.bitcastToAPInt(); // First print a comment with what we think the original floating-point value // should have been. if (AP.isVerbose()) { SmallString<8> StrVal; - CFP->getValueAPF().toString(StrVal); + APF.toString(StrVal); - if (CFP->getType()) - CFP->getType()->print(AP.OutStreamer->GetCommentOS()); + if (ET) + ET->print(AP.OutStreamer->GetCommentOS()); else AP.OutStreamer->GetCommentOS() << "Printing <null> Type"; AP.OutStreamer->GetCommentOS() << ' ' << StrVal << '\n'; @@ -2268,7 +2396,7 @@ static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP) { // PPC's long double has odd notions of endianness compared to how LLVM // handles it: p[0] goes first for *big* endian on PPC. - if (AP.getDataLayout().isBigEndian() && !CFP->getType()->isPPC_FP128Ty()) { + if (AP.getDataLayout().isBigEndian() && !ET->isPPC_FP128Ty()) { int Chunk = API.getNumWords() - 1; if (TrailingBytes) @@ -2287,8 +2415,11 @@ static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP) { // Emit the tail padding for the long double. const DataLayout &DL = AP.getDataLayout(); - AP.OutStreamer->EmitZeros(DL.getTypeAllocSize(CFP->getType()) - - DL.getTypeStoreSize(CFP->getType())); + AP.OutStreamer->EmitZeros(DL.getTypeAllocSize(ET) - DL.getTypeStoreSize(ET)); +} + +static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP) { + emitGlobalConstantFP(CFP->getValueAPF(), CFP->getType(), AP); } static void emitGlobalConstantLargeInt(const ConstantInt *CI, AsmPrinter &AP) { @@ -2347,7 +2478,7 @@ static void emitGlobalConstantLargeInt(const ConstantInt *CI, AsmPrinter &AP) { } } -/// \brief Transform a not absolute MCExpr containing a reference to a GOT +/// Transform a not absolute MCExpr containing a reference to a GOT /// equivalent global, by a target specific GOT pc relative access to the /// final symbol. static void handleIndirectSymViaGOTPCRel(AsmPrinter &AP, const MCExpr **ME, @@ -2560,6 +2691,25 @@ MCSymbol *AsmPrinter::GetBlockAddressSymbol(const BasicBlock *BB) const { /// GetCPISymbol - Return the symbol for the specified constant pool entry. MCSymbol *AsmPrinter::GetCPISymbol(unsigned CPID) const { + if (getSubtargetInfo().getTargetTriple().isKnownWindowsMSVCEnvironment()) { + const MachineConstantPoolEntry &CPE = + MF->getConstantPool()->getConstants()[CPID]; + if (!CPE.isMachineConstantPoolEntry()) { + const DataLayout &DL = MF->getDataLayout(); + SectionKind Kind = CPE.getSectionKind(&DL); + const Constant *C = CPE.Val.ConstVal; + unsigned Align = CPE.Alignment; + if (const MCSectionCOFF *S = dyn_cast<MCSectionCOFF>( + getObjFileLowering().getSectionForConstant(DL, Kind, C, Align))) { + if (MCSymbol *Sym = S->getCOMDATSymbol()) { + if (Sym->isUndefined()) + OutStreamer->EmitSymbolAttribute(Sym, MCSA_Global); + return Sym; + } + } + } + } + const DataLayout &DL = getDataLayout(); return OutContext.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) + "CPI" + Twine(getFunctionNumber()) + "_" + @@ -2658,13 +2808,9 @@ static void emitBasicBlockLoopComments(const MachineBasicBlock &MBB, void AsmPrinter::setupCodePaddingContext(const MachineBasicBlock &MBB, MCCodePaddingContext &Context) const { assert(MF != nullptr && "Machine function must be valid"); - assert(LI != nullptr && "Loop info must be valid"); Context.IsPaddingActive = !MF->hasInlineAsm() && !MF->getFunction().optForSize() && TM.getOptLevel() != CodeGenOpt::None; - const MachineLoop *CurrentLoop = LI->getLoopFor(&MBB); - Context.IsBasicBlockInsideInnermostLoop = - CurrentLoop != nullptr && CurrentLoop->getSubLoops().empty(); Context.IsBasicBlockReachableViaFallthrough = std::find(MBB.pred_begin(), MBB.pred_end(), MBB.getPrevNode()) != MBB.pred_end(); @@ -2720,7 +2866,9 @@ void AsmPrinter::EmitBasicBlockStart(const MachineBasicBlock &MBB) const { OutStreamer->GetCommentOS() << '\n'; } } - emitBasicBlockLoopComments(MBB, LI, *this); + + assert(MLI != nullptr && "MachineLoopInfo should has been computed"); + emitBasicBlockLoopComments(MBB, MLI, *this); } // Print the main label for the block. diff --git a/gnu/llvm/lib/CodeGen/CMakeLists.txt b/gnu/llvm/lib/CodeGen/CMakeLists.txt index 42e91978782..29d4111bbe2 100644 --- a/gnu/llvm/lib/CodeGen/CMakeLists.txt +++ b/gnu/llvm/lib/CodeGen/CMakeLists.txt @@ -6,9 +6,11 @@ add_llvm_library(LLVMCodeGen BasicTargetTransformInfo.cpp BranchFolding.cpp BranchRelaxation.cpp + BreakFalseDeps.cpp BuiltinGCs.cpp CalcSpillWeights.cpp CallingConvLower.cpp + CFIInstrInserter.cpp CodeGen.cpp CodeGenPrepare.cpp CriticalAntiDepBreaker.cpp @@ -18,7 +20,7 @@ add_llvm_library(LLVMCodeGen DwarfEHPrepare.cpp EarlyIfConversion.cpp EdgeBundles.cpp - ExecutionDepsFix.cpp + ExecutionDomainFix.cpp ExpandISelPseudos.cpp ExpandMemCmp.cpp ExpandPostRAPseudos.cpp @@ -56,6 +58,7 @@ add_llvm_library(LLVMCodeGen LiveVariables.cpp LLVMTargetMachine.cpp LocalStackSlotAllocation.cpp + LoopTraversal.cpp LowLevelType.cpp LowerEmuTLS.cpp MachineBasicBlock.cpp @@ -105,6 +108,7 @@ add_llvm_library(LLVMCodeGen ProcessImplicitDefs.cpp PrologEpilogInserter.cpp PseudoSourceValue.cpp + ReachingDefAnalysis.cpp RegAllocBase.cpp RegAllocBasic.cpp RegAllocFast.cpp @@ -153,7 +157,9 @@ add_llvm_library(LLVMCodeGen TargetSubtargetInfo.cpp TwoAddressInstructionPass.cpp UnreachableBlockElim.cpp + ValueTypes.cpp VirtRegMap.cpp + WasmEHPrepare.cpp WinEHPrepare.cpp XRayInstrumentation.cpp diff --git a/gnu/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/gnu/llvm/lib/CodeGen/PrologEpilogInserter.cpp index 4517c3af031..1119b570b7e 100644 --- a/gnu/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/gnu/llvm/lib/CodeGen/PrologEpilogInserter.cpp @@ -38,7 +38,6 @@ #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/RegisterScavenging.h" -#include "llvm/CodeGen/StackProtector.h" #include "llvm/CodeGen/TargetFrameLowering.h" #include "llvm/CodeGen/TargetInstrInfo.h" #include "llvm/CodeGen/TargetOpcodes.h" @@ -90,7 +89,7 @@ public: /// runOnMachineFunction - Insert prolog/epilog code and replace abstract /// frame indexes with appropriate references. - bool runOnMachineFunction(MachineFunction &Fn) override; + bool runOnMachineFunction(MachineFunction &MF) override; private: RegScavenger *RS; @@ -117,15 +116,15 @@ private: // Emit remarks. MachineOptimizationRemarkEmitter *ORE = nullptr; - void calculateCallFrameInfo(MachineFunction &Fn); - void calculateSaveRestoreBlocks(MachineFunction &Fn); + void calculateCallFrameInfo(MachineFunction &MF); + void calculateSaveRestoreBlocks(MachineFunction &MF); void spillCalleeSavedRegs(MachineFunction &MF); - void calculateFrameObjectOffsets(MachineFunction &Fn); - void replaceFrameIndices(MachineFunction &Fn); - void replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &Fn, + void calculateFrameObjectOffsets(MachineFunction &MF); + void replaceFrameIndices(MachineFunction &MF); + void replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &MF, int &SPAdj); - void insertPrologEpilogCode(MachineFunction &Fn); + void insertPrologEpilogCode(MachineFunction &MF); }; } // end anonymous namespace @@ -143,7 +142,6 @@ INITIALIZE_PASS_BEGIN(PEI, DEBUG_TYPE, "Prologue/Epilogue Insertion", false, false) INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo) INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree) -INITIALIZE_PASS_DEPENDENCY(StackProtector) INITIALIZE_PASS_DEPENDENCY(MachineOptimizationRemarkEmitterPass) INITIALIZE_PASS_END(PEI, DEBUG_TYPE, "Prologue/Epilogue Insertion & Frame Finalization", false, @@ -160,7 +158,6 @@ void PEI::getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesCFG(); AU.addPreserved<MachineLoopInfo>(); AU.addPreserved<MachineDominatorTree>(); - AU.addRequired<StackProtector>(); AU.addRequired<MachineOptimizationRemarkEmitterPass>(); MachineFunctionPass::getAnalysisUsage(AU); } @@ -170,40 +167,40 @@ using StackObjSet = SmallSetVector<int, 8>; /// runOnMachineFunction - Insert prolog/epilog code and replace abstract /// frame indexes with appropriate references. -bool PEI::runOnMachineFunction(MachineFunction &Fn) { - const Function &F = Fn.getFunction(); - const TargetRegisterInfo *TRI = Fn.getSubtarget().getRegisterInfo(); - const TargetFrameLowering *TFI = Fn.getSubtarget().getFrameLowering(); +bool PEI::runOnMachineFunction(MachineFunction &MF) { + const Function &F = MF.getFunction(); + const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo(); + const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); const ReturnProtectorLowering *RPL = TFI->getReturnProtector(); if (RPL) - RPL->setupReturnProtector(Fn); + RPL->setupReturnProtector(MF); - RS = TRI->requiresRegisterScavenging(Fn) ? new RegScavenger() : nullptr; - FrameIndexVirtualScavenging = TRI->requiresFrameIndexScavenging(Fn); + RS = TRI->requiresRegisterScavenging(MF) ? new RegScavenger() : nullptr; + FrameIndexVirtualScavenging = TRI->requiresFrameIndexScavenging(MF); FrameIndexEliminationScavenging = (RS && !FrameIndexVirtualScavenging) || - TRI->requiresFrameIndexReplacementScavenging(Fn); + TRI->requiresFrameIndexReplacementScavenging(MF); ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE(); // Calculate the MaxCallFrameSize and AdjustsStack variables for the // function's frame information. Also eliminates call frame pseudo // instructions. - calculateCallFrameInfo(Fn); + calculateCallFrameInfo(MF); // Determine placement of CSR spill/restore code and prolog/epilog code: // place all spills in the entry block, all restores in return blocks. - calculateSaveRestoreBlocks(Fn); + calculateSaveRestoreBlocks(MF); // Handle CSR spilling and restoring, for targets that need it. - if (Fn.getTarget().usesPhysRegsForPEI()) - spillCalleeSavedRegs(Fn); + if (MF.getTarget().usesPhysRegsForPEI()) + spillCalleeSavedRegs(MF); // Allow the target machine to make final modifications to the function // before the frame layout is finalized. - TFI->processFunctionBeforeFrameFinalized(Fn, RS); + TFI->processFunctionBeforeFrameFinalized(MF, RS); // Calculate actual frame offsets for all abstract stack objects... - calculateFrameObjectOffsets(Fn); + calculateFrameObjectOffsets(MF); // Add prolog and epilog code to the function. This function is required // to align the stack frame as necessary for any stack variables or @@ -211,30 +208,36 @@ bool PEI::runOnMachineFunction(MachineFunction &Fn) { // must be called before this function in order to set the AdjustsStack // and MaxCallFrameSize variables. if (!F.hasFnAttribute(Attribute::Naked)) - insertPrologEpilogCode(Fn); + insertPrologEpilogCode(MF); // Add Return Protectors if using them if (RPL) - RPL->insertReturnProtectors(Fn); + RPL->insertReturnProtectors(MF); // Replace all MO_FrameIndex operands with physical register references // and actual offsets. // - replaceFrameIndices(Fn); + replaceFrameIndices(MF); // If register scavenging is needed, as we've enabled doing it as a // post-pass, scavenge the virtual registers that frame index elimination // inserted. - if (TRI->requiresRegisterScavenging(Fn) && FrameIndexVirtualScavenging) - scavengeFrameVirtualRegs(Fn, *RS); + if (TRI->requiresRegisterScavenging(MF) && FrameIndexVirtualScavenging) + scavengeFrameVirtualRegs(MF, *RS); // Warn on stack size when we exceeds the given limit. - MachineFrameInfo &MFI = Fn.getFrameInfo(); + MachineFrameInfo &MFI = MF.getFrameInfo(); uint64_t StackSize = MFI.getStackSize(); if (WarnStackSize.getNumOccurrences() > 0 && WarnStackSize < StackSize) { DiagnosticInfoStackSize DiagStackSize(F, StackSize); F.getContext().diagnose(DiagStackSize); } + ORE->emit([&]() { + return MachineOptimizationRemarkAnalysis(DEBUG_TYPE, "StackSize", + MF.getFunction().getSubprogram(), + &MF.front()) + << ore::NV("NumStackBytes", StackSize) << " stack bytes in function"; + }); delete RS; SaveBlocks.clear(); @@ -247,10 +250,10 @@ bool PEI::runOnMachineFunction(MachineFunction &Fn) { /// Calculate the MaxCallFrameSize and AdjustsStack /// variables for the function's frame information and eliminate call frame /// pseudo instructions. -void PEI::calculateCallFrameInfo(MachineFunction &Fn) { - const TargetInstrInfo &TII = *Fn.getSubtarget().getInstrInfo(); - const TargetFrameLowering *TFI = Fn.getSubtarget().getFrameLowering(); - MachineFrameInfo &MFI = Fn.getFrameInfo(); +void PEI::calculateCallFrameInfo(MachineFunction &MF) { + const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); + const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); + MachineFrameInfo &MFI = MF.getFrameInfo(); unsigned MaxCallFrameSize = 0; bool AdjustsStack = MFI.adjustsStack(); @@ -265,7 +268,7 @@ void PEI::calculateCallFrameInfo(MachineFunction &Fn) { return; std::vector<MachineBasicBlock::iterator> FrameSDOps; - for (MachineFunction::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB) + for (MachineFunction::iterator BB = MF.begin(), E = MF.end(); BB != E; ++BB) for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) if (TII.isFrameInstr(*I)) { unsigned Size = TII.getFrameSize(*I); @@ -293,16 +296,16 @@ void PEI::calculateCallFrameInfo(MachineFunction &Fn) { // the target doesn't indicate otherwise, remove the call frame pseudos // here. The sub/add sp instruction pairs are still inserted, but we don't // need to track the SP adjustment for frame index elimination. - if (TFI->canSimplifyCallFramePseudos(Fn)) - TFI->eliminateCallFramePseudoInstr(Fn, *I->getParent(), I); + if (TFI->canSimplifyCallFramePseudos(MF)) + TFI->eliminateCallFramePseudoInstr(MF, *I->getParent(), I); } } /// Compute the sets of entry and return blocks for saving and restoring /// callee-saved registers, and placing prolog and epilog code. -void PEI::calculateSaveRestoreBlocks(MachineFunction &Fn) { - MachineFrameInfo &MFI = Fn.getFrameInfo(); - const TargetFrameLowering *TFI = Fn.getSubtarget().getFrameLowering(); +void PEI::calculateSaveRestoreBlocks(MachineFunction &MF) { + MachineFrameInfo &MFI = MF.getFrameInfo(); + const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); const ReturnProtectorLowering *RPL = TFI->getReturnProtector(); // Even when we do not change any CSR, we still want to insert the @@ -322,7 +325,7 @@ void PEI::calculateSaveRestoreBlocks(MachineFunction &Fn) { // If we are adding return protectors ensure we can find a free register if (RPL && - !RPL->determineReturnProtectorRegister(Fn, SaveBlocks, RestoreBlocks)) { + !RPL->determineReturnProtectorRegister(MF, SaveBlocks, RestoreBlocks)) { // Shrinkwrapping will prevent finding a free register SaveBlocks.clear(); RestoreBlocks.clear(); @@ -334,8 +337,8 @@ void PEI::calculateSaveRestoreBlocks(MachineFunction &Fn) { } // Save refs to entry and return blocks. - SaveBlocks.push_back(&Fn.front()); - for (MachineBasicBlock &MBB : Fn) { + SaveBlocks.push_back(&MF.front()); + for (MachineBasicBlock &MBB : MF) { if (MBB.isEHFuncletEntry()) SaveBlocks.push_back(&MBB); if (MBB.isReturnBlock()) @@ -343,7 +346,7 @@ void PEI::calculateSaveRestoreBlocks(MachineFunction &Fn) { } if (RPL) - RPL->determineReturnProtectorRegister(Fn, SaveBlocks, RestoreBlocks); + RPL->determineReturnProtectorRegister(MF, SaveBlocks, RestoreBlocks); } static void assignCalleeSavedSpillSlots(MachineFunction &F, @@ -485,10 +488,10 @@ static void updateLiveness(MachineFunction &MF) { /// Insert restore code for the callee-saved registers used in the function. static void insertCSRSaves(MachineBasicBlock &SaveBlock, ArrayRef<CalleeSavedInfo> CSI) { - MachineFunction &Fn = *SaveBlock.getParent(); - const TargetInstrInfo &TII = *Fn.getSubtarget().getInstrInfo(); - const TargetFrameLowering *TFI = Fn.getSubtarget().getFrameLowering(); - const TargetRegisterInfo *TRI = Fn.getSubtarget().getRegisterInfo(); + MachineFunction &MF = *SaveBlock.getParent(); + const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); + const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); + const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo(); MachineBasicBlock::iterator I = SaveBlock.begin(); if (!TFI->spillCalleeSavedRegisters(SaveBlock, I, CSI, TRI)) { @@ -505,10 +508,10 @@ static void insertCSRSaves(MachineBasicBlock &SaveBlock, /// Insert restore code for the callee-saved registers used in the function. static void insertCSRRestores(MachineBasicBlock &RestoreBlock, std::vector<CalleeSavedInfo> &CSI) { - MachineFunction &Fn = *RestoreBlock.getParent(); - const TargetInstrInfo &TII = *Fn.getSubtarget().getInstrInfo(); - const TargetFrameLowering *TFI = Fn.getSubtarget().getFrameLowering(); - const TargetRegisterInfo *TRI = Fn.getSubtarget().getRegisterInfo(); + MachineFunction &MF = *RestoreBlock.getParent(); + const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); + const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); + const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo(); // Restore all registers immediately before the return and any // terminators that precede it. @@ -527,27 +530,27 @@ static void insertCSRRestores(MachineBasicBlock &RestoreBlock, } } -void PEI::spillCalleeSavedRegs(MachineFunction &Fn) { +void PEI::spillCalleeSavedRegs(MachineFunction &MF) { // We can't list this requirement in getRequiredProperties because some // targets (WebAssembly) use virtual registers past this point, and the pass // pipeline is set up without giving the passes a chance to look at the // TargetMachine. // FIXME: Find a way to express this in getRequiredProperties. - assert(Fn.getProperties().hasProperty( + assert(MF.getProperties().hasProperty( MachineFunctionProperties::Property::NoVRegs)); - const Function &F = Fn.getFunction(); - const TargetFrameLowering *TFI = Fn.getSubtarget().getFrameLowering(); - MachineFrameInfo &MFI = Fn.getFrameInfo(); + const Function &F = MF.getFunction(); + const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); + MachineFrameInfo &MFI = MF.getFrameInfo(); MinCSFrameIndex = std::numeric_limits<unsigned>::max(); MaxCSFrameIndex = 0; // Determine which of the registers in the callee save list should be saved. BitVector SavedRegs; - TFI->determineCalleeSaves(Fn, SavedRegs, RS); + TFI->determineCalleeSaves(MF, SavedRegs, RS); // Assign stack slots for any callee-saved registers that must be spilled. - assignCalleeSavedSpillSlots(Fn, SavedRegs, MinCSFrameIndex, MaxCSFrameIndex); + assignCalleeSavedSpillSlots(MF, SavedRegs, MinCSFrameIndex, MaxCSFrameIndex); // Add the code to save and restore the callee saved registers. if (!F.hasFnAttribute(Attribute::Naked)) { @@ -559,7 +562,7 @@ void PEI::spillCalleeSavedRegs(MachineFunction &Fn) { insertCSRSaves(*SaveBlock, CSI); // Update the live-in information of all the blocks up to the save // point. - updateLiveness(Fn); + updateLiveness(MF); } for (MachineBasicBlock *RestoreBlock : RestoreBlocks) insertCSRRestores(*RestoreBlock, CSI); @@ -586,10 +589,12 @@ AdjustStackOffset(MachineFrameInfo &MFI, int FrameIdx, Offset = alignTo(Offset, Align, Skew); if (StackGrowsDown) { - DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") at SP[" << -Offset << "]\n"); + LLVM_DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") at SP[" << -Offset + << "]\n"); MFI.setObjectOffset(FrameIdx, -Offset); // Set the computed offset } else { - DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") at SP[" << Offset << "]\n"); + LLVM_DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") at SP[" << Offset + << "]\n"); MFI.setObjectOffset(FrameIdx, Offset); Offset += MFI.getObjectSize(FrameIdx); } @@ -682,12 +687,12 @@ static inline bool scavengeStackSlot(MachineFrameInfo &MFI, int FrameIdx, if (StackGrowsDown) { int ObjStart = -(FreeStart + ObjSize); - DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") scavenged at SP[" << ObjStart - << "]\n"); + LLVM_DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") scavenged at SP[" + << ObjStart << "]\n"); MFI.setObjectOffset(FrameIdx, ObjStart); } else { - DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") scavenged at SP[" << FreeStart - << "]\n"); + LLVM_DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") scavenged at SP[" + << FreeStart << "]\n"); MFI.setObjectOffset(FrameIdx, FreeStart); } @@ -713,15 +718,14 @@ AssignProtectedObjSet(const StackObjSet &UnassignedObjs, /// calculateFrameObjectOffsets - Calculate actual frame offsets for all of the /// abstract stack objects. -void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) { - const TargetFrameLowering &TFI = *Fn.getSubtarget().getFrameLowering(); - StackProtector *SP = &getAnalysis<StackProtector>(); +void PEI::calculateFrameObjectOffsets(MachineFunction &MF) { + const TargetFrameLowering &TFI = *MF.getSubtarget().getFrameLowering(); bool StackGrowsDown = TFI.getStackGrowthDirection() == TargetFrameLowering::StackGrowsDown; // Loop over all of the stack objects, assigning sequential addresses... - MachineFrameInfo &MFI = Fn.getFrameInfo(); + MachineFrameInfo &MFI = MF.getFrameInfo(); // Start at the beginning of the local area. // The Offset is the distance from the stack top in the direction @@ -734,7 +738,7 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) { int64_t Offset = LocalAreaOffset; // Skew to be applied to alignment. - unsigned Skew = TFI.getStackAlignmentSkew(Fn); + unsigned Skew = TFI.getStackAlignmentSkew(MF); // If there are fixed sized objects that are preallocated in the local area, // non-fixed objects can't be allocated right at the start of local area. @@ -767,7 +771,7 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) { // Adjust to alignment boundary Offset = alignTo(Offset, Align, Skew); - DEBUG(dbgs() << "alloc FI(" << i << ") at SP[" << -Offset << "]\n"); + LLVM_DEBUG(dbgs() << "alloc FI(" << i << ") at SP[" << -Offset << "]\n"); MFI.setObjectOffset(i, -Offset); // Set the computed offset } } else if (MaxCSFrameIndex >= MinCSFrameIndex) { @@ -780,7 +784,7 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) { // Adjust to alignment boundary Offset = alignTo(Offset, Align, Skew); - DEBUG(dbgs() << "alloc FI(" << i << ") at SP[" << Offset << "]\n"); + LLVM_DEBUG(dbgs() << "alloc FI(" << i << ") at SP[" << Offset << "]\n"); MFI.setObjectOffset(i, Offset); Offset += MFI.getObjectSize(i); } @@ -794,11 +798,11 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) { // Make sure the special register scavenging spill slot is closest to the // incoming stack pointer if a frame pointer is required and is closer // to the incoming rather than the final stack pointer. - const TargetRegisterInfo *RegInfo = Fn.getSubtarget().getRegisterInfo(); - bool EarlyScavengingSlots = (TFI.hasFP(Fn) && + const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo(); + bool EarlyScavengingSlots = (TFI.hasFP(MF) && TFI.isFPCloseToIncomingSP() && - RegInfo->useFPForScavengingIndex(Fn) && - !RegInfo->needsStackRealignment(Fn)); + RegInfo->useFPForScavengingIndex(MF) && + !RegInfo->needsStackRealignment(MF)); if (RS && EarlyScavengingSlots) { SmallVector<int, 2> SFIs; RS->getScavengingFrameIndices(SFIs); @@ -817,14 +821,14 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) { // Adjust to alignment boundary. Offset = alignTo(Offset, Align, Skew); - DEBUG(dbgs() << "Local frame base offset: " << Offset << "\n"); + LLVM_DEBUG(dbgs() << "Local frame base offset: " << Offset << "\n"); // Resolve offsets for objects in the local block. for (unsigned i = 0, e = MFI.getLocalFrameObjectCount(); i != e; ++i) { std::pair<int, int64_t> Entry = MFI.getLocalFrameObjectMap(i); int64_t FIOffset = (StackGrowsDown ? -Offset : Offset) + Entry.second; - DEBUG(dbgs() << "alloc FI(" << Entry.first << ") at SP[" << - FIOffset << "]\n"); + LLVM_DEBUG(dbgs() << "alloc FI(" << Entry.first << ") at SP[" << FIOffset + << "]\n"); MFI.setObjectOffset(Entry.first, FIOffset); } // Allocate the local block @@ -835,7 +839,7 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) { // Retrieve the Exception Handler registration node. int EHRegNodeFrameIndex = std::numeric_limits<int>::max(); - if (const WinEHFuncInfo *FuncInfo = Fn.getWinEHFuncInfo()) + if (const WinEHFuncInfo *FuncInfo = MF.getWinEHFuncInfo()) EHRegNodeFrameIndex = FuncInfo->EHRegNodeFrameIndex; // Make sure that the stack protector comes before the local variables on the @@ -864,16 +868,16 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) { EHRegNodeFrameIndex == (int)i) continue; - switch (SP->getSSPLayout(MFI.getObjectAllocation(i))) { - case StackProtector::SSPLK_None: + switch (MFI.getObjectSSPLayout(i)) { + case MachineFrameInfo::SSPLK_None: continue; - case StackProtector::SSPLK_SmallArray: + case MachineFrameInfo::SSPLK_SmallArray: SmallArrayObjs.insert(i); continue; - case StackProtector::SSPLK_AddrOf: + case MachineFrameInfo::SSPLK_AddrOf: AddrOfObjs.insert(i); continue; - case StackProtector::SSPLK_LargeArray: + case MachineFrameInfo::SSPLK_LargeArray: LargeArrayObjs.insert(i); continue; } @@ -917,9 +921,9 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) { MaxAlign, Skew); // Give the targets a chance to order the objects the way they like it. - if (Fn.getTarget().getOptLevel() != CodeGenOpt::None && - Fn.getTarget().Options.StackSymbolOrdering) - TFI.orderFrameObjects(Fn, ObjectsToAllocate); + if (MF.getTarget().getOptLevel() != CodeGenOpt::None && + MF.getTarget().Options.StackSymbolOrdering) + TFI.orderFrameObjects(MF, ObjectsToAllocate); // Keep track of which bytes in the fixed and callee-save range are used so we // can use the holes when allocating later stack objects. Only do this if @@ -927,8 +931,8 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) { // optimizing. BitVector StackBytesFree; if (!ObjectsToAllocate.empty() && - Fn.getTarget().getOptLevel() != CodeGenOpt::None && - MFI.getStackProtectorIndex() < 0 && TFI.enableStackSlotScavenging(Fn)) + MF.getTarget().getOptLevel() != CodeGenOpt::None && + MFI.getStackProtectorIndex() < 0 && TFI.enableStackSlotScavenging(MF)) computeFreeStackSlots(MFI, StackGrowsDown, MinCSFrameIndex, MaxCSFrameIndex, FixedCSEnd, StackBytesFree); @@ -952,7 +956,7 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) { // If we have reserved argument space for call sites in the function // immediately on entry to the current function, count it as part of the // overall stack size. - if (MFI.adjustsStack() && TFI.hasReservedCallFrame(Fn)) + if (MFI.adjustsStack() && TFI.hasReservedCallFrame(MF)) Offset += MFI.getMaxCallFrameSize(); // Round up the size to a multiple of the alignment. If the function has @@ -962,7 +966,7 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) { // value. unsigned StackAlign; if (MFI.adjustsStack() || MFI.hasVarSizedObjects() || - (RegInfo->needsStackRealignment(Fn) && MFI.getObjectIndexEnd() != 0)) + (RegInfo->needsStackRealignment(MF) && MFI.getObjectIndexEnd() != 0)) StackAlign = TFI.getStackAlignment(); else StackAlign = TFI.getTransientStackAlignment(); @@ -977,68 +981,61 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) { int64_t StackSize = Offset - LocalAreaOffset; MFI.setStackSize(StackSize); NumBytesStackSpace += StackSize; - - ORE->emit([&]() { - return MachineOptimizationRemarkAnalysis(DEBUG_TYPE, "StackSize", - Fn.getFunction().getSubprogram(), - &Fn.front()) - << ore::NV("NumStackBytes", StackSize) << " stack bytes in function"; - }); } /// insertPrologEpilogCode - Scan the function for modified callee saved /// registers, insert spill code for these callee saved registers, then add /// prolog and epilog code to the function. -void PEI::insertPrologEpilogCode(MachineFunction &Fn) { - const TargetFrameLowering &TFI = *Fn.getSubtarget().getFrameLowering(); +void PEI::insertPrologEpilogCode(MachineFunction &MF) { + const TargetFrameLowering &TFI = *MF.getSubtarget().getFrameLowering(); // Add prologue to the function... for (MachineBasicBlock *SaveBlock : SaveBlocks) - TFI.emitPrologue(Fn, *SaveBlock); + TFI.emitPrologue(MF, *SaveBlock); // Add epilogue to restore the callee-save registers in each exiting block. for (MachineBasicBlock *RestoreBlock : RestoreBlocks) - TFI.emitEpilogue(Fn, *RestoreBlock); + TFI.emitEpilogue(MF, *RestoreBlock); for (MachineBasicBlock *SaveBlock : SaveBlocks) - TFI.inlineStackProbe(Fn, *SaveBlock); + TFI.inlineStackProbe(MF, *SaveBlock); // Emit additional code that is required to support segmented stacks, if // we've been asked for it. This, when linked with a runtime with support // for segmented stacks (libgcc is one), will result in allocating stack // space in small chunks instead of one large contiguous block. - if (Fn.shouldSplitStack()) { + if (MF.shouldSplitStack()) { for (MachineBasicBlock *SaveBlock : SaveBlocks) - TFI.adjustForSegmentedStacks(Fn, *SaveBlock); + TFI.adjustForSegmentedStacks(MF, *SaveBlock); // Record that there are split-stack functions, so we will emit a // special section to tell the linker. - Fn.getMMI().setHasSplitStack(true); + MF.getMMI().setHasSplitStack(true); } else - Fn.getMMI().setHasNosplitStack(true); + MF.getMMI().setHasNosplitStack(true); // Emit additional code that is required to explicitly handle the stack in // HiPE native code (if needed) when loaded in the Erlang/OTP runtime. The // approach is rather similar to that of Segmented Stacks, but it uses a // different conditional check and another BIF for allocating more stack // space. - if (Fn.getFunction().getCallingConv() == CallingConv::HiPE) + if (MF.getFunction().getCallingConv() == CallingConv::HiPE) for (MachineBasicBlock *SaveBlock : SaveBlocks) - TFI.adjustForHiPEPrologue(Fn, *SaveBlock); + TFI.adjustForHiPEPrologue(MF, *SaveBlock); } /// replaceFrameIndices - Replace all MO_FrameIndex operands with physical /// register references and actual offsets. -void PEI::replaceFrameIndices(MachineFunction &Fn) { - const TargetFrameLowering &TFI = *Fn.getSubtarget().getFrameLowering(); - if (!TFI.needsFrameIndexResolution(Fn)) return; +void PEI::replaceFrameIndices(MachineFunction &MF) { + const TargetFrameLowering &TFI = *MF.getSubtarget().getFrameLowering(); + if (!TFI.needsFrameIndexResolution(MF)) return; // Store SPAdj at exit of a basic block. SmallVector<int, 8> SPState; - SPState.resize(Fn.getNumBlockIDs()); + SPState.resize(MF.getNumBlockIDs()); df_iterator_default_set<MachineBasicBlock*> Reachable; // Iterate over the reachable blocks in DFS order. - for (auto DFI = df_ext_begin(&Fn, Reachable), DFE = df_ext_end(&Fn, Reachable); + for (auto DFI = df_ext_begin(&MF, Reachable), DFE = df_ext_end(&MF, Reachable); DFI != DFE; ++DFI) { int SPAdj = 0; // Check the exit state of the DFS stack predecessor. @@ -1049,27 +1046,27 @@ void PEI::replaceFrameIndices(MachineFunction &Fn) { SPAdj = SPState[StackPred->getNumber()]; } MachineBasicBlock *BB = *DFI; - replaceFrameIndices(BB, Fn, SPAdj); + replaceFrameIndices(BB, MF, SPAdj); SPState[BB->getNumber()] = SPAdj; } // Handle the unreachable blocks. - for (auto &BB : Fn) { + for (auto &BB : MF) { if (Reachable.count(&BB)) // Already handled in DFS traversal. continue; int SPAdj = 0; - replaceFrameIndices(&BB, Fn, SPAdj); + replaceFrameIndices(&BB, MF, SPAdj); } } -void PEI::replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &Fn, +void PEI::replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &MF, int &SPAdj) { - assert(Fn.getSubtarget().getRegisterInfo() && + assert(MF.getSubtarget().getRegisterInfo() && "getRegisterInfo() must be implemented!"); - const TargetInstrInfo &TII = *Fn.getSubtarget().getInstrInfo(); - const TargetRegisterInfo &TRI = *Fn.getSubtarget().getRegisterInfo(); - const TargetFrameLowering *TFI = Fn.getSubtarget().getFrameLowering(); + const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); + const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo(); + const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); if (RS && FrameIndexEliminationScavenging) RS->enterBasicBlock(*BB); @@ -1080,7 +1077,7 @@ void PEI::replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &Fn, if (TII.isFrameInstr(*I)) { InsideCallSequence = TII.isFrameSetup(*I); SPAdj += TII.getSPAdjust(*I); - I = TFI->eliminateCallFramePseudoInstr(Fn, *BB, I); + I = TFI->eliminateCallFramePseudoInstr(MF, *BB, I); continue; } @@ -1099,8 +1096,9 @@ void PEI::replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &Fn, "operand of a DBG_VALUE machine instruction"); unsigned Reg; int64_t Offset = - TFI->getFrameIndexReference(Fn, MI.getOperand(0).getIndex(), Reg); + TFI->getFrameIndexReference(MF, MI.getOperand(0).getIndex(), Reg); MI.getOperand(0).ChangeToRegister(Reg, false /*isDef*/); + MI.getOperand(0).setIsDebug(); auto *DIExpr = DIExpression::prepend(MI.getDebugExpression(), DIExpression::NoDeref, Offset); MI.getOperand(3).setMetadata(DIExpr); @@ -1119,7 +1117,7 @@ void PEI::replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &Fn, unsigned Reg; MachineOperand &Offset = MI.getOperand(i + 1); int refOffset = TFI->getFrameIndexReferencePreferSP( - Fn, MI.getOperand(i).getIndex(), Reg, /*IgnoreSPUpdates*/ false); + MF, MI.getOperand(i).getIndex(), Reg, /*IgnoreSPUpdates*/ false); Offset.setImm(Offset.getImm() + refOffset); MI.getOperand(i).ChangeToRegister(Reg, false /*isDef*/); continue; diff --git a/gnu/llvm/lib/CodeGen/StackProtector.cpp b/gnu/llvm/lib/CodeGen/StackProtector.cpp index 62cef95a4af..cb12c7ce6e8 100644 --- a/gnu/llvm/lib/CodeGen/StackProtector.cpp +++ b/gnu/llvm/lib/CodeGen/StackProtector.cpp @@ -36,6 +36,7 @@ #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" +#include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/MDBuilder.h" #include "llvm/IR/Module.h" @@ -69,32 +70,6 @@ INITIALIZE_PASS_END(StackProtector, DEBUG_TYPE, FunctionPass *llvm::createStackProtectorPass() { return new StackProtector(); } -StackProtector::SSPLayoutKind -StackProtector::getSSPLayout(const AllocaInst *AI) const { - return AI ? Layout.lookup(AI) : SSPLK_None; -} - -void StackProtector::adjustForColoring(const AllocaInst *From, - const AllocaInst *To) { - // When coloring replaces one alloca with another, transfer the SSPLayoutKind - // tag from the remapped to the target alloca. The remapped alloca should - // have a size smaller than or equal to the replacement alloca. - SSPLayoutMap::iterator I = Layout.find(From); - if (I != Layout.end()) { - SSPLayoutKind Kind = I->second; - Layout.erase(I); - - // Transfer the tag, but make sure that SSPLK_AddrOf does not overwrite - // SSPLK_SmallArray or SSPLK_LargeArray, and make sure that - // SSPLK_SmallArray does not overwrite SSPLK_LargeArray. - I = Layout.find(To); - if (I == Layout.end()) - Layout.insert(std::make_pair(To, Kind)); - else if (I->second != SSPLK_LargeArray && Kind != SSPLK_AddrOf) - I->second = Kind; - } -} - void StackProtector::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired<TargetPassConfig>(); AU.addPreserved<DominatorTreeWrapperPass>(); @@ -182,6 +157,14 @@ bool StackProtector::ContainsProtectableArray(Type *Ty, bool &IsLarge, return NeedsProtector; } +static bool isLifetimeInst(const Instruction *I) { + if (const auto Intrinsic = dyn_cast<IntrinsicInst>(I)) { + const auto Id = Intrinsic->getIntrinsicID(); + return Id == Intrinsic::lifetime_start || Id == Intrinsic::lifetime_end; + } + return false; +} + bool StackProtector::HasAddressTaken(const Instruction *AI) { for (const User *U : AI->users()) { if (const StoreInst *SI = dyn_cast<StoreInst>(U)) { @@ -190,8 +173,10 @@ bool StackProtector::HasAddressTaken(const Instruction *AI) { } else if (const PtrToIntInst *SI = dyn_cast<PtrToIntInst>(U)) { if (AI == SI->getOperand(0)) return true; - } else if (isa<CallInst>(U)) { - return true; + } else if (const CallInst *CI = dyn_cast<CallInst>(U)) { + // Ignore intrinsics that are not calls. TODO: Use isLoweredToCall(). + if (!isa<DbgInfoIntrinsic>(CI) && !isLifetimeInst(CI)) + return true; } else if (isa<InvokeInst>(U)) { return true; } else if (const SelectInst *SI = dyn_cast<SelectInst>(U)) { @@ -214,7 +199,7 @@ bool StackProtector::HasAddressTaken(const Instruction *AI) { return false; } -/// \brief Check whether or not this function needs a stack protector based +/// Check whether or not this function needs a stack protector based /// upon the stack protector level. /// /// We use two heuristics: a standard (ssp) and strong (sspstrong). @@ -278,18 +263,21 @@ bool StackProtector::RequiresStackProtector() { if (CI->getLimitedValue(SSPBufferSize) >= SSPBufferSize) { // A call to alloca with size >= SSPBufferSize requires // stack protectors. - Layout.insert(std::make_pair(AI, SSPLK_LargeArray)); + Layout.insert(std::make_pair(AI, + MachineFrameInfo::SSPLK_LargeArray)); ORE.emit(RemarkBuilder); NeedsProtector = true; } else if (Strong) { // Require protectors for all alloca calls in strong mode. - Layout.insert(std::make_pair(AI, SSPLK_SmallArray)); + Layout.insert(std::make_pair(AI, + MachineFrameInfo::SSPLK_SmallArray)); ORE.emit(RemarkBuilder); NeedsProtector = true; } } else { // A call to alloca with a variable size requires protectors. - Layout.insert(std::make_pair(AI, SSPLK_LargeArray)); + Layout.insert(std::make_pair(AI, + MachineFrameInfo::SSPLK_LargeArray)); ORE.emit(RemarkBuilder); NeedsProtector = true; } @@ -298,8 +286,9 @@ bool StackProtector::RequiresStackProtector() { bool IsLarge = false; if (ContainsProtectableArray(AI->getAllocatedType(), IsLarge, Strong)) { - Layout.insert(std::make_pair(AI, IsLarge ? SSPLK_LargeArray - : SSPLK_SmallArray)); + Layout.insert(std::make_pair(AI, IsLarge + ? MachineFrameInfo::SSPLK_LargeArray + : MachineFrameInfo::SSPLK_SmallArray)); ORE.emit([&]() { return OptimizationRemark(DEBUG_TYPE, "StackProtectorBuffer", &I) << "Stack protection applied to function " @@ -313,7 +302,7 @@ bool StackProtector::RequiresStackProtector() { if (Strong && HasAddressTaken(AI)) { ++NumAddrTaken; - Layout.insert(std::make_pair(AI, SSPLK_AddrOf)); + Layout.insert(std::make_pair(AI, MachineFrameInfo::SSPLK_AddrOf)); ORE.emit([&]() { return OptimizationRemark(DEBUG_TYPE, "StackProtectorAddressTaken", &I) @@ -523,3 +512,23 @@ BasicBlock *StackProtector::CreateFailBB() { bool StackProtector::shouldEmitSDCheck(const BasicBlock &BB) const { return HasPrologue && !HasIRCheck && dyn_cast<ReturnInst>(BB.getTerminator()); } + +void StackProtector::copyToMachineFrameInfo(MachineFrameInfo &MFI) const { + if (Layout.empty()) + return; + + for (int I = 0, E = MFI.getObjectIndexEnd(); I != E; ++I) { + if (MFI.isDeadObjectIndex(I)) + continue; + + const AllocaInst *AI = MFI.getObjectAllocation(I); + if (!AI) + continue; + + SSPLayoutMap::const_iterator LI = Layout.find(AI); + if (LI == Layout.end()) + continue; + + MFI.setObjectSSPLayout(I, LI->second); + } +} diff --git a/gnu/llvm/lib/CodeGen/TargetLoweringBase.cpp b/gnu/llvm/lib/CodeGen/TargetLoweringBase.cpp index 40ed55fc348..3976a7601c9 100644 --- a/gnu/llvm/lib/CodeGen/TargetLoweringBase.cpp +++ b/gnu/llvm/lib/CodeGen/TargetLoweringBase.cpp @@ -28,7 +28,6 @@ #include "llvm/CodeGen/MachineMemOperand.h" #include "llvm/CodeGen/MachineOperand.h" #include "llvm/CodeGen/MachineRegisterInfo.h" -#include "llvm/CodeGen/MachineValueType.h" #include "llvm/CodeGen/RuntimeLibcalls.h" #include "llvm/CodeGen/StackMaps.h" #include "llvm/CodeGen/TargetLowering.h" @@ -50,6 +49,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/MachineValueType.h" #include "llvm/Support/MathExtras.h" #include "llvm/Target/TargetMachine.h" #include <algorithm> @@ -118,7 +118,7 @@ static cl::opt<int> MinPercentageForPredictableBranch( void TargetLoweringBase::InitLibcalls(const Triple &TT) { #define HANDLE_LIBCALL(code, name) \ setLibcallName(RTLIB::code, name); -#include "llvm/CodeGen/RuntimeLibcalls.def" +#include "llvm/IR/RuntimeLibcalls.def" #undef HANDLE_LIBCALL // Initialize calling conventions to their default. for (int LC = 0; LC < RTLIB::UNKNOWN_LIBCALL; ++LC) @@ -192,6 +192,9 @@ RTLIB::Libcall RTLIB::getFPEXT(EVT OpVT, EVT RetVT) { return FPEXT_F64_F128; else if (RetVT == MVT::ppcf128) return FPEXT_F64_PPCF128; + } else if (OpVT == MVT::f80) { + if (RetVT == MVT::f128) + return FPEXT_F80_F128; } return UNKNOWN_LIBCALL; @@ -227,6 +230,9 @@ RTLIB::Libcall RTLIB::getFPROUND(EVT OpVT, EVT RetVT) { return FPROUND_F128_F64; if (OpVT == MVT::ppcf128) return FPROUND_PPCF128_F64; + } else if (RetVT == MVT::f80) { + if (OpVT == MVT::f128) + return FPROUND_F128_F80; } return UNKNOWN_LIBCALL; @@ -529,6 +535,7 @@ TargetLoweringBase::TargetLoweringBase(const TargetMachine &tm) : TM(tm) { // Perform these initializations only once. MaxStoresPerMemset = MaxStoresPerMemcpy = MaxStoresPerMemmove = MaxLoadsPerMemcmp = 8; + MaxGluedStoresPerMemcpy = 0; MaxStoresPerMemsetOptSize = MaxStoresPerMemcpyOptSize = MaxStoresPerMemmoveOptSize = MaxLoadsPerMemcmpOptSize = 4; UseUnderscoreSetJmp = false; @@ -614,12 +621,18 @@ void TargetLoweringBase::initActions() { setOperationAction(ISD::SUBCARRY, VT, Expand); setOperationAction(ISD::SETCCCARRY, VT, Expand); + // ADDC/ADDE/SUBC/SUBE default to expand. + setOperationAction(ISD::ADDC, VT, Expand); + setOperationAction(ISD::ADDE, VT, Expand); + setOperationAction(ISD::SUBC, VT, Expand); + setOperationAction(ISD::SUBE, VT, Expand); + // These default to Expand so they will be expanded to CTLZ/CTTZ by default. setOperationAction(ISD::CTLZ_ZERO_UNDEF, VT, Expand); setOperationAction(ISD::CTTZ_ZERO_UNDEF, VT, Expand); setOperationAction(ISD::BITREVERSE, VT, Expand); - + // These library functions default to expand. setOperationAction(ISD::FROUND, VT, Expand); setOperationAction(ISD::FPOWI, VT, Expand); @@ -679,12 +692,13 @@ MVT TargetLoweringBase::getScalarShiftAmountTy(const DataLayout &DL, return MVT::getIntegerVT(8 * DL.getPointerSize(0)); } -EVT TargetLoweringBase::getShiftAmountTy(EVT LHSTy, - const DataLayout &DL) const { +EVT TargetLoweringBase::getShiftAmountTy(EVT LHSTy, const DataLayout &DL, + bool LegalTypes) const { assert(LHSTy.isInteger() && "Shift amount is not an integer type!"); if (LHSTy.isVector()) return LHSTy; - return getScalarShiftAmountTy(DL, LHSTy); + return LegalTypes ? getScalarShiftAmountTy(DL, LHSTy) + : getPointerTy(DL); } bool TargetLoweringBase::canOpTrap(unsigned Op, EVT VT) const { @@ -910,7 +924,7 @@ TargetLoweringBase::emitPatchPoint(MachineInstr &InitialMI, // STATEPOINT Deopt Spill - live-through, read only, indirect // STATEPOINT Deopt Alloca - live-through, read only, direct // (We're currently conservative and mark the deopt slots read/write in - // practice.) + // practice.) // STATEPOINT GC Spill - live-through, read/write, indirect // STATEPOINT GC Alloca - live-through, read/write, direct // The live-in vs live-through is handled already (the live through ones are @@ -979,6 +993,36 @@ TargetLoweringBase::emitPatchPoint(MachineInstr &InitialMI, return MBB; } +MachineBasicBlock * +TargetLoweringBase::emitXRayCustomEvent(MachineInstr &MI, + MachineBasicBlock *MBB) const { + assert(MI.getOpcode() == TargetOpcode::PATCHABLE_EVENT_CALL && + "Called emitXRayCustomEvent on the wrong MI!"); + auto &MF = *MI.getMF(); + auto MIB = BuildMI(MF, MI.getDebugLoc(), MI.getDesc()); + for (unsigned OpIdx = 0; OpIdx != MI.getNumOperands(); ++OpIdx) + MIB.add(MI.getOperand(OpIdx)); + + MBB->insert(MachineBasicBlock::iterator(MI), MIB); + MI.eraseFromParent(); + return MBB; +} + +MachineBasicBlock * +TargetLoweringBase::emitXRayTypedEvent(MachineInstr &MI, + MachineBasicBlock *MBB) const { + assert(MI.getOpcode() == TargetOpcode::PATCHABLE_TYPED_EVENT_CALL && + "Called emitXRayTypedEvent on the wrong MI!"); + auto &MF = *MI.getMF(); + auto MIB = BuildMI(MF, MI.getDebugLoc(), MI.getDesc()); + for (unsigned OpIdx = 0; OpIdx != MI.getNumOperands(); ++OpIdx) + MIB.add(MI.getOperand(OpIdx)); + + MBB->insert(MachineBasicBlock::iterator(MI), MIB); + MI.eraseFromParent(); + return MBB; +} + /// findRepresentativeClass - Return the largest legal super-reg register class /// of the register class for the specified type and its associated "cost". // This function is in TargetLowering because it uses RegClassForVT which would @@ -1293,7 +1337,8 @@ unsigned TargetLoweringBase::getVectorTypeBreakdown(LLVMContext &Context, EVT VT /// type of the given function. This does not require a DAG or a return value, /// and is suitable for use before any DAGs for the function are constructed. /// TODO: Move this out of TargetLowering.cpp. -void llvm::GetReturnInfo(Type *ReturnType, AttributeList attr, +void llvm::GetReturnInfo(CallingConv::ID CC, Type *ReturnType, + AttributeList attr, SmallVectorImpl<ISD::OutputArg> &Outs, const TargetLowering &TLI, const DataLayout &DL) { SmallVector<EVT, 4> ValueVTs; @@ -1321,9 +1366,9 @@ void llvm::GetReturnInfo(Type *ReturnType, AttributeList attr, } unsigned NumParts = - TLI.getNumRegistersForCallingConv(ReturnType->getContext(), VT); + TLI.getNumRegistersForCallingConv(ReturnType->getContext(), CC, VT); MVT PartVT = - TLI.getRegisterTypeForCallingConv(ReturnType->getContext(), VT); + TLI.getRegisterTypeForCallingConv(ReturnType->getContext(), CC, VT); // 'inreg' on function refers to return value ISD::ArgFlagsTy Flags = ISD::ArgFlagsTy(); @@ -1366,7 +1411,7 @@ bool TargetLoweringBase::allowsMemoryAccess(LLVMContext &Context, *Fast = true; return true; } - + // This is a misaligned access. return allowsMisalignedMemoryAccesses(VT, AddrSpace, Alignment, Fast); } @@ -1590,13 +1635,16 @@ Value *TargetLoweringBase::getIRStackGuard(IRBuilder<> &IRB) const { // Currently only support "standard" __stack_chk_guard. // TODO: add LOAD_STACK_GUARD support. void TargetLoweringBase::insertSSPDeclarations(Module &M) const { - M.getOrInsertGlobal("__stack_chk_guard", Type::getInt8PtrTy(M.getContext())); + if (!M.getNamedValue("__stack_chk_guard")) + new GlobalVariable(M, Type::getInt8PtrTy(M.getContext()), false, + GlobalVariable::ExternalLinkage, + nullptr, "__stack_chk_guard"); } // Currently only support "standard" __stack_chk_guard. // TODO: add LOAD_STACK_GUARD support. Value *TargetLoweringBase::getSDagStackGuard(const Module &M) const { - return M.getGlobalVariable("__stack_chk_guard", true); + return M.getNamedValue("__stack_chk_guard"); } Value *TargetLoweringBase::getSSPStackGuardCheck(const Module &M) const { @@ -1686,7 +1734,7 @@ static int getOpEnabled(bool IsSqrt, EVT VT, StringRef Override) { return TargetLoweringBase::ReciprocalEstimate::Unspecified; SmallVector<StringRef, 4> OverrideVector; - SplitString(Override, OverrideVector, ","); + Override.split(OverrideVector, ','); unsigned NumArgs = OverrideVector.size(); // Check if "all", "none", or "default" was specified. @@ -1746,7 +1794,7 @@ static int getOpRefinementSteps(bool IsSqrt, EVT VT, StringRef Override) { return TargetLoweringBase::ReciprocalEstimate::Unspecified; SmallVector<StringRef, 4> OverrideVector; - SplitString(Override, OverrideVector, ","); + Override.split(OverrideVector, ','); unsigned NumArgs = OverrideVector.size(); // Check if "all", "default", or "none" was specified. diff --git a/gnu/llvm/lib/CodeGen/TargetPassConfig.cpp b/gnu/llvm/lib/CodeGen/TargetPassConfig.cpp index 04f60eca18b..be7b8459059 100644 --- a/gnu/llvm/lib/CodeGen/TargetPassConfig.cpp +++ b/gnu/llvm/lib/CodeGen/TargetPassConfig.cpp @@ -41,6 +41,7 @@ #include "llvm/Support/Threading.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/Scalar.h" +#include "llvm/Transforms/Utils.h" #include "llvm/Transforms/Utils/SymbolRewriter.h" #include <cassert> #include <string> @@ -80,6 +81,9 @@ static cl::opt<bool> DisablePostRAMachineLICM("disable-postra-machine-licm", cl::desc("Disable Machine LICM")); static cl::opt<bool> DisableMachineSink("disable-machine-sink", cl::Hidden, cl::desc("Disable Machine Sinking")); +static cl::opt<bool> DisablePostRAMachineSink("disable-postra-machine-sink", + cl::Hidden, + cl::desc("Disable PostRA Machine Sinking")); static cl::opt<bool> DisableLSR("disable-lsr", cl::Hidden, cl::desc("Disable Loop Strength Reduction Pass")); static cl::opt<bool> DisableConstantHoisting("disable-constant-hoisting", @@ -94,10 +98,9 @@ static cl::opt<bool> EnableImplicitNullChecks( "enable-implicit-null-checks", cl::desc("Fold null checks into faulting memory operations"), cl::init(false), cl::Hidden); -static cl::opt<bool> - EnableMergeICmps("enable-mergeicmps", - cl::desc("Merge ICmp chains into a single memcmp"), - cl::init(false), cl::Hidden); +static cl::opt<bool> DisableMergeICmps("disable-mergeicmps", + cl::desc("Disable MergeICmps Pass"), + cl::init(false), cl::Hidden); static cl::opt<bool> PrintLSR("print-lsr-output", cl::Hidden, cl::desc("Print LLVM IR produced by the loop-reduce pass")); static cl::opt<bool> PrintISelInput("print-isel-input", cl::Hidden, @@ -108,14 +111,16 @@ static cl::opt<bool> VerifyMachineCode("verify-machineinstrs", cl::Hidden, cl::desc("Verify generated machine code"), cl::init(false), cl::ZeroOrMore); -static cl::opt<bool> EnableMachineOutliner("enable-machine-outliner", - cl::Hidden, - cl::desc("Enable machine outliner")); -static cl::opt<bool> EnableLinkOnceODROutlining( - "enable-linkonceodr-outlining", - cl::Hidden, - cl::desc("Enable the machine outliner on linkonceodr functions"), - cl::init(false)); +enum RunOutliner { AlwaysOutline, NeverOutline, TargetDefault }; +// Enable or disable the MachineOutliner. +static cl::opt<RunOutliner> EnableMachineOutliner( + "enable-machine-outliner", cl::desc("Enable the machine outliner"), + cl::Hidden, cl::ValueOptional, cl::init(TargetDefault), + cl::values(clEnumValN(AlwaysOutline, "always", + "Run on all functions guaranteed to be beneficial"), + clEnumValN(NeverOutline, "never", "Disable all outlining"), + // Sentinel value for unspecified option. + clEnumValN(AlwaysOutline, "", ""))); // Enable or disable FastISel. Both options are needed, because // FastISel is enabled by default with -fast, and we wish to be // able to enable or disable fast-isel independently from -O0. @@ -123,9 +128,9 @@ static cl::opt<cl::boolOrDefault> EnableFastISelOption("fast-isel", cl::Hidden, cl::desc("Enable the \"fast\" instruction selector")); -static cl::opt<cl::boolOrDefault> - EnableGlobalISel("global-isel", cl::Hidden, - cl::desc("Enable the \"global\" instruction selector")); +static cl::opt<cl::boolOrDefault> EnableGlobalISelOption( + "global-isel", cl::Hidden, + cl::desc("Enable the \"global\" instruction selector")); static cl::opt<std::string> PrintMachineInstrs( "print-machineinstrs", cl::ValueOptional, cl::desc("Print machine instrs"), @@ -161,7 +166,7 @@ static cl::opt<CFLAAType> UseCFLAA( "Enable unification-based CFL-AA"), clEnumValN(CFLAAType::Andersen, "anders", "Enable inclusion-based CFL-AA"), - clEnumValN(CFLAAType::Both, "both", + clEnumValN(CFLAAType::Both, "both", "Enable both variants of CFL-AA"))); /// Option names for limiting the codegen pipeline. @@ -226,7 +231,7 @@ static IdentifyingPassPtr overridePass(AnalysisID StandardID, if (StandardID == &TailDuplicateID) return applyDisable(TargetID, DisableTailDuplicate); - if (StandardID == &TargetPassConfig::EarlyTailDuplicateID) + if (StandardID == &EarlyTailDuplicateID) return applyDisable(TargetID, DisableEarlyTailDup); if (StandardID == &MachineBlockPlacementID) @@ -241,18 +246,21 @@ static IdentifyingPassPtr overridePass(AnalysisID StandardID, if (StandardID == &EarlyIfConverterID) return applyDisable(TargetID, DisableEarlyIfConversion); - if (StandardID == &MachineLICMID) + if (StandardID == &EarlyMachineLICMID) return applyDisable(TargetID, DisableMachineLICM); if (StandardID == &MachineCSEID) return applyDisable(TargetID, DisableMachineCSE); - if (StandardID == &TargetPassConfig::PostRAMachineLICMID) + if (StandardID == &MachineLICMID) return applyDisable(TargetID, DisablePostRAMachineLICM); if (StandardID == &MachineSinkingID) return applyDisable(TargetID, DisableMachineSink); + if (StandardID == &PostRAMachineSinkingID) + return applyDisable(TargetID, DisablePostRAMachineSink); + if (StandardID == &MachineCopyPropagationID) return applyDisable(TargetID, DisableCopyProp); @@ -267,10 +275,6 @@ INITIALIZE_PASS(TargetPassConfig, "targetpassconfig", "Target Pass Configuration", false, false) char TargetPassConfig::ID = 0; -// Pseudo Pass IDs. -char TargetPassConfig::EarlyTailDuplicateID = 0; -char TargetPassConfig::PostRAMachineLICMID = 0; - namespace { struct InsertedPass { @@ -366,10 +370,6 @@ TargetPassConfig::TargetPassConfig(LLVMTargetMachine &TM, PassManagerBase &pm) initializeBasicAAWrapperPassPass(*PassRegistry::getPassRegistry()); initializeAAResultsWrapperPassPass(*PassRegistry::getPassRegistry()); - // Substitute Pseudo Pass IDs for real ones. - substitutePass(&EarlyTailDuplicateID, &TailDuplicateID); - substitutePass(&PostRAMachineLICMID, &MachineLICMID); - if (StringRef(PrintMachineInstrs.getValue()).equals("")) TM.Options.PrintMachineCode = true; @@ -604,7 +604,7 @@ void TargetPassConfig::addIRPasses() { // loads and compares. ExpandMemCmpPass then tries to expand those calls // into optimally-sized loads and compares. The transforms are enabled by a // target lowering hook. - if (EnableMergeICmps) + if (!DisableMergeICmps) addPass(createMergeICmpsPass()); addPass(createExpandMemCmpPass()); } @@ -662,6 +662,14 @@ void TargetPassConfig::addPassesToHandleExceptions() { addPass(createWinEHPass()); addPass(createDwarfEHPass()); break; + case ExceptionHandling::Wasm: + // Wasm EH uses Windows EH instructions, but it does not need to demote PHIs + // on catchpads and cleanuppads because it does not outline them into + // funclets. Catchswitch blocks are not lowered in SelectionDAG, so we + // should remove PHIs there. + addPass(createWinEHPass(/*DemoteCatchSwitchPHIOnly=*/false)); + addPass(createWasmEHPass()); + break; case ExceptionHandling::None: addPass(createLowerInvokePass()); @@ -706,19 +714,18 @@ void TargetPassConfig::addISelPrepare() { } bool TargetPassConfig::addCoreISelPasses() { - // Enable FastISel with -fast, but allow that to be overridden. + // Enable FastISel with -fast-isel, but allow that to be overridden. TM->setO0WantsFastISel(EnableFastISelOption != cl::BOU_FALSE); if (EnableFastISelOption == cl::BOU_TRUE || (TM->getOptLevel() == CodeGenOpt::None && TM->getO0WantsFastISel())) TM->setFastISel(true); - // Ask the target for an isel. - // Enable GlobalISel if the target wants to, but allow that to be overriden. + // Ask the target for an instruction selector. // Explicitly enabling fast-isel should override implicitly enabled // global-isel. - if (EnableGlobalISel == cl::BOU_TRUE || - (EnableGlobalISel == cl::BOU_UNSET && isGlobalISelEnabled() && - EnableFastISelOption != cl::BOU_TRUE)) { + if (EnableGlobalISelOption == cl::BOU_TRUE || + (EnableGlobalISelOption == cl::BOU_UNSET && + TM->Options.EnableGlobalISel && EnableFastISelOption != cl::BOU_TRUE)) { TM->setFastISel(false); if (addIRTranslator()) @@ -757,7 +764,7 @@ bool TargetPassConfig::addCoreISelPasses() { } bool TargetPassConfig::addISelPasses() { - if (TM->Options.EmulatedTLS) + if (TM->useEmulatedTLS()) addPass(createLowerEmuTLSPass()); addPass(createPreISelIntrinsicLoweringPass()); @@ -846,8 +853,10 @@ void TargetPassConfig::addMachinePasses() { addPostRegAlloc(); // Insert prolog/epilog code. Eliminate abstract frame index references... - if (getOptLevel() != CodeGenOpt::None) + if (getOptLevel() != CodeGenOpt::None) { + addPass(&PostRAMachineSinkingID); addPass(&ShrinkWrapID); + } // Prolog/Epilog inserter needs a TargetMachine to instantiate. But only // do so if it hasn't been disabled, substituted, or overridden. @@ -906,8 +915,14 @@ void TargetPassConfig::addMachinePasses() { addPass(&XRayInstrumentationID, false); addPass(&PatchableFunctionID, false); - if (EnableMachineOutliner) - PM->add(createMachineOutlinerPass(EnableLinkOnceODROutlining)); + if (TM->Options.EnableMachineOutliner && getOptLevel() != CodeGenOpt::None && + EnableMachineOutliner != NeverOutline) { + bool RunOnAllFunctions = (EnableMachineOutliner == AlwaysOutline); + bool AddOutliner = RunOnAllFunctions || + TM->Options.SupportsDefaultOutlining; + if (AddOutliner) + addPass(createMachineOutlinerPass(RunOnAllFunctions)); + } // Add passes that directly emit MI after all other MI passes. addPreEmitPass2(); @@ -943,7 +958,7 @@ void TargetPassConfig::addMachineSSAOptimization() { // loop info, just like LICM and CSE below. addILPOpts(); - addPass(&MachineLICMID, false); + addPass(&EarlyMachineLICMID, false); addPass(&MachineCSEID, false); addPass(&MachineSinkingID); @@ -1092,10 +1107,14 @@ void TargetPassConfig::addOptimizedRegAlloc(FunctionPass *RegAllocPass) { // kill markers. addPass(&StackSlotColoringID); + // Copy propagate to forward register uses and try to eliminate COPYs that + // were not coalesced. + addPass(&MachineCopyPropagationID); + // Run post-ra machine LICM to hoist reloads / remats. // // FIXME: can this move into MachineLateOptimization? - addPass(&PostRAMachineLICMID); + addPass(&MachineLICMID); } } @@ -1137,18 +1156,13 @@ void TargetPassConfig::addBlockPlacement() { //===---------------------------------------------------------------------===// /// GlobalISel Configuration //===---------------------------------------------------------------------===// - -bool TargetPassConfig::isGlobalISelEnabled() const { - return false; -} - bool TargetPassConfig::isGlobalISelAbortEnabled() const { if (EnableGlobalISelAbort.getNumOccurrences() > 0) return EnableGlobalISelAbort == 1; // When no abort behaviour is specified, we don't abort if the target says // that GISel is enabled. - return !isGlobalISelEnabled(); + return !TM->Options.EnableGlobalISel; } bool TargetPassConfig::reportDiagnosticWhenGlobalISelFallback() const { |
