| OLD | NEW |
| 1 //===- BitcodeReader.h - Internal BitcodeReader impl ------------*- C++ -*-===// | 1 //===- BitcodeReader.h - Internal BitcodeReader impl ------------*- C++ -*-===// |
| 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 header defines the BitcodeReader class. | 10 // This header defines the BitcodeReader class. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 Value *getValueFwdRef(unsigned Idx); | 120 Value *getValueFwdRef(unsigned Idx); |
| 121 void AssignValue(Value *V, unsigned Idx); | 121 void AssignValue(Value *V, unsigned Idx); |
| 122 }; | 122 }; |
| 123 | 123 |
| 124 class BitcodeReader : public GVMaterializer { | 124 class BitcodeReader : public GVMaterializer { |
| 125 LLVMContext &Context; | 125 LLVMContext &Context; |
| 126 Module *TheModule; | 126 Module *TheModule; |
| 127 MemoryBuffer *Buffer; | 127 MemoryBuffer *Buffer; |
| 128 bool BufferOwned; | 128 bool BufferOwned; |
| 129 BitstreamReader StreamFile; | 129 OwningPtr<BitstreamReader> StreamFile; |
| 130 BitstreamCursor Stream; | 130 BitstreamCursor Stream; |
| 131 BitcodeStreamer *LazyStreamer; |
| 132 uint64_t NextUnreadBit; |
| 131 | 133 |
| 132 const char *ErrorString; | 134 const char *ErrorString; |
| 133 | 135 |
| 134 std::vector<Type*> TypeList; | 136 std::vector<Type*> TypeList; |
| 135 BitcodeReaderValueList ValueList; | 137 BitcodeReaderValueList ValueList; |
| 136 BitcodeReaderMDValueList MDValueList; | 138 BitcodeReaderMDValueList MDValueList; |
| 137 SmallVector<Instruction *, 64> InstructionList; | 139 SmallVector<Instruction *, 64> InstructionList; |
| 138 | 140 |
| 139 std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInits; | 141 std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInits; |
| 140 std::vector<std::pair<GlobalAlias*, unsigned> > AliasInits; | 142 std::vector<std::pair<GlobalAlias*, unsigned> > AliasInits; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 153 std::vector<Function*> FunctionsWithBodies; | 155 std::vector<Function*> FunctionsWithBodies; |
| 154 | 156 |
| 155 // When intrinsic functions are encountered which require upgrading they are | 157 // When intrinsic functions are encountered which require upgrading they are |
| 156 // stored here with their replacement function. | 158 // stored here with their replacement function. |
| 157 typedef std::vector<std::pair<Function*, Function*> > UpgradedIntrinsicMap; | 159 typedef std::vector<std::pair<Function*, Function*> > UpgradedIntrinsicMap; |
| 158 UpgradedIntrinsicMap UpgradedIntrinsics; | 160 UpgradedIntrinsicMap UpgradedIntrinsics; |
| 159 | 161 |
| 160 // Map the bitcode's custom MDKind ID to the Module's MDKind ID. | 162 // Map the bitcode's custom MDKind ID to the Module's MDKind ID. |
| 161 DenseMap<unsigned, unsigned> MDKindMap; | 163 DenseMap<unsigned, unsigned> MDKindMap; |
| 162 | 164 |
| 163 // After the module header has been read, the FunctionsWithBodies list is | 165 // Several operations happen after the module header has been read, but |
| 164 // reversed. This keeps track of whether we've done this yet. | 166 // before function bodies are processed. This keeps track of whether |
| 165 bool HasReversedFunctionsWithBodies; | 167 // we've done this yet. |
| 168 bool SeenFirstFunctionBody; |
| 166 | 169 |
| 167 /// DeferredFunctionInfo - When function bodies are initially scanned, this | 170 /// DeferredFunctionInfo - When function bodies are initially scanned, this |
| 168 /// map contains info about where to find deferred function body in the | 171 /// map contains info about where to find deferred function body in the |
| 169 /// stream. | 172 /// stream. |
| 170 DenseMap<Function*, uint64_t> DeferredFunctionInfo; | 173 DenseMap<Function*, uint64_t> DeferredFunctionInfo; |
| 171 | 174 |
| 172 /// BlockAddrFwdRefs - These are blockaddr references to basic blocks. These | 175 /// BlockAddrFwdRefs - These are blockaddr references to basic blocks. These |
| 173 /// are resolved lazily when functions are loaded. | 176 /// are resolved lazily when functions are loaded. |
| 174 typedef std::pair<unsigned, GlobalVariable*> BlockAddrRefTy; | 177 typedef std::pair<unsigned, GlobalVariable*> BlockAddrRefTy; |
| 175 DenseMap<Function*, std::vector<BlockAddrRefTy> > BlockAddrFwdRefs; | 178 DenseMap<Function*, std::vector<BlockAddrRefTy> > BlockAddrFwdRefs; |
| 176 | 179 |
| 177 public: | 180 public: |
| 178 explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C) | 181 explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C) |
| 179 : Context(C), TheModule(0), Buffer(buffer), BufferOwned(false), | 182 : Context(C), TheModule(0), Buffer(buffer), BufferOwned(false), |
| 180 ErrorString(0), ValueList(C), MDValueList(C) { | 183 LazyStreamer(0), ErrorString(0), ValueList(C), MDValueList(C), |
| 181 HasReversedFunctionsWithBodies = false; | 184 SeenFirstFunctionBody(false) { |
| 185 } |
| 186 explicit BitcodeReader(BitcodeStreamer *streamer, LLVMContext &C) |
| 187 : Context(C), TheModule(0), Buffer(0), BufferOwned(false), |
| 188 LazyStreamer(streamer), ErrorString(0), ValueList(C), MDValueList(C), |
| 189 SeenFirstFunctionBody(false) { |
| 182 } | 190 } |
| 183 ~BitcodeReader() { | 191 ~BitcodeReader() { |
| 184 FreeState(); | 192 FreeState(); |
| 185 } | 193 } |
| 186 | 194 |
| 187 void FreeState(); | 195 void FreeState(); |
| 188 | 196 |
| 189 /// setBufferOwned - If this is true, the reader will destroy the MemoryBuffer | 197 /// setBufferOwned - If this is true, the reader will destroy the MemoryBuffer |
| 190 /// when the reader is destroyed. | 198 /// when the reader is destroyed. |
| 191 void setBufferOwned(bool Owned) { BufferOwned = Owned; } | 199 void setBufferOwned(bool Owned) { BufferOwned = Owned; } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 } | 256 } |
| 249 bool getValue(SmallVector<uint64_t, 64> &Record, unsigned &Slot, | 257 bool getValue(SmallVector<uint64_t, 64> &Record, unsigned &Slot, |
| 250 Type *Ty, Value *&ResVal) { | 258 Type *Ty, Value *&ResVal) { |
| 251 if (Slot == Record.size()) return true; | 259 if (Slot == Record.size()) return true; |
| 252 unsigned ValNo = (unsigned)Record[Slot++]; | 260 unsigned ValNo = (unsigned)Record[Slot++]; |
| 253 ResVal = getFnValueByID(ValNo, Ty); | 261 ResVal = getFnValueByID(ValNo, Ty); |
| 254 return ResVal == 0; | 262 return ResVal == 0; |
| 255 } | 263 } |
| 256 | 264 |
| 257 | 265 |
| 258 bool ParseModule(); | 266 bool ParseModule(bool Resume); |
| 259 bool ParseAttributeBlock(); | 267 bool ParseAttributeBlock(); |
| 260 bool ParseTypeTable(); | 268 bool ParseTypeTable(); |
| 261 bool ParseTypeTableBody(); | 269 bool ParseTypeTableBody(); |
| 262 | 270 |
| 263 bool ParseValueSymbolTable(); | 271 bool ParseValueSymbolTable(); |
| 264 bool ParseConstants(); | 272 bool ParseConstants(); |
| 265 bool RememberAndSkipFunctionBody(); | 273 bool RememberAndSkipFunctionBody(); |
| 266 bool ParseFunctionBody(Function *F); | 274 bool ParseFunctionBody(Function *F); |
| 275 bool GlobalCleanup(); |
| 267 bool ResolveGlobalAndAliasInits(); | 276 bool ResolveGlobalAndAliasInits(); |
| 268 bool ParseMetadata(); | 277 bool ParseMetadata(); |
| 269 bool ParseMetadataAttachment(); | 278 bool ParseMetadataAttachment(); |
| 270 bool ParseModuleTriple(std::string &Triple); | 279 bool ParseModuleTriple(std::string &Triple); |
| 280 bool InitStream(); |
| 281 bool InitStreamFromBuffer(); |
| 282 bool InitLazyStream(); |
| 283 bool SuspendModuleParse(); |
| 284 bool FindFunctionInStream(Function *F, |
| 285 DenseMap<Function*, uint64_t>::iterator DeferredFunctionInfoIterator); |
| 271 }; | 286 }; |
| 272 | 287 |
| 273 } // End llvm namespace | 288 } // End llvm namespace |
| 274 | 289 |
| 275 #endif | 290 #endif |
| OLD | NEW |