blob: 639ddb9035040d02ac0d663cb9a18654688fa331 [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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_BITCODE_READER_BITCODEREADER_H
15#define LLVM_LIB_BITCODE_READER_BITCODEREADER_H
Chris Lattner1314b992007-04-22 06:23:29 +000016
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"
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +000022#include "llvm/IR/Metadata.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000023#include "llvm/IR/OperandTraits.h"
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +000024#include "llvm/IR/TrackingMDRef.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000025#include "llvm/IR/Type.h"
Chandler Carruth4220e9c2014-03-04 11:17:44 +000026#include "llvm/IR/ValueHandle.h"
Duncan P. N. Exon Smith5a511b52014-08-05 17:49:48 +000027#include <deque>
Rafael Espindolaa6e9c3e2014-06-12 17:38:55 +000028#include <system_error>
Chris Lattner1314b992007-04-22 06:23:29 +000029#include <vector>
30
31namespace llvm {
David Majnemerdad0a642014-06-27 18:19:56 +000032 class Comdat;
Chris Lattner6694f602007-04-29 07:54:31 +000033 class MemoryBuffer;
Benjamin Kramer78c3bcb2009-08-11 17:45:13 +000034 class LLVMContext;
Joe Abbey2ad8df22012-11-25 15:23:39 +000035
Gabor Greiff6caff662008-05-10 08:32:32 +000036//===----------------------------------------------------------------------===//
37// BitcodeReaderValueList Class
38//===----------------------------------------------------------------------===//
39
Benjamin Kramer079b96e2013-09-11 18:05:11 +000040class BitcodeReaderValueList {
Chris Lattner2d8cd802009-03-31 22:55:09 +000041 std::vector<WeakVH> ValuePtrs;
Joe Abbey2ad8df22012-11-25 15:23:39 +000042
Chris Lattner74429932008-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 Lattnercdfcc2d2011-07-07 05:12:37 +000052 LLVMContext &Context;
Chris Lattner1663cca2007-04-24 05:48:56 +000053public:
Chris Lattnercdfcc2d2011-07-07 05:12:37 +000054 BitcodeReaderValueList(LLVMContext &C) : Context(C) {}
Chris Lattner74429932008-08-21 02:34:16 +000055 ~BitcodeReaderValueList() {
56 assert(ResolveConstants.empty() && "Constants not resolved?");
57 }
Gabor Greiff6caff662008-05-10 08:32:32 +000058
Chris Lattner1663cca2007-04-24 05:48:56 +000059 // vector compatibility methods
Chris Lattner2d8cd802009-03-31 22:55:09 +000060 unsigned size() const { return ValuePtrs.size(); }
61 void resize(unsigned N) { ValuePtrs.resize(N); }
Chris Lattner1663cca2007-04-24 05:48:56 +000062 void push_back(Value *V) {
Chris Lattner2d8cd802009-03-31 22:55:09 +000063 ValuePtrs.push_back(V);
Chris Lattner1663cca2007-04-24 05:48:56 +000064 }
Joe Abbey2ad8df22012-11-25 15:23:39 +000065
Chris Lattner9eeada92007-05-18 04:02:46 +000066 void clear() {
Chris Lattner74429932008-08-21 02:34:16 +000067 assert(ResolveConstants.empty() && "Constants not resolved?");
Chris Lattner2d8cd802009-03-31 22:55:09 +000068 ValuePtrs.clear();
Chris Lattner9eeada92007-05-18 04:02:46 +000069 }
Joe Abbey2ad8df22012-11-25 15:23:39 +000070
Chris Lattner2d8cd802009-03-31 22:55:09 +000071 Value *operator[](unsigned i) const {
72 assert(i < ValuePtrs.size());
73 return ValuePtrs[i];
74 }
Joe Abbey2ad8df22012-11-25 15:23:39 +000075
Chris Lattner2d8cd802009-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 Lattner831d4202007-04-26 03:27:58 +000079 void shrinkTo(unsigned N) {
Chris Lattner2d8cd802009-03-31 22:55:09 +000080 assert(N <= size() && "Invalid shrinkTo request!");
81 ValuePtrs.resize(N);
Chris Lattner831d4202007-04-26 03:27:58 +000082 }
Joe Abbey2ad8df22012-11-25 15:23:39 +000083
Chris Lattner229907c2011-07-18 04:54:35 +000084 Constant *getConstantFwdRef(unsigned Idx, Type *Ty);
85 Value *getValueFwdRef(unsigned Idx, Type *Ty);
Joe Abbey2ad8df22012-11-25 15:23:39 +000086
Chris Lattner2d8cd802009-03-31 22:55:09 +000087 void AssignValue(Value *V, unsigned Idx);
Joe Abbey2ad8df22012-11-25 15:23:39 +000088
Chris Lattner74429932008-08-21 02:34:16 +000089 /// ResolveConstantForwardRefs - Once all constants are read, this method bulk
90 /// resolves any forward references.
91 void ResolveConstantForwardRefs();
Chris Lattner1663cca2007-04-24 05:48:56 +000092};
Gabor Greiff6caff662008-05-10 08:32:32 +000093
Devang Patel05eb6172009-08-04 06:00:18 +000094
95//===----------------------------------------------------------------------===//
96// BitcodeReaderMDValueList Class
97//===----------------------------------------------------------------------===//
98
Benjamin Kramer079b96e2013-09-11 18:05:11 +000099class BitcodeReaderMDValueList {
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000100 unsigned NumFwdRefs;
101 bool AnyFwdRefs;
102 std::vector<TrackingMDRef> MDValuePtrs;
Joe Abbey2ad8df22012-11-25 15:23:39 +0000103
Chris Lattner5956dc82009-10-28 05:53:48 +0000104 LLVMContext &Context;
Devang Patel05eb6172009-08-04 06:00:18 +0000105public:
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000106 BitcodeReaderMDValueList(LLVMContext &C)
107 : NumFwdRefs(0), AnyFwdRefs(false), Context(C) {}
Devang Patel05eb6172009-08-04 06:00:18 +0000108
109 // vector compatibility methods
110 unsigned size() const { return MDValuePtrs.size(); }
111 void resize(unsigned N) { MDValuePtrs.resize(N); }
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000112 void push_back(Metadata *MD) { MDValuePtrs.emplace_back(MD); }
Devang Patel05eb6172009-08-04 06:00:18 +0000113 void clear() { MDValuePtrs.clear(); }
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000114 Metadata *back() const { return MDValuePtrs.back(); }
Devang Patel05eb6172009-08-04 06:00:18 +0000115 void pop_back() { MDValuePtrs.pop_back(); }
116 bool empty() const { return MDValuePtrs.empty(); }
Joe Abbey2ad8df22012-11-25 15:23:39 +0000117
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000118 Metadata *operator[](unsigned i) const {
Devang Patel05eb6172009-08-04 06:00:18 +0000119 assert(i < MDValuePtrs.size());
120 return MDValuePtrs[i];
121 }
Joe Abbey2ad8df22012-11-25 15:23:39 +0000122
Devang Patel05eb6172009-08-04 06:00:18 +0000123 void shrinkTo(unsigned N) {
124 assert(N <= size() && "Invalid shrinkTo request!");
125 MDValuePtrs.resize(N);
126 }
127
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000128 Metadata *getValueFwdRef(unsigned Idx);
129 void AssignValue(Metadata *MD, unsigned Idx);
130 void tryToResolveCycles();
Devang Patel05eb6172009-08-04 06:00:18 +0000131};
132
Benjamin Kramer079b96e2013-09-11 18:05:11 +0000133class BitcodeReader : public GVMaterializer {
Chris Lattner5956dc82009-10-28 05:53:48 +0000134 LLVMContext &Context;
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000135 Module *TheModule;
Rafael Espindolac3f9b5a2014-06-23 21:53:12 +0000136 std::unique_ptr<MemoryBuffer> Buffer;
Ahmed Charles56440fd2014-03-06 05:51:42 +0000137 std::unique_ptr<BitstreamReader> StreamFile;
Chris Lattner277800a2009-04-26 20:59:02 +0000138 BitstreamCursor Stream;
Derek Schuff8b2dcad2012-02-06 22:30:29 +0000139 DataStreamer *LazyStreamer;
140 uint64_t NextUnreadBit;
141 bool SeenValueSymbolTable;
Joe Abbey2ad8df22012-11-25 15:23:39 +0000142
Chris Lattnerb1ed91f2011-07-09 17:41:24 +0000143 std::vector<Type*> TypeList;
Chris Lattner1663cca2007-04-24 05:48:56 +0000144 BitcodeReaderValueList ValueList;
Devang Patel05eb6172009-08-04 06:00:18 +0000145 BitcodeReaderMDValueList MDValueList;
David Majnemerdad0a642014-06-27 18:19:56 +0000146 std::vector<Comdat *> ComdatList;
Devang Patelaf206b82009-09-18 19:26:43 +0000147 SmallVector<Instruction *, 64> InstructionList;
148
Chris Lattnerfbc1d332007-04-24 03:30:34 +0000149 std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInits;
Chris Lattner44c17072007-04-26 02:46:40 +0000150 std::vector<std::pair<GlobalAlias*, unsigned> > AliasInits;
Peter Collingbourne3fa50f92013-09-16 01:08:15 +0000151 std::vector<std::pair<Function*, unsigned> > FunctionPrefixes;
Peter Collingbourne51d2de72014-12-03 02:08:38 +0000152 std::vector<std::pair<Function*, unsigned> > FunctionPrologues;
Joe Abbey2ad8df22012-11-25 15:23:39 +0000153
Manman Ren209b17c2013-09-28 00:22:27 +0000154 SmallVector<Instruction*, 64> InstsWithTBAATag;
155
Devang Patela05633e2008-09-26 22:53:05 +0000156 /// MAttributes - The set of attributes by index. Index zero in the
Chris Lattnerfee5a372007-05-04 03:30:17 +0000157 /// file is for null, and is thus not represented here. As such all indices
158 /// are off by one.
Bill Wendlinge94d8432012-12-07 23:16:57 +0000159 std::vector<AttributeSet> MAttributes;
Joe Abbey2ad8df22012-11-25 15:23:39 +0000160
Bill Wendlingba629332013-02-10 23:24:25 +0000161 /// \brief The set of attribute groups.
Bill Wendlinge46707e2013-02-11 22:32:29 +0000162 std::map<unsigned, AttributeSet> MAttributeGroups;
Bill Wendlingba629332013-02-10 23:24:25 +0000163
Chris Lattner85b7b402007-05-01 05:52:21 +0000164 /// FunctionBBs - While parsing a function body, this is a list of the basic
165 /// blocks for the function.
166 std::vector<BasicBlock*> FunctionBBs;
Joe Abbey2ad8df22012-11-25 15:23:39 +0000167
Chris Lattner51ffe7c2007-05-01 04:59:48 +0000168 // When reading the module header, this list is populated with functions that
169 // have bodies later in the file.
170 std::vector<Function*> FunctionsWithBodies;
Chandler Carruth7132e002007-08-04 01:51:18 +0000171
Joe Abbey2ad8df22012-11-25 15:23:39 +0000172 // When intrinsic functions are encountered which require upgrading they are
Chandler Carruth7132e002007-08-04 01:51:18 +0000173 // stored here with their replacement function.
174 typedef std::vector<std::pair<Function*, Function*> > UpgradedIntrinsicMap;
175 UpgradedIntrinsicMap UpgradedIntrinsics;
Dan Gohman43aa8f02010-07-20 21:42:28 +0000176
177 // Map the bitcode's custom MDKind ID to the Module's MDKind ID.
178 DenseMap<unsigned, unsigned> MDKindMap;
Joe Abbey2ad8df22012-11-25 15:23:39 +0000179
Derek Schuff8b2dcad2012-02-06 22:30:29 +0000180 // Several operations happen after the module header has been read, but
181 // before function bodies are processed. This keeps track of whether
182 // we've done this yet.
183 bool SeenFirstFunctionBody;
Joe Abbey2ad8df22012-11-25 15:23:39 +0000184
Chris Lattner51ffe7c2007-05-01 04:59:48 +0000185 /// DeferredFunctionInfo - When function bodies are initially scanned, this
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000186 /// map contains info about where to find deferred function body in the
187 /// stream.
188 DenseMap<Function*, uint64_t> DeferredFunctionInfo;
Joe Abbey2ad8df22012-11-25 15:23:39 +0000189
Duncan P. N. Exon Smith00f20ac2014-08-01 21:51:52 +0000190 /// These are basic blocks forward-referenced by block addresses. They are
Duncan P. N. Exon Smith5a5fd7b2014-08-16 01:54:37 +0000191 /// inserted lazily into functions when they're loaded. The basic block ID is
192 /// its index into the vector.
193 DenseMap<Function *, std::vector<BasicBlock *>> BasicBlockFwdRefs;
Duncan P. N. Exon Smith5a511b52014-08-05 17:49:48 +0000194 std::deque<Function *> BasicBlockFwdRefQueue;
Dan Gohmanbbcd04d2010-09-13 18:00:48 +0000195
Jan Wen Voungafaced02012-10-11 20:20:40 +0000196 /// UseRelativeIDs - Indicates that we are using a new encoding for
Jan Wen Voung8c9e9412012-10-11 21:45:16 +0000197 /// instruction operands where most operands in the current
Jan Wen Voungafaced02012-10-11 20:20:40 +0000198 /// FUNCTION_BLOCK are encoded relative to the instruction number,
199 /// for a more compact encoding. Some instruction operands are not
200 /// relative to the instruction ID: basic block numbers, and types.
201 /// Once the old style function blocks have been phased out, we would
202 /// not need this flag.
203 bool UseRelativeIDs;
204
Duncan P. N. Exon Smith908d8092014-08-01 21:11:34 +0000205 /// True if all functions will be materialized, negating the need to process
206 /// (e.g.) blockaddress forward references.
207 bool WillMaterializeAllForwardRefs;
208
209 /// Functions that have block addresses taken. This is usually empty.
210 SmallPtrSet<const Function *, 4> BlockAddressesTaken;
211
Chris Lattner1314b992007-04-22 06:23:29 +0000212public:
Rafael Espindolac3f2e732014-07-29 20:22:46 +0000213 std::error_code Error(BitcodeError E) { return make_error_code(E); }
Rafael Espindola48da4f42013-11-04 16:16:24 +0000214
Rafael Espindolac3f9b5a2014-06-23 21:53:12 +0000215 explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C)
216 : Context(C), TheModule(nullptr), Buffer(buffer), LazyStreamer(nullptr),
217 NextUnreadBit(0), SeenValueSymbolTable(false), ValueList(C),
Duncan P. N. Exon Smith908d8092014-08-01 21:11:34 +0000218 MDValueList(C), SeenFirstFunctionBody(false), UseRelativeIDs(false),
219 WillMaterializeAllForwardRefs(false) {}
Derek Schuff8b2dcad2012-02-06 22:30:29 +0000220 explicit BitcodeReader(DataStreamer *streamer, LLVMContext &C)
Rafael Espindolac3f9b5a2014-06-23 21:53:12 +0000221 : Context(C), TheModule(nullptr), Buffer(nullptr), LazyStreamer(streamer),
222 NextUnreadBit(0), SeenValueSymbolTable(false), ValueList(C),
Duncan P. N. Exon Smith908d8092014-08-01 21:11:34 +0000223 MDValueList(C), SeenFirstFunctionBody(false), UseRelativeIDs(false),
224 WillMaterializeAllForwardRefs(false) {}
Rafael Espindolacd2de412014-06-18 18:26:53 +0000225 ~BitcodeReader() { FreeState(); }
Rafael Espindolab7993462012-01-02 07:49:53 +0000226
Duncan P. N. Exon Smith908d8092014-08-01 21:11:34 +0000227 std::error_code materializeForwardReferencedFunctions();
Rafael Espindolab7993462012-01-02 07:49:53 +0000228
Chris Lattner9eeada92007-05-18 04:02:46 +0000229 void FreeState();
Joe Abbey2ad8df22012-11-25 15:23:39 +0000230
Rafael Espindolad96d5532014-08-26 21:49:01 +0000231 void releaseBuffer();
Rafael Espindola8fb31112014-06-18 20:07:35 +0000232
Craig Topper85482992014-03-05 07:52:44 +0000233 bool isDematerializable(const GlobalValue *GV) const override;
Rafael Espindola5a52e6d2014-10-24 22:50:48 +0000234 std::error_code materialize(GlobalValue *GV) override;
Rafael Espindolabff5d0d2014-06-13 01:25:41 +0000235 std::error_code MaterializeModule(Module *M) override;
Rafael Espindola2fa1e432014-12-03 07:18:23 +0000236 std::vector<StructType *> getIdentifiedStructTypes() const override;
Craig Topper85482992014-03-05 07:52:44 +0000237 void Dematerialize(GlobalValue *GV) override;
Chris Lattnera6f88ce2007-05-15 06:29:44 +0000238
Chris Lattner1314b992007-04-22 06:23:29 +0000239 /// @brief Main interface to parsing a bitcode buffer.
240 /// @returns true if an error occurred.
Rafael Espindolabff5d0d2014-06-13 01:25:41 +0000241 std::error_code ParseBitcodeInto(Module *M);
Bill Wendling0198ce02010-10-06 01:22:42 +0000242
243 /// @brief Cheap mechanism to just extract module triple
244 /// @returns true if an error occurred.
Rafael Espindolac75c4fa2014-07-04 20:02:42 +0000245 ErrorOr<std::string> parseTriple();
Jan Wen Voungafaced02012-10-11 20:20:40 +0000246
247 static uint64_t decodeSignRotatedValue(uint64_t V);
248
Chris Lattner1314b992007-04-22 06:23:29 +0000249private:
Rafael Espindola2fa1e432014-12-03 07:18:23 +0000250 std::vector<StructType *> IdentifiedStructTypes;
251 StructType *createIdentifiedStructType(LLVMContext &Context, StringRef Name);
252 StructType *createIdentifiedStructType(LLVMContext &Context);
253
Chris Lattnerb1ed91f2011-07-09 17:41:24 +0000254 Type *getTypeByID(unsigned ID);
Chris Lattner229907c2011-07-18 04:54:35 +0000255 Value *getFnValueByID(unsigned ID, Type *Ty) {
Chris Lattner54677c12011-07-07 05:29:18 +0000256 if (Ty && Ty->isMetadataTy())
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000257 return MetadataAsValue::get(Ty->getContext(), getFnMetadataByID(ID));
Chris Lattnercdfcc2d2011-07-07 05:12:37 +0000258 return ValueList.getValueFwdRef(ID, Ty);
Chris Lattner83930552007-05-01 07:01:57 +0000259 }
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000260 Metadata *getFnMetadataByID(unsigned ID) {
261 return MDValueList.getValueFwdRef(ID);
262 }
Chris Lattner5285b5e2007-05-02 05:46:45 +0000263 BasicBlock *getBasicBlock(unsigned ID) const {
Craig Toppere73658d2014-04-28 04:05:08 +0000264 if (ID >= FunctionBBs.size()) return nullptr; // Invalid ID
Chris Lattner5285b5e2007-05-02 05:46:45 +0000265 return FunctionBBs[ID];
266 }
Bill Wendlinge94d8432012-12-07 23:16:57 +0000267 AttributeSet getAttributes(unsigned i) const {
Devang Patela05633e2008-09-26 22:53:05 +0000268 if (i-1 < MAttributes.size())
269 return MAttributes[i-1];
Bill Wendlinge94d8432012-12-07 23:16:57 +0000270 return AttributeSet();
Chris Lattnerfee5a372007-05-04 03:30:17 +0000271 }
Joe Abbey2ad8df22012-11-25 15:23:39 +0000272
Chris Lattnerdf1233d2007-05-06 00:00:00 +0000273 /// getValueTypePair - Read a value/type pair out of the specified record from
274 /// slot 'Slot'. Increment Slot past the number of slots used in the record.
275 /// Return true on failure.
Craig Topper2cd5ff82013-07-11 16:22:38 +0000276 bool getValueTypePair(SmallVectorImpl<uint64_t> &Record, unsigned &Slot,
Chris Lattnerdf1233d2007-05-06 00:00:00 +0000277 unsigned InstNum, Value *&ResVal) {
278 if (Slot == Record.size()) return true;
Jeff Cohenfd73e542007-05-06 03:23:14 +0000279 unsigned ValNo = (unsigned)Record[Slot++];
Jan Wen Voungafaced02012-10-11 20:20:40 +0000280 // Adjust the ValNo, if it was encoded relative to the InstNum.
281 if (UseRelativeIDs)
282 ValNo = InstNum - ValNo;
Chris Lattnerdf1233d2007-05-06 00:00:00 +0000283 if (ValNo < InstNum) {
284 // If this is not a forward reference, just return the value we already
285 // have.
Craig Toppere73658d2014-04-28 04:05:08 +0000286 ResVal = getFnValueByID(ValNo, nullptr);
287 return ResVal == nullptr;
Chris Lattnerdf1233d2007-05-06 00:00:00 +0000288 } else if (Slot == Record.size()) {
289 return true;
290 }
Jan Wen Voungafaced02012-10-11 20:20:40 +0000291
Jeff Cohenfd73e542007-05-06 03:23:14 +0000292 unsigned TypeNo = (unsigned)Record[Slot++];
Chris Lattnerdf1233d2007-05-06 00:00:00 +0000293 ResVal = getFnValueByID(ValNo, getTypeByID(TypeNo));
Craig Toppere73658d2014-04-28 04:05:08 +0000294 return ResVal == nullptr;
Chris Lattnerdf1233d2007-05-06 00:00:00 +0000295 }
Jan Wen Voungafaced02012-10-11 20:20:40 +0000296
297 /// popValue - Read a value out of the specified record from slot 'Slot'.
298 /// Increment Slot past the number of slots used by the value in the record.
299 /// Return true if there is an error.
Craig Topper2cd5ff82013-07-11 16:22:38 +0000300 bool popValue(SmallVectorImpl<uint64_t> &Record, unsigned &Slot,
Jan Wen Voungafaced02012-10-11 20:20:40 +0000301 unsigned InstNum, Type *Ty, Value *&ResVal) {
302 if (getValue(Record, Slot, InstNum, Ty, ResVal))
303 return true;
304 // All values currently take a single record slot.
305 ++Slot;
306 return false;
307 }
308
309 /// getValue -- Like popValue, but does not increment the Slot number.
Craig Topper2cd5ff82013-07-11 16:22:38 +0000310 bool getValue(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
Jan Wen Voungafaced02012-10-11 20:20:40 +0000311 unsigned InstNum, Type *Ty, Value *&ResVal) {
312 ResVal = getValue(Record, Slot, InstNum, Ty);
Craig Toppere73658d2014-04-28 04:05:08 +0000313 return ResVal == nullptr;
Chris Lattnerdf1233d2007-05-06 00:00:00 +0000314 }
Chris Lattnerfee5a372007-05-04 03:30:17 +0000315
Jan Wen Voungafaced02012-10-11 20:20:40 +0000316 /// getValue -- Version of getValue that returns ResVal directly,
317 /// or 0 if there is an error.
Craig Topper2cd5ff82013-07-11 16:22:38 +0000318 Value *getValue(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
Jan Wen Voungafaced02012-10-11 20:20:40 +0000319 unsigned InstNum, Type *Ty) {
Craig Toppere73658d2014-04-28 04:05:08 +0000320 if (Slot == Record.size()) return nullptr;
Jan Wen Voungafaced02012-10-11 20:20:40 +0000321 unsigned ValNo = (unsigned)Record[Slot];
322 // Adjust the ValNo, if it was encoded relative to the InstNum.
323 if (UseRelativeIDs)
324 ValNo = InstNum - ValNo;
325 return getFnValueByID(ValNo, Ty);
326 }
327
328 /// getValueSigned -- Like getValue, but decodes signed VBRs.
Craig Topper2cd5ff82013-07-11 16:22:38 +0000329 Value *getValueSigned(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
Jan Wen Voungafaced02012-10-11 20:20:40 +0000330 unsigned InstNum, Type *Ty) {
Craig Toppere73658d2014-04-28 04:05:08 +0000331 if (Slot == Record.size()) return nullptr;
Jan Wen Voungafaced02012-10-11 20:20:40 +0000332 unsigned ValNo = (unsigned)decodeSignRotatedValue(Record[Slot]);
333 // Adjust the ValNo, if it was encoded relative to the InstNum.
334 if (UseRelativeIDs)
335 ValNo = InstNum - ValNo;
336 return getFnValueByID(ValNo, Ty);
337 }
338
Rafael Espindolabff5d0d2014-06-13 01:25:41 +0000339 std::error_code ParseAttrKind(uint64_t Code, Attribute::AttrKind *Kind);
340 std::error_code ParseModule(bool Resume);
341 std::error_code ParseAttributeBlock();
342 std::error_code ParseAttributeGroupBlock();
343 std::error_code ParseTypeTable();
344 std::error_code ParseTypeTableBody();
Chris Lattnerb1ed91f2011-07-09 17:41:24 +0000345
Rafael Espindolabff5d0d2014-06-13 01:25:41 +0000346 std::error_code ParseValueSymbolTable();
347 std::error_code ParseConstants();
348 std::error_code RememberAndSkipFunctionBody();
349 std::error_code ParseFunctionBody(Function *F);
350 std::error_code GlobalCleanup();
351 std::error_code ResolveGlobalAndAliasInits();
352 std::error_code ParseMetadata();
353 std::error_code ParseMetadataAttachment();
Rafael Espindolac75c4fa2014-07-04 20:02:42 +0000354 ErrorOr<std::string> parseModuleTriple();
Rafael Espindolabff5d0d2014-06-13 01:25:41 +0000355 std::error_code ParseUseLists();
356 std::error_code InitStream();
357 std::error_code InitStreamFromBuffer();
358 std::error_code InitLazyStream();
359 std::error_code FindFunctionInStream(
360 Function *F,
361 DenseMap<Function *, uint64_t>::iterator DeferredFunctionInfoIterator);
Chris Lattner1314b992007-04-22 06:23:29 +0000362};
Joe Abbey2ad8df22012-11-25 15:23:39 +0000363
Chris Lattner1314b992007-04-22 06:23:29 +0000364} // End llvm namespace
365
366#endif