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"
|
2012-12-04 07:12:27 +00:00
|
|
|
#include "llvm/GVMaterializer.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Attributes.h"
|
|
|
|
#include "llvm/IR/OperandTraits.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
2009-03-31 22:55:09 +00:00
|
|
|
#include "llvm/Support/ValueHandle.h"
|
2007-04-22 06:23:29 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llvm {
|
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;
|
2007-04-29 07:54:31 +00:00
|
|
|
MemoryBuffer *Buffer;
|
2010-01-27 20:34:15 +00:00
|
|
|
bool BufferOwned;
|
2012-02-06 22:30:29 +00:00
|
|
|
OwningPtr<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
|
|
|
|
2007-04-22 06:23:29 +00:00
|
|
|
const char *ErrorString;
|
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;
|
2009-09-18 19:26:43 +00:00
|
|
|
SmallVector<Instruction *, 64> InstructionList;
|
2011-12-07 21:44:12 +00:00
|
|
|
SmallVector<SmallVector<uint64_t, 64>, 64> UseListRecords;
|
2009-09-18 19:26:43 +00:00
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
|
2007-04-22 06:23:29 +00:00
|
|
|
public:
|
2009-12-29 09:01:33 +00:00
|
|
|
explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C)
|
2010-01-27 20:34:15 +00:00
|
|
|
: Context(C), TheModule(0), Buffer(buffer), BufferOwned(false),
|
2012-02-29 00:07:09 +00:00
|
|
|
LazyStreamer(0), NextUnreadBit(0), SeenValueSymbolTable(false),
|
|
|
|
ErrorString(0), ValueList(C), MDValueList(C),
|
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
|
|
|
SeenFirstFunctionBody(false), UseRelativeIDs(false) {
|
2012-02-06 22:30:29 +00:00
|
|
|
}
|
|
|
|
explicit BitcodeReader(DataStreamer *streamer, LLVMContext &C)
|
|
|
|
: Context(C), TheModule(0), Buffer(0), BufferOwned(false),
|
2012-02-29 00:07:09 +00:00
|
|
|
LazyStreamer(streamer), NextUnreadBit(0), SeenValueSymbolTable(false),
|
|
|
|
ErrorString(0), ValueList(C), MDValueList(C),
|
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
|
|
|
SeenFirstFunctionBody(false), UseRelativeIDs(false) {
|
2007-05-01 04:59:48 +00:00
|
|
|
}
|
2007-05-18 04:02:46 +00:00
|
|
|
~BitcodeReader() {
|
|
|
|
FreeState();
|
|
|
|
}
|
2012-01-02 07:49:53 +00:00
|
|
|
|
|
|
|
void materializeForwardReferencedFunctions();
|
|
|
|
|
2007-05-18 04:02:46 +00:00
|
|
|
void FreeState();
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2010-01-27 20:34:15 +00:00
|
|
|
/// setBufferOwned - If this is true, the reader will destroy the MemoryBuffer
|
|
|
|
/// when the reader is destroyed.
|
|
|
|
void setBufferOwned(bool Owned) { BufferOwned = Owned; }
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2010-01-27 20:34:15 +00:00
|
|
|
virtual bool isMaterializable(const GlobalValue *GV) const;
|
|
|
|
virtual bool isDematerializable(const GlobalValue *GV) const;
|
|
|
|
virtual bool Materialize(GlobalValue *GV, std::string *ErrInfo = 0);
|
|
|
|
virtual bool MaterializeModule(Module *M, std::string *ErrInfo = 0);
|
|
|
|
virtual void Dematerialize(GlobalValue *GV);
|
2007-05-15 06:29:44 +00:00
|
|
|
|
2007-04-22 06:23:29 +00:00
|
|
|
bool Error(const char *Str) {
|
|
|
|
ErrorString = Str;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const char *getErrorString() const { return ErrorString; }
|
2012-11-25 15:23:39 +00:00
|
|
|
|
2007-04-22 06:23:29 +00:00
|
|
|
/// @brief Main interface to parsing a bitcode buffer.
|
|
|
|
/// @returns true if an error occurred.
|
2010-01-27 20:34:15 +00:00
|
|
|
bool 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.
|
|
|
|
bool ParseTriple(std::string &Triple);
|
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 {
|
|
|
|
if (ID >= FunctionBBs.size()) return 0; // Invalid ID
|
|
|
|
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.
|
|
|
|
ResVal = getFnValueByID(ValNo, 0);
|
|
|
|
return ResVal == 0;
|
|
|
|
} 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));
|
|
|
|
return ResVal == 0;
|
|
|
|
}
|
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);
|
2007-05-06 00:00:00 +00:00
|
|
|
return ResVal == 0;
|
|
|
|
}
|
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) {
|
|
|
|
if (Slot == Record.size()) return 0;
|
|
|
|
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) {
|
|
|
|
if (Slot == Record.size()) return 0;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-07-26 04:16:55 +00:00
|
|
|
bool ParseAttrKind(uint64_t Code, Attribute::AttrKind *Kind);
|
2012-02-06 22:30:29 +00:00
|
|
|
bool ParseModule(bool Resume);
|
2008-09-25 21:00:45 +00:00
|
|
|
bool ParseAttributeBlock();
|
2013-02-10 23:24:25 +00:00
|
|
|
bool ParseAttributeGroupBlock();
|
2007-05-01 05:01:34 +00:00
|
|
|
bool ParseTypeTable();
|
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
|
|
|
bool ParseTypeTableBody();
|
|
|
|
|
2007-05-01 05:01:34 +00:00
|
|
|
bool ParseValueSymbolTable();
|
|
|
|
bool ParseConstants();
|
2007-05-01 05:52:21 +00:00
|
|
|
bool RememberAndSkipFunctionBody();
|
|
|
|
bool ParseFunctionBody(Function *F);
|
2012-02-06 22:30:29 +00:00
|
|
|
bool GlobalCleanup();
|
2007-04-26 02:46:40 +00:00
|
|
|
bool ResolveGlobalAndAliasInits();
|
2009-07-22 17:43:22 +00:00
|
|
|
bool ParseMetadata();
|
2009-09-18 19:26:43 +00:00
|
|
|
bool ParseMetadataAttachment();
|
2010-10-06 01:22:42 +00:00
|
|
|
bool ParseModuleTriple(std::string &Triple);
|
2011-12-07 21:44:12 +00:00
|
|
|
bool ParseUseLists();
|
2012-02-06 22:30:29 +00:00
|
|
|
bool InitStream();
|
|
|
|
bool InitStreamFromBuffer();
|
|
|
|
bool InitLazyStream();
|
|
|
|
bool 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
|