mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-10-06 14:57:41 +00:00
Redirect DataLayout from TargetMachine to Module in MachineFunction
Summary: This change is part of a series of commits dedicated to have a single DataLayout during compilation by using always the one owned by the module. Reviewers: echristo Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D10984 From: Mehdi Amini <mehdi.amini@apple.com> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241610 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d0c71cfdf6
commit
33c4d685e3
@ -135,17 +135,18 @@ public:
|
|||||||
/// address of the function constant pool values.
|
/// address of the function constant pool values.
|
||||||
/// @brief The machine constant pool.
|
/// @brief The machine constant pool.
|
||||||
class MachineConstantPool {
|
class MachineConstantPool {
|
||||||
const TargetMachine &TM; ///< The target machine.
|
|
||||||
unsigned PoolAlignment; ///< The alignment for the pool.
|
unsigned PoolAlignment; ///< The alignment for the pool.
|
||||||
std::vector<MachineConstantPoolEntry> Constants; ///< The pool of constants.
|
std::vector<MachineConstantPoolEntry> Constants; ///< The pool of constants.
|
||||||
/// MachineConstantPoolValues that use an existing MachineConstantPoolEntry.
|
/// MachineConstantPoolValues that use an existing MachineConstantPoolEntry.
|
||||||
DenseSet<MachineConstantPoolValue*> MachineCPVsSharingEntries;
|
DenseSet<MachineConstantPoolValue*> MachineCPVsSharingEntries;
|
||||||
|
const DataLayout &DL;
|
||||||
|
|
||||||
|
const DataLayout &getDataLayout() const { return DL; }
|
||||||
|
|
||||||
const DataLayout *getDataLayout() const;
|
|
||||||
public:
|
public:
|
||||||
/// @brief The only constructor.
|
/// @brief The only constructor.
|
||||||
explicit MachineConstantPool(const TargetMachine &TM)
|
explicit MachineConstantPool(const DataLayout &DL)
|
||||||
: TM(TM), PoolAlignment(1) {}
|
: PoolAlignment(1), DL(DL) {}
|
||||||
~MachineConstantPool();
|
~MachineConstantPool();
|
||||||
|
|
||||||
/// getConstantPoolAlignment - Return the alignment required by
|
/// getConstantPoolAlignment - Return the alignment required by
|
||||||
|
@ -155,6 +155,9 @@ public:
|
|||||||
MachineModuleInfo &getMMI() const { return MMI; }
|
MachineModuleInfo &getMMI() const { return MMI; }
|
||||||
MCContext &getContext() const { return Ctx; }
|
MCContext &getContext() const { return Ctx; }
|
||||||
|
|
||||||
|
/// Return the DataLayout attached to the Module associated to this MF.
|
||||||
|
const DataLayout &getDataLayout() const;
|
||||||
|
|
||||||
/// getFunction - Return the LLVM function that this machine code represents
|
/// getFunction - Return the LLVM function that this machine code represents
|
||||||
///
|
///
|
||||||
const Function *getFunction() const { return Fn; }
|
const Function *getFunction() const { return Fn; }
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "llvm/IR/DataLayout.h"
|
#include "llvm/IR/DataLayout.h"
|
||||||
#include "llvm/IR/DebugInfo.h"
|
#include "llvm/IR/DebugInfo.h"
|
||||||
#include "llvm/IR/Function.h"
|
#include "llvm/IR/Function.h"
|
||||||
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/IR/ModuleSlotTracker.h"
|
#include "llvm/IR/ModuleSlotTracker.h"
|
||||||
#include "llvm/MC/MCAsmInfo.h"
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
#include "llvm/MC/MCContext.h"
|
#include "llvm/MC/MCContext.h"
|
||||||
@ -74,7 +75,7 @@ MachineFunction::MachineFunction(const Function *F, const TargetMachine &TM,
|
|||||||
if (Fn->hasFnAttribute(Attribute::StackAlignment))
|
if (Fn->hasFnAttribute(Attribute::StackAlignment))
|
||||||
FrameInfo->ensureMaxAlignment(Fn->getFnStackAlignment());
|
FrameInfo->ensureMaxAlignment(Fn->getFnStackAlignment());
|
||||||
|
|
||||||
ConstantPool = new (Allocator) MachineConstantPool(TM);
|
ConstantPool = new (Allocator) MachineConstantPool(getDataLayout());
|
||||||
Alignment = STI->getTargetLowering()->getMinFunctionAlignment();
|
Alignment = STI->getTargetLowering()->getMinFunctionAlignment();
|
||||||
|
|
||||||
// FIXME: Shouldn't use pref alignment if explicit alignment is set on Fn.
|
// FIXME: Shouldn't use pref alignment if explicit alignment is set on Fn.
|
||||||
@ -118,6 +119,10 @@ MachineFunction::~MachineFunction() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DataLayout &MachineFunction::getDataLayout() const {
|
||||||
|
return Fn->getParent()->getDataLayout();
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the JumpTableInfo for this function.
|
/// Get the JumpTableInfo for this function.
|
||||||
/// If it does not already exist, allocate one.
|
/// If it does not already exist, allocate one.
|
||||||
MachineJumpTableInfo *MachineFunction::
|
MachineJumpTableInfo *MachineFunction::
|
||||||
@ -458,12 +463,12 @@ unsigned MachineFunction::addLiveIn(unsigned PReg,
|
|||||||
/// normal 'L' label is returned.
|
/// normal 'L' label is returned.
|
||||||
MCSymbol *MachineFunction::getJTISymbol(unsigned JTI, MCContext &Ctx,
|
MCSymbol *MachineFunction::getJTISymbol(unsigned JTI, MCContext &Ctx,
|
||||||
bool isLinkerPrivate) const {
|
bool isLinkerPrivate) const {
|
||||||
const DataLayout *DL = getTarget().getDataLayout();
|
const DataLayout &DL = getDataLayout();
|
||||||
assert(JumpTableInfo && "No jump tables");
|
assert(JumpTableInfo && "No jump tables");
|
||||||
assert(JTI < JumpTableInfo->getJumpTables().size() && "Invalid JTI!");
|
assert(JTI < JumpTableInfo->getJumpTables().size() && "Invalid JTI!");
|
||||||
|
|
||||||
const char *Prefix = isLinkerPrivate ? DL->getLinkerPrivateGlobalPrefix() :
|
const char *Prefix = isLinkerPrivate ? DL.getLinkerPrivateGlobalPrefix()
|
||||||
DL->getPrivateGlobalPrefix();
|
: DL.getPrivateGlobalPrefix();
|
||||||
SmallString<60> Name;
|
SmallString<60> Name;
|
||||||
raw_svector_ostream(Name)
|
raw_svector_ostream(Name)
|
||||||
<< Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
|
<< Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
|
||||||
@ -472,9 +477,9 @@ MCSymbol *MachineFunction::getJTISymbol(unsigned JTI, MCContext &Ctx,
|
|||||||
|
|
||||||
/// Return a function-local symbol to represent the PIC base.
|
/// Return a function-local symbol to represent the PIC base.
|
||||||
MCSymbol *MachineFunction::getPICBaseSymbol() const {
|
MCSymbol *MachineFunction::getPICBaseSymbol() const {
|
||||||
const DataLayout *DL = getTarget().getDataLayout();
|
const DataLayout &DL = getDataLayout();
|
||||||
return Ctx.getOrCreateSymbol(Twine(DL->getPrivateGlobalPrefix())+
|
return Ctx.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
|
||||||
Twine(getFunctionNumber())+"$pb");
|
Twine(getFunctionNumber()) + "$pb");
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@ -790,10 +795,6 @@ void MachineJumpTableInfo::dump() const { print(dbgs()); }
|
|||||||
|
|
||||||
void MachineConstantPoolValue::anchor() { }
|
void MachineConstantPoolValue::anchor() { }
|
||||||
|
|
||||||
const DataLayout *MachineConstantPool::getDataLayout() const {
|
|
||||||
return TM.getDataLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
Type *MachineConstantPoolEntry::getType() const {
|
Type *MachineConstantPoolEntry::getType() const {
|
||||||
if (isMachineConstantPoolEntry())
|
if (isMachineConstantPoolEntry())
|
||||||
return Val.MachineCPVal->getType();
|
return Val.MachineCPVal->getType();
|
||||||
@ -851,7 +852,7 @@ MachineConstantPool::~MachineConstantPool() {
|
|||||||
/// Test whether the given two constants can be allocated the same constant pool
|
/// Test whether the given two constants can be allocated the same constant pool
|
||||||
/// entry.
|
/// entry.
|
||||||
static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B,
|
static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B,
|
||||||
const DataLayout *TD) {
|
const DataLayout &DL) {
|
||||||
// Handle the trivial case quickly.
|
// Handle the trivial case quickly.
|
||||||
if (A == B) return true;
|
if (A == B) return true;
|
||||||
|
|
||||||
@ -865,8 +866,8 @@ static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// For now, only support constants with the same size.
|
// For now, only support constants with the same size.
|
||||||
uint64_t StoreSize = TD->getTypeStoreSize(A->getType());
|
uint64_t StoreSize = DL.getTypeStoreSize(A->getType());
|
||||||
if (StoreSize != TD->getTypeStoreSize(B->getType()) || StoreSize > 128)
|
if (StoreSize != DL.getTypeStoreSize(B->getType()) || StoreSize > 128)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Type *IntTy = IntegerType::get(A->getContext(), StoreSize*8);
|
Type *IntTy = IntegerType::get(A->getContext(), StoreSize*8);
|
||||||
@ -877,16 +878,16 @@ static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B,
|
|||||||
// DataLayout.
|
// DataLayout.
|
||||||
if (isa<PointerType>(A->getType()))
|
if (isa<PointerType>(A->getType()))
|
||||||
A = ConstantFoldInstOperands(Instruction::PtrToInt, IntTy,
|
A = ConstantFoldInstOperands(Instruction::PtrToInt, IntTy,
|
||||||
const_cast<Constant *>(A), *TD);
|
const_cast<Constant *>(A), DL);
|
||||||
else if (A->getType() != IntTy)
|
else if (A->getType() != IntTy)
|
||||||
A = ConstantFoldInstOperands(Instruction::BitCast, IntTy,
|
A = ConstantFoldInstOperands(Instruction::BitCast, IntTy,
|
||||||
const_cast<Constant *>(A), *TD);
|
const_cast<Constant *>(A), DL);
|
||||||
if (isa<PointerType>(B->getType()))
|
if (isa<PointerType>(B->getType()))
|
||||||
B = ConstantFoldInstOperands(Instruction::PtrToInt, IntTy,
|
B = ConstantFoldInstOperands(Instruction::PtrToInt, IntTy,
|
||||||
const_cast<Constant *>(B), *TD);
|
const_cast<Constant *>(B), DL);
|
||||||
else if (B->getType() != IntTy)
|
else if (B->getType() != IntTy)
|
||||||
B = ConstantFoldInstOperands(Instruction::BitCast, IntTy,
|
B = ConstantFoldInstOperands(Instruction::BitCast, IntTy,
|
||||||
const_cast<Constant *>(B), *TD);
|
const_cast<Constant *>(B), DL);
|
||||||
|
|
||||||
return A == B;
|
return A == B;
|
||||||
}
|
}
|
||||||
@ -903,8 +904,7 @@ unsigned MachineConstantPool::getConstantPoolIndex(const Constant *C,
|
|||||||
// FIXME, this could be made much more efficient for large constant pools.
|
// FIXME, this could be made much more efficient for large constant pools.
|
||||||
for (unsigned i = 0, e = Constants.size(); i != e; ++i)
|
for (unsigned i = 0, e = Constants.size(); i != e; ++i)
|
||||||
if (!Constants[i].isMachineConstantPoolEntry() &&
|
if (!Constants[i].isMachineConstantPoolEntry() &&
|
||||||
CanShareConstantPoolEntry(Constants[i].Val.ConstVal, C,
|
CanShareConstantPoolEntry(Constants[i].Val.ConstVal, C, DL)) {
|
||||||
getDataLayout())) {
|
|
||||||
if ((unsigned)Constants[i].getAlignment() < Alignment)
|
if ((unsigned)Constants[i].getAlignment() < Alignment)
|
||||||
Constants[i].Alignment = Alignment;
|
Constants[i].Alignment = Alignment;
|
||||||
return i;
|
return i;
|
||||||
|
Loading…
Reference in New Issue
Block a user