summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
diff options
context:
space:
mode:
authorAlina Sbirlea <asbirlea@google.com>2018-03-09 18:48:20 +0000
committerAlina Sbirlea <asbirlea@google.com>2018-03-09 18:48:20 +0000
commit08fa594298452d32ed539a01c6bff1f9d9a72615 (patch)
treed1675b1375c2d6cfbdb6343e5a491b2d781f9fc1 /llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
parent47b4d6ba196d09900284caff7ed372b3878f28ef (diff)
downloadbcm5719-llvm-08fa594298452d32ed539a01c6bff1f9d9a72615.tar.gz
bcm5719-llvm-08fa594298452d32ed539a01c6bff1f9d9a72615.zip
Avoid creating a Constant for each value in a ConstantDataSequential.
Summary: We create a ConstantDataSequential (ConstantDataArray or ConstantDataVector) to avoid creating a Constant for each element in an array of constants. But them in AsmPrinter, we do create a ConstantFP for each element in the ConstantDataSequential. This triggers excessive memory use when generating large global FP constants. Reviewers: bogner, lhames, t.p.northover Subscribers: jlebar, sanjoy, llvm-commits Differential Revision: https://reviews.llvm.org/D44277 llvm-svn: 327161
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 61389037d5d..568d99269aa 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2127,6 +2127,7 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *C,
uint64_t Offset = 0);
static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP);
+static void emitGlobalConstantFP(APFloat APF, Type *ET, AsmPrinter &AP);
/// isRepeatedByteSequence - Determine whether the given value is
/// composed of a repeated sequence of identical bytes and return the
@@ -2204,8 +2205,9 @@ static void emitGlobalConstantDataSequential(const DataLayout &DL,
ElementByteSize);
}
} else {
+ Type *ET = CDS->getElementType();
for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I)
- emitGlobalConstantFP(cast<ConstantFP>(CDS->getElementAsConstant(I)), AP);
+ emitGlobalConstantFP(CDS->getElementAsAPFloat(I), ET, AP);
}
unsigned Size = DL.getTypeAllocSize(CDS->getType());
@@ -2274,17 +2276,17 @@ static void emitGlobalConstantStruct(const DataLayout &DL,
"Layout of constant struct may be incorrect!");
}
-static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP) {
- APInt API = CFP->getValueAPF().bitcastToAPInt();
+static void emitGlobalConstantFP(APFloat APF, Type *ET, AsmPrinter &AP) {
+ APInt API = APF.bitcastToAPInt();
// First print a comment with what we think the original floating-point value
// should have been.
if (AP.isVerbose()) {
SmallString<8> StrVal;
- CFP->getValueAPF().toString(StrVal);
+ APF.toString(StrVal);
- if (CFP->getType())
- CFP->getType()->print(AP.OutStreamer->GetCommentOS());
+ if (ET)
+ ET->print(AP.OutStreamer->GetCommentOS());
else
AP.OutStreamer->GetCommentOS() << "Printing <null> Type";
AP.OutStreamer->GetCommentOS() << ' ' << StrVal << '\n';
@@ -2299,7 +2301,7 @@ static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP) {
// PPC's long double has odd notions of endianness compared to how LLVM
// handles it: p[0] goes first for *big* endian on PPC.
- if (AP.getDataLayout().isBigEndian() && !CFP->getType()->isPPC_FP128Ty()) {
+ if (AP.getDataLayout().isBigEndian() && !ET->isPPC_FP128Ty()) {
int Chunk = API.getNumWords() - 1;
if (TrailingBytes)
@@ -2318,8 +2320,11 @@ static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP) {
// Emit the tail padding for the long double.
const DataLayout &DL = AP.getDataLayout();
- AP.OutStreamer->EmitZeros(DL.getTypeAllocSize(CFP->getType()) -
- DL.getTypeStoreSize(CFP->getType()));
+ AP.OutStreamer->EmitZeros(DL.getTypeAllocSize(ET) - DL.getTypeStoreSize(ET));
+}
+
+static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP) {
+ emitGlobalConstantFP(CFP->getValueAPF(), CFP->getType(), AP);
}
static void emitGlobalConstantLargeInt(const ConstantInt *CI, AsmPrinter &AP) {
OpenPOWER on IntegriCloud