| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 *ResultOffset = 0; | 129 *ResultOffset = 0; |
| 130 } else if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) { | 130 } else if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) { |
| 131 *ResultGlobal = NULL; | 131 *ResultGlobal = NULL; |
| 132 *ResultOffset = CI->getZExtValue(); | 132 *ResultOffset = CI->getZExtValue(); |
| 133 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Val)) { | 133 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Val)) { |
| 134 ExpandConstant(DL, CE->getOperand(0), ResultGlobal, ResultOffset); | 134 ExpandConstant(DL, CE->getOperand(0), ResultGlobal, ResultOffset); |
| 135 if (CE->getOpcode() == Instruction::GetElementPtr) { | 135 if (CE->getOpcode() == Instruction::GetElementPtr) { |
| 136 SmallVector<Value *, 8> Indexes(CE->op_begin() + 1, CE->op_end()); | 136 SmallVector<Value *, 8> Indexes(CE->op_begin() + 1, CE->op_end()); |
| 137 *ResultOffset += DL->getIndexedOffset(CE->getOperand(0)->getType(), | 137 *ResultOffset += DL->getIndexedOffset(CE->getOperand(0)->getType(), |
| 138 Indexes); | 138 Indexes); |
| 139 } else if (CE->getOpcode() == Instruction::Add && |
| 140 isa<ConstantInt>(CE->getOperand(1))) { |
| 141 *ResultOffset += cast<ConstantInt>(CE->getOperand(1))->getZExtValue(); |
| 139 } else if (CE->getOpcode() == Instruction::BitCast || | 142 } else if (CE->getOpcode() == Instruction::BitCast || |
| 140 CE->getOpcode() == Instruction::IntToPtr) { | 143 CE->getOpcode() == Instruction::IntToPtr) { |
| 141 // Nothing more to do. | 144 // Nothing more to do. |
| 142 } else if (CE->getOpcode() == Instruction::PtrToInt) { | 145 } else if (CE->getOpcode() == Instruction::PtrToInt) { |
| 143 if (Val->getType()->getIntegerBitWidth() < DL->getPointerSizeInBits()) { | 146 if (Val->getType()->getIntegerBitWidth() < DL->getPointerSizeInBits()) { |
| 144 errs() << "Not handled: " << *CE << "\n"; | 147 errs() << "Not handled: " << *CE << "\n"; |
| 145 report_fatal_error("FlattenGlobals: a ptrtoint that truncates " | 148 report_fatal_error("FlattenGlobals: a ptrtoint that truncates " |
| 146 "a pointer is not allowed"); | 149 "a pointer is not allowed"); |
| 147 } | 150 } |
| 148 } else { | 151 } else { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 ConstantExpr::getBitCast(NewGlobal, Global->getType())); | 296 ConstantExpr::getBitCast(NewGlobal, Global->getType())); |
| 294 Global->eraseFromParent(); | 297 Global->eraseFromParent(); |
| 295 } | 298 } |
| 296 return Modified; | 299 return Modified; |
| 297 | 300 |
| 298 } | 301 } |
| 299 | 302 |
| 300 ModulePass *llvm::createFlattenGlobalsPass() { | 303 ModulePass *llvm::createFlattenGlobalsPass() { |
| 301 return new FlattenGlobals(); | 304 return new FlattenGlobals(); |
| 302 } | 305 } |
| OLD | NEW |