[llvm] r231147 - Remove getDataLayout() from Instruction/GlobalValue/BasicBlock/Function
Mehdi Amini
mehdi.amini at apple.com
Tue Mar 3 14:01:14 PST 2015
Author: mehdi_amini
Date: Tue Mar 3 16:01:13 2015
New Revision: 231147
URL: http://llvm.org/viewvc/llvm-project?rev=231147&view=rev
Log:
Remove getDataLayout() from Instruction/GlobalValue/BasicBlock/Function
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 at apple.com>
Modified:
llvm/trunk/include/llvm/IR/BasicBlock.h
llvm/trunk/include/llvm/IR/GlobalValue.h
llvm/trunk/include/llvm/IR/Instruction.h
llvm/trunk/lib/Analysis/IPA/InlineCost.cpp
llvm/trunk/lib/Analysis/Loads.cpp
llvm/trunk/lib/IR/BasicBlock.cpp
llvm/trunk/lib/IR/Globals.cpp
llvm/trunk/lib/IR/Instruction.cpp
Modified: llvm/trunk/include/llvm/IR/BasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/BasicBlock.h?rev=231147&r1=231146&r2=231147&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/BasicBlock.h (original)
+++ llvm/trunk/include/llvm/IR/BasicBlock.h Tue Mar 3 16:01:13 2015
@@ -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.
Modified: llvm/trunk/include/llvm/IR/GlobalValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GlobalValue.h?rev=231147&r1=231146&r2=231147&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GlobalValue.h (original)
+++ llvm/trunk/include/llvm/IR/GlobalValue.h Tue Mar 3 16:01:13 2015
@@ -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 ||
Modified: llvm/trunk/include/llvm/IR/Instruction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Instruction.h?rev=231147&r1=231146&r2=231147&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Instruction.h (original)
+++ llvm/trunk/include/llvm/IR/Instruction.h Tue Mar 3 16:01:13 2015
@@ -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.
Modified: llvm/trunk/lib/Analysis/IPA/InlineCost.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IPA/InlineCost.cpp?rev=231147&r1=231146&r2=231147&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/IPA/InlineCost.cpp (original)
+++ llvm/trunk/lib/Analysis/IPA/InlineCost.cpp Tue Mar 3 16:01:13 2015
@@ -396,7 +396,7 @@ bool CallAnalyzer::visitBitCast(BitCastI
}
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(PtrToIn
}
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::getInline
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);
Modified: llvm/trunk/lib/Analysis/Loads.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Loads.cpp?rev=231147&r1=231146&r2=231147&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/Loads.cpp (original)
+++ llvm/trunk/lib/Analysis/Loads.cpp Tue Mar 3 16:01:13 2015
@@ -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(Va
// 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)
Modified: llvm/trunk/lib/IR/BasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/BasicBlock.cpp?rev=231147&r1=231146&r2=231147&view=diff
==============================================================================
--- llvm/trunk/lib/IR/BasicBlock.cpp (original)
+++ llvm/trunk/lib/IR/BasicBlock.cpp Tue Mar 3 16:01:13 2015
@@ -29,10 +29,6 @@ ValueSymbolTable *BasicBlock::getValueSy
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 *M
getParent()->getBasicBlockList(), this);
}
+const Module *BasicBlock::getModule() const {
+ return getParent()->getParent();
+}
TerminatorInst *BasicBlock::getTerminator() {
if (InstList.empty()) return nullptr;
Modified: llvm/trunk/lib/IR/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Globals.cpp?rev=231147&r1=231146&r2=231147&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Globals.cpp (original)
+++ llvm/trunk/lib/IR/Globals.cpp Tue Mar 3 16:01:13 2015
@@ -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() {
Modified: llvm/trunk/lib/IR/Instruction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instruction.cpp?rev=231147&r1=231146&r2=231147&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instruction.cpp (original)
+++ llvm/trunk/lib/IR/Instruction.cpp Tue Mar 3 16:01:13 2015
@@ -32,10 +32,6 @@ Instruction::Instruction(Type *ty, unsig
}
}
-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 *
Parent = P;
}
+const Module *Instruction::getModule() const {
+ return getParent()->getModule();
+}
+
void Instruction::removeFromParent() {
getParent()->getInstList().remove(this);
}
More information about the llvm-commits
mailing list