Skip to content

Commit

Permalink
Remove getDataLayout() from Instruction/GlobalValue/BasicBlock/Function
Browse files Browse the repository at this point in the history
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>
llvm-svn: 231147
  • Loading branch information
joker-eph committed Mar 3, 2015
1 parent 1dbe2e3 commit 9a9738f
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 20 deletions.
6 changes: 5 additions & 1 deletion llvm/include/llvm/IR/BasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ class BasicBlock : public Value, // Basic blocks are data objects also
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.
Expand Down
2 changes: 0 additions & 2 deletions llvm/include/llvm/IR/GlobalValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,6 @@ class GlobalValue : public Constant {
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 ||
Expand Down
7 changes: 6 additions & 1 deletion llvm/include/llvm/IR/Instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ class Instruction : public User, public ilist_node<Instruction> {
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.
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Analysis/IPA/InlineCost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Analysis/Loads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/IR/BasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ ValueSymbolTable *BasicBlock::getValueSymbolTable() {
return nullptr;
}

const DataLayout *BasicBlock::getDataLayout() const {
return getParent()->getDataLayout();
}

LLVMContext &BasicBlock::getContext() const {
return getType()->getContext();
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/IR/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/IR/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down

0 comments on commit 9a9738f

Please sign in to comment.