blob: e831ea59231aab843136dd9515b93f150ac6fe9e [file] [log] [blame]
Chris Lattner1314b992007-04-22 06:23:29 +00001//===- BitcodeReader.h - Internal BitcodeReader impl ------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner1314b992007-04-22 06:23:29 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This header defines the BitcodeReader class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef BITCODE_READER_H
15#define BITCODE_READER_H
16
Chandler Carruth802d7552012-12-04 07:12:27 +000017#include "llvm/ADT/DenseMap.h"
Chris Lattner51ffe7c2007-05-01 04:59:48 +000018#include "llvm/Bitcode/BitstreamReader.h"
Chris Lattner362b4a12007-04-23 01:01:37 +000019#include "llvm/Bitcode/LLVMBitCodes.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000020#include "llvm/IR/Attributes.h"
Chandler Carruthd1163aa2014-03-06 03:50:29 +000021#include "llvm/IR/GVMaterializer.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000022#include "llvm/IR/OperandTraits.h"
23#include "llvm/IR/Type.h"
Chandler Carruth4220e9c2014-03-04 11:17:44 +000024#include "llvm/IR/ValueHandle.h"
Rafael Espindolaa6e9c3e2014-06-12 17:38:55 +000025#include <system_error>
Chris Lattner1314b992007-04-22 06:23:29 +000026#include <vector>
27
28namespace llvm {
David Majnemerdad0a642014-06-27 18:19:56 +000029 class Comdat;
Chris Lattner6694f602007-04-29 07:54:31 +000030 class MemoryBuffer;
Benjamin Kramer78c3bcb2009-08-11 17:45:13 +000031 class LLVMContext;
Joe Abbey2ad8df22012-11-25 15:23:39 +000032
Gabor Greiff6caff662008-05-10 08:32:32 +000033//===----------------------------------------------------------------------===//
34// BitcodeReaderValueList Class
35//===----------------------------------------------------------------------===//
36
Benjamin Kramer079b96e2013-09-11 18:05:11 +000037class BitcodeReaderValueList {
Chris Lattner2d8cd802009-03-31 22:55:09 +000038 std::vector<WeakVH> ValuePtrs;
Joe Abbey2ad8df22012-11-25 15:23:39 +000039
Chris Lattner74429932008-08-21 02:34:16 +000040 /// ResolveConstants - As we resolve forward-referenced constants, we add
41 /// information about them to this vector. This allows us to resolve them in
42 /// bulk instead of resolving each reference at a time. See the code in
43 /// ResolveConstantForwardRefs for more information about this.
44 ///
45 /// The key of this vector is the placeholder constant, the value is the slot
46 /// number that holds the resolved value.
47 typedef std::vector<std::pair<Constant*, unsigned> > ResolveConstantsTy;
48 ResolveConstantsTy ResolveConstants;
Chris Lattnercdfcc2d2011-07-07 05:12:37 +000049 LLVMContext &Context;
Chris Lattner1663cca2007-04-24 05:48:56 +000050public:
Chris Lattnercdfcc2d2011-07-07 05:12:37 +000051 BitcodeReaderValueList(LLVMContext &C) : Context(C) {}
Chris Lattner74429932008-08-21 02:34:16 +000052 ~BitcodeReaderValueList() {
53 assert(ResolveConstants.empty() && "Constants not resolved?");
54 }
Gabor Greiff6caff662008-05-10 08:32:32 +000055
Chris Lattner1663cca2007-04-24 05:48:56 +000056 // vector compatibility methods
Chris Lattner2d8cd802009-03-31 22:55:09 +000057 unsigned size() const { return ValuePtrs.size(); }
58 void resize(unsigned N) { ValuePtrs.resize(N); }
Chris Lattner1663cca2007-04-24 05:48:56 +000059 void push_back(Value *V) {
Chris Lattner2d8cd802009-03-31 22:55:09 +000060 ValuePtrs.push_back(V);
Chris Lattner1663cca2007-04-24 05:48:56 +000061 }
Joe Abbey2ad8df22012-11-25 15:23:39 +000062
Chris Lattner9eeada92007-05-18 04:02:46 +000063 void clear() {
Chris Lattner74429932008-08-21 02:34:16 +000064 assert(ResolveConstants.empty() && "Constants not resolved?");
Chris Lattner2d8cd802009-03-31 22:55:09 +000065 ValuePtrs.clear();
Chris Lattner9eeada92007-05-18 04:02:46 +000066 }
Joe Abbey2ad8df22012-11-25 15:23:39 +000067
Chris Lattner2d8cd802009-03-31 22:55:09 +000068 Value *operator[](unsigned i) const {
69 assert(i < ValuePtrs.size());
70 return ValuePtrs[i];
71 }
Joe Abbey2ad8df22012-11-25 15:23:39 +000072
Chris Lattner2d8cd802009-03-31 22:55:09 +000073 Value *back() const { return ValuePtrs.back(); }
74 void pop_back() { ValuePtrs.pop_back(); }
75 bool empty() const { return ValuePtrs.empty(); }
Chris Lattner831d4202007-04-26 03:27:58 +000076 void shrinkTo(unsigned N) {
Chris Lattner2d8cd802009-03-31 22:55:09 +000077 assert(N <= size() && "Invalid shrinkTo request!");
78 ValuePtrs.resize(N);
Chris Lattner831d4202007-04-26 03:27:58 +000079 }
Joe Abbey2ad8df22012-11-25 15:23:39 +000080
Chris Lattner229907c2011-07-18 04:54:35 +000081 Constant *getConstantFwdRef(unsigned Idx, Type *Ty);
82 Value *getValueFwdRef(unsigned Idx, Type *Ty);
Joe Abbey2ad8df22012-11-25 15:23:39 +000083
Chris Lattner2d8cd802009-03-31 22:55:09 +000084 void AssignValue(Value *V, unsigned Idx);
Joe Abbey2ad8df22012-11-25 15:23:39 +000085
Chris Lattner74429932008-08-21 02:34:16 +000086 /// ResolveConstantForwardRefs - Once all constants are read, this method bulk
87 /// resolves any forward references.
88 void ResolveConstantForwardRefs();
Chris Lattner1663cca2007-04-24 05:48:56 +000089};
Gabor Greiff6caff662008-05-10 08:32:32 +000090
Devang Patel05eb6172009-08-04 06:00:18 +000091
92//===----------------------------------------------------------------------===//
93// BitcodeReaderMDValueList Class
94//===----------------------------------------------------------------------===//
95
Benjamin Kramer079b96e2013-09-11 18:05:11 +000096class BitcodeReaderMDValueList {
Devang Patel05eb6172009-08-04 06:00:18 +000097 std::vector<WeakVH> MDValuePtrs;
Joe Abbey2ad8df22012-11-25 15:23:39 +000098
Chris Lattner5956dc82009-10-28 05:53:48 +000099 LLVMContext &Context;
Devang Patel05eb6172009-08-04 06:00:18 +0000100public:
101 BitcodeReaderMDValueList(LLVMContext& C) : Context(C) {}
102
103 // vector compatibility methods
104 unsigned size() const { return MDValuePtrs.size(); }
105 void resize(unsigned N) { MDValuePtrs.resize(N); }
106 void push_back(Value *V) { MDValuePtrs.push_back(V); }
107 void clear() { MDValuePtrs.clear(); }
108 Value *back() const { return MDValuePtrs.back(); }
109 void pop_back() { MDValuePtrs.pop_back(); }
110 bool empty() const { return MDValuePtrs.empty(); }
Joe Abbey2ad8df22012-11-25 15:23:39 +0000111
Devang Patel05eb6172009-08-04 06:00:18 +0000112 Value *operator[](unsigned i) const {
113 assert(i < MDValuePtrs.size());
114 return MDValuePtrs[i];
115 }
Joe Abbey2ad8df22012-11-25 15:23:39 +0000116
Devang Patel05eb6172009-08-04 06:00:18 +0000117 void shrinkTo(unsigned N) {
118 assert(N <= size() && "Invalid shrinkTo request!");
119 MDValuePtrs.resize(N);
120 }
121
122 Value *getValueFwdRef(unsigned Idx);
123 void AssignValue(Value *V, unsigned Idx);
124};
125
Benjamin Kramer079b96e2013-09-11 18:05:11 +0000126class BitcodeReader : public GVMaterializer {
Chris Lattner5956dc82009-10-28 05:53:48 +0000127 LLVMContext &Context;
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000128 Module *TheModule;
Rafael Espindolac3f9b5a2014-06-23 21:53:12 +0000129 std::unique_ptr<MemoryBuffer> Buffer;
Ahmed Charles56440fd2014-03-06 05:51:42 +0000130 std::unique_ptr<BitstreamReader> StreamFile;
Chris Lattner277800a2009-04-26 20:59:02 +0000131 BitstreamCursor Stream;
Derek Schuff8b2dcad2012-02-06 22:30:29 +0000132 DataStreamer *LazyStreamer;
133 uint64_t NextUnreadBit;
134 bool SeenValueSymbolTable;
Joe Abbey2ad8df22012-11-25 15:23:39 +0000135
Chris Lattnerb1ed91f2011-07-09 17:41:24 +0000136 std::vector<Type*> TypeList;
Chris Lattner1663cca2007-04-24 05:48:56 +0000137 BitcodeReaderValueList ValueList;
Devang Patel05eb6172009-08-04 06:00:18 +0000138 BitcodeReaderMDValueList MDValueList;
David Majnemerdad0a642014-06-27 18:19:56 +0000139 std::vector<Comdat *> ComdatList;
Devang Patelaf206b82009-09-18 19:26:43 +0000140 SmallVector<Instruction *, 64> InstructionList;
Chad Rosierca2567b2011-12-07 21:44:12 +0000141 SmallVector<SmallVector<uint64_t, 64>, 64> UseListRecords;
Devang Patelaf206b82009-09-18 19:26:43 +0000142
Chris Lattnerfbc1d332007-04-24 03:30:34 +0000143 std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInits;
Chris Lattner44c17072007-04-26 02:46:40 +0000144 std::vector<std::pair<GlobalAlias*, unsigned> > AliasInits;
Peter Collingbourne3fa50f92013-09-16 01:08:15 +0000145 std::vector<std::pair<Function*, unsigned> > FunctionPrefixes;
Joe Abbey2ad8df22012-11-25 15:23:39 +0000146
Manman Ren209b17c2013-09-28 00:22:27 +0000147 SmallVector<Instruction*, 64> InstsWithTBAATag;
148
Devang Patela05633e2008-09-26 22:53:05 +0000149 /// MAttributes - The set of attributes by index. Index zero in the
Chris Lattnerfee5a372007-05-04 03:30:17 +0000150 /// file is for null, and is thus not represented here. As such all indices
151 /// are off by one.
Bill Wendlinge94d8432012-12-07 23:16:57 +0000152 std::vector<AttributeSet> MAttributes;
Joe Abbey2ad8df22012-11-25 15:23:39 +0000153
Bill Wendlingba629332013-02-10 23:24:25 +0000154 /// \brief The set of attribute groups.
Bill Wendlinge46707e2013-02-11 22:32:29 +0000155 std::map<unsigned, AttributeSet> MAttributeGroups;
Bill Wendlingba629332013-02-10 23:24:25 +0000156
Chris Lattner85b7b402007-05-01 05:52:21 +0000157 /// FunctionBBs - While parsing a function body, this is a list of the basic
158 /// blocks for the function.
159 std::vector<BasicBlock*> FunctionBBs;
Joe Abbey2ad8df22012-11-25 15:23:39 +0000160
Chris Lattner51ffe7c2007-05-01 04:59:48 +0000161 // When reading the module header, this list is populated with functions that
162 // have bodies later in the file.
163 std::vector<Function*> FunctionsWithBodies;
Chandler Carruth7132e002007-08-04 01:51:18 +0000164
Joe Abbey2ad8df22012-11-25 15:23:39 +0000165 // When intrinsic functions are encountered which require upgrading they are
Chandler Carruth7132e002007-08-04 01:51:18 +0000166 // stored here with their replacement function.
167 typedef std::vector<std::pair<Function*, Function*> > UpgradedIntrinsicMap;
168 UpgradedIntrinsicMap UpgradedIntrinsics;
Dan Gohman43aa8f02010-07-20 21:42:28 +0000169
170 // Map the bitcode's custom MDKind ID to the Module's MDKind ID.
171 DenseMap<unsigned, unsigned> MDKindMap;
Joe Abbey2ad8df22012-11-25 15:23:39 +0000172
Derek Schuff8b2dcad2012-02-06 22:30:29 +0000173 // Several operations happen after the module header has been read, but
174 // before function bodies are processed. This keeps track of whether
175 // we've done this yet.
176 bool SeenFirstFunctionBody;
Joe Abbey2ad8df22012-11-25 15:23:39 +0000177
Chris Lattner51ffe7c2007-05-01 04:59:48 +0000178 /// DeferredFunctionInfo - When function bodies are initially scanned, this
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000179 /// map contains info about where to find deferred function body in the
180 /// stream.
181 DenseMap<Function*, uint64_t> DeferredFunctionInfo;
Joe Abbey2ad8df22012-11-25 15:23:39 +0000182
Chris Lattner5956dc82009-10-28 05:53:48 +0000183 /// BlockAddrFwdRefs - These are blockaddr references to basic blocks. These
184 /// are resolved lazily when functions are loaded.
185 typedef std::pair<unsigned, GlobalVariable*> BlockAddrRefTy;
186 DenseMap<Function*, std::vector<BlockAddrRefTy> > BlockAddrFwdRefs;
Dan Gohmanbbcd04d2010-09-13 18:00:48 +0000187
Jan Wen Voungafaced02012-10-11 20:20:40 +0000188 /// UseRelativeIDs - Indicates that we are using a new encoding for
Jan Wen Voung8c9e9412012-10-11 21:45:16 +0000189 /// instruction operands where most operands in the current
Jan Wen Voungafaced02012-10-11 20:20:40 +0000190 /// FUNCTION_BLOCK are encoded relative to the instruction number,
191 /// for a more compact encoding. Some instruction operands are not
192 /// relative to the instruction ID: basic block numbers, and types.
193 /// Once the old style function blocks have been phased out, we would
194 /// not need this flag.
195 bool UseRelativeIDs;
196
Rafael Espindola25188c92014-06-12 01:45:43 +0000197 static const std::error_category &BitcodeErrorCategory();
Rafael Espindola48da4f42013-11-04 16:16:24 +0000198
Rafael Espindolaf98536a2014-07-04 14:12:46 +0000199 static ErrorOr<StringRef> convertToStringRef(ArrayRef<uint64_t> Record,
200 unsigned Idx);
201
Chris Lattner1314b992007-04-22 06:23:29 +0000202public:
Rafael Espindola48da4f42013-11-04 16:16:24 +0000203 enum ErrorType {
204 BitcodeStreamInvalidSize,
205 ConflictingMETADATA_KINDRecords,
206 CouldNotFindFunctionInStream,
207 ExpectedConstant,
208 InsufficientFunctionProtos,
209 InvalidBitcodeSignature,
210 InvalidBitcodeWrapperHeader,
211 InvalidConstantReference,
212 InvalidID, // A read identifier is not found in the table it should be in.
213 InvalidInstructionWithNoBB,
214 InvalidRecord, // A read record doesn't have the expected size or structure
215 InvalidTypeForValue, // Type read OK, but is invalid for its use
216 InvalidTYPETable,
217 InvalidType, // We were unable to read a type
218 MalformedBlock, // We are unable to advance in the stream.
219 MalformedGlobalInitializerSet,
220 InvalidMultipleBlocks, // We found multiple blocks of a kind that should
221 // have only one
222 NeverResolvedValueFoundInFunction,
223 InvalidValue // Invalid version, inst number, attr number, etc
224 };
225
Rafael Espindolaf98536a2014-07-04 14:12:46 +0000226 static std::error_code Error(ErrorType E) {
Rafael Espindolabff5d0d2014-06-13 01:25:41 +0000227 return std::error_code(E, BitcodeErrorCategory());
Rafael Espindola48da4f42013-11-04 16:16:24 +0000228 }
229
Rafael Espindolac3f9b5a2014-06-23 21:53:12 +0000230 explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C)
231 : Context(C), TheModule(nullptr), Buffer(buffer), LazyStreamer(nullptr),
232 NextUnreadBit(0), SeenValueSymbolTable(false), ValueList(C),
233 MDValueList(C), SeenFirstFunctionBody(false), UseRelativeIDs(false) {}
Derek Schuff8b2dcad2012-02-06 22:30:29 +0000234 explicit BitcodeReader(DataStreamer *streamer, LLVMContext &C)
Rafael Espindolac3f9b5a2014-06-23 21:53:12 +0000235 : Context(C), TheModule(nullptr), Buffer(nullptr), LazyStreamer(streamer),
236 NextUnreadBit(0), SeenValueSymbolTable(false), ValueList(C),
237 MDValueList(C), SeenFirstFunctionBody(false), UseRelativeIDs(false) {}
Rafael Espindolacd2de412014-06-18 18:26:53 +0000238 ~BitcodeReader() { FreeState(); }
Rafael Espindolab7993462012-01-02 07:49:53 +0000239
240 void materializeForwardReferencedFunctions();
241
Chris Lattner9eeada92007-05-18 04:02:46 +0000242 void FreeState();
Joe Abbey2ad8df22012-11-25 15:23:39 +0000243
Rafael Espindolac3f9b5a2014-06-23 21:53:12 +0000244 void releaseBuffer() override;
Rafael Espindola8fb31112014-06-18 20:07:35 +0000245
Craig Topper85482992014-03-05 07:52:44 +0000246 bool isMaterializable(const GlobalValue *GV) const override;
247 bool isDematerializable(const GlobalValue *GV) const override;
Rafael Espindolabff5d0d2014-06-13 01:25:41 +0000248 std::error_code Materialize(GlobalValue *GV) override;
249 std::error_code MaterializeModule(Module *M) override;
Craig Topper85482992014-03-05 07:52:44 +0000250 void Dematerialize(GlobalValue *GV) override;
Chris Lattnera6f88ce2007-05-15 06:29:44 +0000251
Chris Lattner1314b992007-04-22 06:23:29 +0000252 /// @brief Main interface to parsing a bitcode buffer.
253 /// @returns true if an error occurred.
Rafael Espindolabff5d0d2014-06-13 01:25:41 +0000254 std::error_code ParseBitcodeInto(Module *M);
Bill Wendling0198ce02010-10-06 01:22:42 +0000255
256 /// @brief Cheap mechanism to just extract module triple
257 /// @returns true if an error occurred.
Rafael Espindolaf98536a2014-07-04 14:12:46 +0000258 ErrorOr<StringRef> parseTriple();
Jan Wen Voungafaced02012-10-11 20:20:40 +0000259
260 static uint64_t decodeSignRotatedValue(uint64_t V);
261
Chris Lattner1314b992007-04-22 06:23:29 +0000262private:
Chris Lattnerb1ed91f2011-07-09 17:41:24 +0000263 Type *getTypeByID(unsigned ID);
Chris Lattner229907c2011-07-18 04:54:35 +0000264 Value *getFnValueByID(unsigned ID, Type *Ty) {
Chris Lattner54677c12011-07-07 05:29:18 +0000265 if (Ty && Ty->isMetadataTy())
Devang Patel05eb6172009-08-04 06:00:18 +0000266 return MDValueList.getValueFwdRef(ID);
Chris Lattnercdfcc2d2011-07-07 05:12:37 +0000267 return ValueList.getValueFwdRef(ID, Ty);
Chris Lattner83930552007-05-01 07:01:57 +0000268 }
Chris Lattner5285b5e2007-05-02 05:46:45 +0000269 BasicBlock *getBasicBlock(unsigned ID) const {
Craig Toppere73658d2014-04-28 04:05:08 +0000270 if (ID >= FunctionBBs.size()) return nullptr; // Invalid ID
Chris Lattner5285b5e2007-05-02 05:46:45 +0000271 return FunctionBBs[ID];
272 }
Bill Wendlinge94d8432012-12-07 23:16:57 +0000273 AttributeSet getAttributes(unsigned i) const {
Devang Patela05633e2008-09-26 22:53:05 +0000274 if (i-1 < MAttributes.size())
275 return MAttributes[i-1];
Bill Wendlinge94d8432012-12-07 23:16:57 +0000276 return AttributeSet();
Chris Lattnerfee5a372007-05-04 03:30:17 +0000277 }
Joe Abbey2ad8df22012-11-25 15:23:39 +0000278
Chris Lattnerdf1233d2007-05-06 00:00:00 +0000279 /// getValueTypePair - Read a value/type pair out of the specified record from
280 /// slot 'Slot'. Increment Slot past the number of slots used in the record.
281 /// Return true on failure.
Craig Topper2cd5ff82013-07-11 16:22:38 +0000282 bool getValueTypePair(SmallVectorImpl<uint64_t> &Record, unsigned &Slot,
Chris Lattnerdf1233d2007-05-06 00:00:00 +0000283 unsigned InstNum, Value *&ResVal) {
284 if (Slot == Record.size()) return true;
Jeff Cohenfd73e542007-05-06 03:23:14 +0000285 unsigned ValNo = (unsigned)Record[Slot++];
Jan Wen Voungafaced02012-10-11 20:20:40 +0000286 // Adjust the ValNo, if it was encoded relative to the InstNum.
287 if (UseRelativeIDs)
288 ValNo = InstNum - ValNo;
Chris Lattnerdf1233d2007-05-06 00:00:00 +0000289 if (ValNo < InstNum) {
290 // If this is not a forward reference, just return the value we already
291 // have.
Craig Toppere73658d2014-04-28 04:05:08 +0000292 ResVal = getFnValueByID(ValNo, nullptr);
293 return ResVal == nullptr;
Chris Lattnerdf1233d2007-05-06 00:00:00 +0000294 } else if (Slot == Record.size()) {
295 return true;
296 }
Jan Wen Voungafaced02012-10-11 20:20:40 +0000297
Jeff Cohenfd73e542007-05-06 03:23:14 +0000298 unsigned TypeNo = (unsigned)Record[Slot++];
Chris Lattnerdf1233d2007-05-06 00:00:00 +0000299 ResVal = getFnValueByID(ValNo, getTypeByID(TypeNo));
Craig Toppere73658d2014-04-28 04:05:08 +0000300 return ResVal == nullptr;
Chris Lattnerdf1233d2007-05-06 00:00:00 +0000301 }
Jan Wen Voungafaced02012-10-11 20:20:40 +0000302
303 /// popValue - Read a value out of the specified record from slot 'Slot'.
304 /// Increment Slot past the number of slots used by the value in the record.
305 /// Return true if there is an error.
Craig Topper2cd5ff82013-07-11 16:22:38 +0000306 bool popValue(SmallVectorImpl<uint64_t> &Record, unsigned &Slot,
Jan Wen Voungafaced02012-10-11 20:20:40 +0000307 unsigned InstNum, Type *Ty, Value *&ResVal) {
308 if (getValue(Record, Slot, InstNum, Ty, ResVal))
309 return true;
310 // All values currently take a single record slot.
311 ++Slot;
312 return false;
313 }
314
315 /// getValue -- Like popValue, but does not increment the Slot number.
Craig Topper2cd5ff82013-07-11 16:22:38 +0000316 bool getValue(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
Jan Wen Voungafaced02012-10-11 20:20:40 +0000317 unsigned InstNum, Type *Ty, Value *&ResVal) {
318 ResVal = getValue(Record, Slot, InstNum, Ty);
Craig Toppere73658d2014-04-28 04:05:08 +0000319 return ResVal == nullptr;
Chris Lattnerdf1233d2007-05-06 00:00:00 +0000320 }
Chris Lattnerfee5a372007-05-04 03:30:17 +0000321
Jan Wen Voungafaced02012-10-11 20:20:40 +0000322 /// getValue -- Version of getValue that returns ResVal directly,
323 /// or 0 if there is an error.
Craig Topper2cd5ff82013-07-11 16:22:38 +0000324 Value *getValue(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
Jan Wen Voungafaced02012-10-11 20:20:40 +0000325 unsigned InstNum, Type *Ty) {
Craig Toppere73658d2014-04-28 04:05:08 +0000326 if (Slot == Record.size()) return nullptr;
Jan Wen Voungafaced02012-10-11 20:20:40 +0000327 unsigned ValNo = (unsigned)Record[Slot];
328 // Adjust the ValNo, if it was encoded relative to the InstNum.
329 if (UseRelativeIDs)
330 ValNo = InstNum - ValNo;
331 return getFnValueByID(ValNo, Ty);
332 }
333
334 /// getValueSigned -- Like getValue, but decodes signed VBRs.
Craig Topper2cd5ff82013-07-11 16:22:38 +0000335 Value *getValueSigned(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
Jan Wen Voungafaced02012-10-11 20:20:40 +0000336 unsigned InstNum, Type *Ty) {
Craig Toppere73658d2014-04-28 04:05:08 +0000337 if (Slot == Record.size()) return nullptr;
Jan Wen Voungafaced02012-10-11 20:20:40 +0000338 unsigned ValNo = (unsigned)decodeSignRotatedValue(Record[Slot]);
339 // Adjust the ValNo, if it was encoded relative to the InstNum.
340 if (UseRelativeIDs)
341 ValNo = InstNum - ValNo;
342 return getFnValueByID(ValNo, Ty);
343 }
344
Rafael Espindolabff5d0d2014-06-13 01:25:41 +0000345 std::error_code ParseAttrKind(uint64_t Code, Attribute::AttrKind *Kind);
346 std::error_code ParseModule(bool Resume);
347 std::error_code ParseAttributeBlock();
348 std::error_code ParseAttributeGroupBlock();
349 std::error_code ParseTypeTable();
350 std::error_code ParseTypeTableBody();
Chris Lattnerb1ed91f2011-07-09 17:41:24 +0000351
Rafael Espindolabff5d0d2014-06-13 01:25:41 +0000352 std::error_code ParseValueSymbolTable();
353 std::error_code ParseConstants();
354 std::error_code RememberAndSkipFunctionBody();
355 std::error_code ParseFunctionBody(Function *F);
356 std::error_code GlobalCleanup();
357 std::error_code ResolveGlobalAndAliasInits();
358 std::error_code ParseMetadata();
359 std::error_code ParseMetadataAttachment();
Rafael Espindolaf98536a2014-07-04 14:12:46 +0000360 ErrorOr<StringRef> parseModuleTriple();
Rafael Espindolabff5d0d2014-06-13 01:25:41 +0000361 std::error_code ParseUseLists();
362 std::error_code InitStream();
363 std::error_code InitStreamFromBuffer();
364 std::error_code InitLazyStream();
365 std::error_code FindFunctionInStream(
366 Function *F,
367 DenseMap<Function *, uint64_t>::iterator DeferredFunctionInfoIterator);
Chris Lattner1314b992007-04-22 06:23:29 +0000368};
Joe Abbey2ad8df22012-11-25 15:23:39 +0000369
Chris Lattner1314b992007-04-22 06:23:29 +0000370} // End llvm namespace
371
372#endif