diff options
Diffstat (limited to 'lib/Bitcode/Writer')
-rw-r--r-- | lib/Bitcode/Writer/Android.mk | 2 | ||||
-rw-r--r-- | lib/Bitcode/Writer/BitWriter.cpp | 2 | ||||
-rw-r--r-- | lib/Bitcode/Writer/BitcodeWriter.cpp | 45 | ||||
-rw-r--r-- | lib/Bitcode/Writer/BitcodeWriterPass.cpp | 16 | ||||
-rw-r--r-- | lib/Bitcode/Writer/ValueEnumerator.cpp | 37 |
5 files changed, 52 insertions, 50 deletions
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 |