| OLD | NEW |
| 1 //===- FlattenGlobals.cpp - Flatten global variable initializers-----------===// | 1 //===- FlattenGlobals.cpp - Flatten global variable initializers-----------===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This pass converts initializers for global variables into a | 10 // This pass converts initializers for global variables into a |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 APInt Data = CF->getValueAPF().bitcastToAPInt(); | 171 APInt Data = CF->getValueAPF().bitcastToAPInt(); |
| 172 assert((Data.getBitWidth() + 7) / 8 == ValSize); | 172 assert((Data.getBitWidth() + 7) / 8 == ValSize); |
| 173 assert(Data.getBitWidth() % 8 == 0); | 173 assert(Data.getBitWidth() % 8 == 0); |
| 174 memcpy(Dest, Data.getRawData(), ValSize); | 174 memcpy(Dest, Data.getRawData(), ValSize); |
| 175 } else if (ConstantDataSequential *CD = | 175 } else if (ConstantDataSequential *CD = |
| 176 dyn_cast<ConstantDataSequential>(Val)) { | 176 dyn_cast<ConstantDataSequential>(Val)) { |
| 177 // Note that getRawDataValues() assumes the host endianness is the same. | 177 // Note that getRawDataValues() assumes the host endianness is the same. |
| 178 StringRef Data = CD->getRawDataValues(); | 178 StringRef Data = CD->getRawDataValues(); |
| 179 assert(Data.size() == ValSize); | 179 assert(Data.size() == ValSize); |
| 180 memcpy(Dest, Data.data(), Data.size()); | 180 memcpy(Dest, Data.data(), Data.size()); |
| 181 } else if (isa<ConstantArray>(Val) || isa<ConstantVector>(Val)) { | 181 } else if (isa<ConstantArray>(Val) || isa<ConstantDataVector>(Val) || |
| 182 isa<ConstantVector>(Val)) { |
| 182 uint64_t ElementSize = DL->getTypeAllocSize( | 183 uint64_t ElementSize = DL->getTypeAllocSize( |
| 183 Val->getType()->getSequentialElementType()); | 184 Val->getType()->getSequentialElementType()); |
| 184 for (unsigned I = 0; I < Val->getNumOperands(); ++I) { | 185 for (unsigned I = 0; I < Val->getNumOperands(); ++I) { |
| 185 putAtDest(DL, cast<Constant>(Val->getOperand(I)), Dest + ElementSize * I); | 186 putAtDest(DL, cast<Constant>(Val->getOperand(I)), Dest + ElementSize * I); |
| 186 } | 187 } |
| 187 } else if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Val)) { | 188 } else if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Val)) { |
| 188 const StructLayout *Layout = DL->getStructLayout(CS->getType()); | 189 const StructLayout *Layout = DL->getStructLayout(CS->getType()); |
| 189 for (unsigned I = 0; I < CS->getNumOperands(); ++I) { | 190 for (unsigned I = 0; I < CS->getNumOperands(); ++I) { |
| 190 putAtDest(DL, CS->getOperand(I), Dest + Layout->getElementOffset(I)); | 191 putAtDest(DL, CS->getOperand(I), Dest + Layout->getElementOffset(I)); |
| 191 } | 192 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 ConstantExpr::getBitCast(NewGlobal, Global->getType())); | 293 ConstantExpr::getBitCast(NewGlobal, Global->getType())); |
| 293 Global->eraseFromParent(); | 294 Global->eraseFromParent(); |
| 294 } | 295 } |
| 295 return Modified; | 296 return Modified; |
| 296 | 297 |
| 297 } | 298 } |
| 298 | 299 |
| 299 ModulePass *llvm::createFlattenGlobalsPass() { | 300 ModulePass *llvm::createFlattenGlobalsPass() { |
| 300 return new FlattenGlobals(); | 301 return new FlattenGlobals(); |
| 301 } | 302 } |
| OLD | NEW |