diff options
author | Jan Wen Voung <jvoung@google.com> | 2010-10-04 17:32:41 +0000 |
---|---|---|
committer | Jan Wen Voung <jvoung@google.com> | 2010-10-04 17:32:41 +0000 |
commit | 87f77b5f9a5654490cef338ae9f13703b915168e (patch) | |
tree | 242c3ab65b821a1972dce6be26aecb15207e13e9 /llvm/lib | |
parent | 0d9c993401bd557b0c5953a4e6fdf4d79f5a52bc (diff) | |
download | bcm5719-llvm-87f77b5f9a5654490cef338ae9f13703b915168e.tar.gz bcm5719-llvm-87f77b5f9a5654490cef338ae9f13703b915168e.zip |
Add hook in MCSection to decide when to use "optimized nops", for each
section kind. Previously, optimized nops were only used for MachO.
Also added tests for ELF and COFF.
llvm-svn: 115523
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/MC/MCParser/AsmParser.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/MC/MCSectionCOFF.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/MC/MCSectionELF.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/MC/MCSectionMachO.cpp | 5 | ||||
-rw-r--r-- | llvm/lib/Target/PIC16/PIC16Section.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Target/PIC16/PIC16Section.h | 2 |
6 files changed, 19 insertions, 7 deletions
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index fbac34a15ea..688827d2c76 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -1654,12 +1654,7 @@ bool AsmParser::ParseDirectiveAlign(bool IsPow2, unsigned ValueSize) { // Check whether we should use optimal code alignment for this .align // directive. - // - // FIXME: This should be using a target hook. - bool UseCodeAlign = false; - if (const MCSectionMachO *S = dyn_cast<MCSectionMachO>( - getStreamer().getCurrentSection())) - UseCodeAlign = S->hasAttribute(MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS); + bool UseCodeAlign = getStreamer().getCurrentSection()->UseCodeAlign(); if ((!HasFillExpr || Lexer.getMAI().getTextAlignFillValue() == FillExpr) && ValueSize == 1 && UseCodeAlign) { getStreamer().EmitCodeAlignment(Alignment, MaxBytesToFill); diff --git a/llvm/lib/MC/MCSectionCOFF.cpp b/llvm/lib/MC/MCSectionCOFF.cpp index eb531600f72..0909df42227 100644 --- a/llvm/lib/MC/MCSectionCOFF.cpp +++ b/llvm/lib/MC/MCSectionCOFF.cpp @@ -74,3 +74,7 @@ void MCSectionCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, } } } + +bool MCSectionCOFF::UseCodeAlign() const { + return getKind().isText(); +} diff --git a/llvm/lib/MC/MCSectionELF.cpp b/llvm/lib/MC/MCSectionELF.cpp index ef935d0c64b..133cad1b32c 100644 --- a/llvm/lib/MC/MCSectionELF.cpp +++ b/llvm/lib/MC/MCSectionELF.cpp @@ -112,6 +112,10 @@ void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI, OS << '\n'; } +bool MCSectionELF::UseCodeAlign() const { + return getFlags() & MCSectionELF::SHF_EXECINSTR; +} + // HasCommonSymbols - True if this section holds common symbols, this is // indicated on the ELF object file by a symbol with SHN_COMMON section // header index. diff --git a/llvm/lib/MC/MCSectionMachO.cpp b/llvm/lib/MC/MCSectionMachO.cpp index ded3b20eaf5..12b3efe663f 100644 --- a/llvm/lib/MC/MCSectionMachO.cpp +++ b/llvm/lib/MC/MCSectionMachO.cpp @@ -148,6 +148,10 @@ void MCSectionMachO::PrintSwitchToSection(const MCAsmInfo &MAI, OS << '\n'; } +bool MCSectionMachO::UseCodeAlign() const { + return hasAttribute(MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS); +} + /// StripSpaces - This removes leading and trailing spaces from the StringRef. static void StripSpaces(StringRef &Str) { while (!Str.empty() && isspace(Str[0])) @@ -283,4 +287,3 @@ std::string MCSectionMachO::ParseSectionSpecifier(StringRef Spec, // In. return ""; } - diff --git a/llvm/lib/Target/PIC16/PIC16Section.cpp b/llvm/lib/Target/PIC16/PIC16Section.cpp index 2505b111f1e..7664fbbb7d4 100644 --- a/llvm/lib/Target/PIC16/PIC16Section.cpp +++ b/llvm/lib/Target/PIC16/PIC16Section.cpp @@ -102,3 +102,7 @@ void PIC16Section::PrintSwitchToSection(const MCAsmInfo &MAI, OS << '\n'; } + +bool PIC16Section::UseCodeAlign() const { + return isCODE_Type(); +} diff --git a/llvm/lib/Target/PIC16/PIC16Section.h b/llvm/lib/Target/PIC16/PIC16Section.h index 5b33b51a386..98e590229bd 100644 --- a/llvm/lib/Target/PIC16/PIC16Section.h +++ b/llvm/lib/Target/PIC16/PIC16Section.h @@ -88,6 +88,8 @@ namespace llvm { virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS) const; + virtual bool UseCodeAlign() const; + static bool classof(const MCSection *S) { return S->getVariant() == SV_PIC16; } |