diff options
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 107 |
1 files changed, 73 insertions, 34 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 3072edc5088e..7bd3fb33b47d 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -503,13 +503,7 @@ bool AsmPrinter::doInitialization(Module &M) { // don't, this at least helps the user find where a global came from. if (MAI->hasSingleParameterDotFile()) { // .file "foo.c" - - SmallString<128> FileName; - if (MAI->hasBasenameOnlyForFileDirective()) - FileName = llvm::sys::path::filename(M.getSourceFileName()); - else - FileName = M.getSourceFileName(); - if (MAI->hasFourStringsDotFile()) { + if (MAI->isAIX()) { const char VerStr[] = #ifdef PACKAGE_VENDOR PACKAGE_VENDOR " " @@ -520,9 +514,10 @@ bool AsmPrinter::doInitialization(Module &M) { #endif ; // TODO: Add timestamp and description. - OutStreamer->emitFileDirective(FileName, VerStr, "", ""); + OutStreamer->emitFileDirective(M.getSourceFileName(), VerStr, "", ""); } else { - OutStreamer->emitFileDirective(FileName); + OutStreamer->emitFileDirective( + llvm::sys::path::filename(M.getSourceFileName())); } } @@ -531,7 +526,8 @@ bool AsmPrinter::doInitialization(Module &M) { if (TM.getTargetTriple().isOSBinFormatXCOFF()) { emitModuleCommandLines(M); // Now we can generate section information. - OutStreamer->initSections(false, *TM.getMCSubtargetInfo()); + OutStreamer->switchSection( + OutContext.getObjectFileInfo()->getTextSection()); // To work around an AIX assembler and/or linker bug, generate // a rename for the default text-section symbol name. This call has @@ -966,11 +962,10 @@ void AsmPrinter::emitFunctionHeader() { MF->setSection(getObjFileLowering().SectionForGlobal(&F, TM)); OutStreamer->switchSection(MF->getSection()); - if (!MAI->hasVisibilityOnlyWithLinkage()) - emitVisibility(CurrentFnSym, F.getVisibility()); - - if (MAI->needsFunctionDescriptors()) + if (MAI->isAIX()) emitLinkage(&F, CurrentFnDescSym); + else + emitVisibility(CurrentFnSym, F.getVisibility()); emitLinkage(&F, CurrentFnSym); if (MAI->hasFunctionAlignment()) @@ -1030,7 +1025,7 @@ void AsmPrinter::emitFunctionHeader() { // to emit their specific function descriptor. Right now it is only used by // the AIX target. The PowerPC 64-bit V1 ELF target also uses function // descriptors and should be converted to use this hook as well. - if (MAI->needsFunctionDescriptors()) + if (MAI->isAIX()) emitFunctionDescriptor(); // Emit the CurrentFnSym. This is a virtual function to allow targets to do @@ -1791,7 +1786,7 @@ void AsmPrinter::emitFunctionBody() { MDT = MDTWrapper ? &MDTWrapper->getDomTree() : nullptr; if (!MDT) { OwnedMDT = std::make_unique<MachineDominatorTree>(); - OwnedMDT->getBase().recalculate(*MF); + OwnedMDT->recalculate(*MF); MDT = OwnedMDT.get(); } @@ -1800,7 +1795,7 @@ void AsmPrinter::emitFunctionBody() { MLI = MLIWrapper ? &MLIWrapper->getLI() : nullptr; if (!MLI) { OwnedMLI = std::make_unique<MachineLoopInfo>(); - OwnedMLI->analyze(MDT->getBase()); + OwnedMLI->analyze(*MDT); MLI = OwnedMLI.get(); } } @@ -2233,9 +2228,6 @@ void AsmPrinter::emitGlobalAlias(const Module &M, const GlobalAlias &GA) { // point, all the extra label is emitted, we just have to emit linkage for // those labels. if (TM.getTargetTriple().isOSBinFormatXCOFF()) { - assert(MAI->hasVisibilityOnlyWithLinkage() && - "Visibility should be handled with emitLinkage() on AIX."); - // Linkage for alias of global variable has been emitted. if (isa<GlobalVariable>(GA.getAliaseeObject())) return; @@ -2406,12 +2398,53 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) { OutStreamer->emitBinaryData(Buf); } +static void tagGlobalDefinition(Module &M, GlobalVariable *G) { + Constant *Initializer = G->getInitializer(); + uint64_t SizeInBytes = + M.getDataLayout().getTypeAllocSize(Initializer->getType()); + + uint64_t NewSize = alignTo(SizeInBytes, 16); + if (SizeInBytes != NewSize) { + // Pad the initializer out to the next multiple of 16 bytes. + llvm::SmallVector<uint8_t> Init(NewSize - SizeInBytes, 0); + Constant *Padding = ConstantDataArray::get(M.getContext(), Init); + Initializer = ConstantStruct::getAnon({Initializer, Padding}); + auto *NewGV = new GlobalVariable( + M, Initializer->getType(), G->isConstant(), G->getLinkage(), + Initializer, "", G, G->getThreadLocalMode(), G->getAddressSpace()); + NewGV->copyAttributesFrom(G); + NewGV->setComdat(G->getComdat()); + NewGV->copyMetadata(G, 0); + + NewGV->takeName(G); + G->replaceAllUsesWith(NewGV); + G->eraseFromParent(); + G = NewGV; + } + + if (G->getAlign().valueOrOne() < 16) + G->setAlignment(Align(16)); + + // Ensure that tagged globals don't get merged by ICF - as they should have + // different tags at runtime. + G->setUnnamedAddr(GlobalValue::UnnamedAddr::None); +} + bool AsmPrinter::doFinalization(Module &M) { // Set the MachineFunction to nullptr so that we can catch attempted // accesses to MF specific features at the module level and so that // we can conditionalize accesses based on whether or not it is nullptr. MF = nullptr; + std::vector<GlobalVariable *> GlobalsToTag; + for (GlobalVariable &G : M.globals()) { + if (G.isDeclaration() || !G.isTagged()) + continue; + GlobalsToTag.push_back(&G); + } + for (GlobalVariable *G : GlobalsToTag) + tagGlobalDefinition(M, G); + // Gather all GOT equivalent globals in the module. We really need two // passes over the globals: one to compute and another to avoid its emission // in EmitGlobalVariable, otherwise we would not be able to handle cases @@ -2688,7 +2721,7 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) { HasNoSplitStack = true; // Get the function symbol. - if (!MAI->needsFunctionDescriptors()) { + if (!MAI->isAIX()) { CurrentFnSym = getSymbol(&MF.getFunction()); } else { assert(TM.getTargetTriple().isOSAIX() && @@ -3602,10 +3635,11 @@ static void emitGlobalConstantArray(const DataLayout &DL, static void emitGlobalConstantLargeInt(const ConstantInt *CI, AsmPrinter &AP); -static void emitGlobalConstantVector(const DataLayout &DL, - const ConstantVector *CV, AsmPrinter &AP, +static void emitGlobalConstantVector(const DataLayout &DL, const Constant *CV, + AsmPrinter &AP, AsmPrinter::AliasMapTy *AliasList) { - Type *ElementType = CV->getType()->getElementType(); + auto *VTy = cast<FixedVectorType>(CV->getType()); + Type *ElementType = VTy->getElementType(); uint64_t ElementSizeInBits = DL.getTypeSizeInBits(ElementType); uint64_t ElementAllocSizeInBits = DL.getTypeAllocSizeInBits(ElementType); uint64_t EmittedSize; @@ -3618,7 +3652,7 @@ static void emitGlobalConstantVector(const DataLayout &DL, Type *IntT = IntegerType::get(CV->getContext(), DL.getTypeSizeInBits(CV->getType())); ConstantInt *CI = dyn_cast_or_null<ConstantInt>(ConstantFoldConstant( - ConstantExpr::getBitCast(const_cast<ConstantVector *>(CV), IntT), DL)); + ConstantExpr::getBitCast(const_cast<Constant *>(CV), IntT), DL)); if (!CI) { report_fatal_error( "Cannot lower vector global with unusual element type"); @@ -3627,12 +3661,11 @@ static void emitGlobalConstantVector(const DataLayout &DL, emitGlobalConstantLargeInt(CI, AP); EmittedSize = DL.getTypeStoreSize(CV->getType()); } else { - for (unsigned I = 0, E = CV->getType()->getNumElements(); I != E; ++I) { + for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) { emitGlobalAliasInline(AP, DL.getTypeAllocSize(CV->getType()) * I, AliasList); - emitGlobalConstantImpl(DL, CV->getOperand(I), AP); + emitGlobalConstantImpl(DL, CV->getAggregateElement(I), AP); } - EmittedSize = - DL.getTypeAllocSize(ElementType) * CV->getType()->getNumElements(); + EmittedSize = DL.getTypeAllocSize(ElementType) * VTy->getNumElements(); } unsigned Size = DL.getTypeAllocSize(CV->getType()); @@ -3902,8 +3935,10 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *CV, return AP.OutStreamer->emitZeros(Size); if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { - const uint64_t StoreSize = DL.getTypeStoreSize(CV->getType()); + if (isa<VectorType>(CV->getType())) + return emitGlobalConstantVector(DL, CV, AP, AliasList); + const uint64_t StoreSize = DL.getTypeStoreSize(CV->getType()); if (StoreSize <= 8) { if (AP.isVerbose()) AP.OutStreamer->getCommentOS() @@ -3920,8 +3955,12 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *CV, return; } - if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) - return emitGlobalConstantFP(CFP, AP); + if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) { + if (isa<VectorType>(CV->getType())) + return emitGlobalConstantVector(DL, CV, AP, AliasList); + else + return emitGlobalConstantFP(CFP, AP); + } if (isa<ConstantPointerNull>(CV)) { AP.OutStreamer->emitIntValue(0, Size); @@ -3953,8 +3992,8 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *CV, } } - if (const ConstantVector *V = dyn_cast<ConstantVector>(CV)) - return emitGlobalConstantVector(DL, V, AP, AliasList); + if (isa<ConstantVector>(CV)) + return emitGlobalConstantVector(DL, CV, AP, AliasList); // Otherwise, it must be a ConstantExpr. Lower it to an MCExpr, then emit it // thread the streamer with EmitValue. |
