blob: 1d4869a2d5a795c8de9949b25fe2e92122ef8512 [file] [log] [blame]
Chris Lattnercaee0dc2007-04-22 06:23:29 +00001//===- BitcodeReader.h - Internal BitcodeReader impl ------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Lattnercaee0dc2007-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 Carrutha1514e22012-12-04 07:12:27 +000017#include "llvm/ADT/DenseMap.h"
Chris Lattner48f84872007-05-01 04:59:48 +000018#include "llvm/Bitcode/BitstreamReader.h"
Chris Lattner47f96bf2007-04-23 01:01:37 +000019#include "llvm/Bitcode/LLVMBitCodes.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000020#include "llvm/IR/Attributes.h"
Stephen Hines36b56882014-04-23 16:57:46 -070021#include "llvm/IR/GVMaterializer.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000022#include "llvm/IR/OperandTraits.h"
23#include "llvm/IR/Type.h"
Stephen Hines36b56882014-04-23 16:57:46 -070024#include "llvm/IR/ValueHandle.h"
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070025#include <system_error>
Chris Lattnercaee0dc2007-04-22 06:23:29 +000026#include <vector>
27
28namespace llvm {
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070029 class Comdat;
Chris Lattnerc453f762007-04-29 07:54:31 +000030 class MemoryBuffer;
Benjamin Kramer12ddd402009-08-11 17:45:13 +000031 class LLVMContext;
Joe Abbey170a15e2012-11-25 15:23:39 +000032
Gabor Greifefe65362008-05-10 08:32:32 +000033//===----------------------------------------------------------------------===//
34// BitcodeReaderValueList Class
35//===----------------------------------------------------------------------===//
36
Benjamin Kramer55c06ae2013-09-11 18:05:11 +000037class BitcodeReaderValueList {
Chris Lattner46e77402009-03-31 22:55:09 +000038 std::vector<WeakVH> ValuePtrs;
Joe Abbey170a15e2012-11-25 15:23:39 +000039
Chris Lattnerea693df2008-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 Lattner7af453a2011-07-07 05:12:37 +000049 LLVMContext &Context;
Chris Lattner522b7b12007-04-24 05:48:56 +000050public:
Chris Lattner7af453a2011-07-07 05:12:37 +000051 BitcodeReaderValueList(LLVMContext &C) : Context(C) {}
Chris Lattnerea693df2008-08-21 02:34:16 +000052 ~BitcodeReaderValueList() {
53 assert(ResolveConstants.empty() && "Constants not resolved?");
54 }
Gabor Greifefe65362008-05-10 08:32:32 +000055
Chris Lattner522b7b12007-04-24 05:48:56 +000056 // vector compatibility methods
Chris Lattner46e77402009-03-31 22:55:09 +000057 unsigned size() const { return ValuePtrs.size(); }
58 void resize(unsigned N) { ValuePtrs.resize(N); }
Chris Lattner522b7b12007-04-24 05:48:56 +000059 void push_back(Value *V) {
Chris Lattner46e77402009-03-31 22:55:09 +000060 ValuePtrs.push_back(V);
Chris Lattner522b7b12007-04-24 05:48:56 +000061 }
Joe Abbey170a15e2012-11-25 15:23:39 +000062
Chris Lattnerb348bb82007-05-18 04:02:46 +000063 void clear() {
Chris Lattnerea693df2008-08-21 02:34:16 +000064 assert(ResolveConstants.empty() && "Constants not resolved?");
Chris Lattner46e77402009-03-31 22:55:09 +000065 ValuePtrs.clear();
Chris Lattnerb348bb82007-05-18 04:02:46 +000066 }
Joe Abbey170a15e2012-11-25 15:23:39 +000067
Chris Lattner46e77402009-03-31 22:55:09 +000068 Value *operator[](unsigned i) const {
69 assert(i < ValuePtrs.size());
70 return ValuePtrs[i];
71 }
Joe Abbey170a15e2012-11-25 15:23:39 +000072
Chris Lattner46e77402009-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 Lattner198f34a2007-04-26 03:27:58 +000076 void shrinkTo(unsigned N) {
Chris Lattner46e77402009-03-31 22:55:09 +000077 assert(N <= size() && "Invalid shrinkTo request!");
78 ValuePtrs.resize(N);
Chris Lattner198f34a2007-04-26 03:27:58 +000079 }
Joe Abbey170a15e2012-11-25 15:23:39 +000080
Chris Lattnerdb125cf2011-07-18 04:54:35 +000081 Constant *getConstantFwdRef(unsigned Idx, Type *Ty);
82 Value *getValueFwdRef(unsigned Idx, Type *Ty);
Joe Abbey170a15e2012-11-25 15:23:39 +000083
Chris Lattner46e77402009-03-31 22:55:09 +000084 void AssignValue(Value *V, unsigned Idx);
Joe Abbey170a15e2012-11-25 15:23:39 +000085
Chris Lattnerea693df2008-08-21 02:34:16 +000086 /// ResolveConstantForwardRefs - Once all constants are read, this method bulk
87 /// resolves any forward references.
88 void ResolveConstantForwardRefs();
Chris Lattner522b7b12007-04-24 05:48:56 +000089};
Gabor Greifefe65362008-05-10 08:32:32 +000090
Devang Pateld5ac4042009-08-04 06:00:18 +000091
92//===----------------------------------------------------------------------===//
93// BitcodeReaderMDValueList Class
94//===----------------------------------------------------------------------===//
95
Benjamin Kramer55c06ae2013-09-11 18:05:11 +000096class BitcodeReaderMDValueList {
Devang Pateld5ac4042009-08-04 06:00:18 +000097 std::vector<WeakVH> MDValuePtrs;
Joe Abbey170a15e2012-11-25 15:23:39 +000098
Chris Lattner50b136d2009-10-28 05:53:48 +000099 LLVMContext &Context;
Devang Pateld5ac4042009-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 Abbey170a15e2012-11-25 15:23:39 +0000111
Devang Pateld5ac4042009-08-04 06:00:18 +0000112 Value *operator[](unsigned i) const {
113 assert(i < MDValuePtrs.size());
114 return MDValuePtrs[i];
115 }
Joe Abbey170a15e2012-11-25 15:23:39 +0000116
Devang Pateld5ac4042009-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 Kramer55c06ae2013-09-11 18:05:11 +0000126class BitcodeReader : public GVMaterializer {
Chris Lattner50b136d2009-10-28 05:53:48 +0000127 LLVMContext &Context;
Jeffrey Yasskinf0356fe2010-01-27 20:34:15 +0000128 Module *TheModule;
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700129 std::unique_ptr<MemoryBuffer> Buffer;
Stephen Hines36b56882014-04-23 16:57:46 -0700130 std::unique_ptr<BitstreamReader> StreamFile;
Chris Lattner962dde32009-04-26 20:59:02 +0000131 BitstreamCursor Stream;
Derek Schuff2ea93872012-02-06 22:30:29 +0000132 DataStreamer *LazyStreamer;
133 uint64_t NextUnreadBit;
134 bool SeenValueSymbolTable;
Joe Abbey170a15e2012-11-25 15:23:39 +0000135
Chris Lattner1afcace2011-07-09 17:41:24 +0000136 std::vector<Type*> TypeList;
Chris Lattner522b7b12007-04-24 05:48:56 +0000137 BitcodeReaderValueList ValueList;
Devang Pateld5ac4042009-08-04 06:00:18 +0000138 BitcodeReaderMDValueList MDValueList;
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700139 std::vector<Comdat *> ComdatList;
Devang Patele8e02132009-09-18 19:26:43 +0000140 SmallVector<Instruction *, 64> InstructionList;
Chad Rosiercbbb0962011-12-07 21:44:12 +0000141 SmallVector<SmallVector<uint64_t, 64>, 64> UseListRecords;
Devang Patele8e02132009-09-18 19:26:43 +0000142
Chris Lattnere16504e2007-04-24 03:30:34 +0000143 std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInits;
Chris Lattner07d98b42007-04-26 02:46:40 +0000144 std::vector<std::pair<GlobalAlias*, unsigned> > AliasInits;
Peter Collingbourne1e3037f2013-09-16 01:08:15 +0000145 std::vector<std::pair<Function*, unsigned> > FunctionPrefixes;
Joe Abbey170a15e2012-11-25 15:23:39 +0000146
Manman Ren804f0342013-09-28 00:22:27 +0000147 SmallVector<Instruction*, 64> InstsWithTBAATag;
148
Devang Patel19c87462008-09-26 22:53:05 +0000149 /// MAttributes - The set of attributes by index. Index zero in the
Chris Lattner48c85b82007-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 Wendling99faa3b2012-12-07 23:16:57 +0000152 std::vector<AttributeSet> MAttributes;
Joe Abbey170a15e2012-11-25 15:23:39 +0000153
Bill Wendlingc3ba0a82013-02-10 23:24:25 +0000154 /// \brief The set of attribute groups.
Bill Wendling04ef4be2013-02-11 22:32:29 +0000155 std::map<unsigned, AttributeSet> MAttributeGroups;
Bill Wendlingc3ba0a82013-02-10 23:24:25 +0000156
Chris Lattner980e5aa2007-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 Abbey170a15e2012-11-25 15:23:39 +0000160
Chris Lattner48f84872007-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 Carruth69940402007-08-04 01:51:18 +0000164
Joe Abbey170a15e2012-11-25 15:23:39 +0000165 // When intrinsic functions are encountered which require upgrading they are
Chandler Carruth69940402007-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 Gohman19538d12010-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 Abbey170a15e2012-11-25 15:23:39 +0000172
Derek Schuff2ea93872012-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 Abbey170a15e2012-11-25 15:23:39 +0000177
Chris Lattner48f84872007-05-01 04:59:48 +0000178 /// DeferredFunctionInfo - When function bodies are initially scanned, this
Jeffrey Yasskinf0356fe2010-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 Abbey170a15e2012-11-25 15:23:39 +0000182
Chris Lattner50b136d2009-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 Gohman9b10dfb2010-09-13 18:00:48 +0000187
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000188 /// UseRelativeIDs - Indicates that we are using a new encoding for
Jan Wen Voung7b8d9492012-10-11 21:45:16 +0000189 /// instruction operands where most operands in the current
Jan Wen Voungd9a3bad2012-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
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700197 static const std::error_category &BitcodeErrorCategory();
Rafael Espindolae076b532013-11-04 16:16:24 +0000198
Chris Lattnercaee0dc2007-04-22 06:23:29 +0000199public:
Rafael Espindolae076b532013-11-04 16:16:24 +0000200 enum ErrorType {
201 BitcodeStreamInvalidSize,
202 ConflictingMETADATA_KINDRecords,
203 CouldNotFindFunctionInStream,
204 ExpectedConstant,
205 InsufficientFunctionProtos,
206 InvalidBitcodeSignature,
207 InvalidBitcodeWrapperHeader,
208 InvalidConstantReference,
209 InvalidID, // A read identifier is not found in the table it should be in.
210 InvalidInstructionWithNoBB,
211 InvalidRecord, // A read record doesn't have the expected size or structure
212 InvalidTypeForValue, // Type read OK, but is invalid for its use
213 InvalidTYPETable,
214 InvalidType, // We were unable to read a type
215 MalformedBlock, // We are unable to advance in the stream.
216 MalformedGlobalInitializerSet,
217 InvalidMultipleBlocks, // We found multiple blocks of a kind that should
218 // have only one
219 NeverResolvedValueFoundInFunction,
220 InvalidValue // Invalid version, inst number, attr number, etc
221 };
222
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700223 std::error_code Error(ErrorType E) {
224 return std::error_code(E, BitcodeErrorCategory());
Rafael Espindolae076b532013-11-04 16:16:24 +0000225 }
226
Chris Lattner08113472009-12-29 09:01:33 +0000227 explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C)
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700228 : Context(C), TheModule(nullptr), Buffer(buffer), LazyStreamer(nullptr),
229 NextUnreadBit(0), SeenValueSymbolTable(false), ValueList(C),
230 MDValueList(C), SeenFirstFunctionBody(false), UseRelativeIDs(false) {}
Derek Schuff2ea93872012-02-06 22:30:29 +0000231 explicit BitcodeReader(DataStreamer *streamer, LLVMContext &C)
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700232 : Context(C), TheModule(nullptr), Buffer(nullptr), LazyStreamer(streamer),
233 NextUnreadBit(0), SeenValueSymbolTable(false), ValueList(C),
234 MDValueList(C), SeenFirstFunctionBody(false), UseRelativeIDs(false) {}
235 ~BitcodeReader() { FreeState(); }
Rafael Espindola47f79bb2012-01-02 07:49:53 +0000236
237 void materializeForwardReferencedFunctions();
238
Chris Lattnerb348bb82007-05-18 04:02:46 +0000239 void FreeState();
Joe Abbey170a15e2012-11-25 15:23:39 +0000240
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700241 void releaseBuffer() override;
Joe Abbey170a15e2012-11-25 15:23:39 +0000242
Stephen Hines36b56882014-04-23 16:57:46 -0700243 bool isMaterializable(const GlobalValue *GV) const override;
244 bool isDematerializable(const GlobalValue *GV) const override;
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700245 std::error_code Materialize(GlobalValue *GV) override;
246 std::error_code MaterializeModule(Module *M) override;
Stephen Hines36b56882014-04-23 16:57:46 -0700247 void Dematerialize(GlobalValue *GV) override;
Chris Lattnerd67c6322007-05-15 06:29:44 +0000248
Chris Lattnercaee0dc2007-04-22 06:23:29 +0000249 /// @brief Main interface to parsing a bitcode buffer.
250 /// @returns true if an error occurred.
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700251 std::error_code ParseBitcodeInto(Module *M);
Bill Wendling34711742010-10-06 01:22:42 +0000252
253 /// @brief Cheap mechanism to just extract module triple
254 /// @returns true if an error occurred.
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700255 ErrorOr<std::string> parseTriple();
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000256
257 static uint64_t decodeSignRotatedValue(uint64_t V);
258
Chris Lattnercaee0dc2007-04-22 06:23:29 +0000259private:
Chris Lattner1afcace2011-07-09 17:41:24 +0000260 Type *getTypeByID(unsigned ID);
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000261 Value *getFnValueByID(unsigned ID, Type *Ty) {
Chris Lattnercbd40f82011-07-07 05:29:18 +0000262 if (Ty && Ty->isMetadataTy())
Devang Pateld5ac4042009-08-04 06:00:18 +0000263 return MDValueList.getValueFwdRef(ID);
Chris Lattner7af453a2011-07-07 05:12:37 +0000264 return ValueList.getValueFwdRef(ID, Ty);
Chris Lattnera7c49aa2007-05-01 07:01:57 +0000265 }
Chris Lattnerf4c8e522007-05-02 05:46:45 +0000266 BasicBlock *getBasicBlock(unsigned ID) const {
Stephen Hinesdce4a402014-05-29 02:49:00 -0700267 if (ID >= FunctionBBs.size()) return nullptr; // Invalid ID
Chris Lattnerf4c8e522007-05-02 05:46:45 +0000268 return FunctionBBs[ID];
269 }
Bill Wendling99faa3b2012-12-07 23:16:57 +0000270 AttributeSet getAttributes(unsigned i) const {
Devang Patel19c87462008-09-26 22:53:05 +0000271 if (i-1 < MAttributes.size())
272 return MAttributes[i-1];
Bill Wendling99faa3b2012-12-07 23:16:57 +0000273 return AttributeSet();
Chris Lattner48c85b82007-05-04 03:30:17 +0000274 }
Joe Abbey170a15e2012-11-25 15:23:39 +0000275
Chris Lattner7337ab92007-05-06 00:00:00 +0000276 /// getValueTypePair - Read a value/type pair out of the specified record from
277 /// slot 'Slot'. Increment Slot past the number of slots used in the record.
278 /// Return true on failure.
Craig Topper9e639e82013-07-11 16:22:38 +0000279 bool getValueTypePair(SmallVectorImpl<uint64_t> &Record, unsigned &Slot,
Chris Lattner7337ab92007-05-06 00:00:00 +0000280 unsigned InstNum, Value *&ResVal) {
281 if (Slot == Record.size()) return true;
Jeff Cohen650c9382007-05-06 03:23:14 +0000282 unsigned ValNo = (unsigned)Record[Slot++];
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000283 // Adjust the ValNo, if it was encoded relative to the InstNum.
284 if (UseRelativeIDs)
285 ValNo = InstNum - ValNo;
Chris Lattner7337ab92007-05-06 00:00:00 +0000286 if (ValNo < InstNum) {
287 // If this is not a forward reference, just return the value we already
288 // have.
Stephen Hinesdce4a402014-05-29 02:49:00 -0700289 ResVal = getFnValueByID(ValNo, nullptr);
290 return ResVal == nullptr;
Chris Lattner7337ab92007-05-06 00:00:00 +0000291 } else if (Slot == Record.size()) {
292 return true;
293 }
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000294
Jeff Cohen650c9382007-05-06 03:23:14 +0000295 unsigned TypeNo = (unsigned)Record[Slot++];
Chris Lattner7337ab92007-05-06 00:00:00 +0000296 ResVal = getFnValueByID(ValNo, getTypeByID(TypeNo));
Stephen Hinesdce4a402014-05-29 02:49:00 -0700297 return ResVal == nullptr;
Chris Lattner7337ab92007-05-06 00:00:00 +0000298 }
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000299
300 /// popValue - Read a value out of the specified record from slot 'Slot'.
301 /// Increment Slot past the number of slots used by the value in the record.
302 /// Return true if there is an error.
Craig Topper9e639e82013-07-11 16:22:38 +0000303 bool popValue(SmallVectorImpl<uint64_t> &Record, unsigned &Slot,
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000304 unsigned InstNum, Type *Ty, Value *&ResVal) {
305 if (getValue(Record, Slot, InstNum, Ty, ResVal))
306 return true;
307 // All values currently take a single record slot.
308 ++Slot;
309 return false;
310 }
311
312 /// getValue -- Like popValue, but does not increment the Slot number.
Craig Topper9e639e82013-07-11 16:22:38 +0000313 bool getValue(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000314 unsigned InstNum, Type *Ty, Value *&ResVal) {
315 ResVal = getValue(Record, Slot, InstNum, Ty);
Stephen Hinesdce4a402014-05-29 02:49:00 -0700316 return ResVal == nullptr;
Chris Lattner7337ab92007-05-06 00:00:00 +0000317 }
Chris Lattner48c85b82007-05-04 03:30:17 +0000318
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000319 /// getValue -- Version of getValue that returns ResVal directly,
320 /// or 0 if there is an error.
Craig Topper9e639e82013-07-11 16:22:38 +0000321 Value *getValue(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000322 unsigned InstNum, Type *Ty) {
Stephen Hinesdce4a402014-05-29 02:49:00 -0700323 if (Slot == Record.size()) return nullptr;
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000324 unsigned ValNo = (unsigned)Record[Slot];
325 // Adjust the ValNo, if it was encoded relative to the InstNum.
326 if (UseRelativeIDs)
327 ValNo = InstNum - ValNo;
328 return getFnValueByID(ValNo, Ty);
329 }
330
331 /// getValueSigned -- Like getValue, but decodes signed VBRs.
Craig Topper9e639e82013-07-11 16:22:38 +0000332 Value *getValueSigned(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000333 unsigned InstNum, Type *Ty) {
Stephen Hinesdce4a402014-05-29 02:49:00 -0700334 if (Slot == Record.size()) return nullptr;
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000335 unsigned ValNo = (unsigned)decodeSignRotatedValue(Record[Slot]);
336 // Adjust the ValNo, if it was encoded relative to the InstNum.
337 if (UseRelativeIDs)
338 ValNo = InstNum - ValNo;
339 return getFnValueByID(ValNo, Ty);
340 }
341
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700342 std::error_code ParseAttrKind(uint64_t Code, Attribute::AttrKind *Kind);
343 std::error_code ParseModule(bool Resume);
344 std::error_code ParseAttributeBlock();
345 std::error_code ParseAttributeGroupBlock();
346 std::error_code ParseTypeTable();
347 std::error_code ParseTypeTableBody();
Chris Lattner1afcace2011-07-09 17:41:24 +0000348
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700349 std::error_code ParseValueSymbolTable();
350 std::error_code ParseConstants();
351 std::error_code RememberAndSkipFunctionBody();
352 std::error_code ParseFunctionBody(Function *F);
353 std::error_code GlobalCleanup();
354 std::error_code ResolveGlobalAndAliasInits();
355 std::error_code ParseMetadata();
356 std::error_code ParseMetadataAttachment();
357 ErrorOr<std::string> parseModuleTriple();
358 std::error_code ParseUseLists();
359 std::error_code InitStream();
360 std::error_code InitStreamFromBuffer();
361 std::error_code InitLazyStream();
362 std::error_code FindFunctionInStream(
363 Function *F,
364 DenseMap<Function *, uint64_t>::iterator DeferredFunctionInfoIterator);
Chris Lattnercaee0dc2007-04-22 06:23:29 +0000365};
Joe Abbey170a15e2012-11-25 15:23:39 +0000366
Chris Lattnercaee0dc2007-04-22 06:23:29 +0000367} // End llvm namespace
368
369#endif