aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Bitcode
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2014-04-23 16:57:46 -0700
committerStephen Hines <srhines@google.com>2014-04-24 15:53:16 -0700
commit36b56886974eae4f9c5ebc96befd3e7bfe5de338 (patch)
treee6cfb69fbbd937f450eeb83bfb83b9da3b01275a /lib/Bitcode
parent69a8640022b04415ae9fac62f8ab090601d8f889 (diff)
downloadexternal_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.zip
external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.gz
external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.bz2
Update to LLVM 3.5a.
Change-Id: Ifadecab779f128e62e430c2b4f6ddd84953ed617
Diffstat (limited to 'lib/Bitcode')
-rw-r--r--lib/Bitcode/Reader/Android.mk2
-rw-r--r--lib/Bitcode/Reader/BitReader.cpp23
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp129
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.h16
-rw-r--r--lib/Bitcode/Writer/Android.mk2
-rw-r--r--lib/Bitcode/Writer/BitWriter.cpp2
-rw-r--r--lib/Bitcode/Writer/BitcodeWriter.cpp45
-rw-r--r--lib/Bitcode/Writer/BitcodeWriterPass.cpp16
-rw-r--r--lib/Bitcode/Writer/ValueEnumerator.cpp37
9 files changed, 161 insertions, 111 deletions
diff --git a/lib/Bitcode/Reader/Android.mk b/lib/Bitcode/Reader/Android.mk
index 6e95cbc..3bdcdda 100644
--- a/lib/Bitcode/Reader/Android.mk
+++ b/lib/Bitcode/Reader/Android.mk
@@ -22,6 +22,7 @@ include $(BUILD_HOST_STATIC_LIBRARY)
# For the device
# =====================================================
include $(CLEAR_VARS)
+ifneq (true,$(DISABLE_LLVM_DEVICE_BUILDS))
LOCAL_SRC_FILES := $(bitcode_reader_SRC_FILES)
@@ -32,3 +33,4 @@ LOCAL_MODULE_TAGS := optional
include $(LLVM_DEVICE_BUILD_MK)
include $(LLVM_GEN_INTRINSICS_MK)
include $(BUILD_STATIC_LIBRARY)
+endif
diff --git a/lib/Bitcode/Reader/BitReader.cpp b/lib/Bitcode/Reader/BitReader.cpp
index 23630e5..3e360a8 100644
--- a/lib/Bitcode/Reader/BitReader.cpp
+++ b/lib/Bitcode/Reader/BitReader.cpp
@@ -30,16 +30,16 @@ LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef,
LLVMMemoryBufferRef MemBuf,
LLVMModuleRef *OutModule,
char **OutMessage) {
- std::string Message;
-
- *OutModule = wrap(ParseBitcodeFile(unwrap(MemBuf), *unwrap(ContextRef),
- &Message));
- if (!*OutModule) {
+ ErrorOr<Module *> ModuleOrErr =
+ parseBitcodeFile(unwrap(MemBuf), *unwrap(ContextRef));
+ if (error_code EC = ModuleOrErr.getError()) {
if (OutMessage)
- *OutMessage = strdup(Message.c_str());
+ *OutMessage = strdup(EC.message().c_str());
+ *OutModule = wrap((Module*)0);
return 1;
}
+ *OutModule = wrap(ModuleOrErr.get());
return 0;
}
@@ -51,15 +51,18 @@ LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef,
LLVMModuleRef *OutM,
char **OutMessage) {
std::string Message;
+ ErrorOr<Module *> ModuleOrErr =
+ getLazyBitcodeModule(unwrap(MemBuf), *unwrap(ContextRef));
- *OutM = wrap(getLazyBitcodeModule(unwrap(MemBuf), *unwrap(ContextRef),
- &Message));
- if (!*OutM) {
+ if (error_code EC = ModuleOrErr.getError()) {
+ *OutM = wrap((Module *)NULL);
if (OutMessage)
- *OutMessage = strdup(Message.c_str());
+ *OutMessage = strdup(EC.message().c_str());
return 1;
}
+ *OutM = wrap(ModuleOrErr.get());
+
return 0;
}
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index ce3b7d1..f712d9d 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -11,8 +11,8 @@
#include "BitcodeReader.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
-#include "llvm/AutoUpgrade.h"
#include "llvm/Bitcode/LLVMBitCodes.h"
+#include "llvm/IR/AutoUpgrade.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/InlineAsm.h"
@@ -80,16 +80,18 @@ static GlobalValue::LinkageTypes GetDecodedLinkage(unsigned Val) {
case 2: return GlobalValue::AppendingLinkage;
case 3: return GlobalValue::InternalLinkage;
case 4: return GlobalValue::LinkOnceAnyLinkage;
- case 5: return GlobalValue::DLLImportLinkage;
- case 6: return GlobalValue::DLLExportLinkage;
+ case 5: return GlobalValue::ExternalLinkage; // Obsolete DLLImportLinkage
+ case 6: return GlobalValue::ExternalLinkage; // Obsolete DLLExportLinkage
case 7: return GlobalValue::ExternalWeakLinkage;
case 8: return GlobalValue::CommonLinkage;
case 9: return GlobalValue::PrivateLinkage;
case 10: return GlobalValue::WeakODRLinkage;
case 11: return GlobalValue::LinkOnceODRLinkage;
case 12: return GlobalValue::AvailableExternallyLinkage;
- case 13: return GlobalValue::LinkerPrivateLinkage;
- case 14: return GlobalValue::LinkerPrivateWeakLinkage;
+ case 13:
+ return GlobalValue::PrivateLinkage; // Obsolete LinkerPrivateLinkage
+ case 14:
+ return GlobalValue::PrivateLinkage; // Obsolete LinkerPrivateWeakLinkage
}
}
@@ -102,6 +104,16 @@ static GlobalValue::VisibilityTypes GetDecodedVisibility(unsigned Val) {
}
}
+static GlobalValue::DLLStorageClassTypes
+GetDecodedDLLStorageClass(unsigned Val) {
+ switch (Val) {
+ default: // Map unknown values to default.
+ case 0: return GlobalValue::DefaultStorageClass;
+ case 1: return GlobalValue::DLLImportStorageClass;
+ case 2: return GlobalValue::DLLExportStorageClass;
+ }
+}
+
static GlobalVariable::ThreadLocalMode GetDecodedThreadLocalMode(unsigned Val) {
switch (Val) {
case 0: return GlobalVariable::NotThreadLocal;
@@ -193,6 +205,13 @@ static SynchronizationScope GetDecodedSynchScope(unsigned Val) {
}
}
+static void UpgradeDLLImportExportLinkage(llvm::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
@@ -315,7 +334,7 @@ void BitcodeReaderValueList::ResolveConstantForwardRefs() {
// new value. If they reference more than one placeholder, update them all
// at once.
while (!Placeholder->use_empty()) {
- Value::use_iterator UI = Placeholder->use_begin();
+ auto UI = Placeholder->user_begin();
User *U = *UI;
// If the using object isn't uniqued, just update the operands. This
@@ -522,6 +541,8 @@ static Attribute::AttrKind GetAttrFromCode(uint64_t Code) {
return Attribute::Builtin;
case bitc::ATTR_KIND_BY_VAL:
return Attribute::ByVal;
+ case bitc::ATTR_KIND_IN_ALLOCA:
+ return Attribute::InAlloca;
case bitc::ATTR_KIND_COLD:
return Attribute::Cold;
case bitc::ATTR_KIND_INLINE_HINT:
@@ -939,7 +960,7 @@ error_code BitcodeReader::ParseValueSymbolTable() {
if (ConvertToString(Record, 1, ValueName))
return Error(InvalidRecord);
unsigned ValueID = Record[0];
- if (ValueID >= ValueList.size())
+ if (ValueID >= ValueList.size() || !ValueList[ValueID])
return Error(InvalidRecord);
Value *V = ValueList[ValueID];
@@ -1006,7 +1027,7 @@ error_code BitcodeReader::ParseMetadata() {
unsigned Size = Record.size();
NamedMDNode *NMD = TheModule->getOrInsertNamedMetadata(Name);
for (unsigned i = 0; i != Size; ++i) {
- MDNode *MD = dyn_cast<MDNode>(MDValueList.getValueFwdRef(Record[i]));
+ MDNode *MD = dyn_cast_or_null<MDNode>(MDValueList.getValueFwdRef(Record[i]));
if (MD == 0)
return Error(InvalidRecord);
NMD->addOperand(MD);
@@ -1088,7 +1109,7 @@ error_code BitcodeReader::ResolveGlobalAndAliasInits() {
// Not ready to resolve this yet, it requires something later in the file.
GlobalInits.push_back(GlobalInitWorklist.back());
} else {
- if (Constant *C = dyn_cast<Constant>(ValueList[ValID]))
+ if (Constant *C = dyn_cast_or_null<Constant>(ValueList[ValID]))
GlobalInitWorklist.back().first->setInitializer(C);
else
return Error(ExpectedConstant);
@@ -1101,7 +1122,7 @@ error_code BitcodeReader::ResolveGlobalAndAliasInits() {
if (ValID >= ValueList.size()) {
AliasInits.push_back(AliasInitWorklist.back());
} else {
- if (Constant *C = dyn_cast<Constant>(ValueList[ValID]))
+ if (Constant *C = dyn_cast_or_null<Constant>(ValueList[ValID]))
AliasInitWorklist.back().first->setAliasee(C);
else
return Error(ExpectedConstant);
@@ -1114,7 +1135,7 @@ error_code BitcodeReader::ResolveGlobalAndAliasInits() {
if (ValID >= ValueList.size()) {
FunctionPrefixes.push_back(FunctionPrefixWorklist.back());
} else {
- if (Constant *C = dyn_cast<Constant>(ValueList[ValID]))
+ if (Constant *C = dyn_cast_or_null<Constant>(ValueList[ValID]))
FunctionPrefixWorklist.back().first->setPrefixData(C);
else
return Error(ExpectedConstant);
@@ -1174,7 +1195,7 @@ error_code BitcodeReader::ParseConstants() {
case bitc::CST_CODE_SETTYPE: // SETTYPE: [typeid]
if (Record.empty())
return Error(InvalidRecord);
- if (Record[0] >= TypeList.size())
+ if (Record[0] >= TypeList.size() || !TypeList[Record[0]])
return Error(InvalidRecord);
CurTy = TypeList[Record[0]];
continue; // Skip the ValueList manipulation.
@@ -1795,7 +1816,7 @@ error_code BitcodeReader::ParseModule(bool Resume) {
}
// GLOBALVAR: [pointer type, isconst, initid,
// linkage, alignment, section, visibility, threadlocal,
- // unnamed_addr]
+ // unnamed_addr, dllstorageclass]
case bitc::MODULE_CODE_GLOBALVAR: {
if (Record.size() < 6)
return Error(InvalidRecord);
@@ -1841,6 +1862,11 @@ error_code BitcodeReader::ParseModule(bool Resume) {
NewGV->setVisibility(Visibility);
NewGV->setUnnamedAddr(UnnamedAddr);
+ if (Record.size() > 10)
+ NewGV->setDLLStorageClass(GetDecodedDLLStorageClass(Record[10]));
+ else
+ UpgradeDLLImportExportLinkage(NewGV, Record[3]);
+
ValueList.push_back(NewGV);
// Remember which value to use for the global initializer.
@@ -1849,7 +1875,8 @@ error_code BitcodeReader::ParseModule(bool Resume) {
break;
}
// FUNCTION: [type, callingconv, isproto, linkage, paramattr,
- // alignment, section, visibility, gc, unnamed_addr]
+ // alignment, section, visibility, gc, unnamed_addr,
+ // dllstorageclass]
case bitc::MODULE_CODE_FUNCTION: {
if (Record.size() < 8)
return Error(InvalidRecord);
@@ -1889,6 +1916,12 @@ error_code BitcodeReader::ParseModule(bool Resume) {
Func->setUnnamedAddr(UnnamedAddr);
if (Record.size() > 10 && Record[10] != 0)
FunctionPrefixes.push_back(std::make_pair(Func, Record[10]-1));
+
+ if (Record.size() > 11)
+ Func->setDLLStorageClass(GetDecodedDLLStorageClass(Record[11]));
+ else
+ UpgradeDLLImportExportLinkage(Func, Record[3]);
+
ValueList.push_back(Func);
// If this is a function with a body, remember the prototype we are
@@ -1900,7 +1933,7 @@ error_code BitcodeReader::ParseModule(bool Resume) {
break;
}
// ALIAS: [alias type, aliasee val#, linkage]
- // ALIAS: [alias type, aliasee val#, linkage, visibility]
+ // ALIAS: [alias type, aliasee val#, linkage, visibility, dllstorageclass]
case bitc::MODULE_CODE_ALIAS: {
if (Record.size() < 3)
return Error(InvalidRecord);
@@ -1915,6 +1948,10 @@ error_code BitcodeReader::ParseModule(bool Resume) {
// Old bitcode files didn't have visibility field.
if (Record.size() > 3)
NewGA->setVisibility(GetDecodedVisibility(Record[3]));
+ if (Record.size() > 4)
+ NewGA->setDLLStorageClass(GetDecodedDLLStorageClass(Record[4]));
+ else
+ UpgradeDLLImportExportLinkage(NewGA, Record[2]);
ValueList.push_back(NewGA);
AliasInits.push_back(std::make_pair(NewGA, Record[1]));
break;
@@ -2847,7 +2884,8 @@ error_code BitcodeReader::ParseFunctionBody(Function *F) {
break;
}
case bitc::FUNC_CODE_INST_CMPXCHG: {
- // CMPXCHG:[ptrty, ptr, cmp, new, vol, ordering, synchscope]
+ // CMPXCHG:[ptrty, ptr, cmp, new, vol, successordering, synchscope,
+ // failureordering]
unsigned OpNum = 0;
Value *Ptr, *Cmp, *New;
if (getValueTypePair(Record, OpNum, NextValueNo, Ptr) ||
@@ -2855,13 +2893,22 @@ error_code BitcodeReader::ParseFunctionBody(Function *F) {
cast<PointerType>(Ptr->getType())->getElementType(), Cmp) ||
popValue(Record, OpNum, NextValueNo,
cast<PointerType>(Ptr->getType())->getElementType(), New) ||
- OpNum+3 != Record.size())
+ (OpNum + 3 != Record.size() && OpNum + 4 != Record.size()))
return Error(InvalidRecord);
- AtomicOrdering Ordering = GetDecodedOrdering(Record[OpNum+1]);
- if (Ordering == NotAtomic || Ordering == Unordered)
+ AtomicOrdering SuccessOrdering = GetDecodedOrdering(Record[OpNum+1]);
+ if (SuccessOrdering == NotAtomic || SuccessOrdering == Unordered)
return Error(InvalidRecord);
SynchronizationScope SynchScope = GetDecodedSynchScope(Record[OpNum+2]);
- I = new AtomicCmpXchgInst(Ptr, Cmp, New, Ordering, SynchScope);
+
+ AtomicOrdering FailureOrdering;
+ if (Record.size() < 7)
+ FailureOrdering =
+ AtomicCmpXchgInst::getStrongestFailureOrdering(SuccessOrdering);
+ else
+ FailureOrdering = GetDecodedOrdering(Record[OpNum+3]);
+
+ I = new AtomicCmpXchgInst(Ptr, Cmp, New, SuccessOrdering, FailureOrdering,
+ SynchScope);
cast<AtomicCmpXchgInst>(I)->setVolatile(Record[OpNum]);
InstructionList.push_back(I);
break;
@@ -2992,7 +3039,7 @@ OutOfRecordLoop:
if (A->getParent() == 0) {
// We found at least one unresolved value. Nuke them all to avoid leaks.
for (unsigned i = ModuleValueListSize, e = ValueList.size(); i != e; ++i){
- if ((A = dyn_cast<Argument>(ValueList[i])) && A->getParent() == 0) {
+ if ((A = dyn_cast_or_null<Argument>(ValueList[i])) && A->getParent() == 0) {
A->replaceAllUsesWith(UndefValue::get(A->getType()));
delete A;
}
@@ -3081,8 +3128,8 @@ error_code BitcodeReader::Materialize(GlobalValue *GV) {
for (UpgradedIntrinsicMap::iterator I = UpgradedIntrinsics.begin(),
E = UpgradedIntrinsics.end(); I != E; ++I) {
if (I->first != I->second) {
- for (Value::use_iterator UI = I->first->use_begin(),
- UE = I->first->use_end(); UI != UE; ) {
+ for (auto UI = I->first->user_begin(), UE = I->first->user_end();
+ UI != UE;) {
if (CallInst* CI = dyn_cast<CallInst>(*UI++))
UpgradeIntrinsicCall(CI, I->second);
}
@@ -3137,8 +3184,8 @@ error_code BitcodeReader::MaterializeModule(Module *M) {
for (std::vector<std::pair<Function*, Function*> >::iterator I =
UpgradedIntrinsics.begin(), E = UpgradedIntrinsics.end(); I != E; ++I) {
if (I->first != I->second) {
- for (Value::use_iterator UI = I->first->use_begin(),
- UE = I->first->use_end(); UI != UE; ) {
+ for (auto UI = I->first->user_begin(), UE = I->first->user_end();
+ UI != UE;) {
if (CallInst* CI = dyn_cast<CallInst>(*UI++))
UpgradeIntrinsicCall(CI, I->second);
}
@@ -3210,11 +3257,11 @@ error_code BitcodeReader::InitLazyStream() {
}
namespace {
-class BitcodeErrorCategoryType : public _do_message {
- const char *name() const LLVM_OVERRIDE {
+class BitcodeErrorCategoryType : public error_category {
+ const char *name() const override {
return "llvm.bitcode";
}
- std::string message(int IE) const LLVM_OVERRIDE {
+ std::string message(int IE) const override {
BitcodeReader::ErrorType E = static_cast<BitcodeReader::ErrorType>(IE);
switch (E) {
case BitcodeReader::BitcodeStreamInvalidSize:
@@ -3272,18 +3319,14 @@ const error_category &BitcodeReader::BitcodeErrorCategory() {
/// getLazyBitcodeModule - lazy function-at-a-time loading from a file.
///
-Module *llvm::getLazyBitcodeModule(MemoryBuffer *Buffer,
- LLVMContext& Context,
- std::string *ErrMsg) {
+ErrorOr<Module *> llvm::getLazyBitcodeModule(MemoryBuffer *Buffer,
+ LLVMContext &Context) {
Module *M = new Module(Buffer->getBufferIdentifier(), Context);
BitcodeReader *R = new BitcodeReader(Buffer, Context);
M->setMaterializer(R);
if (error_code EC = R->ParseBitcodeInto(M)) {
- if (ErrMsg)
- *ErrMsg = EC.message();
-
delete M; // Also deletes R.
- return 0;
+ return EC;
}
// Have the BitcodeReader dtor delete 'Buffer'.
R->setBufferOwned(true);
@@ -3311,21 +3354,21 @@ Module *llvm::getStreamedBitcodeModule(const std::string &name,
return M;
}
-/// ParseBitcodeFile - Read the specified bitcode file, returning the module.
-/// If an error occurs, return null and fill in *ErrMsg if non-null.
-Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext& Context,
- std::string *ErrMsg){
- Module *M = getLazyBitcodeModule(Buffer, Context, ErrMsg);
- if (!M) return 0;
+ErrorOr<Module *> llvm::parseBitcodeFile(MemoryBuffer *Buffer,
+ LLVMContext &Context) {
+ ErrorOr<Module *> ModuleOrErr = getLazyBitcodeModule(Buffer, Context);
+ if (!ModuleOrErr)
+ return ModuleOrErr;
+ Module *M = ModuleOrErr.get();
// Don't let the BitcodeReader dtor delete 'Buffer', regardless of whether
// there was an error.
static_cast<BitcodeReader*>(M->getMaterializer())->setBufferOwned(false);
// Read in the entire module, and destroy the BitcodeReader.
- if (M->MaterializeAllPermanently(ErrMsg)) {
+ if (error_code EC = M->materializeAllPermanently()) {
delete M;
- return 0;
+ return EC;
}
// TODO: Restore the use-lists to the in-memory state when the bitcode was
diff --git a/lib/Bitcode/Reader/BitcodeReader.h b/lib/Bitcode/Reader/BitcodeReader.h
index c5d345b..15be31f 100644
--- a/lib/Bitcode/Reader/BitcodeReader.h
+++ b/lib/Bitcode/Reader/BitcodeReader.h
@@ -17,12 +17,12 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/Bitcode/BitstreamReader.h"
#include "llvm/Bitcode/LLVMBitCodes.h"
-#include "llvm/GVMaterializer.h"
#include "llvm/IR/Attributes.h"
+#include "llvm/IR/GVMaterializer.h"
#include "llvm/IR/OperandTraits.h"
#include "llvm/IR/Type.h"
+#include "llvm/IR/ValueHandle.h"
#include "llvm/Support/system_error.h"
-#include "llvm/Support/ValueHandle.h"
#include <vector>
namespace llvm {
@@ -127,7 +127,7 @@ class BitcodeReader : public GVMaterializer {
Module *TheModule;
MemoryBuffer *Buffer;
bool BufferOwned;
- OwningPtr<BitstreamReader> StreamFile;
+ std::unique_ptr<BitstreamReader> StreamFile;
BitstreamCursor Stream;
DataStreamer *LazyStreamer;
uint64_t NextUnreadBit;
@@ -247,11 +247,11 @@ public:
/// when the reader is destroyed.
void setBufferOwned(bool Owned) { BufferOwned = Owned; }
- virtual bool isMaterializable(const GlobalValue *GV) const;
- virtual bool isDematerializable(const GlobalValue *GV) const;
- virtual error_code Materialize(GlobalValue *GV);
- virtual error_code MaterializeModule(Module *M);
- virtual void Dematerialize(GlobalValue *GV);
+ bool isMaterializable(const GlobalValue *GV) const override;
+ bool isDematerializable(const GlobalValue *GV) const override;
+ error_code Materialize(GlobalValue *GV) override;
+ error_code MaterializeModule(Module *M) override;
+ void Dematerialize(GlobalValue *GV) override;
/// @brief Main interface to parsing a bitcode buffer.
/// @returns true if an error occurred.
diff --git a/lib/Bitcode/Writer/Android.mk b/lib/Bitcode/Writer/Android.mk
index fcafe37..6aa208c 100644
--- a/lib/Bitcode/Writer/Android.mk
+++ b/lib/Bitcode/Writer/Android.mk
@@ -23,6 +23,7 @@ include $(BUILD_HOST_STATIC_LIBRARY)
# For the device
# =====================================================
include $(CLEAR_VARS)
+ifneq (true,$(DISABLE_LLVM_DEVICE_BUILDS))
LOCAL_SRC_FILES := $(bitcode_writer_SRC_FILES)
@@ -33,3 +34,4 @@ LOCAL_MODULE_TAGS := optional
include $(LLVM_DEVICE_BUILD_MK)
include $(LLVM_GEN_INTRINSICS_MK)
include $(BUILD_STATIC_LIBRARY)
+endif
diff --git a/lib/Bitcode/Writer/BitWriter.cpp b/lib/Bitcode/Writer/BitWriter.cpp
index cd1ada2..0275f96 100644
--- a/lib/Bitcode/Writer/BitWriter.cpp
+++ b/lib/Bitcode/Writer/BitWriter.cpp
@@ -18,7 +18,7 @@ using namespace llvm;
int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
std::string ErrorInfo;
- raw_fd_ostream OS(Path, ErrorInfo, sys::fs::F_Binary);
+ raw_fd_ostream OS(Path, ErrorInfo, sys::fs::F_None);
if (!ErrorInfo.empty())
return -1;
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp
index 4cfc6bd..5d1dac1 100644
--- a/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -169,6 +169,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) {
return bitc::ATTR_KIND_BUILTIN;
case Attribute::ByVal:
return bitc::ATTR_KIND_BY_VAL;
+ case Attribute::InAlloca:
+ return bitc::ATTR_KIND_IN_ALLOCA;
case Attribute::Cold:
return bitc::ATTR_KIND_COLD;
case Attribute::InlineHint:
@@ -382,7 +384,6 @@ static void WriteTypeTable(const ValueEnumerator &VE, BitstreamWriter &Stream) {
unsigned Code = 0;
switch (T->getTypeID()) {
- default: llvm_unreachable("Unknown type!");
case Type::VoidTyID: Code = bitc::TYPE_CODE_VOID; break;
case Type::HalfTyID: Code = bitc::TYPE_CODE_HALF; break;
case Type::FloatTyID: Code = bitc::TYPE_CODE_FLOAT; break;
@@ -480,16 +481,12 @@ static unsigned getEncodedLinkage(const GlobalValue *GV) {
case GlobalValue::AppendingLinkage: return 2;
case GlobalValue::InternalLinkage: return 3;
case GlobalValue::LinkOnceAnyLinkage: return 4;
- case GlobalValue::DLLImportLinkage: return 5;
- case GlobalValue::DLLExportLinkage: return 6;
case GlobalValue::ExternalWeakLinkage: return 7;
case GlobalValue::CommonLinkage: return 8;
case GlobalValue::PrivateLinkage: return 9;
case GlobalValue::WeakODRLinkage: return 10;
case GlobalValue::LinkOnceODRLinkage: return 11;
case GlobalValue::AvailableExternallyLinkage: return 12;
- case GlobalValue::LinkerPrivateLinkage: return 13;
- case GlobalValue::LinkerPrivateWeakLinkage: return 14;
}
llvm_unreachable("Invalid linkage");
}
@@ -503,6 +500,15 @@ static unsigned getEncodedVisibility(const GlobalValue *GV) {
llvm_unreachable("Invalid visibility");
}
+static unsigned getEncodedDLLStorageClass(const GlobalValue *GV) {
+ switch (GV->getDLLStorageClass()) {
+ case GlobalValue::DefaultStorageClass: return 0;
+ case GlobalValue::DLLImportStorageClass: return 1;
+ case GlobalValue::DLLExportStorageClass: return 2;
+ }
+ llvm_unreachable("Invalid DLL storage class");
+}
+
static unsigned getEncodedThreadLocalMode(const GlobalVariable *GV) {
switch (GV->getThreadLocalMode()) {
case GlobalVariable::NotThreadLocal: return 0;
@@ -522,9 +528,9 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
if (!M->getTargetTriple().empty())
WriteStringRecord(bitc::MODULE_CODE_TRIPLE, M->getTargetTriple(),
0/*TODO*/, Stream);
- if (!M->getDataLayout().empty())
- WriteStringRecord(bitc::MODULE_CODE_DATALAYOUT, M->getDataLayout(),
- 0/*TODO*/, Stream);
+ const std::string &DL = M->getDataLayoutStr();
+ if (!DL.empty())
+ WriteStringRecord(bitc::MODULE_CODE_DATALAYOUT, DL, 0 /*TODO*/, Stream);
if (!M->getModuleInlineAsm().empty())
WriteStringRecord(bitc::MODULE_CODE_ASM, M->getModuleInlineAsm(),
0/*TODO*/, Stream);
@@ -606,7 +612,7 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
// GLOBALVAR: [type, isconst, initid,
// linkage, alignment, section, visibility, threadlocal,
- // unnamed_addr, externally_initialized]
+ // unnamed_addr, externally_initialized, dllstorageclass]
Vals.push_back(VE.getTypeID(GV->getType()));
Vals.push_back(GV->isConstant());
Vals.push_back(GV->isDeclaration() ? 0 :
@@ -616,11 +622,13 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
Vals.push_back(GV->hasSection() ? SectionMap[GV->getSection()] : 0);
if (GV->isThreadLocal() ||
GV->getVisibility() != GlobalValue::DefaultVisibility ||
- GV->hasUnnamedAddr() || GV->isExternallyInitialized()) {
+ GV->hasUnnamedAddr() || GV->isExternallyInitialized() ||
+ GV->getDLLStorageClass() != GlobalValue::DefaultStorageClass) {
Vals.push_back(getEncodedVisibility(GV));
Vals.push_back(getEncodedThreadLocalMode(GV));
Vals.push_back(GV->hasUnnamedAddr());
Vals.push_back(GV->isExternallyInitialized());
+ Vals.push_back(getEncodedDLLStorageClass(GV));
} else {
AbbrevToUse = SimpleGVarAbbrev;
}
@@ -645,6 +653,7 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
Vals.push_back(F->hasUnnamedAddr());
Vals.push_back(F->hasPrefixData() ? (VE.getValueID(F->getPrefixData()) + 1)
: 0);
+ Vals.push_back(getEncodedDLLStorageClass(F));
unsigned AbbrevToUse = 0;
Stream.EmitRecord(bitc::MODULE_CODE_FUNCTION, Vals, AbbrevToUse);
@@ -659,6 +668,7 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
Vals.push_back(VE.getValueID(AI->getAliasee()));
Vals.push_back(getEncodedLinkage(AI));
Vals.push_back(getEncodedVisibility(AI));
+ Vals.push_back(getEncodedDLLStorageClass(AI));
unsigned AbbrevToUse = 0;
Stream.EmitRecord(bitc::MODULE_CODE_ALIAS, Vals, AbbrevToUse);
Vals.clear();
@@ -1429,9 +1439,11 @@ static void WriteInstruction(const Instruction &I, unsigned InstID,
pushValue(I.getOperand(2), InstID, Vals, VE); // newval.
Vals.push_back(cast<AtomicCmpXchgInst>(I).isVolatile());
Vals.push_back(GetEncodedOrdering(
- cast<AtomicCmpXchgInst>(I).getOrdering()));
+ cast<AtomicCmpXchgInst>(I).getSuccessOrdering()));
Vals.push_back(GetEncodedSynchScope(
cast<AtomicCmpXchgInst>(I).getSynchScope()));
+ Vals.push_back(GetEncodedOrdering(
+ cast<AtomicCmpXchgInst>(I).getFailureOrdering()));
break;
case Instruction::AtomicRMW:
Code = bitc::FUNC_CODE_INST_ATOMICRMW;
@@ -1795,17 +1807,10 @@ static void WriteUseList(const Value *V, const ValueEnumerator &VE,
return;
// Make a copy of the in-memory use-list for sorting.
- unsigned UseListSize = std::distance(V->use_begin(), V->use_end());
- SmallVector<const User*, 8> UseList;
- UseList.reserve(UseListSize);
- for (Value::const_use_iterator I = V->use_begin(), E = V->use_end();
- I != E; ++I) {
- const User *U = *I;
- UseList.push_back(U);
- }
+ SmallVector<const User*, 8> UserList(V->user_begin(), V->user_end());
// Sort the copy based on the order read by the BitcodeReader.
- std::sort(UseList.begin(), UseList.end(), bitcodereader_order);
+ std::sort(UserList.begin(), UserList.end(), bitcodereader_order);
// TODO: Generate a diff between the BitcodeWriter in-memory use-list and the
// sorted list (i.e., the expected BitcodeReader in-memory use-list).
diff --git a/lib/Bitcode/Writer/BitcodeWriterPass.cpp b/lib/Bitcode/Writer/BitcodeWriterPass.cpp
index e5e76e2..4167f6d 100644
--- a/lib/Bitcode/Writer/BitcodeWriterPass.cpp
+++ b/lib/Bitcode/Writer/BitcodeWriterPass.cpp
@@ -1,4 +1,4 @@
-//===--- Bitcode/Writer/BitcodeWriterPass.cpp - Bitcode Writer ------------===//
+//===- BitcodeWriterPass.cpp - Bitcode writing pass -----------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -11,10 +11,18 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Bitcode/BitcodeWriterPass.h"
#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"
using namespace llvm;
+PreservedAnalyses BitcodeWriterPass::run(Module *M) {
+ WriteBitcodeToFile(M, OS);
+ return PreservedAnalyses::all();
+}
+
namespace {
class WriteBitcodePass : public ModulePass {
raw_ostream &OS; // raw_ostream to print on
@@ -23,9 +31,9 @@ namespace {
explicit WriteBitcodePass(raw_ostream &o)
: ModulePass(ID), OS(o) {}
- const char *getPassName() const { return "Bitcode Writer"; }
+ const char *getPassName() const override { return "Bitcode Writer"; }
- bool runOnModule(Module &M) {
+ bool runOnModule(Module &M) override {
WriteBitcodeToFile(&M, OS);
return false;
}
@@ -34,8 +42,6 @@ namespace {
char WriteBitcodePass::ID = 0;
-/// createBitcodeWriterPass - Create and return a pass that writes the module
-/// to the specified ostream.
ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str) {
return new WriteBitcodePass(Str);
}
diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp
index a164104..8531e76 100644
--- a/lib/Bitcode/Writer/ValueEnumerator.cpp
+++ b/lib/Bitcode/Writer/ValueEnumerator.cpp
@@ -159,12 +159,11 @@ void ValueEnumerator::print(raw_ostream &OS, const ValueMapType &Map,
V->dump();
OS << " Uses(" << std::distance(V->use_begin(),V->use_end()) << "):";
- for (Value::const_use_iterator UI = V->use_begin(), UE = V->use_end();
- UI != UE; ++UI) {
- if (UI != V->use_begin())
+ for (const Use &U : V->uses()) {
+ if (&U != &*V->use_begin())
OS << ",";
- if((*UI)->hasName())
- OS << " " << (*UI)->getName();
+ if(U->hasName())
+ OS << " " << U->getName();
else
OS << " [null]";
@@ -173,29 +172,19 @@ void ValueEnumerator::print(raw_ostream &OS, const ValueMapType &Map,
}
}
-// Optimize constant ordering.
-namespace {
- struct CstSortPredicate {
- ValueEnumerator &VE;
- explicit CstSortPredicate(ValueEnumerator &ve) : VE(ve) {}
- bool operator()(const std::pair<const Value*, unsigned> &LHS,
- const std::pair<const Value*, unsigned> &RHS) {
- // Sort by plane.
- if (LHS.first->getType() != RHS.first->getType())
- return VE.getTypeID(LHS.first->getType()) <
- VE.getTypeID(RHS.first->getType());
- // Then by frequency.
- return LHS.second > RHS.second;
- }
- };
-}
-
/// OptimizeConstants - Reorder constant pool for denser encoding.
void ValueEnumerator::OptimizeConstants(unsigned CstStart, unsigned CstEnd) {
if (CstStart == CstEnd || CstStart+1 == CstEnd) return;
- CstSortPredicate P(*this);
- std::stable_sort(Values.begin()+CstStart, Values.begin()+CstEnd, P);
+ std::stable_sort(Values.begin() + CstStart, Values.begin() + CstEnd,
+ [this](const std::pair<const Value *, unsigned> &LHS,
+ const std::pair<const Value *, unsigned> &RHS) {
+ // Sort by plane.
+ if (LHS.first->getType() != RHS.first->getType())
+ return getTypeID(LHS.first->getType()) < getTypeID(RHS.first->getType());
+ // Then by frequency.
+ return LHS.second > RHS.second;
+ });
// Ensure that integer and vector of integer constants are at the start of the
// constant pool. This is important so that GEP structure indices come before