blob: 9803e78b929a0430cfa2bded645af9cfb7bc9955 [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
Stephen Hines37ed9c12014-12-01 14:51:49 -080014#ifndef LLVM_LIB_BITCODE_READER_BITCODEREADER_H
15#define LLVM_LIB_BITCODE_READER_BITCODEREADER_H
Chris Lattnercaee0dc2007-04-22 06:23:29 +000016
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"
Stephen Hinesebe69fe2015-03-23 12:10:34 -070022#include "llvm/IR/Metadata.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000023#include "llvm/IR/OperandTraits.h"
Stephen Hinesebe69fe2015-03-23 12:10:34 -070024#include "llvm/IR/TrackingMDRef.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000025#include "llvm/IR/Type.h"
Stephen Hines36b56882014-04-23 16:57:46 -070026#include "llvm/IR/ValueHandle.h"
Stephen Hines37ed9c12014-12-01 14:51:49 -080027#include <deque>
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070028#include <system_error>
Chris Lattnercaee0dc2007-04-22 06:23:29 +000029#include <vector>
30
31namespace llvm {
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070032 class Comdat;
Chris Lattnerc453f762007-04-29 07:54:31 +000033 class MemoryBuffer;
Benjamin Kramer12ddd402009-08-11 17:45:13 +000034 class LLVMContext;
Joe Abbey170a15e2012-11-25 15:23:39 +000035
Gabor Greifefe65362008-05-10 08:32:32 +000036//===----------------------------------------------------------------------===//
37// BitcodeReaderValueList Class
38//===----------------------------------------------------------------------===//
39
Benjamin Kramer55c06ae2013-09-11 18:05:11 +000040class BitcodeReaderValueList {
Chris Lattner46e77402009-03-31 22:55:09 +000041 std::vector<WeakVH> ValuePtrs;
Joe Abbey170a15e2012-11-25 15:23:39 +000042
Chris Lattnerea693df2008-08-21 02:34:16 +000043 /// ResolveConstants - As we resolve forward-referenced constants, we add
44 /// information about them to this vector. This allows us to resolve them in
45 /// bulk instead of resolving each reference at a time. See the code in
46 /// ResolveConstantForwardRefs for more information about this.
47 ///
48 /// The key of this vector is the placeholder constant, the value is the slot
49 /// number that holds the resolved value.
50 typedef std::vector<std::pair<Constant*, unsigned> > ResolveConstantsTy;
51 ResolveConstantsTy ResolveConstants;
Chris Lattner7af453a2011-07-07 05:12:37 +000052 LLVMContext &Context;
Chris Lattner522b7b12007-04-24 05:48:56 +000053public:
Chris Lattner7af453a2011-07-07 05:12:37 +000054 BitcodeReaderValueList(LLVMContext &C) : Context(C) {}
Chris Lattnerea693df2008-08-21 02:34:16 +000055 ~BitcodeReaderValueList() {
56 assert(ResolveConstants.empty() && "Constants not resolved?");
57 }
Gabor Greifefe65362008-05-10 08:32:32 +000058
Chris Lattner522b7b12007-04-24 05:48:56 +000059 // vector compatibility methods
Chris Lattner46e77402009-03-31 22:55:09 +000060 unsigned size() const { return ValuePtrs.size(); }
61 void resize(unsigned N) { ValuePtrs.resize(N); }
Chris Lattner522b7b12007-04-24 05:48:56 +000062 void push_back(Value *V) {
Chris Lattner46e77402009-03-31 22:55:09 +000063 ValuePtrs.push_back(V);
Chris Lattner522b7b12007-04-24 05:48:56 +000064 }
Joe Abbey170a15e2012-11-25 15:23:39 +000065
Chris Lattnerb348bb82007-05-18 04:02:46 +000066 void clear() {
Chris Lattnerea693df2008-08-21 02:34:16 +000067 assert(ResolveConstants.empty() && "Constants not resolved?");
Chris Lattner46e77402009-03-31 22:55:09 +000068 ValuePtrs.clear();
Chris Lattnerb348bb82007-05-18 04:02:46 +000069 }
Joe Abbey170a15e2012-11-25 15:23:39 +000070
Chris Lattner46e77402009-03-31 22:55:09 +000071 Value *operator[](unsigned i) const {
72 assert(i < ValuePtrs.size());
73 return ValuePtrs[i];
74 }
Joe Abbey170a15e2012-11-25 15:23:39 +000075
Chris Lattner46e77402009-03-31 22:55:09 +000076 Value *back() const { return ValuePtrs.back(); }
77 void pop_back() { ValuePtrs.pop_back(); }
78 bool empty() const { return ValuePtrs.empty(); }
Chris Lattner198f34a2007-04-26 03:27:58 +000079 void shrinkTo(unsigned N) {
Chris Lattner46e77402009-03-31 22:55:09 +000080 assert(N <= size() && "Invalid shrinkTo request!");
81 ValuePtrs.resize(N);
Chris Lattner198f34a2007-04-26 03:27:58 +000082 }
Joe Abbey170a15e2012-11-25 15:23:39 +000083
Chris Lattnerdb125cf2011-07-18 04:54:35 +000084 Constant *getConstantFwdRef(unsigned Idx, Type *Ty);
85 Value *getValueFwdRef(unsigned Idx, Type *Ty);
Joe Abbey170a15e2012-11-25 15:23:39 +000086
Chris Lattner46e77402009-03-31 22:55:09 +000087 void AssignValue(Value *V, unsigned Idx);
Joe Abbey170a15e2012-11-25 15:23:39 +000088
Chris Lattnerea693df2008-08-21 02:34:16 +000089 /// ResolveConstantForwardRefs - Once all constants are read, this method bulk
90 /// resolves any forward references.
91 void ResolveConstantForwardRefs();
Chris Lattner522b7b12007-04-24 05:48:56 +000092};
Gabor Greifefe65362008-05-10 08:32:32 +000093
Devang Pateld5ac4042009-08-04 06:00:18 +000094
95//===----------------------------------------------------------------------===//
96// BitcodeReaderMDValueList Class
97//===----------------------------------------------------------------------===//
98
Benjamin Kramer55c06ae2013-09-11 18:05:11 +000099class BitcodeReaderMDValueList {
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700100 unsigned NumFwdRefs;
101 bool AnyFwdRefs;
102 unsigned MinFwdRef;
103 unsigned MaxFwdRef;
104 std::vector<TrackingMDRef> MDValuePtrs;
Joe Abbey170a15e2012-11-25 15:23:39 +0000105
Chris Lattner50b136d2009-10-28 05:53:48 +0000106 LLVMContext &Context;
Devang Pateld5ac4042009-08-04 06:00:18 +0000107public:
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700108 BitcodeReaderMDValueList(LLVMContext &C)
109 : NumFwdRefs(0), AnyFwdRefs(false), Context(C) {}
Devang Pateld5ac4042009-08-04 06:00:18 +0000110
111 // vector compatibility methods
112 unsigned size() const { return MDValuePtrs.size(); }
113 void resize(unsigned N) { MDValuePtrs.resize(N); }
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700114 void push_back(Metadata *MD) { MDValuePtrs.emplace_back(MD); }
Devang Pateld5ac4042009-08-04 06:00:18 +0000115 void clear() { MDValuePtrs.clear(); }
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700116 Metadata *back() const { return MDValuePtrs.back(); }
Devang Pateld5ac4042009-08-04 06:00:18 +0000117 void pop_back() { MDValuePtrs.pop_back(); }
118 bool empty() const { return MDValuePtrs.empty(); }
Joe Abbey170a15e2012-11-25 15:23:39 +0000119
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700120 Metadata *operator[](unsigned i) const {
Devang Pateld5ac4042009-08-04 06:00:18 +0000121 assert(i < MDValuePtrs.size());
122 return MDValuePtrs[i];
123 }
Joe Abbey170a15e2012-11-25 15:23:39 +0000124
Devang Pateld5ac4042009-08-04 06:00:18 +0000125 void shrinkTo(unsigned N) {
126 assert(N <= size() && "Invalid shrinkTo request!");
127 MDValuePtrs.resize(N);
128 }
129
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700130 Metadata *getValueFwdRef(unsigned Idx);
131 void AssignValue(Metadata *MD, unsigned Idx);
132 void tryToResolveCycles();
Devang Pateld5ac4042009-08-04 06:00:18 +0000133};
134
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000135class BitcodeReader : public GVMaterializer {
Chris Lattner50b136d2009-10-28 05:53:48 +0000136 LLVMContext &Context;
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700137 DiagnosticHandlerFunction DiagnosticHandler;
Jeffrey Yasskinf0356fe2010-01-27 20:34:15 +0000138 Module *TheModule;
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700139 std::unique_ptr<MemoryBuffer> Buffer;
Stephen Hines36b56882014-04-23 16:57:46 -0700140 std::unique_ptr<BitstreamReader> StreamFile;
Chris Lattner962dde32009-04-26 20:59:02 +0000141 BitstreamCursor Stream;
Derek Schuff2ea93872012-02-06 22:30:29 +0000142 DataStreamer *LazyStreamer;
143 uint64_t NextUnreadBit;
144 bool SeenValueSymbolTable;
Joe Abbey170a15e2012-11-25 15:23:39 +0000145
Chris Lattner1afcace2011-07-09 17:41:24 +0000146 std::vector<Type*> TypeList;
Chris Lattner522b7b12007-04-24 05:48:56 +0000147 BitcodeReaderValueList ValueList;
Devang Pateld5ac4042009-08-04 06:00:18 +0000148 BitcodeReaderMDValueList MDValueList;
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700149 std::vector<Comdat *> ComdatList;
Devang Patele8e02132009-09-18 19:26:43 +0000150 SmallVector<Instruction *, 64> InstructionList;
151
Chris Lattnere16504e2007-04-24 03:30:34 +0000152 std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInits;
Chris Lattner07d98b42007-04-26 02:46:40 +0000153 std::vector<std::pair<GlobalAlias*, unsigned> > AliasInits;
Peter Collingbourne1e3037f2013-09-16 01:08:15 +0000154 std::vector<std::pair<Function*, unsigned> > FunctionPrefixes;
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700155 std::vector<std::pair<Function*, unsigned> > FunctionPrologues;
Joe Abbey170a15e2012-11-25 15:23:39 +0000156
Manman Ren804f0342013-09-28 00:22:27 +0000157 SmallVector<Instruction*, 64> InstsWithTBAATag;
158
Devang Patel19c87462008-09-26 22:53:05 +0000159 /// MAttributes - The set of attributes by index. Index zero in the
Chris Lattner48c85b82007-05-04 03:30:17 +0000160 /// file is for null, and is thus not represented here. As such all indices
161 /// are off by one.
Bill Wendling99faa3b2012-12-07 23:16:57 +0000162 std::vector<AttributeSet> MAttributes;
Joe Abbey170a15e2012-11-25 15:23:39 +0000163
Bill Wendlingc3ba0a82013-02-10 23:24:25 +0000164 /// \brief The set of attribute groups.
Bill Wendling04ef4be2013-02-11 22:32:29 +0000165 std::map<unsigned, AttributeSet> MAttributeGroups;
Bill Wendlingc3ba0a82013-02-10 23:24:25 +0000166
Chris Lattner980e5aa2007-05-01 05:52:21 +0000167 /// FunctionBBs - While parsing a function body, this is a list of the basic
168 /// blocks for the function.
169 std::vector<BasicBlock*> FunctionBBs;
Joe Abbey170a15e2012-11-25 15:23:39 +0000170
Chris Lattner48f84872007-05-01 04:59:48 +0000171 // When reading the module header, this list is populated with functions that
172 // have bodies later in the file.
173 std::vector<Function*> FunctionsWithBodies;
Chandler Carruth69940402007-08-04 01:51:18 +0000174
Joe Abbey170a15e2012-11-25 15:23:39 +0000175 // When intrinsic functions are encountered which require upgrading they are
Chandler Carruth69940402007-08-04 01:51:18 +0000176 // stored here with their replacement function.
177 typedef std::vector<std::pair<Function*, Function*> > UpgradedIntrinsicMap;
178 UpgradedIntrinsicMap UpgradedIntrinsics;
Dan Gohman19538d12010-07-20 21:42:28 +0000179
180 // Map the bitcode's custom MDKind ID to the Module's MDKind ID.
181 DenseMap<unsigned, unsigned> MDKindMap;
Joe Abbey170a15e2012-11-25 15:23:39 +0000182
Derek Schuff2ea93872012-02-06 22:30:29 +0000183 // Several operations happen after the module header has been read, but
184 // before function bodies are processed. This keeps track of whether
185 // we've done this yet.
186 bool SeenFirstFunctionBody;
Joe Abbey170a15e2012-11-25 15:23:39 +0000187
Chris Lattner48f84872007-05-01 04:59:48 +0000188 /// DeferredFunctionInfo - When function bodies are initially scanned, this
Jeffrey Yasskinf0356fe2010-01-27 20:34:15 +0000189 /// map contains info about where to find deferred function body in the
190 /// stream.
191 DenseMap<Function*, uint64_t> DeferredFunctionInfo;
Joe Abbey170a15e2012-11-25 15:23:39 +0000192
Stephen Hines37ed9c12014-12-01 14:51:49 -0800193 /// These are basic blocks forward-referenced by block addresses. They are
194 /// inserted lazily into functions when they're loaded. The basic block ID is
195 /// its index into the vector.
196 DenseMap<Function *, std::vector<BasicBlock *>> BasicBlockFwdRefs;
197 std::deque<Function *> BasicBlockFwdRefQueue;
Dan Gohman9b10dfb2010-09-13 18:00:48 +0000198
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000199 /// UseRelativeIDs - Indicates that we are using a new encoding for
Jan Wen Voung7b8d9492012-10-11 21:45:16 +0000200 /// instruction operands where most operands in the current
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000201 /// FUNCTION_BLOCK are encoded relative to the instruction number,
202 /// for a more compact encoding. Some instruction operands are not
203 /// relative to the instruction ID: basic block numbers, and types.
204 /// Once the old style function blocks have been phased out, we would
205 /// not need this flag.
206 bool UseRelativeIDs;
207
Stephen Hines37ed9c12014-12-01 14:51:49 -0800208 /// True if all functions will be materialized, negating the need to process
209 /// (e.g.) blockaddress forward references.
210 bool WillMaterializeAllForwardRefs;
211
212 /// Functions that have block addresses taken. This is usually empty.
213 SmallPtrSet<const Function *, 4> BlockAddressesTaken;
Rafael Espindolae076b532013-11-04 16:16:24 +0000214
Chris Lattnercaee0dc2007-04-22 06:23:29 +0000215public:
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700216 std::error_code Error(BitcodeError E, const Twine &Message);
217 std::error_code Error(BitcodeError E);
218 std::error_code Error(const Twine &Message);
Rafael Espindolae076b532013-11-04 16:16:24 +0000219
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700220 explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C,
221 DiagnosticHandlerFunction DiagnosticHandler);
222 explicit BitcodeReader(DataStreamer *streamer, LLVMContext &C,
223 DiagnosticHandlerFunction DiagnosticHandler);
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700224 ~BitcodeReader() { FreeState(); }
Rafael Espindola47f79bb2012-01-02 07:49:53 +0000225
Stephen Hines37ed9c12014-12-01 14:51:49 -0800226 std::error_code materializeForwardReferencedFunctions();
Rafael Espindola47f79bb2012-01-02 07:49:53 +0000227
Chris Lattnerb348bb82007-05-18 04:02:46 +0000228 void FreeState();
Joe Abbey170a15e2012-11-25 15:23:39 +0000229
Stephen Hines37ed9c12014-12-01 14:51:49 -0800230 void releaseBuffer();
Joe Abbey170a15e2012-11-25 15:23:39 +0000231
Stephen Hines36b56882014-04-23 16:57:46 -0700232 bool isDematerializable(const GlobalValue *GV) const override;
Stephen Hines37ed9c12014-12-01 14:51:49 -0800233 std::error_code materialize(GlobalValue *GV) override;
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700234 std::error_code MaterializeModule(Module *M) override;
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700235 std::vector<StructType *> getIdentifiedStructTypes() const override;
Stephen Hines36b56882014-04-23 16:57:46 -0700236 void Dematerialize(GlobalValue *GV) override;
Chris Lattnerd67c6322007-05-15 06:29:44 +0000237
Chris Lattnercaee0dc2007-04-22 06:23:29 +0000238 /// @brief Main interface to parsing a bitcode buffer.
239 /// @returns true if an error occurred.
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700240 std::error_code ParseBitcodeInto(Module *M);
Bill Wendling34711742010-10-06 01:22:42 +0000241
242 /// @brief Cheap mechanism to just extract module triple
243 /// @returns true if an error occurred.
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700244 ErrorOr<std::string> parseTriple();
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000245
246 static uint64_t decodeSignRotatedValue(uint64_t V);
247
Chris Lattnercaee0dc2007-04-22 06:23:29 +0000248private:
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700249 std::vector<StructType *> IdentifiedStructTypes;
250 StructType *createIdentifiedStructType(LLVMContext &Context, StringRef Name);
251 StructType *createIdentifiedStructType(LLVMContext &Context);
252
Chris Lattner1afcace2011-07-09 17:41:24 +0000253 Type *getTypeByID(unsigned ID);
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000254 Value *getFnValueByID(unsigned ID, Type *Ty) {
Chris Lattnercbd40f82011-07-07 05:29:18 +0000255 if (Ty && Ty->isMetadataTy())
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700256 return MetadataAsValue::get(Ty->getContext(), getFnMetadataByID(ID));
Chris Lattner7af453a2011-07-07 05:12:37 +0000257 return ValueList.getValueFwdRef(ID, Ty);
Chris Lattnera7c49aa2007-05-01 07:01:57 +0000258 }
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700259 Metadata *getFnMetadataByID(unsigned ID) {
260 return MDValueList.getValueFwdRef(ID);
261 }
Chris Lattnerf4c8e522007-05-02 05:46:45 +0000262 BasicBlock *getBasicBlock(unsigned ID) const {
Stephen Hinesdce4a402014-05-29 02:49:00 -0700263 if (ID >= FunctionBBs.size()) return nullptr; // Invalid ID
Chris Lattnerf4c8e522007-05-02 05:46:45 +0000264 return FunctionBBs[ID];
265 }
Bill Wendling99faa3b2012-12-07 23:16:57 +0000266 AttributeSet getAttributes(unsigned i) const {
Devang Patel19c87462008-09-26 22:53:05 +0000267 if (i-1 < MAttributes.size())
268 return MAttributes[i-1];
Bill Wendling99faa3b2012-12-07 23:16:57 +0000269 return AttributeSet();
Chris Lattner48c85b82007-05-04 03:30:17 +0000270 }
Joe Abbey170a15e2012-11-25 15:23:39 +0000271
Chris Lattner7337ab92007-05-06 00:00:00 +0000272 /// getValueTypePair - Read a value/type pair out of the specified record from
273 /// slot 'Slot'. Increment Slot past the number of slots used in the record.
274 /// Return true on failure.
Craig Topper9e639e82013-07-11 16:22:38 +0000275 bool getValueTypePair(SmallVectorImpl<uint64_t> &Record, unsigned &Slot,
Chris Lattner7337ab92007-05-06 00:00:00 +0000276 unsigned InstNum, Value *&ResVal) {
277 if (Slot == Record.size()) return true;
Jeff Cohen650c9382007-05-06 03:23:14 +0000278 unsigned ValNo = (unsigned)Record[Slot++];
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000279 // Adjust the ValNo, if it was encoded relative to the InstNum.
280 if (UseRelativeIDs)
281 ValNo = InstNum - ValNo;
Chris Lattner7337ab92007-05-06 00:00:00 +0000282 if (ValNo < InstNum) {
283 // If this is not a forward reference, just return the value we already
284 // have.
Stephen Hinesdce4a402014-05-29 02:49:00 -0700285 ResVal = getFnValueByID(ValNo, nullptr);
286 return ResVal == nullptr;
Chris Lattner7337ab92007-05-06 00:00:00 +0000287 } else if (Slot == Record.size()) {
288 return true;
289 }
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000290
Jeff Cohen650c9382007-05-06 03:23:14 +0000291 unsigned TypeNo = (unsigned)Record[Slot++];
Chris Lattner7337ab92007-05-06 00:00:00 +0000292 ResVal = getFnValueByID(ValNo, getTypeByID(TypeNo));
Stephen Hinesdce4a402014-05-29 02:49:00 -0700293 return ResVal == nullptr;
Chris Lattner7337ab92007-05-06 00:00:00 +0000294 }
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000295
296 /// popValue - Read a value out of the specified record from slot 'Slot'.
297 /// Increment Slot past the number of slots used by the value in the record.
298 /// Return true if there is an error.
Craig Topper9e639e82013-07-11 16:22:38 +0000299 bool popValue(SmallVectorImpl<uint64_t> &Record, unsigned &Slot,
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000300 unsigned InstNum, Type *Ty, Value *&ResVal) {
301 if (getValue(Record, Slot, InstNum, Ty, ResVal))
302 return true;
303 // All values currently take a single record slot.
304 ++Slot;
305 return false;
306 }
307
308 /// getValue -- Like popValue, but does not increment the Slot number.
Craig Topper9e639e82013-07-11 16:22:38 +0000309 bool getValue(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000310 unsigned InstNum, Type *Ty, Value *&ResVal) {
311 ResVal = getValue(Record, Slot, InstNum, Ty);
Stephen Hinesdce4a402014-05-29 02:49:00 -0700312 return ResVal == nullptr;
Chris Lattner7337ab92007-05-06 00:00:00 +0000313 }
Chris Lattner48c85b82007-05-04 03:30:17 +0000314
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000315 /// getValue -- Version of getValue that returns ResVal directly,
316 /// or 0 if there is an error.
Craig Topper9e639e82013-07-11 16:22:38 +0000317 Value *getValue(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000318 unsigned InstNum, Type *Ty) {
Stephen Hinesdce4a402014-05-29 02:49:00 -0700319 if (Slot == Record.size()) return nullptr;
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000320 unsigned ValNo = (unsigned)Record[Slot];
321 // Adjust the ValNo, if it was encoded relative to the InstNum.
322 if (UseRelativeIDs)
323 ValNo = InstNum - ValNo;
324 return getFnValueByID(ValNo, Ty);
325 }
326
327 /// getValueSigned -- Like getValue, but decodes signed VBRs.
Craig Topper9e639e82013-07-11 16:22:38 +0000328 Value *getValueSigned(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000329 unsigned InstNum, Type *Ty) {
Stephen Hinesdce4a402014-05-29 02:49:00 -0700330 if (Slot == Record.size()) return nullptr;
Jan Wen Voungd9a3bad2012-10-11 20:20:40 +0000331 unsigned ValNo = (unsigned)decodeSignRotatedValue(Record[Slot]);
332 // Adjust the ValNo, if it was encoded relative to the InstNum.
333 if (UseRelativeIDs)
334 ValNo = InstNum - ValNo;
335 return getFnValueByID(ValNo, Ty);
336 }
337
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700338 /// Converts alignment exponent (i.e. power of two (or zero)) to the
339 /// corresponding alignment to use. If alignment is too large, returns
340 /// a corresponding error code.
341 std::error_code parseAlignmentValue(uint64_t Exponent, unsigned &Alignment);
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