Remove getDataLayout() from Instruction/GlobalValue/BasicBlock/Function
authorMehdi Amini <mehdi.amini@apple.com>
Tue, 3 Mar 2015 22:01:13 +0000 (22:01 +0000)
committerMehdi Amini <mehdi.amini@apple.com>
Tue, 3 Mar 2015 22:01:13 +0000 (22:01 +0000)
Summary:
This does not conceptually belongs here. Instead provide a shortcut
getModule() that provides access to the DataLayout.

Reviewers: chandlerc, echristo

Reviewed By: echristo

Subscribers: llvm-commits

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

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231147 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/BasicBlock.h
include/llvm/IR/GlobalValue.h
include/llvm/IR/Instruction.h
lib/Analysis/IPA/InlineCost.cpp
lib/Analysis/Loads.cpp
lib/IR/BasicBlock.cpp
lib/IR/Globals.cpp
lib/IR/Instruction.cpp

index 185fc2952ecac11d0cea64770ecb7b34d3f3e282..8f5cdebcd10b2f4b1aad8fe2561de13051616d88 100644 (file)
@@ -119,7 +119,11 @@ public:
   const Function *getParent() const { return Parent; }
         Function *getParent()       { return Parent; }
 
-  const DataLayout *getDataLayout() const;
+  /// \brief Return the module owning the function this basic block belongs to,
+  /// or nullptr it the function does not have a module.
+  ///
+  /// Note: this is undefined behavior if the block does not have a parent.
+  const Module *getModule() const;
 
   /// \brief Returns the terminator instruction if the block is well formed or
   /// null if the block is not well formed.
index aaecc1dcc3fb3553ddde41d75c4cf4ed8d0f93af..002e5e79fd46a4b1351af3e6d49ac19220c32758 100644 (file)
@@ -346,8 +346,6 @@ public:
   inline Module *getParent() { return Parent; }
   inline const Module *getParent() const { return Parent; }
 
-  const DataLayout *getDataLayout() const;
-
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const Value *V) {
     return V->getValueID() == Value::FunctionVal ||
index dfece3e3f2fc518c58f038aa3afd31dda5c92adc..dc96b57674c6a5901a881f23b98d606e31808afb 100644 (file)
@@ -54,7 +54,12 @@ public:
   inline const BasicBlock *getParent() const { return Parent; }
   inline       BasicBlock *getParent()       { return Parent; }
 
-  const DataLayout *getDataLayout() const;
+  /// \brief Return the module owning the function this instruction belongs to
+  /// or nullptr it the function does not have a module.
+  ///
+  /// Note: this is undefined behavior if the instruction does not have a
+  /// parent, or the parent basic block does not have a parent function.
+  const Module *getModule() const;
 
   /// removeFromParent - This method unlinks 'this' from the containing basic
   /// block, but does not delete it.
index cd494ba84c99781af2a5e6ada75102059f439e6b..eb02b80c94a868f7c8afc58675a516771ed9e512 100644 (file)
@@ -396,7 +396,7 @@ bool CallAnalyzer::visitBitCast(BitCastInst &I) {
 }
 
 bool CallAnalyzer::visitPtrToInt(PtrToIntInst &I) {
-  const DataLayout *DL = I.getDataLayout();
+  const DataLayout *DL = I.getModule()->getDataLayout();
   // Propagate constants through ptrtoint.
   Constant *COp = dyn_cast<Constant>(I.getOperand(0));
   if (!COp)
@@ -433,7 +433,7 @@ bool CallAnalyzer::visitPtrToInt(PtrToIntInst &I) {
 }
 
 bool CallAnalyzer::visitIntToPtr(IntToPtrInst &I) {
-  const DataLayout *DL = I.getDataLayout();
+  const DataLayout *DL = I.getModule()->getDataLayout();
   // Propagate constants through ptrtoint.
   Constant *COp = dyn_cast<Constant>(I.getOperand(0));
   if (!COp)
@@ -1333,7 +1333,7 @@ InlineCost InlineCostAnalysis::getInlineCost(CallSite CS, Function *Callee,
   DEBUG(llvm::dbgs() << "      Analyzing call of " << Callee->getName()
         << "...\n");
 
-  CallAnalyzer CA(Callee->getDataLayout(), TTIWP->getTTI(*Callee),
+  CallAnalyzer CA(Callee->getParent()->getDataLayout(), TTIWP->getTTI(*Callee),
                   ACT, *Callee, Threshold);
   bool ShouldInline = CA.analyzeCall(CS);
 
index 5042eb9777ac9fbb9dd1f550c69cdcb619a9d027..aaaf75f3015c8bed1be78f439a92d2b3f005ca57 100644 (file)
@@ -19,6 +19,7 @@
 #include "llvm/IR/GlobalVariable.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
 #include "llvm/IR/Operator.h"
 using namespace llvm;
 
@@ -178,7 +179,7 @@ Value *llvm::FindAvailableLoadedValue(Value *Ptr, BasicBlock *ScanBB,
 
   // Try to get the DataLayout for this module. This may be null, in which case
   // the optimizations will be limited.
-  const DataLayout *DL = ScanBB->getDataLayout();
+  const DataLayout *DL = ScanBB->getModule()->getDataLayout();
 
   // Try to get the store size for the type.
   uint64_t AccessSize = DL ? DL->getTypeStoreSize(AccessTy)
index eac7d3afbe598f7c4acc26b69fcc639dae027b99..fe38385d34159c01f5ac08a0a8c922bc902b52fe 100644 (file)
@@ -29,10 +29,6 @@ ValueSymbolTable *BasicBlock::getValueSymbolTable() {
   return nullptr;
 }
 
-const DataLayout *BasicBlock::getDataLayout() const {
-  return getParent()->getDataLayout();
-}
-
 LLVMContext &BasicBlock::getContext() const {
   return getType()->getContext();
 }
@@ -117,6 +113,9 @@ void BasicBlock::moveAfter(BasicBlock *MovePos) {
                                        getParent()->getBasicBlockList(), this);
 }
 
+const Module *BasicBlock::getModule() const {
+  return getParent()->getParent();
+}
 
 TerminatorInst *BasicBlock::getTerminator() {
   if (InstList.empty()) return nullptr;
index 54197d96763f049e071cdfe560e51137dd6b2e30..5a6adb3f304555324e9c6510b29ef75d19970258 100644 (file)
@@ -42,10 +42,6 @@ void GlobalValue::Dematerialize() {
   getParent()->Dematerialize(this);
 }
 
-const DataLayout *GlobalValue::getDataLayout() const {
-  return getParent()->getDataLayout();
-}
-
 /// Override destroyConstant to make sure it doesn't get called on
 /// GlobalValue's because they shouldn't be treated like other constants.
 void GlobalValue::destroyConstant() {
index 92c6e9f3dede0f475270dc8a0dbe418b9732b8c3..7d9bd7ed5ffc6da90349ca3ea5aebfb481f9c0f8 100644 (file)
@@ -32,10 +32,6 @@ Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
   }
 }
 
-const DataLayout *Instruction::getDataLayout() const {
-  return getParent()->getDataLayout();
-}
-
 Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
                          BasicBlock *InsertAtEnd)
   : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
@@ -58,6 +54,10 @@ void Instruction::setParent(BasicBlock *P) {
   Parent = P;
 }
 
+const Module *Instruction::getModule() const {
+  return getParent()->getModule();
+}
+
 void Instruction::removeFromParent() {
   getParent()->getInstList().remove(this);
 }