14 #ifndef BITCODE_READER_H
15 #define BITCODE_READER_H
37 std::vector<WeakVH> ValuePtrs;
46 typedef std::vector<std::pair<Constant*, unsigned> > ResolveConstantsTy;
47 ResolveConstantsTy ResolveConstants;
52 assert(ResolveConstants.empty() &&
"Constants not resolved?");
56 unsigned size()
const {
return ValuePtrs.size(); }
57 void resize(
unsigned N) { ValuePtrs.resize(N); }
59 ValuePtrs.push_back(V);
63 assert(ResolveConstants.empty() &&
"Constants not resolved?");
68 assert(i < ValuePtrs.size());
74 bool empty()
const {
return ValuePtrs.empty(); }
76 assert(N <=
size() &&
"Invalid shrinkTo request!");
96 std::vector<WeakVH> MDValuePtrs;
103 unsigned size()
const {
return MDValuePtrs.size(); }
104 void resize(
unsigned N) { MDValuePtrs.resize(N); }
106 void clear() { MDValuePtrs.clear(); }
109 bool empty()
const {
return MDValuePtrs.empty(); }
112 assert(i < MDValuePtrs.size());
113 return MDValuePtrs[i];
117 assert(N <=
size() &&
"Invalid shrinkTo request!");
118 MDValuePtrs.resize(N);
133 uint64_t NextUnreadBit;
134 bool SeenValueSymbolTable;
136 std::vector<Type*> TypeList;
142 std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInits;
143 std::vector<std::pair<GlobalAlias*, unsigned> > AliasInits;
144 std::vector<std::pair<Function*, unsigned> > FunctionPrefixes;
151 std::vector<AttributeSet> MAttributes;
154 std::map<unsigned, AttributeSet> MAttributeGroups;
158 std::vector<BasicBlock*> FunctionBBs;
162 std::vector<Function*> FunctionsWithBodies;
166 typedef std::vector<std::pair<Function*, Function*> > UpgradedIntrinsicMap;
167 UpgradedIntrinsicMap UpgradedIntrinsics;
175 bool SeenFirstFunctionBody;
184 typedef std::pair<unsigned, GlobalVariable*> BlockAddrRefTy;
227 : Context(C), TheModule(0), Buffer(buffer), BufferOwned(
false),
228 LazyStreamer(0), NextUnreadBit(0), SeenValueSymbolTable(
false),
229 ValueList(C), MDValueList(C),
230 SeenFirstFunctionBody(
false), UseRelativeIDs(
false) {
233 : Context(C), TheModule(0), Buffer(0), BufferOwned(
false),
234 LazyStreamer(streamer), NextUnreadBit(0), SeenValueSymbolTable(
false),
235 ValueList(C), MDValueList(C),
236 SeenFirstFunctionBody(
false), UseRelativeIDs(
false) {
267 Type *getTypeByID(
unsigned ID);
273 BasicBlock *getBasicBlock(
unsigned ID)
const {
274 if (ID >= FunctionBBs.size())
return 0;
275 return FunctionBBs[
ID];
277 AttributeSet getAttributes(
unsigned i)
const {
278 if (i-1 < MAttributes.size())
279 return MAttributes[i-1];
280 return AttributeSet();
286 bool getValueTypePair(SmallVectorImpl<uint64_t> &Record,
unsigned &Slot,
287 unsigned InstNum, Value *&ResVal) {
288 if (Slot == Record.size())
return true;
289 unsigned ValNo = (
unsigned)Record[Slot++];
292 ValNo = InstNum - ValNo;
293 if (ValNo < InstNum) {
296 ResVal = getFnValueByID(ValNo, 0);
298 }
else if (Slot == Record.size()) {
302 unsigned TypeNo = (
unsigned)Record[Slot++];
303 ResVal = getFnValueByID(ValNo, getTypeByID(TypeNo));
310 bool popValue(SmallVectorImpl<uint64_t> &Record,
unsigned &Slot,
311 unsigned InstNum,
Type *Ty, Value *&ResVal) {
312 if (getValue(Record, Slot, InstNum, Ty, ResVal))
320 bool getValue(SmallVectorImpl<uint64_t> &Record,
unsigned Slot,
321 unsigned InstNum,
Type *Ty, Value *&ResVal) {
322 ResVal = getValue(Record, Slot, InstNum, Ty);
328 Value *getValue(SmallVectorImpl<uint64_t> &Record,
unsigned Slot,
329 unsigned InstNum,
Type *Ty) {
330 if (Slot == Record.size())
return 0;
331 unsigned ValNo = (
unsigned)Record[Slot];
334 ValNo = InstNum - ValNo;
335 return getFnValueByID(ValNo, Ty);
339 Value *getValueSigned(SmallVectorImpl<uint64_t> &Record,
unsigned Slot,
340 unsigned InstNum,
Type *Ty) {
341 if (Slot == Record.size())
return 0;
345 ValNo = InstNum - ValNo;
346 return getFnValueByID(ValNo, Ty);
350 error_code ParseModule(
bool Resume);
351 error_code ParseAttributeBlock();
352 error_code ParseAttributeGroupBlock();
353 error_code ParseTypeTable();
354 error_code ParseTypeTableBody();
356 error_code ParseValueSymbolTable();
357 error_code ParseConstants();
358 error_code RememberAndSkipFunctionBody();
359 error_code ParseFunctionBody(Function *
F);
360 error_code GlobalCleanup();
361 error_code ResolveGlobalAndAliasInits();
362 error_code ParseMetadata();
363 error_code ParseMetadataAttachment();
364 error_code ParseModuleTriple(std::string &Triple);
365 error_code ParseUseLists();
366 error_code InitStream();
367 error_code InitStreamFromBuffer();
368 error_code InitLazyStream();
369 error_code FindFunctionInStream(Function *
F,
370 DenseMap<Function*, uint64_t>::iterator DeferredFunctionInfoIterator);
COFF::RelocationTypeX86 Type
static uint64_t decodeSignRotatedValue(uint64_t V)
The main container class for the LLVM Intermediate Representation.
BitcodeReaderValueList(LLVMContext &C)
Value * operator[](unsigned i) const
BitcodeReaderMDValueList(LLVMContext &C)
BitcodeReader(DataStreamer *streamer, LLVMContext &C)
BitcodeReader(MemoryBuffer *buffer, LLVMContext &C)
void AssignValue(Value *V, unsigned Idx)
void shrinkTo(unsigned N)
Value * getValueFwdRef(unsigned Idx, Type *Ty)
This file contains the simple types necessary to represent the attributes associated with functions a...
ID
LLVM Calling Convention Representation.
void ResolveConstantForwardRefs()
void AssignValue(Value *V, unsigned Idx)
Value * getValueFwdRef(unsigned Idx)
void shrinkTo(unsigned N)
error_code Error(ErrorType E)
virtual error_code Materialize(GlobalValue *GV)
LLVM Constant Representation.
Value * operator[](unsigned i) const
error_code ParseTriple(std::string &Triple)
Cheap mechanism to just extract module triple.
Constant * getConstantFwdRef(unsigned Idx, Type *Ty)
~BitcodeReaderValueList()
error_code ParseBitcodeInto(Module *M)
Main interface to parsing a bitcode buffer.
void setBufferOwned(bool Owned)
virtual bool isDematerializable(const GlobalValue *GV) const
virtual bool isMaterializable(const GlobalValue *GV) const
virtual void Dematerialize(GlobalValue *GV)
void materializeForwardReferencedFunctions()
LLVM Value Representation.
virtual error_code MaterializeModule(Module *M)
bool isMetadataTy() const
isMetadataTy - Return true if this is 'metadata'.