summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorGuillaume Chatelet <gchatelet@google.com>2019-09-11 13:37:35 +0000
committerGuillaume Chatelet <gchatelet@google.com>2019-09-11 13:37:35 +0000
commit97264366fbad7105e55c770b5bb4c83f135334f0 (patch)
treeb18473b2eb5aaffd608ddd9f0765443e953510f1 /llvm/lib/CodeGen
parent3183466aa60442f099f52a004b5ebe81cf5a5eb0 (diff)
downloadbcm5719-llvm-97264366fbad7105e55c770b5bb4c83f135334f0.tar.gz
bcm5719-llvm-97264366fbad7105e55c770b5bb4c83f135334f0.zip
[Alignment][NFC] use llvm::Align for AsmPrinter::EmitAlignment
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: dschuff, sdardis, nemanjai, hiraditya, kbarton, jrtc27, MaskRay, atanasyan, jsji, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67443 llvm-svn: 371616
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp100
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp6
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/ErlangGCPrinter.cpp2
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp4
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/WinException.cpp4
5 files changed, 56 insertions, 60 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 077f4ac73ca..ca223f78c16 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -159,31 +159,31 @@ static gcp_map_type &getGCMap(void *&P) {
return *(gcp_map_type*)P;
}
-/// getGVAlignmentLog2 - Return the alignment to use for the specified global
-/// value in log2 form. This rounds up to the preferred alignment if possible
-/// and legal.
-unsigned AsmPrinter::getGVAlignmentLog2(const GlobalValue *GV,
- const DataLayout &DL,
- unsigned InBits) {
- unsigned NumBits = 0;
+/// getGVAlignment - Return the alignment to use for the specified global
+/// value. This rounds up to the preferred alignment if possible and legal.
+llvm::Align AsmPrinter::getGVAlignment(const GlobalValue *GV,
+ const DataLayout &DL,
+ llvm::Align InAlign) {
+ llvm::Align Align;
if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
- NumBits = DL.getPreferredAlignmentLog(GVar);
+ Align = llvm::Align(DL.getPreferredAlignment(GVar));
- // If InBits is specified, round it to it.
- if (InBits > NumBits)
- NumBits = InBits;
+ // If InAlign is specified, round it to it.
+ if (InAlign > Align)
+ Align = InAlign;
// If the GV has a specified alignment, take it into account.
- if (GV->getAlignment() == 0)
- return NumBits;
+ const llvm::MaybeAlign GVAlign(GV->getAlignment());
+ if (!GVAlign)
+ return Align;
- unsigned GVAlign = Log2_32(GV->getAlignment());
+ assert(GVAlign && "GVAlign must be set");
// If the GVAlign is larger than NumBits, or if we are required to obey
// NumBits because the GV has an assigned section, obey it.
- if (GVAlign > NumBits || GV->hasSection())
- NumBits = GVAlign;
- return NumBits;
+ if (*GVAlign > Align || GV->hasSection())
+ Align = *GVAlign;
+ return Align;
}
AsmPrinter::AsmPrinter(TargetMachine &tm, std::unique_ptr<MCStreamer> Streamer)
@@ -502,7 +502,7 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
// If the alignment is specified, we *must* obey it. Overaligning a global
// with a specified alignment is a prompt way to break globals emitted to
// sections and expected to be contiguous (e.g. ObjC metadata).
- unsigned AlignLog = getGVAlignmentLog2(GV, DL);
+ const llvm::Align Align = getGVAlignment(GV, DL);
for (const HandlerInfo &HI : Handlers) {
NamedRegionTimer T(HI.TimerName, HI.TimerDescription,
@@ -514,12 +514,11 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
// Handle common symbols
if (GVKind.isCommon()) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
- unsigned Align = 1 << AlignLog;
- if (!getObjFileLowering().getCommDirectiveSupportsAlignment())
- Align = 0;
-
// .comm _foo, 42, 4
- OutStreamer->EmitCommonSymbol(GVSym, Size, Align);
+ const bool SupportsAlignment =
+ getObjFileLowering().getCommDirectiveSupportsAlignment();
+ OutStreamer->EmitCommonSymbol(GVSym, Size,
+ SupportsAlignment ? Align.value() : 0);
return;
}
@@ -532,10 +531,9 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
TheSection->isVirtualSection()) {
if (Size == 0)
Size = 1; // zerofill of 0 bytes is undefined.
- unsigned Align = 1 << AlignLog;
EmitLinkage(GV, GVSym);
// .zerofill __DATA, __bss, _foo, 400, 5
- OutStreamer->EmitZerofill(TheSection, GVSym, Size, Align);
+ OutStreamer->EmitZerofill(TheSection, GVSym, Size, Align.value());
return;
}
@@ -545,7 +543,6 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
getObjFileLowering().getBSSSection() == TheSection) {
if (Size == 0)
Size = 1; // .comm Foo, 0 is undefined, avoid it.
- unsigned Align = 1 << AlignLog;
// Use .lcomm only if it supports user-specified alignment.
// Otherwise, while it would still be correct to use .lcomm in some
@@ -555,17 +552,17 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
// Prefer to simply fall back to .local / .comm in this case.
if (MAI->getLCOMMDirectiveAlignmentType() != LCOMM::NoAlignment) {
// .lcomm _foo, 42
- OutStreamer->EmitLocalCommonSymbol(GVSym, Size, Align);
+ OutStreamer->EmitLocalCommonSymbol(GVSym, Size, Align.value());
return;
}
- if (!getObjFileLowering().getCommDirectiveSupportsAlignment())
- Align = 0;
-
// .local _foo
OutStreamer->EmitSymbolAttribute(GVSym, MCSA_Local);
// .comm _foo, 42, 4
- OutStreamer->EmitCommonSymbol(GVSym, Size, Align);
+ const bool SupportsAlignment =
+ getObjFileLowering().getCommDirectiveSupportsAlignment();
+ OutStreamer->EmitCommonSymbol(GVSym, Size,
+ SupportsAlignment ? Align.value() : 0);
return;
}
@@ -586,11 +583,11 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
if (GVKind.isThreadBSS()) {
TheSection = getObjFileLowering().getTLSBSSSection();
- OutStreamer->EmitTBSSSymbol(TheSection, MangSym, Size, 1 << AlignLog);
+ OutStreamer->EmitTBSSSymbol(TheSection, MangSym, Size, Align.value());
} else if (GVKind.isThreadData()) {
OutStreamer->SwitchSection(TheSection);
- EmitAlignment(AlignLog, GV);
+ EmitAlignment(Align, GV);
OutStreamer->EmitLabel(MangSym);
EmitGlobalConstant(GV->getParent()->getDataLayout(),
@@ -626,7 +623,7 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
OutStreamer->SwitchSection(TheSection);
EmitLinkage(GV, EmittedInitSym);
- EmitAlignment(AlignLog, GV);
+ EmitAlignment(Align, GV);
OutStreamer->EmitLabel(EmittedInitSym);
@@ -667,7 +664,7 @@ void AsmPrinter::EmitFunctionHeader() {
EmitLinkage(&F, CurrentFnSym);
if (MAI->hasFunctionAlignment())
- EmitAlignment(Log2(MF->getAlignment()), &F);
+ EmitAlignment(MF->getAlignment(), &F);
if (MAI->hasDotTypeDotSizeDirective())
OutStreamer->EmitSymbolAttribute(CurrentFnSym, MCSA_ELF_TypeFunction);
@@ -1421,7 +1418,7 @@ bool AsmPrinter::doFinalization(Module &M) {
OutStreamer->SwitchSection(TLOF.getDataSection());
const DataLayout &DL = M.getDataLayout();
- EmitAlignment(Log2_32(DL.getPointerSize()));
+ EmitAlignment(llvm::Align(DL.getPointerSize()));
for (const auto &Stub : Stubs) {
OutStreamer->EmitLabel(Stub.first);
OutStreamer->EmitSymbolValue(Stub.second.getPointer(),
@@ -1448,7 +1445,7 @@ bool AsmPrinter::doFinalization(Module &M) {
COFF::IMAGE_SCN_LNK_COMDAT,
SectionKind::getReadOnly(), Stub.first->getName(),
COFF::IMAGE_COMDAT_SELECT_ANY));
- EmitAlignment(Log2_32(DL.getPointerSize()));
+ EmitAlignment(llvm::Align(DL.getPointerSize()));
OutStreamer->EmitSymbolAttribute(Stub.first, MCSA_Global);
OutStreamer->EmitLabel(Stub.first);
OutStreamer->EmitSymbolValue(Stub.second.getPointer(),
@@ -1730,7 +1727,7 @@ void AsmPrinter::EmitConstantPool() {
if (CurSection != CPSections[i].S) {
OutStreamer->SwitchSection(CPSections[i].S);
- EmitAlignment(Log2_32(CPSections[i].Alignment));
+ EmitAlignment(llvm::Align(CPSections[i].Alignment));
CurSection = CPSections[i].S;
Offset = 0;
}
@@ -1777,7 +1774,7 @@ void AsmPrinter::EmitJumpTableInfo() {
OutStreamer->SwitchSection(ReadOnlySection);
}
- EmitAlignment(Log2_32(MJTI->getEntryAlignment(DL)));
+ EmitAlignment(llvm::Align(MJTI->getEntryAlignment(DL)));
// Jump tables in code sections are marked with a data_region directive
// where that's supported.
@@ -1990,7 +1987,7 @@ void AsmPrinter::EmitXXStructorList(const DataLayout &DL, const Constant *List,
}
// Emit the function pointers in the target-specific order
- unsigned Align = Log2_32(DL.getPointerPrefAlignment());
+ const llvm::Align Align = llvm::Align(DL.getPointerPrefAlignment());
llvm::stable_sort(Structors, [](const Structor &L, const Structor &R) {
return L.Priority < R.Priority;
});
@@ -2114,23 +2111,21 @@ void AsmPrinter::EmitLabelPlusOffset(const MCSymbol *Label, uint64_t Offset,
//===----------------------------------------------------------------------===//
// EmitAlignment - Emit an alignment directive to the specified power of
-// two boundary. For example, if you pass in 3 here, you will get an 8
-// byte alignment. If a global value is specified, and if that global has
+// two boundary. If a global value is specified, and if that global has
// an explicit alignment requested, it will override the alignment request
// if required for correctness.
-void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalObject *GV) const {
+void AsmPrinter::EmitAlignment(llvm::Align Align,
+ const GlobalObject *GV) const {
if (GV)
- NumBits = getGVAlignmentLog2(GV, GV->getParent()->getDataLayout(), NumBits);
+ Align = getGVAlignment(GV, GV->getParent()->getDataLayout(), Align);
- if (NumBits == 0) return; // 1-byte aligned: no need to emit alignment.
+ if (Align == 1)
+ return; // 1-byte aligned: no need to emit alignment.
- assert(NumBits <
- static_cast<unsigned>(std::numeric_limits<unsigned>::digits) &&
- "undefined behavior");
if (getCurrentSection()->getKind().isText())
- OutStreamer->EmitCodeAlignment(1u << NumBits);
+ OutStreamer->EmitCodeAlignment(Align.value());
else
- OutStreamer->EmitValueToAlignment(1u << NumBits);
+ OutStreamer->EmitValueToAlignment(Align.value());
}
//===----------------------------------------------------------------------===//
@@ -2905,8 +2900,9 @@ void AsmPrinter::EmitBasicBlockStart(const MachineBasicBlock &MBB) {
}
// Emit an alignment directive for this block, if needed.
- if (unsigned LogAlign = MBB.getLogAlignment())
- EmitAlignment(LogAlign);
+ const llvm::Align Align = MBB.getAlignment();
+ if (Align > 1)
+ EmitAlignment(Align);
MCCodePaddingContext Context;
setupCodePaddingContext(MBB, Context);
OutStreamer->EmitCodePaddingBasicBlockStart(Context);
diff --git a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
index 99e3687b36b..689d55b3caa 100644
--- a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
@@ -426,7 +426,7 @@ MCSymbol *EHStreamer::emitExceptionTable() {
// EHABI). In this case LSDASection will be NULL.
if (LSDASection)
Asm->OutStreamer->SwitchSection(LSDASection);
- Asm->EmitAlignment(2);
+ Asm->EmitAlignment(llvm::Align(4));
// Emit the LSDA.
MCSymbol *GCCETSym =
@@ -602,11 +602,11 @@ MCSymbol *EHStreamer::emitExceptionTable() {
}
if (HaveTTData) {
- Asm->EmitAlignment(2);
+ Asm->EmitAlignment(llvm::Align(4));
emitTypeInfos(TTypeEncoding, TTBaseLabel);
}
- Asm->EmitAlignment(2);
+ Asm->EmitAlignment(llvm::Align(4));
return GCCETSym;
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/ErlangGCPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/ErlangGCPrinter.cpp
index 39392b79e96..aac08041d63 100644
--- a/llvm/lib/CodeGen/AsmPrinter/ErlangGCPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/ErlangGCPrinter.cpp
@@ -72,7 +72,7 @@ void ErlangGCPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
**/
// Align to address width.
- AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3);
+ AP.EmitAlignment(IntPtrSize == 4 ? llvm::Align(4) : llvm::Align(8));
// Emit PointCount.
OS.AddComment("safe point count");
diff --git a/llvm/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
index 3145cc90dc7..824d0cbcb0c 100644
--- a/llvm/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
@@ -129,7 +129,7 @@ void OcamlGCMetadataPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
report_fatal_error(" Too much descriptor for ocaml GC");
}
AP.emitInt16(NumDescriptors);
- AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3);
+ AP.EmitAlignment(IntPtrSize == 4 ? llvm::Align(4) : llvm::Align(8));
for (GCModuleInfo::FuncInfoVec::iterator I = Info.funcinfo_begin(),
IE = Info.funcinfo_end();
@@ -180,7 +180,7 @@ void OcamlGCMetadataPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
AP.emitInt16(K->StackOffset);
}
- AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3);
+ AP.EmitAlignment(IntPtrSize == 4 ? llvm::Align(4) : llvm::Align(8));
}
}
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp
index 4f561771723..155e91ce61a 100644
--- a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp
@@ -203,8 +203,8 @@ void WinException::beginFunclet(const MachineBasicBlock &MBB,
// We want our funclet's entry point to be aligned such that no nops will be
// present after the label.
- Asm->EmitAlignment(
- Log2(std::max(Asm->MF->getAlignment(), MBB.getAlignment())), &F);
+ Asm->EmitAlignment(std::max(Asm->MF->getAlignment(), MBB.getAlignment()),
+ &F);
// Now that we've emitted the alignment directive, point at our funclet.
Asm->OutStreamer->EmitLabel(Sym);
OpenPOWER on IntegriCloud