Begin the painful process of tearing apart the rat'ss nest that is Constants.cpp and ConstantFold.cpp.
This involves temporarily hard wiring some parts to use the global context. This isn't ideal, but it's
the only way I could figure out to make this process vaguely incremental.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75445 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp
index f922146..a403f2e 100644
--- a/lib/Target/CBackend/CBackend.cpp
+++ b/lib/Target/CBackend/CBackend.cpp
@@ -1239,7 +1239,7 @@
Out << '{';
if (AT->getNumElements()) {
Out << ' ';
- Constant *CZ = Constant::getNullValue(AT->getElementType());
+ Constant *CZ = Context->getNullValue(AT->getElementType());
printConstant(CZ, Static);
for (unsigned i = 1, e = AT->getNumElements(); i != e; ++i) {
Out << ", ";
@@ -1264,7 +1264,7 @@
assert(isa<ConstantAggregateZero>(CPV) || isa<UndefValue>(CPV));
const VectorType *VT = cast<VectorType>(CPV->getType());
Out << "{ ";
- Constant *CZ = Constant::getNullValue(VT->getElementType());
+ Constant *CZ = Context->getNullValue(VT->getElementType());
printConstant(CZ, Static);
for (unsigned i = 1, e = VT->getNumElements(); i != e; ++i) {
Out << ", ";
@@ -1286,10 +1286,10 @@
Out << '{';
if (ST->getNumElements()) {
Out << ' ';
- printConstant(Constant::getNullValue(ST->getElementType(0)), Static);
+ printConstant(Context->getNullValue(ST->getElementType(0)), Static);
for (unsigned i = 1, e = ST->getNumElements(); i != e; ++i) {
Out << ", ";
- printConstant(Constant::getNullValue(ST->getElementType(i)), Static);
+ printConstant(Context->getNullValue(ST->getElementType(i)), Static);
}
}
Out << " }";
@@ -2621,11 +2621,11 @@
// If this is a negation operation, print it out as such. For FP, we don't
// want to print "-0.0 - X".
- if (BinaryOperator::isNeg(&I)) {
+ if (BinaryOperator::isNeg(*Context, &I)) {
Out << "-(";
writeOperand(BinaryOperator::getNegArgument(cast<BinaryOperator>(&I)));
Out << ")";
- } else if (BinaryOperator::isFNeg(&I)) {
+ } else if (BinaryOperator::isFNeg(*Context, &I)) {
Out << "-(";
writeOperand(BinaryOperator::getFNegArgument(cast<BinaryOperator>(&I)));
Out << ")";
diff --git a/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp b/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp
index 17c7640..89e9426 100644
--- a/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp
+++ b/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp
@@ -541,7 +541,7 @@
// Fall Through
case GlobalValue::PrivateLinkage:
case GlobalValue::InternalLinkage:
- if (CVA && CVA->isCString())
+ if (CVA && CVA->isCString(GVar->getParent()->getContext()))
printSizeAndType = false;
break;
case GlobalValue::GhostLinkage:
diff --git a/lib/Target/Mips/MipsISelLowering.cpp b/lib/Target/Mips/MipsISelLowering.cpp
index f3fa179..3727918 100644
--- a/lib/Target/Mips/MipsISelLowering.cpp
+++ b/lib/Target/Mips/MipsISelLowering.cpp
@@ -227,7 +227,7 @@
if (GVA->hasInitializer() && GV->hasLocalLinkage()) {
Constant *C = GVA->getInitializer();
const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
- if (CVA && CVA->isCString())
+ if (CVA && CVA->isCString(GV->getParent()->getContext()))
return false;
}
diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp
index 782e7b4..4fbe1ae 100644
--- a/lib/Target/TargetAsmInfo.cpp
+++ b/lib/Target/TargetAsmInfo.cpp
@@ -170,11 +170,11 @@
return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS);
}
-static bool isConstantString(const Constant *C) {
+static bool isConstantString(LLVMContext &Context, const Constant *C) {
// First check: is we have constant array of i8 terminated with zero
const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
// Check, if initializer is a null-terminated string
- if (CVA && CVA->isCString())
+ if (CVA && CVA->isCString(Context))
return true;
// Another possibility: [1 x i8] zeroinitializer
@@ -229,7 +229,7 @@
}
} else {
// Check, if initializer is a null-terminated string
- if (isConstantString(C))
+ if (isConstantString(GV->getParent()->getContext(), C))
return SectionKind::RODataMergeStr;
else
return SectionKind::RODataMergeConst;
diff --git a/lib/Target/X86/X86FastISel.cpp b/lib/Target/X86/X86FastISel.cpp
index feb3d4c..2b3304d 100644
--- a/lib/Target/X86/X86FastISel.cpp
+++ b/lib/Target/X86/X86FastISel.cpp
@@ -272,7 +272,7 @@
const X86AddressMode &AM) {
// Handle 'null' like i32/i64 0.
if (isa<ConstantPointerNull>(Val))
- Val = Constant::getNullValue(TD.getIntPtrType());
+ Val = Context->getNullValue(TD.getIntPtrType());
// If this is a store of a simple constant, fold the constant into the store.
if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) {
@@ -672,7 +672,7 @@
// Handle 'null' like i32/i64 0.
if (isa<ConstantPointerNull>(Op1))
- Op1 = Constant::getNullValue(TD.getIntPtrType());
+ Op1 = Context->getNullValue(TD.getIntPtrType());
// We have two options: compare with register or immediate. If the RHS of
// the compare is an immediate that we can fold into this compare, use
diff --git a/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp
index 572b71d..cb98c05 100644
--- a/lib/Target/X86/X86InstrInfo.cpp
+++ b/lib/Target/X86/X86InstrInfo.cpp
@@ -20,6 +20,7 @@
#include "X86TargetMachine.h"
#include "llvm/GlobalVariable.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/LLVMContext.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
@@ -2312,7 +2313,7 @@
MachineConstantPool &MCP = *MF.getConstantPool();
const VectorType *Ty = VectorType::get(Type::Int32Ty, 4);
Constant *C = LoadMI->getOpcode() == X86::V_SET0 ?
- ConstantVector::getNullValue(Ty) :
+ MF.getFunction()->getContext()->getNullValue(Ty) :
ConstantVector::getAllOnesValue(Ty);
unsigned CPI = MCP.getConstantPoolIndex(C, 16);