diff options
author | Chris Lattner <sabre@nondot.org> | 2004-02-15 05:55:15 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-02-15 05:55:15 +0000 |
commit | de512b5b2edebe9c9021a92c7c7a9ae9fbc380d6 (patch) | |
tree | 4da44078e014b4c44afa0a73fd0f57c26a748553 /lib/Transforms/Utils | |
parent | cfb0fd2ce8a1a7d5ac83d5bf42742219179ffa03 (diff) |
Adjustments to support the new ConstantAggregateZero class
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11474 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils')
-rw-r--r-- | lib/Transforms/Utils/Linker.cpp | 27 | ||||
-rw-r--r-- | lib/Transforms/Utils/ValueMapper.cpp | 2 |
2 files changed, 21 insertions, 8 deletions
diff --git a/lib/Transforms/Utils/Linker.cpp b/lib/Transforms/Utils/Linker.cpp index 457a8b97b6..aa7720ece3 100644 --- a/lib/Transforms/Utils/Linker.cpp +++ b/lib/Transforms/Utils/Linker.cpp @@ -284,7 +284,8 @@ static Value *RemapOperand(const Value *In, // Check to see if it's a constant that we are interesting in transforming... if (const Constant *CPV = dyn_cast<Constant>(In)) { - if (!isa<DerivedType>(CPV->getType()) && !isa<ConstantExpr>(CPV)) + if ((!isa<DerivedType>(CPV->getType()) && !isa<ConstantExpr>(CPV)) || + isa<ConstantAggregateZero>(CPV)) return const_cast<Constant*>(CPV); // Simple constants stay identical... Constant *Result = 0; @@ -796,12 +797,24 @@ static bool LinkAppendingVars(Module *M, // Merge the initializer... Inits.reserve(NewSize); - ConstantArray *I = cast<ConstantArray>(G1->getInitializer()); - for (unsigned i = 0, e = T1->getNumElements(); i != e; ++i) - Inits.push_back(cast<Constant>(I->getValues()[i])); - I = cast<ConstantArray>(G2->getInitializer()); - for (unsigned i = 0, e = T2->getNumElements(); i != e; ++i) - Inits.push_back(cast<Constant>(I->getValues()[i])); + if (ConstantArray *I = dyn_cast<ConstantArray>(G1->getInitializer())) { + for (unsigned i = 0, e = T1->getNumElements(); i != e; ++i) + Inits.push_back(cast<Constant>(I->getValues()[i])); + } else { + assert(isa<ConstantAggregateZero>(G1->getInitializer())); + Constant *CV = Constant::getNullValue(T1->getElementType()); + for (unsigned i = 0, e = T1->getNumElements(); i != e; ++i) + Inits.push_back(CV); + } + if (ConstantArray *I = dyn_cast<ConstantArray>(G2->getInitializer())) { + for (unsigned i = 0, e = T2->getNumElements(); i != e; ++i) + Inits.push_back(cast<Constant>(I->getValues()[i])); + } else { + assert(isa<ConstantAggregateZero>(G2->getInitializer())); + Constant *CV = Constant::getNullValue(T2->getElementType()); + for (unsigned i = 0, e = T2->getNumElements(); i != e; ++i) + Inits.push_back(CV); + } NG->setInitializer(ConstantArray::get(NewType, Inits)); Inits.clear(); diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp index acc433a6ed..2cb6a9d221 100644 --- a/lib/Transforms/Utils/ValueMapper.cpp +++ b/lib/Transforms/Utils/ValueMapper.cpp @@ -28,7 +28,7 @@ Value *llvm::MapValue(const Value *V, std::map<const Value*, Value*> &VM) { if (Constant *C = const_cast<Constant*>(dyn_cast<Constant>(V))) { if (isa<ConstantIntegral>(C) || isa<ConstantFP>(C) || - isa<ConstantPointerNull>(C)) + isa<ConstantPointerNull>(C) || isa<ConstantAggregateZero>(C)) return VMSlot = C; // Primitive constants map directly else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C)) { GlobalValue *MV = cast<GlobalValue>(MapValue((Value*)CPR->getValue(),VM)); |