//
//===----------------------------------------------------------------------===//
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/None.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/Bitcode/BitstreamReader.h"
#include "llvm/Bitcode/LLVMBitCodes.h"
#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/IR/Argument.h"
+#include "llvm/IR/Attributes.h"
#include "llvm/IR/AutoUpgrade.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/CallingConv.h"
#include "llvm/IR/CallSite.h"
+#include "llvm/IR/Comdat.h"
+#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/DiagnosticPrinter.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/GlobalAlias.h"
+#include "llvm/IR/GlobalIFunc.h"
+#include "llvm/IR/GlobalIndirectSymbol.h"
+#include "llvm/IR/GlobalObject.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/GVMaterializer.h"
#include "llvm/IR/InlineAsm.h"
-#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/InstrTypes.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSummaryIndex.h"
#include "llvm/IR/OperandTraits.h"
#include "llvm/IR/Operator.h"
+#include "llvm/IR/TrackingMDRef.h"
+#include "llvm/IR/Type.h"
#include "llvm/IR/ValueHandle.h"
+#include "llvm/Support/AtomicOrdering.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataStream.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/StreamingMemoryObject.h"
+#include <algorithm>
+#include <cassert>
+#include <cstddef>
+#include <cstdint>
#include <deque>
+#include <limits>
+#include <map>
+#include <memory>
+#include <string>
+#include <system_error>
+#include <tuple>
#include <utility>
+#include <vector>
using namespace llvm;
"Print the global id for each value when reading the module summary"));
namespace {
+
enum {
SWITCH_INST_MAGIC = 0x4B5 // May 2012 => 1205 => Hex
};
typedef std::vector<std::pair<Constant*, unsigned> > ResolveConstantsTy;
ResolveConstantsTy ResolveConstants;
LLVMContext &Context;
+
public:
BitcodeReaderValueList(LLVMContext &C) : Context(C) {}
~BitcodeReaderValueList() {
Value *back() const { return ValuePtrs.back(); }
void pop_back() { ValuePtrs.pop_back(); }
bool empty() const { return ValuePtrs.empty(); }
+
void shrinkTo(unsigned N) {
assert(N <= size() && "Invalid shrinkTo request!");
ValuePtrs.resize(N);
} OldTypeRefs;
LLVMContext &Context;
+
public:
BitcodeReaderMetadataList(LLVMContext &C)
: NumFwdRefs(0), AnyFwdRefs(false), Context(C) {}
StructType *createIdentifiedStructType(LLVMContext &Context);
Type *getTypeByID(unsigned ID);
+
Value *getFnValueByID(unsigned ID, Type *Ty) {
if (Ty && Ty->isMetadataTy())
return MetadataAsValue::get(Ty->getContext(), getFnMetadataByID(ID));
return ValueList.getValueFwdRef(ID, Ty);
}
+
Metadata *getFnMetadataByID(unsigned ID) {
return MetadataList.getMetadataFwdRef(ID);
}
+
BasicBlock *getBasicBlock(unsigned ID) const {
if (ID >= FunctionBBs.size()) return nullptr; // Invalid ID
return FunctionBBs[ID];
}
+
AttributeSet getAttributes(unsigned i) const {
if (i-1 < MAttributes.size())
return MAttributes[i-1];
std::error_code initStreamFromBuffer();
std::error_code initLazyStream(std::unique_ptr<DataStreamer> Streamer);
std::pair<GlobalValue::GUID, GlobalValue::GUID>
+
getGUIDFromValueId(unsigned ValueId);
};
+
} // end anonymous namespace
BitcodeDiagnosticInfo::BitcodeDiagnosticInfo(std::error_code EC,
return FMF;
}
-static void upgradeDLLImportExportLinkage(llvm::GlobalValue *GV, unsigned Val) {
+static void upgradeDLLImportExportLinkage(GlobalValue *GV, unsigned Val) {
switch (Val) {
case 5: GV->setDLLStorageClass(GlobalValue::DLLImportStorageClass); break;
case 6: GV->setDLLStorageClass(GlobalValue::DLLExportStorageClass); break;
namespace llvm {
namespace {
+
/// \brief A class for maintaining the slot number definition
/// as a placeholder for the actual definition for forward constants defs.
class ConstantPlaceHolder : public ConstantExpr {
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
};
+
} // end anonymous namespace
// FIXME: can we inherit this from ConstantExpr?
public FixedNumOperandTraits<ConstantPlaceHolder, 1> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantPlaceHolder, Value)
+
} // end namespace llvm
void BitcodeReaderValueList::assignValue(Value *V, unsigned Idx) {
Value *BitcodeReaderValueList::getValueFwdRef(unsigned Idx, Type *Ty) {
// Bail out for a clearly invalid value. This would make us call resize(0)
- if (Idx == UINT_MAX)
+ if (Idx == std::numeric_limits<unsigned>::max())
return nullptr;
if (Idx >= size())
// Functions for parsing blocks from the bitcode file
//===----------------------------------------------------------------------===//
-
/// \brief This fills an AttrBuilder object with the LLVM attributes that have
/// been decoded from the given integer. This function must stay in sync with
/// 'encodeLLVMAttributesForBitcode'.
SmallVector<AttributeSet, 8> Attrs;
// Read all the records.
- while (1) {
+ while (true) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
switch (Entry.Kind) {
SmallVector<uint64_t, 64> Record;
// Read all the records.
- while (1) {
+ while (true) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
switch (Entry.Kind) {
SmallString<64> TypeName;
// Read all the records for this type table.
- while (1) {
+ while (true) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
switch (Entry.Kind) {
SmallVector<uint64_t, 64> Record;
- while (1) {
+ while (true) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
switch (Entry.Kind) {
// Read all the records for this value table.
SmallString<128> ValueName;
- while (1) {
+
+ while (true) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
switch (Entry.Kind) {
}
namespace {
+
class PlaceholderQueue {
// Placeholders would thrash around when moved, so store in a std::deque
// instead of some sort of vector.
DistinctMDOperandPlaceholder &getPlaceholderOp(unsigned ID);
void flush(BitcodeReaderMetadataList &MetadataList);
};
-} // end namespace
+
+} // end anonymous namespace
DistinctMDOperandPlaceholder &PlaceholderQueue::getPlaceholderOp(unsigned ID) {
PHs.emplace_back(ID);
(IsDistinct ? CLASS::getDistinct ARGS : CLASS::get ARGS)
// Read all the records.
- while (1) {
+ while (true) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
switch (Entry.Kind) {
}
}
}
+
#undef GET_OR_DISTINCT
}
SmallVector<uint64_t, 64> Record;
// Read all the records.
- while (1) {
+ while (true) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
switch (Entry.Kind) {
// Read all the records for this value table.
Type *CurTy = Type::getInt32Ty(Context);
unsigned NextCstNo = ValueList.size();
- while (1) {
+
+ while (true) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
switch (Entry.Kind) {
// Read all the records.
SmallVector<uint64_t, 64> Record;
- while (1) {
+
+ while (true) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
switch (Entry.Kind) {
SmallVector<uint64_t, 64> Record;
- while (1) {
+ while (true) {
BitstreamEntry Entry = Stream.advance();
switch (Entry.Kind) {
default:
// Read all the records.
SmallVector<uint64_t, 64> Record;
- while (1) {
+
+ while (true) {
BitstreamEntry Entry = Stream.advance();
switch (Entry.Kind) {
std::vector<std::string> GCTable;
// Read all the records for this module.
- while (1) {
+ while (true) {
BitstreamEntry Entry = Stream.advance();
switch (Entry.Kind) {
// We expect a number of well-defined blocks, though we don't necessarily
// need to understand them all.
- while (1) {
+ while (true) {
if (Stream.AtEndOfStream()) {
// We didn't really read a proper Module.
return error("Malformed IR file");
SmallVector<uint64_t, 64> Record;
std::string Triple;
+
// Read all the records for this module.
- while (1) {
+ while (true) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
switch (Entry.Kind) {
// We expect a number of well-defined blocks, though we don't necessarily
// need to understand them all.
- while (1) {
+ while (true) {
BitstreamEntry Entry = Stream.advance();
switch (Entry.Kind) {
// We expect a number of well-defined blocks, though we don't necessarily
// need to understand them all.
- while (1) {
+ while (true) {
BitstreamEntry Entry = Stream.advance();
switch (Entry.Kind) {
case BitstreamEntry::Error:
// We expect a number of well-defined blocks, though we don't necessarily
// need to understand them all.
- while (1) {
+ while (true) {
BitstreamEntry Entry = Stream.advance();
switch (Entry.Kind) {
SmallVector<uint64_t, 64> Record;
// Read all the records for this module.
- while (1) {
+
+ while (true) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
switch (Entry.Kind) {
return error("Invalid record");
SmallVector<uint64_t, 64> Record;
- while (1) {
+
+ while (true) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
switch (Entry.Kind) {
// Read all the records.
SmallVector<uint64_t, 64> Record;
- while (1) {
+
+ while (true) {
BitstreamEntry Entry = Stream.advance();
switch (Entry.Kind) {
// Read all the records for this value table.
SmallString<128> ValueName;
- while (1) {
+
+ while (true) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
switch (Entry.Kind) {
unsigned ValueId = 0;
// Read the index for this module.
- while (1) {
+ while (true) {
BitstreamEntry Entry = Stream.advance();
switch (Entry.Kind) {
// "OriginalName" attachement.
GlobalValueSummary *LastSeenSummary = nullptr;
bool Combined = false;
- while (1) {
+
+ while (true) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
switch (Entry.Kind) {
SmallString<128> ModulePath;
ModulePathStringTableTy::iterator LastSeenModulePath;
- while (1) {
+
+ while (true) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
switch (Entry.Kind) {
// We expect a number of well-defined blocks, though we don't necessarily
// need to understand them all.
- while (1) {
+ while (true) {
if (Stream.AtEndOfStream()) {
// We didn't really read a proper Module block.
return error("Malformed block");
}
namespace {
+
// FIXME: This class is only here to support the transition to llvm::Error. It
// will be removed once this transition is complete. Clients should prefer to
// deal with the Error value directly, rather than converting to error_code.
llvm_unreachable("Unknown error type!");
}
};
+
} // end anonymous namespace
static ManagedStatic<BitcodeErrorCategoryType> ErrorCategory;
getBitcodeModuleImpl(std::unique_ptr<DataStreamer> Streamer, StringRef Name,
BitcodeReader *R, LLVMContext &Context,
bool MaterializeAll, bool ShouldLazyLoadMetadata) {
- std::unique_ptr<Module> M = make_unique<Module>(Name, Context);
+ std::unique_ptr<Module> M = llvm::make_unique<Module>(Name, Context);
M->setMaterializer(R);
auto cleanupOnError = [&](std::error_code EC) {
llvm::getStreamedBitcodeModule(StringRef Name,
std::unique_ptr<DataStreamer> Streamer,
LLVMContext &Context) {
- std::unique_ptr<Module> M = make_unique<Module>(Name, Context);
+ std::unique_ptr<Module> M = llvm::make_unique<Module>(Name, Context);
BitcodeReader *R = new BitcodeReader(Context);
return getBitcodeModuleImpl(std::move(Streamer), Name, R, Context, false,