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 | 083cf1574facc9ce468fba1735c794bd7e520108 (patch) | |
tree | 89bc4a3eeececcf7162c44251e43316055fa47e0 /lib | |
parent | 7a391832f46ca2947f6ee46f6fad53cf64197d28 (diff) | |
download | external_llvm-083cf1574facc9ce468fba1735c794bd7e520108.tar.gz external_llvm-083cf1574facc9ce468fba1735c794bd7e520108.tar.bz2 external_llvm-083cf1574facc9ce468fba1735c794bd7e520108.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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115523 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MC/MCParser/AsmParser.cpp | 7 | ||||
-rw-r--r-- | lib/MC/MCSectionCOFF.cpp | 4 | ||||
-rw-r--r-- | lib/MC/MCSectionELF.cpp | 4 | ||||
-rw-r--r-- | lib/MC/MCSectionMachO.cpp | 5 | ||||
-rw-r--r-- | lib/Target/PIC16/PIC16Section.cpp | 4 | ||||
-rw-r--r-- | lib/Target/PIC16/PIC16Section.h | 2 |
6 files changed, 19 insertions, 7 deletions
diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index fbac34a15e..688827d2c7 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/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/lib/MC/MCSectionCOFF.cpp b/lib/MC/MCSectionCOFF.cpp index eb531600f7..0909df4222 100644 --- a/lib/MC/MCSectionCOFF.cpp +++ b/lib/MC/MCSectionCOFF.cpp @@ -74,3 +74,7 @@ void MCSectionCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, } } } + +bool MCSectionCOFF::UseCodeAlign() const { + return getKind().isText(); +} diff --git a/lib/MC/MCSectionELF.cpp b/lib/MC/MCSectionELF.cpp index ef935d0c64..133cad1b32 100644 --- a/lib/MC/MCSectionELF.cpp +++ b/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/lib/MC/MCSectionMachO.cpp b/lib/MC/MCSectionMachO.cpp index ded3b20eaf..12b3efe663 100644 --- a/lib/MC/MCSectionMachO.cpp +++ b/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/lib/Target/PIC16/PIC16Section.cpp b/lib/Target/PIC16/PIC16Section.cpp index 2505b111f1..7664fbbb7d 100644 --- a/lib/Target/PIC16/PIC16Section.cpp +++ b/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/lib/Target/PIC16/PIC16Section.h b/lib/Target/PIC16/PIC16Section.h index 5b33b51a38..98e590229b 100644 --- a/lib/Target/PIC16/PIC16Section.h +++ b/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; } |