Make DataLayout Non-Optional in the Module

Summary:
DataLayout keeps the string used for its creation.

As a side effect it is no longer needed in the Module.
This is "almost" NFC, the string is no longer
canonicalized, you can't rely on two "equals" DataLayout
having the same string returned by getStringRepresentation().

Get rid of DataLayoutPass: the DataLayout is in the Module

The DataLayout is "per-module", let's enforce this by not
duplicating it more than necessary.
One more step toward non-optionality of the DataLayout in the
module.

Make DataLayout Non-Optional in the Module

Module->getDataLayout() will never returns nullptr anymore.

Reviewers: echristo

Subscribers: resistor, llvm-commits, jholewinski

Differential Revision: http://reviews.llvm.org/D7992

From: Mehdi Amini <mehdi.amini@apple.com>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231270 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Mehdi Amini
2015-03-04 18:43:29 +00:00
parent 2337c1fd83
commit c94da20917
163 changed files with 617 additions and 973 deletions

View File

@@ -68,7 +68,7 @@ protected:
/// typically called by the run* methods of these subclasses. This may be
/// called multiple times.
///
void InitializeAliasAnalysis(Pass *P);
void InitializeAliasAnalysis(Pass *P, const DataLayout *DL);
/// getAnalysisUsage - All alias analysis implementations should invoke this
/// directly (using AliasAnalysis::getAnalysisUsage(AU)).

View File

@@ -15,6 +15,7 @@
#define LLVM_ANALYSIS_LIBCALLALIASANALYSIS_H
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
namespace llvm {
@@ -48,11 +49,8 @@ namespace llvm {
void getAnalysisUsage(AnalysisUsage &AU) const override;
bool runOnFunction(Function &F) override {
InitializeAliasAnalysis(this); // set up super class
return false;
}
bool runOnFunction(Function &F) override;
/// getAdjustedAnalysisPointer - This method is used when a pass implements
/// an analysis interface through multiple inheritance. If needed, it
/// should override this to adjust the this pointer as needed for the

View File

@@ -183,7 +183,7 @@ private:
auto Names = llvm::make_unique<StringMap<bool>>();
for (const auto &M : Ms) {
Mangler Mang(M->getDataLayout());
Mangler Mang(&M->getDataLayout());
for (const auto &GV : M->globals())
if (addGlobalValue(*Names, GV, Mang, SearchName, ExportedSymbolsOnly))

View File

@@ -116,6 +116,9 @@ private:
/// \brief Primitive type alignment data.
SmallVector<LayoutAlignElem, 16> Alignments;
/// \brief The string representation used to create this DataLayout
std::string StringRepresentation;
typedef SmallVector<PointerAlignElem, 8> PointersTy;
PointersTy Pointers;
@@ -185,6 +188,7 @@ public:
DataLayout &operator=(const DataLayout &DL) {
clear();
StringRepresentation = DL.StringRepresentation;
BigEndian = DL.isBigEndian();
StackNaturalAlign = DL.StackNaturalAlign;
ManglingMode = DL.ManglingMode;
@@ -209,8 +213,12 @@ public:
/// \brief Returns the string representation of the DataLayout.
///
/// This representation is in the same format accepted by the string
/// constructor above.
std::string getStringRepresentation() const;
/// constructor above. This should not be used to compare two DataLayout as
/// different string can represent the same layout.
std::string getStringRepresentation() const { return StringRepresentation; }
/// \brief Test if the DataLayout was constructed from an empty string.
bool isDefault() const { return StringRepresentation.empty(); }
/// \brief Returns true if the specified type is known to be a native integer
/// type supported by the CPU.
@@ -451,22 +459,6 @@ inline LLVMTargetDataRef wrap(const DataLayout *P) {
return reinterpret_cast<LLVMTargetDataRef>(const_cast<DataLayout *>(P));
}
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; }
static char ID; // Pass identification, replacement for typeid
bool doFinalization(Module &M) override;
bool doInitialization(Module &M) override;
};
/// Used to lazily calculate structure layout information for a target machine,
/// based on the DataLayout structure.
class StructLayout {

View File

@@ -219,14 +219,7 @@ private:
std::string TargetTriple; ///< Platform target triple Module compiled on
///< Format: (arch)(sub)-(vendor)-(sys0-(abi)
void *NamedMDSymTab; ///< NamedMDNode names.
// We need to keep the string because the C API expects us to own the string
// representation.
// Since we have it, we also use an empty string to represent a module without
// a DataLayout. If it has a DataLayout, these variables are in sync and the
// string is just a cache of getDataLayout()->getStringRepresentation().
std::string DataLayoutStr;
DataLayout DL;
DataLayout DL; ///< DataLayout associated with the module
friend class Constant;
@@ -256,10 +249,12 @@ public:
/// Get the data layout string for the module's target platform. This is
/// equivalent to getDataLayout()->getStringRepresentation().
const std::string &getDataLayoutStr() const { return DataLayoutStr; }
const std::string getDataLayoutStr() const {
return DL.getStringRepresentation();
}
/// Get the data layout for the module's target platform.
const DataLayout *getDataLayout() const;
const DataLayout &getDataLayout() const;
/// Get the target triple which is a string describing the target host.
/// @returns a string containing the target triple.
@@ -293,7 +288,7 @@ public:
/// Set the data layout
void setDataLayout(StringRef Desc);
void setDataLayout(const DataLayout *Other);
void setDataLayout(const DataLayout &Other);
/// Set the target triple.
void setTargetTriple(StringRef T) { TargetTriple = T; }

View File

@@ -192,15 +192,13 @@ void CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
class InlineFunctionInfo {
public:
explicit InlineFunctionInfo(CallGraph *cg = nullptr,
const DataLayout *DL = nullptr,
AliasAnalysis *AA = nullptr,
AssumptionCacheTracker *ACT = nullptr)
: CG(cg), DL(DL), AA(AA), ACT(ACT) {}
: CG(cg), AA(AA), ACT(ACT) {}
/// CG - If non-null, InlineFunction will update the callgraph to reflect the
/// changes it makes.
CallGraph *CG;
const DataLayout *DL;
AliasAnalysis *AA;
AssumptionCacheTracker *ACT;