mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-17 18:24:34 +00:00
Hoist the definition of getTypeSizeInBits to be inlinable and in the
header. This method is called in the hot path for *many* passes, SROA is what caught my interest. A common pattern is that which branch of the switch should be taken is known in the callsite and so it is a very good candidate for inlining and simplification. Moving it into the header allows the optimizer to fold a lot of boring, repeatitive code in callers of this routine. I'm seeing pretty significant speedups in parts of SROA and I suspect other passes will see similar speedups if they end up working with type sizes frequently. I've not seen any significant growth of the binaries as a consequence, but let me know if you see anything suspicious here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@177632 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseMap.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
|
#include "llvm/IR/DerivedTypes.h"
|
||||||
|
#include "llvm/IR/Type.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Support/DataTypes.h"
|
#include "llvm/Support/DataTypes.h"
|
||||||
|
|
||||||
@@ -423,6 +425,49 @@ private:
|
|||||||
StructLayout(StructType *ST, const DataLayout &TD);
|
StructLayout(StructType *ST, const DataLayout &TD);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// The implementation of this method is provided inline as it is particularly
|
||||||
|
// well suited to constant folding when called on a specific Type subclass.
|
||||||
|
inline uint64_t DataLayout::getTypeSizeInBits(Type *Ty) const {
|
||||||
|
assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
|
||||||
|
switch (Ty->getTypeID()) {
|
||||||
|
case Type::LabelTyID:
|
||||||
|
return getPointerSizeInBits(0);
|
||||||
|
case Type::PointerTyID:
|
||||||
|
return getPointerSizeInBits(cast<PointerType>(Ty)->getAddressSpace());
|
||||||
|
case Type::ArrayTyID: {
|
||||||
|
ArrayType *ATy = cast<ArrayType>(Ty);
|
||||||
|
return ATy->getNumElements() *
|
||||||
|
getTypeAllocSizeInBits(ATy->getElementType());
|
||||||
|
}
|
||||||
|
case Type::StructTyID:
|
||||||
|
// Get the layout annotation... which is lazily created on demand.
|
||||||
|
return getStructLayout(cast<StructType>(Ty))->getSizeInBits();
|
||||||
|
case Type::IntegerTyID:
|
||||||
|
return cast<IntegerType>(Ty)->getBitWidth();
|
||||||
|
case Type::HalfTyID:
|
||||||
|
return 16;
|
||||||
|
case Type::FloatTyID:
|
||||||
|
return 32;
|
||||||
|
case Type::DoubleTyID:
|
||||||
|
case Type::X86_MMXTyID:
|
||||||
|
return 64;
|
||||||
|
case Type::PPC_FP128TyID:
|
||||||
|
case Type::FP128TyID:
|
||||||
|
return 128;
|
||||||
|
// In memory objects this is always aligned to a higher boundary, but
|
||||||
|
// only 80 bits contain information.
|
||||||
|
case Type::X86_FP80TyID:
|
||||||
|
return 80;
|
||||||
|
case Type::VectorTyID: {
|
||||||
|
VectorType *VTy = cast<VectorType>(Ty);
|
||||||
|
return VTy->getNumElements() * getTypeSizeInBits(VTy->getElementType());
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
llvm_unreachable("DataLayout::getTypeSizeInBits(): Unsupported type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -510,47 +510,6 @@ std::string DataLayout::getStringRepresentation() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint64_t DataLayout::getTypeSizeInBits(Type *Ty) const {
|
|
||||||
assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
|
|
||||||
switch (Ty->getTypeID()) {
|
|
||||||
case Type::LabelTyID:
|
|
||||||
return getPointerSizeInBits(0);
|
|
||||||
case Type::PointerTyID: {
|
|
||||||
unsigned AS = dyn_cast<PointerType>(Ty)->getAddressSpace();
|
|
||||||
return getPointerSizeInBits(AS);
|
|
||||||
}
|
|
||||||
case Type::ArrayTyID: {
|
|
||||||
ArrayType *ATy = cast<ArrayType>(Ty);
|
|
||||||
return getTypeAllocSizeInBits(ATy->getElementType())*ATy->getNumElements();
|
|
||||||
}
|
|
||||||
case Type::StructTyID:
|
|
||||||
// Get the layout annotation... which is lazily created on demand.
|
|
||||||
return getStructLayout(cast<StructType>(Ty))->getSizeInBits();
|
|
||||||
case Type::IntegerTyID:
|
|
||||||
return cast<IntegerType>(Ty)->getBitWidth();
|
|
||||||
case Type::HalfTyID:
|
|
||||||
return 16;
|
|
||||||
case Type::FloatTyID:
|
|
||||||
return 32;
|
|
||||||
case Type::DoubleTyID:
|
|
||||||
case Type::X86_MMXTyID:
|
|
||||||
return 64;
|
|
||||||
case Type::PPC_FP128TyID:
|
|
||||||
case Type::FP128TyID:
|
|
||||||
return 128;
|
|
||||||
// In memory objects this is always aligned to a higher boundary, but
|
|
||||||
// only 80 bits contain information.
|
|
||||||
case Type::X86_FP80TyID:
|
|
||||||
return 80;
|
|
||||||
case Type::VectorTyID: {
|
|
||||||
VectorType *VTy = cast<VectorType>(Ty);
|
|
||||||
return VTy->getNumElements()*getTypeSizeInBits(VTy->getElementType());
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
llvm_unreachable("DataLayout::getTypeSizeInBits(): Unsupported type");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\param abi_or_pref Flag that determines which alignment is returned. true
|
\param abi_or_pref Flag that determines which alignment is returned. true
|
||||||
returns the ABI alignment, false returns the preferred alignment.
|
returns the ABI alignment, false returns the preferred alignment.
|
||||||
|
Reference in New Issue
Block a user