2007-04-22 06:23:29 +00:00
|
|
|
//===- BitcodeReader.h - Internal BitcodeReader impl ------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-04-22 06:23:29 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This header defines the BitcodeReader class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef BITCODE_READER_H
|
|
|
|
#define BITCODE_READER_H
|
|
|
|
|
2012-12-04 07:12:27 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2007-05-01 04:59:48 +00:00
|
|
|
#include "llvm/Bitcode/BitstreamReader.h"
|
2007-04-23 01:01:37 +00:00
|
|
|
#include "llvm/Bitcode/LLVMBitCodes.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Attributes.h"
|
2014-03-06 03:50:29 +00:00
|
|
|
#include "llvm/IR/GVMaterializer.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/OperandTraits.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
2014-03-04 11:17:44 +00:00
|
|
|
#include "llvm/IR/ValueHandle.h"
|
2014-06-12 17:38:55 +00:00
|
|
|
#include <system_error>
|
2007-04-22 06:23:29 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llvm {
|
2014-06-27 18:19:56 +00:00
|
|
|
class Comdat;
|
2007-04-29 07:54:31 +00:00
|
|
|
class MemoryBuffer;
|
2009-08-11 17:45:13 +00:00
|
|
|
class LLVMContext;
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// BitcodeReaderValueList Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-09-11 18:05:11 +00:00
|
|
|
class BitcodeReaderValueList {
|
2009-03-31 22:55:09 +00:00
|
|
|
std::vector<WeakVH> ValuePtrs;
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2008-08-21 02:34:16 +00:00
|
|
|
/// ResolveConstants - As we resolve forward-referenced constants, we add
|
|
|
|
/// information about them to this vector. This allows us to resolve them in
|
|
|
|
/// bulk instead of resolving each reference at a time. See the code in
|
|
|
|
/// ResolveConstantForwardRefs for more information about this.
|
|
|
|
///
|
|
|
|
/// The key of this vector is the placeholder constant, the value is the slot
|
|
|
|
/// number that holds the resolved value.
|
|
|
|
typedef std::vector<std::pair<Constant*, unsigned> > ResolveConstantsTy;
|
|
|
|
ResolveConstantsTy ResolveConstants;
|
2011-07-07 05:12:37 +00:00
|
|
|
LLVMContext &Context;
|
2007-04-24 05:48:56 +00:00
|
|
|
public:
|
2011-07-07 05:12:37 +00:00
|
|
|
BitcodeReaderValueList(LLVMContext &C) : Context(C) {}
|
2008-08-21 02:34:16 +00:00
|
|
|
~BitcodeReaderValueList() {
|
|
|
|
assert(ResolveConstants.empty() && "Constants not resolved?");
|
|
|
|
}
|
2008-05-10 08:32:32 +00:00
|
|
|
|
2007-04-24 05:48:56 +00:00
|
|
|
// vector compatibility methods
|
2009-03-31 22:55:09 +00:00
|
|
|
unsigned size() const { return ValuePtrs.size(); }
|
|
|
|
void resize(unsigned N) { ValuePtrs.resize(N); }
|
2007-04-24 05:48:56 +00:00
|
|
|
void push_back(Value *V) {
|
2009-03-31 22:55:09 +00:00
|
|
|
ValuePtrs.push_back(V);
|
2007-04-24 05:48:56 +00:00
|
|
|
}
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2007-05-18 04:02:46 +00:00
|
|
|
void clear() {
|
2008-08-21 02:34:16 +00:00
|
|
|
assert(ResolveConstants.empty() && "Constants not resolved?");
|
2009-03-31 22:55:09 +00:00
|
|
|
ValuePtrs.clear();
|
2007-05-18 04:02:46 +00:00
|
|
|
}
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2009-03-31 22:55:09 +00:00
|
|
|
Value *operator[](unsigned i) const {
|
|
|
|
assert(i < ValuePtrs.size());
|
|
|
|
return ValuePtrs[i];
|
|
|
|
}
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2009-03-31 22:55:09 +00:00
|
|
|
Value *back() const { return ValuePtrs.back(); }
|
|
|
|
void pop_back() { ValuePtrs.pop_back(); }
|
|
|
|
bool empty() const { return ValuePtrs.empty(); }
|
2007-04-26 03:27:58 +00:00
|
|
|
void shrinkTo(unsigned N) {
|
2009-03-31 22:55:09 +00:00
|
|
|
assert(N <= size() && "Invalid shrinkTo request!");
|
|
|
|
ValuePtrs.resize(N);
|
2007-04-26 03:27:58 +00:00
|
|
|
}
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
Constant *getConstantFwdRef(unsigned Idx, Type *Ty);
|
|
|
|
Value *getValueFwdRef(unsigned Idx, Type *Ty);
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2009-03-31 22:55:09 +00:00
|
|
|
void AssignValue(Value *V, unsigned Idx);
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2008-08-21 02:34:16 +00:00
|
|
|
/// ResolveConstantForwardRefs - Once all constants are read, this method bulk
|
|
|
|
/// resolves any forward references.
|
|
|
|
void ResolveConstantForwardRefs();
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
2009-08-04 06:00:18 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// BitcodeReaderMDValueList Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-09-11 18:05:11 +00:00
|
|
|
class BitcodeReaderMDValueList {
|
2009-08-04 06:00:18 +00:00
|
|
|
std::vector<WeakVH> MDValuePtrs;
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2009-10-28 05:53:48 +00:00
|
|
|
LLVMContext &Context;
|
2009-08-04 06:00:18 +00:00
|
|
|
public:
|
|
|
|
BitcodeReaderMDValueList(LLVMContext& C) : Context(C) {}
|
|
|
|
|
|
|
|
// vector compatibility methods
|
|
|
|
unsigned size() const { return MDValuePtrs.size(); }
|
|
|
|
void resize(unsigned N) { MDValuePtrs.resize(N); }
|
|
|
|
void push_back(Value *V) { MDValuePtrs.push_back(V); }
|
|
|
|
void clear() { MDValuePtrs.clear(); }
|
|
|
|
Value *back() const { return MDValuePtrs.back(); }
|
|
|
|
void pop_back() { MDValuePtrs.pop_back(); }
|
|
|
|
bool empty() const { return MDValuePtrs.empty(); }
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2009-08-04 06:00:18 +00:00
|
|
|
Value *operator[](unsigned i) const {
|
|
|
|
assert(i < MDValuePtrs.size());
|
|
|
|
return MDValuePtrs[i];
|
|
|
|
}
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2009-08-04 06:00:18 +00:00
|
|
|
void shrinkTo(unsigned N) {
|
|
|
|
assert(N <= size() && "Invalid shrinkTo request!");
|
|
|
|
MDValuePtrs.resize(N);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *getValueFwdRef(unsigned Idx);
|
|
|
|
void AssignValue(Value *V, unsigned Idx);
|
|
|
|
};
|
|
|
|
|
2013-09-11 18:05:11 +00:00
|
|
|
class BitcodeReader : public GVMaterializer {
|
2009-10-28 05:53:48 +00:00
|
|
|
LLVMContext &Context;
|
2010-01-27 20:34:15 +00:00
|
|
|
Module *TheModule;
|
2014-06-23 21:53:12 +00:00
|
|
|
std::unique_ptr<MemoryBuffer> Buffer;
|
2014-03-06 05:51:42 +00:00
|
|
|
std::unique_ptr<BitstreamReader> StreamFile;
|
2009-04-26 20:59:02 +00:00
|
|
|
BitstreamCursor Stream;
|
2012-02-06 22:30:29 +00:00
|
|
|
DataStreamer *LazyStreamer;
|
|
|
|
uint64_t NextUnreadBit;
|
|
|
|
bool SeenValueSymbolTable;
|
2012-11-25 15:23:39 +00:00
|
|
|
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
std::vector<Type*> TypeList;
|
2007-04-24 05:48:56 +00:00
|
|
|
BitcodeReaderValueList ValueList;
|
2009-08-04 06:00:18 +00:00
|
|
|
BitcodeReaderMDValueList MDValueList;
|
2014-06-27 18:19:56 +00:00
|
|
|
std::vector<Comdat *> ComdatList;
|
2009-09-18 19:26:43 +00:00
|
|
|
SmallVector<Instruction *, 64> InstructionList;
|
|
|
|
|
2007-04-24 03:30:34 +00:00
|
|
|
std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInits;
|
2007-04-26 02:46:40 +00:00
|
|
|
std::vector<std::pair<GlobalAlias*, unsigned> > AliasInits;
|
2013-09-16 01:08:15 +00:00
|
|
|
std::vector<std::pair<Function*, unsigned> > FunctionPrefixes;
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2013-09-28 00:22:27 +00:00
|
|
|
SmallVector<Instruction*, 64> InstsWithTBAATag;
|
|
|
|
|
2008-09-26 22:53:05 +00:00
|
|
|
/// MAttributes - The set of attributes by index. Index zero in the
|
2007-05-04 03:30:17 +00:00
|
|
|
/// file is for null, and is thus not represented here. As such all indices
|
|
|
|
/// are off by one.
|
2012-12-07 23:16:57 +00:00
|
|
|
std::vector<AttributeSet> MAttributes;
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2013-02-10 23:24:25 +00:00
|
|
|
/// \brief The set of attribute groups.
|
2013-02-11 22:32:29 +00:00
|
|
|
std::map<unsigned, AttributeSet> MAttributeGroups;
|
2013-02-10 23:24:25 +00:00
|
|
|
|
2007-05-01 05:52:21 +00:00
|
|
|
/// FunctionBBs - While parsing a function body, this is a list of the basic
|
|
|
|
/// blocks for the function.
|
|
|
|
std::vector<BasicBlock*> FunctionBBs;
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2007-05-01 04:59:48 +00:00
|
|
|
// When reading the module header, this list is populated with functions that
|
|
|
|
// have bodies later in the file.
|
|
|
|
std::vector<Function*> FunctionsWithBodies;
|
2007-08-04 01:51:18 +00:00
|
|
|
|
2012-11-25 15:23:39 +00:00
|
|
|
// When intrinsic functions are encountered which require upgrading they are
|
2007-08-04 01:51:18 +00:00
|
|
|
// stored here with their replacement function.
|
|
|
|
typedef std::vector<std::pair<Function*, Function*> > UpgradedIntrinsicMap;
|
|
|
|
UpgradedIntrinsicMap UpgradedIntrinsics;
|
2010-07-20 21:42:28 +00:00
|
|
|
|
|
|
|
// Map the bitcode's custom MDKind ID to the Module's MDKind ID.
|
|
|
|
DenseMap<unsigned, unsigned> MDKindMap;
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2012-02-06 22:30:29 +00:00
|
|
|
// Several operations happen after the module header has been read, but
|
|
|
|
// before function bodies are processed. This keeps track of whether
|
|
|
|
// we've done this yet.
|
|
|
|
bool SeenFirstFunctionBody;
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2007-05-01 04:59:48 +00:00
|
|
|
/// DeferredFunctionInfo - When function bodies are initially scanned, this
|
2010-01-27 20:34:15 +00:00
|
|
|
/// map contains info about where to find deferred function body in the
|
|
|
|
/// stream.
|
|
|
|
DenseMap<Function*, uint64_t> DeferredFunctionInfo;
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2009-10-28 05:53:48 +00:00
|
|
|
/// BlockAddrFwdRefs - These are blockaddr references to basic blocks. These
|
|
|
|
/// are resolved lazily when functions are loaded.
|
|
|
|
typedef std::pair<unsigned, GlobalVariable*> BlockAddrRefTy;
|
|
|
|
DenseMap<Function*, std::vector<BlockAddrRefTy> > BlockAddrFwdRefs;
|
2010-09-13 18:00:48 +00:00
|
|
|
|
Change encoding of instruction operands in bitcode binaries to be relative
to the instruction position. The old encoding would give an absolute
ID which counts up within a function, and only resets at the next function.
I.e., Instead of having:
... = icmp eq i32 n-1, n-2
br i1 ..., label %bb1, label %bb2
it will now be roughly:
... = icmp eq i32 1, 2
br i1 1, label %bb1, label %bb2
This makes it so that ids remain relatively small and can be encoded
in fewer bits.
With this encoding, forward reference operands will be given
negative-valued IDs. Use signed VBRs for the most common case
of forward references, which is phi instructions.
To retain backward compatibility we bump the bitcode version
from 0 to 1 to distinguish between the different encodings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165739 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-11 20:20:40 +00:00
|
|
|
/// UseRelativeIDs - Indicates that we are using a new encoding for
|
2012-10-11 21:45:16 +00:00
|
|
|
/// instruction operands where most operands in the current
|
Change encoding of instruction operands in bitcode binaries to be relative
to the instruction position. The old encoding would give an absolute
ID which counts up within a function, and only resets at the next function.
I.e., Instead of having:
... = icmp eq i32 n-1, n-2
br i1 ..., label %bb1, label %bb2
it will now be roughly:
... = icmp eq i32 1, 2
br i1 1, label %bb1, label %bb2
This makes it so that ids remain relatively small and can be encoded
in fewer bits.
With this encoding, forward reference operands will be given
negative-valued IDs. Use signed VBRs for the most common case
of forward references, which is phi instructions.
To retain backward compatibility we bump the bitcode version
from 0 to 1 to distinguish between the different encodings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165739 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-11 20:20:40 +00:00
|
|
|
/// FUNCTION_BLOCK are encoded relative to the instruction number,
|
|
|
|
/// for a more compact encoding. Some instruction operands are not
|
|
|
|
/// relative to the instruction ID: basic block numbers, and types.
|
|
|
|
/// Once the old style function blocks have been phased out, we would
|
|
|
|
/// not need this flag.
|
|
|
|
bool UseRelativeIDs;
|
|
|
|
|
2014-08-01 21:11:34 +00:00
|
|
|
/// True if all functions will be materialized, negating the need to process
|
|
|
|
/// (e.g.) blockaddress forward references.
|
|
|
|
bool WillMaterializeAllForwardRefs;
|
|
|
|
|
|
|
|
/// Functions that have block addresses taken. This is usually empty.
|
|
|
|
SmallPtrSet<const Function *, 4> BlockAddressesTaken;
|
|
|
|
|
2007-04-22 06:23:29 +00:00
|
|
|
public:
|
2014-07-29 20:22:46 +00:00
|
|
|
std::error_code Error(BitcodeError E) { return make_error_code(E); }
|
2013-11-04 16:16:24 +00:00
|
|
|
|
2014-06-23 21:53:12 +00:00
|
|
|
explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C)
|
|
|
|
: Context(C), TheModule(nullptr), Buffer(buffer), LazyStreamer(nullptr),
|
|
|
|
NextUnreadBit(0), SeenValueSymbolTable(false), ValueList(C),
|
2014-08-01 21:11:34 +00:00
|
|
|
MDValueList(C), SeenFirstFunctionBody(false), UseRelativeIDs(false),
|
|
|
|
WillMaterializeAllForwardRefs(false) {}
|
2012-02-06 22:30:29 +00:00
|
|
|
explicit BitcodeReader(DataStreamer *streamer, LLVMContext &C)
|
2014-06-23 21:53:12 +00:00
|
|
|
: Context(C), TheModule(nullptr), Buffer(nullptr), LazyStreamer(streamer),
|
|
|
|
NextUnreadBit(0), SeenValueSymbolTable(false), ValueList(C),
|
2014-08-01 21:11:34 +00:00
|
|
|
MDValueList(C), SeenFirstFunctionBody(false), UseRelativeIDs(false),
|
|
|
|
WillMaterializeAllForwardRefs(false) {}
|
2014-06-18 18:26:53 +00:00
|
|
|
~BitcodeReader() { FreeState(); }
|
2012-01-02 07:49:53 +00:00
|
|
|
|
2014-08-01 21:11:34 +00:00
|
|
|
std::error_code materializeForwardReferencedFunctions();
|
2012-01-02 07:49:53 +00:00
|
|
|
|
2007-05-18 04:02:46 +00:00
|
|
|
void FreeState();
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2014-06-23 21:53:12 +00:00
|
|
|
void releaseBuffer() override;
|
2014-06-18 20:07:35 +00:00
|
|
|
|
2014-03-05 07:52:44 +00:00
|
|
|
bool isMaterializable(const GlobalValue *GV) const override;
|
|
|
|
bool isDematerializable(const GlobalValue *GV) const override;
|
2014-06-13 01:25:41 +00:00
|
|
|
std::error_code Materialize(GlobalValue *GV) override;
|
|
|
|
std::error_code MaterializeModule(Module *M) override;
|
2014-03-05 07:52:44 +00:00
|
|
|
void Dematerialize(GlobalValue *GV) override;
|
2007-05-15 06:29:44 +00:00
|
|
|
|
2007-04-22 06:23:29 +00:00
|
|
|
/// @brief Main interface to parsing a bitcode buffer.
|
|
|
|
/// @returns true if an error occurred.
|
2014-06-13 01:25:41 +00:00
|
|
|
std::error_code ParseBitcodeInto(Module *M);
|
2010-10-06 01:22:42 +00:00
|
|
|
|
|
|
|
/// @brief Cheap mechanism to just extract module triple
|
|
|
|
/// @returns true if an error occurred.
|
2014-07-04 20:02:42 +00:00
|
|
|
ErrorOr<std::string> parseTriple();
|
Change encoding of instruction operands in bitcode binaries to be relative
to the instruction position. The old encoding would give an absolute
ID which counts up within a function, and only resets at the next function.
I.e., Instead of having:
... = icmp eq i32 n-1, n-2
br i1 ..., label %bb1, label %bb2
it will now be roughly:
... = icmp eq i32 1, 2
br i1 1, label %bb1, label %bb2
This makes it so that ids remain relatively small and can be encoded
in fewer bits.
With this encoding, forward reference operands will be given
negative-valued IDs. Use signed VBRs for the most common case
of forward references, which is phi instructions.
To retain backward compatibility we bump the bitcode version
from 0 to 1 to distinguish between the different encodings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165739 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-11 20:20:40 +00:00
|
|
|
|
|
|
|
static uint64_t decodeSignRotatedValue(uint64_t V);
|
|
|
|
|
2007-04-22 06:23:29 +00:00
|
|
|
private:
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
Type *getTypeByID(unsigned ID);
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *getFnValueByID(unsigned ID, Type *Ty) {
|
2011-07-07 05:29:18 +00:00
|
|
|
if (Ty && Ty->isMetadataTy())
|
2009-08-04 06:00:18 +00:00
|
|
|
return MDValueList.getValueFwdRef(ID);
|
2011-07-07 05:12:37 +00:00
|
|
|
return ValueList.getValueFwdRef(ID, Ty);
|
2007-05-01 07:01:57 +00:00
|
|
|
}
|
2007-05-02 05:46:45 +00:00
|
|
|
BasicBlock *getBasicBlock(unsigned ID) const {
|
2014-04-28 04:05:08 +00:00
|
|
|
if (ID >= FunctionBBs.size()) return nullptr; // Invalid ID
|
2007-05-02 05:46:45 +00:00
|
|
|
return FunctionBBs[ID];
|
|
|
|
}
|
2012-12-07 23:16:57 +00:00
|
|
|
AttributeSet getAttributes(unsigned i) const {
|
2008-09-26 22:53:05 +00:00
|
|
|
if (i-1 < MAttributes.size())
|
|
|
|
return MAttributes[i-1];
|
2012-12-07 23:16:57 +00:00
|
|
|
return AttributeSet();
|
2007-05-04 03:30:17 +00:00
|
|
|
}
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2007-05-06 00:00:00 +00:00
|
|
|
/// getValueTypePair - Read a value/type pair out of the specified record from
|
|
|
|
/// slot 'Slot'. Increment Slot past the number of slots used in the record.
|
|
|
|
/// Return true on failure.
|
2013-07-11 16:22:38 +00:00
|
|
|
bool getValueTypePair(SmallVectorImpl<uint64_t> &Record, unsigned &Slot,
|
2007-05-06 00:00:00 +00:00
|
|
|
unsigned InstNum, Value *&ResVal) {
|
|
|
|
if (Slot == Record.size()) return true;
|
2007-05-06 03:23:14 +00:00
|
|
|
unsigned ValNo = (unsigned)Record[Slot++];
|
Change encoding of instruction operands in bitcode binaries to be relative
to the instruction position. The old encoding would give an absolute
ID which counts up within a function, and only resets at the next function.
I.e., Instead of having:
... = icmp eq i32 n-1, n-2
br i1 ..., label %bb1, label %bb2
it will now be roughly:
... = icmp eq i32 1, 2
br i1 1, label %bb1, label %bb2
This makes it so that ids remain relatively small and can be encoded
in fewer bits.
With this encoding, forward reference operands will be given
negative-valued IDs. Use signed VBRs for the most common case
of forward references, which is phi instructions.
To retain backward compatibility we bump the bitcode version
from 0 to 1 to distinguish between the different encodings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165739 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-11 20:20:40 +00:00
|
|
|
// Adjust the ValNo, if it was encoded relative to the InstNum.
|
|
|
|
if (UseRelativeIDs)
|
|
|
|
ValNo = InstNum - ValNo;
|
2007-05-06 00:00:00 +00:00
|
|
|
if (ValNo < InstNum) {
|
|
|
|
// If this is not a forward reference, just return the value we already
|
|
|
|
// have.
|
2014-04-28 04:05:08 +00:00
|
|
|
ResVal = getFnValueByID(ValNo, nullptr);
|
|
|
|
return ResVal == nullptr;
|
2007-05-06 00:00:00 +00:00
|
|
|
} else if (Slot == Record.size()) {
|
|
|
|
return true;
|
|
|
|
}
|
Change encoding of instruction operands in bitcode binaries to be relative
to the instruction position. The old encoding would give an absolute
ID which counts up within a function, and only resets at the next function.
I.e., Instead of having:
... = icmp eq i32 n-1, n-2
br i1 ..., label %bb1, label %bb2
it will now be roughly:
... = icmp eq i32 1, 2
br i1 1, label %bb1, label %bb2
This makes it so that ids remain relatively small and can be encoded
in fewer bits.
With this encoding, forward reference operands will be given
negative-valued IDs. Use signed VBRs for the most common case
of forward references, which is phi instructions.
To retain backward compatibility we bump the bitcode version
from 0 to 1 to distinguish between the different encodings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165739 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-11 20:20:40 +00:00
|
|
|
|
2007-05-06 03:23:14 +00:00
|
|
|
unsigned TypeNo = (unsigned)Record[Slot++];
|
2007-05-06 00:00:00 +00:00
|
|
|
ResVal = getFnValueByID(ValNo, getTypeByID(TypeNo));
|
2014-04-28 04:05:08 +00:00
|
|
|
return ResVal == nullptr;
|
2007-05-06 00:00:00 +00:00
|
|
|
}
|
Change encoding of instruction operands in bitcode binaries to be relative
to the instruction position. The old encoding would give an absolute
ID which counts up within a function, and only resets at the next function.
I.e., Instead of having:
... = icmp eq i32 n-1, n-2
br i1 ..., label %bb1, label %bb2
it will now be roughly:
... = icmp eq i32 1, 2
br i1 1, label %bb1, label %bb2
This makes it so that ids remain relatively small and can be encoded
in fewer bits.
With this encoding, forward reference operands will be given
negative-valued IDs. Use signed VBRs for the most common case
of forward references, which is phi instructions.
To retain backward compatibility we bump the bitcode version
from 0 to 1 to distinguish between the different encodings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165739 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-11 20:20:40 +00:00
|
|
|
|
|
|
|
/// popValue - Read a value out of the specified record from slot 'Slot'.
|
|
|
|
/// Increment Slot past the number of slots used by the value in the record.
|
|
|
|
/// Return true if there is an error.
|
2013-07-11 16:22:38 +00:00
|
|
|
bool popValue(SmallVectorImpl<uint64_t> &Record, unsigned &Slot,
|
Change encoding of instruction operands in bitcode binaries to be relative
to the instruction position. The old encoding would give an absolute
ID which counts up within a function, and only resets at the next function.
I.e., Instead of having:
... = icmp eq i32 n-1, n-2
br i1 ..., label %bb1, label %bb2
it will now be roughly:
... = icmp eq i32 1, 2
br i1 1, label %bb1, label %bb2
This makes it so that ids remain relatively small and can be encoded
in fewer bits.
With this encoding, forward reference operands will be given
negative-valued IDs. Use signed VBRs for the most common case
of forward references, which is phi instructions.
To retain backward compatibility we bump the bitcode version
from 0 to 1 to distinguish between the different encodings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165739 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-11 20:20:40 +00:00
|
|
|
unsigned InstNum, Type *Ty, Value *&ResVal) {
|
|
|
|
if (getValue(Record, Slot, InstNum, Ty, ResVal))
|
|
|
|
return true;
|
|
|
|
// All values currently take a single record slot.
|
|
|
|
++Slot;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getValue -- Like popValue, but does not increment the Slot number.
|
2013-07-11 16:22:38 +00:00
|
|
|
bool getValue(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
|
Change encoding of instruction operands in bitcode binaries to be relative
to the instruction position. The old encoding would give an absolute
ID which counts up within a function, and only resets at the next function.
I.e., Instead of having:
... = icmp eq i32 n-1, n-2
br i1 ..., label %bb1, label %bb2
it will now be roughly:
... = icmp eq i32 1, 2
br i1 1, label %bb1, label %bb2
This makes it so that ids remain relatively small and can be encoded
in fewer bits.
With this encoding, forward reference operands will be given
negative-valued IDs. Use signed VBRs for the most common case
of forward references, which is phi instructions.
To retain backward compatibility we bump the bitcode version
from 0 to 1 to distinguish between the different encodings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165739 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-11 20:20:40 +00:00
|
|
|
unsigned InstNum, Type *Ty, Value *&ResVal) {
|
|
|
|
ResVal = getValue(Record, Slot, InstNum, Ty);
|
2014-04-28 04:05:08 +00:00
|
|
|
return ResVal == nullptr;
|
2007-05-06 00:00:00 +00:00
|
|
|
}
|
2007-05-04 03:30:17 +00:00
|
|
|
|
Change encoding of instruction operands in bitcode binaries to be relative
to the instruction position. The old encoding would give an absolute
ID which counts up within a function, and only resets at the next function.
I.e., Instead of having:
... = icmp eq i32 n-1, n-2
br i1 ..., label %bb1, label %bb2
it will now be roughly:
... = icmp eq i32 1, 2
br i1 1, label %bb1, label %bb2
This makes it so that ids remain relatively small and can be encoded
in fewer bits.
With this encoding, forward reference operands will be given
negative-valued IDs. Use signed VBRs for the most common case
of forward references, which is phi instructions.
To retain backward compatibility we bump the bitcode version
from 0 to 1 to distinguish between the different encodings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165739 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-11 20:20:40 +00:00
|
|
|
/// getValue -- Version of getValue that returns ResVal directly,
|
|
|
|
/// or 0 if there is an error.
|
2013-07-11 16:22:38 +00:00
|
|
|
Value *getValue(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
|
Change encoding of instruction operands in bitcode binaries to be relative
to the instruction position. The old encoding would give an absolute
ID which counts up within a function, and only resets at the next function.
I.e., Instead of having:
... = icmp eq i32 n-1, n-2
br i1 ..., label %bb1, label %bb2
it will now be roughly:
... = icmp eq i32 1, 2
br i1 1, label %bb1, label %bb2
This makes it so that ids remain relatively small and can be encoded
in fewer bits.
With this encoding, forward reference operands will be given
negative-valued IDs. Use signed VBRs for the most common case
of forward references, which is phi instructions.
To retain backward compatibility we bump the bitcode version
from 0 to 1 to distinguish between the different encodings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165739 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-11 20:20:40 +00:00
|
|
|
unsigned InstNum, Type *Ty) {
|
2014-04-28 04:05:08 +00:00
|
|
|
if (Slot == Record.size()) return nullptr;
|
Change encoding of instruction operands in bitcode binaries to be relative
to the instruction position. The old encoding would give an absolute
ID which counts up within a function, and only resets at the next function.
I.e., Instead of having:
... = icmp eq i32 n-1, n-2
br i1 ..., label %bb1, label %bb2
it will now be roughly:
... = icmp eq i32 1, 2
br i1 1, label %bb1, label %bb2
This makes it so that ids remain relatively small and can be encoded
in fewer bits.
With this encoding, forward reference operands will be given
negative-valued IDs. Use signed VBRs for the most common case
of forward references, which is phi instructions.
To retain backward compatibility we bump the bitcode version
from 0 to 1 to distinguish between the different encodings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165739 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-11 20:20:40 +00:00
|
|
|
unsigned ValNo = (unsigned)Record[Slot];
|
|
|
|
// Adjust the ValNo, if it was encoded relative to the InstNum.
|
|
|
|
if (UseRelativeIDs)
|
|
|
|
ValNo = InstNum - ValNo;
|
|
|
|
return getFnValueByID(ValNo, Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getValueSigned -- Like getValue, but decodes signed VBRs.
|
2013-07-11 16:22:38 +00:00
|
|
|
Value *getValueSigned(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
|
Change encoding of instruction operands in bitcode binaries to be relative
to the instruction position. The old encoding would give an absolute
ID which counts up within a function, and only resets at the next function.
I.e., Instead of having:
... = icmp eq i32 n-1, n-2
br i1 ..., label %bb1, label %bb2
it will now be roughly:
... = icmp eq i32 1, 2
br i1 1, label %bb1, label %bb2
This makes it so that ids remain relatively small and can be encoded
in fewer bits.
With this encoding, forward reference operands will be given
negative-valued IDs. Use signed VBRs for the most common case
of forward references, which is phi instructions.
To retain backward compatibility we bump the bitcode version
from 0 to 1 to distinguish between the different encodings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165739 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-11 20:20:40 +00:00
|
|
|
unsigned InstNum, Type *Ty) {
|
2014-04-28 04:05:08 +00:00
|
|
|
if (Slot == Record.size()) return nullptr;
|
Change encoding of instruction operands in bitcode binaries to be relative
to the instruction position. The old encoding would give an absolute
ID which counts up within a function, and only resets at the next function.
I.e., Instead of having:
... = icmp eq i32 n-1, n-2
br i1 ..., label %bb1, label %bb2
it will now be roughly:
... = icmp eq i32 1, 2
br i1 1, label %bb1, label %bb2
This makes it so that ids remain relatively small and can be encoded
in fewer bits.
With this encoding, forward reference operands will be given
negative-valued IDs. Use signed VBRs for the most common case
of forward references, which is phi instructions.
To retain backward compatibility we bump the bitcode version
from 0 to 1 to distinguish between the different encodings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165739 91177308-0d34-0410-b5e6-96231b3b80d8
2012-10-11 20:20:40 +00:00
|
|
|
unsigned ValNo = (unsigned)decodeSignRotatedValue(Record[Slot]);
|
|
|
|
// Adjust the ValNo, if it was encoded relative to the InstNum.
|
|
|
|
if (UseRelativeIDs)
|
|
|
|
ValNo = InstNum - ValNo;
|
|
|
|
return getFnValueByID(ValNo, Ty);
|
|
|
|
}
|
|
|
|
|
2014-06-13 01:25:41 +00:00
|
|
|
std::error_code ParseAttrKind(uint64_t Code, Attribute::AttrKind *Kind);
|
|
|
|
std::error_code ParseModule(bool Resume);
|
|
|
|
std::error_code ParseAttributeBlock();
|
|
|
|
std::error_code ParseAttributeGroupBlock();
|
|
|
|
std::error_code ParseTypeTable();
|
|
|
|
std::error_code ParseTypeTableBody();
|
|
|
|
|
|
|
|
std::error_code ParseValueSymbolTable();
|
|
|
|
std::error_code ParseConstants();
|
|
|
|
std::error_code RememberAndSkipFunctionBody();
|
|
|
|
std::error_code ParseFunctionBody(Function *F);
|
|
|
|
std::error_code GlobalCleanup();
|
|
|
|
std::error_code ResolveGlobalAndAliasInits();
|
|
|
|
std::error_code ParseMetadata();
|
|
|
|
std::error_code ParseMetadataAttachment();
|
2014-07-04 20:02:42 +00:00
|
|
|
ErrorOr<std::string> parseModuleTriple();
|
2014-06-13 01:25:41 +00:00
|
|
|
std::error_code ParseUseLists();
|
|
|
|
std::error_code InitStream();
|
|
|
|
std::error_code InitStreamFromBuffer();
|
|
|
|
std::error_code InitLazyStream();
|
|
|
|
std::error_code FindFunctionInStream(
|
|
|
|
Function *F,
|
|
|
|
DenseMap<Function *, uint64_t>::iterator DeferredFunctionInfoIterator);
|
2007-04-22 06:23:29 +00:00
|
|
|
};
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2007-04-22 06:23:29 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|