From 57edc9d4ff1648568a5dd7e9958649065b260dca Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 25 Feb 2014 17:30:31 +0000 Subject: Make DataLayout a plain object, not a pass. Instead, have a DataLayoutPass that holds one. This will allow parts of LLVM don't don't handle passes to also use DataLayout. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202168 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/DataLayout.h | 70 +++++++++++++++++++++-------------------- include/llvm/InitializePasses.h | 2 +- 2 files changed, 37 insertions(+), 35 deletions(-) (limited to 'include/llvm') diff --git a/include/llvm/IR/DataLayout.h b/include/llvm/IR/DataLayout.h index acd3d82555..f9ab9cf94c 100644 --- a/include/llvm/IR/DataLayout.h +++ b/include/llvm/IR/DataLayout.h @@ -88,14 +88,11 @@ struct PointerAlignElem { bool operator==(const PointerAlignElem &rhs) const; }; - -/// DataLayout - This class holds a parsed version of the target data layout -/// string in a module and provides methods for querying it. The target data -/// layout string is specified *by the target* - a frontend generating LLVM IR -/// is required to generate the right target data for the target being codegen'd -/// to. If some measure of portability is desired, an empty string may be -/// specified in the module. -class DataLayout : public ImmutablePass { +/// This class holds a parsed version of the target data layout string in a +/// module and provides methods for querying it. The target data layout string +/// is specified *by the target* - a frontend generating LLVM IR is required to +/// generate the right target data for the target being codegen'd to. +class DataLayout { private: bool LittleEndian; ///< Defaults to false unsigned StackNaturalAlign; ///< Stack natural alignment @@ -165,40 +162,28 @@ private: void parseSpecifier(StringRef LayoutDescription); public: - /// Default ctor. - /// - /// @note This has to exist, because this is a pass, but it should never be - /// used. - DataLayout(); - /// Constructs a DataLayout from a specification string. See init(). - explicit DataLayout(StringRef LayoutDescription) - : ImmutablePass(ID) { - init(LayoutDescription); - } + explicit DataLayout(StringRef LayoutDescription) { init(LayoutDescription); } /// Initialize target data from properties stored in the module. explicit DataLayout(const Module *M); - DataLayout(const DataLayout &DL) : - ImmutablePass(ID), - LittleEndian(DL.isLittleEndian()), - StackNaturalAlign(DL.StackNaturalAlign), - ManglingMode(DL.ManglingMode), - LegalIntWidths(DL.LegalIntWidths), - Alignments(DL.Alignments), - Pointers(DL.Pointers), - LayoutMap(0) - { } + DataLayout(const DataLayout &DL) { *this = DL; } + + DataLayout &operator=(const DataLayout &DL) { + LittleEndian = DL.isLittleEndian(); + StackNaturalAlign = DL.StackNaturalAlign; + ManglingMode = DL.ManglingMode; + LegalIntWidths = DL.LegalIntWidths; + Alignments = DL.Alignments; + Pointers = DL.Pointers; + LayoutMap = 0; + return *this; + } ~DataLayout(); // Not virtual, do not subclass this class - /// DataLayout is an immutable pass, but holds state. This allows the pass - /// manager to clear its mutable state. - bool doFinalization(Module &M); - - /// Parse a data layout string (with fallback to default values). Ensure that - /// the data layout pass is registered. + /// Parse a data layout string (with fallback to default values). void init(StringRef LayoutDescription); /// Layout endianness... @@ -458,6 +443,23 @@ public: assert((Alignment & (Alignment-1)) == 0 && "Alignment must be power of 2!"); return (Val + (Alignment-1)) & ~UIntTy(Alignment-1); } +}; + +class DataLayoutPass : public ImmutablePass { + DataLayout DL; + +public: + /// This has to exist, because this is a pass, but it should never be used. + DataLayoutPass(); + ~DataLayoutPass(); + + const DataLayout &getDataLayout() const { return DL; } + + explicit DataLayoutPass(const DataLayout &DL); + + explicit DataLayoutPass(StringRef LayoutDescription); + + explicit DataLayoutPass(const Module *M); static char ID; // Pass identification, replacement for typeid }; diff --git a/include/llvm/InitializePasses.h b/include/llvm/InitializePasses.h index 923571ea4b..c244257a6e 100644 --- a/include/llvm/InitializePasses.h +++ b/include/llvm/InitializePasses.h @@ -248,7 +248,7 @@ void initializeStripSymbolsPass(PassRegistry&); void initializeTailCallElimPass(PassRegistry&); void initializeTailDuplicatePassPass(PassRegistry&); void initializeTargetPassConfigPass(PassRegistry&); -void initializeDataLayoutPass(PassRegistry&); +void initializeDataLayoutPassPass(PassRegistry &); void initializeTargetTransformInfoAnalysisGroup(PassRegistry&); void initializeNoTTIPass(PassRegistry&); void initializeTargetLibraryInfoPass(PassRegistry&); -- cgit v1.2.3