diff options
author | Jush Lu <jush.msn@gmail.com> | 2011-03-09 19:39:16 +0800 |
---|---|---|
committer | Jush Lu <jush.msn@gmail.com> | 2011-03-09 19:39:16 +0800 |
commit | b5530586d68bd25831a6796b5d3199cb0769a35c (patch) | |
tree | fac4a03b53b6a64b0c00f433e4d8b3c9f2bc67cd /lib/Bitcode | |
parent | b4e17c5bf4361bbdeced39aa071150d7fa9c3c10 (diff) | |
parent | d01f50f42ce60207ed6d27fb1778e456d83be06c (diff) | |
download | external_llvm-b5530586d68bd25831a6796b5d3199cb0769a35c.zip external_llvm-b5530586d68bd25831a6796b5d3199cb0769a35c.tar.gz external_llvm-b5530586d68bd25831a6796b5d3199cb0769a35c.tar.bz2 |
Merge upstream r127116
Diffstat (limited to 'lib/Bitcode')
-rw-r--r-- | lib/Bitcode/CMakeLists.txt | 2 | ||||
-rw-r--r-- | lib/Bitcode/Reader/BitcodeReader.cpp | 39 | ||||
-rw-r--r-- | lib/Bitcode/Writer/BitcodeWriter.cpp | 31 |
3 files changed, 51 insertions, 21 deletions
diff --git a/lib/Bitcode/CMakeLists.txt b/lib/Bitcode/CMakeLists.txt new file mode 100644 index 0000000..ff7e290 --- /dev/null +++ b/lib/Bitcode/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(Reader) +add_subdirectory(Writer) diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index e8b998e..dbf8da0 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -162,7 +162,8 @@ namespace { // FIXME: can we inherit this from ConstantExpr? template <> -struct OperandTraits<ConstantPlaceHolder> : public FixedNumOperandTraits<1> { +struct OperandTraits<ConstantPlaceHolder> : + public FixedNumOperandTraits<ConstantPlaceHolder, 1> { }; } @@ -297,7 +298,7 @@ void BitcodeReaderValueList::ResolveConstantForwardRefs() { NewC = ConstantStruct::get(Context, &NewOps[0], NewOps.size(), UserCS->getType()->isPacked()); } else if (isa<ConstantVector>(UserC)) { - NewC = ConstantVector::get(&NewOps[0], NewOps.size()); + NewC = ConstantVector::get(NewOps); } else { assert(isa<ConstantExpr>(UserC) && "Must be a ConstantExpr."); NewC = cast<ConstantExpr>(UserC)->getWithOperands(&NewOps[0], @@ -1084,13 +1085,17 @@ bool BitcodeReader::ParseConstants() { if (Record.size() >= 4) { if (Opc == Instruction::Add || Opc == Instruction::Sub || - Opc == Instruction::Mul) { + Opc == Instruction::Mul || + Opc == Instruction::Shl) { if (Record[3] & (1 << bitc::OBO_NO_SIGNED_WRAP)) Flags |= OverflowingBinaryOperator::NoSignedWrap; if (Record[3] & (1 << bitc::OBO_NO_UNSIGNED_WRAP)) Flags |= OverflowingBinaryOperator::NoUnsignedWrap; - } else if (Opc == Instruction::SDiv) { - if (Record[3] & (1 << bitc::SDIV_EXACT)) + } else if (Opc == Instruction::SDiv || + Opc == Instruction::UDiv || + Opc == Instruction::LShr || + Opc == Instruction::AShr) { + if (Record[3] & (1 << bitc::PEO_EXACT)) Flags |= SDivOperator::IsExact; } } @@ -1422,7 +1427,8 @@ bool BitcodeReader::ParseModule() { break; } // GLOBALVAR: [pointer type, isconst, initid, - // linkage, alignment, section, visibility, threadlocal] + // linkage, alignment, section, visibility, threadlocal, + // unnamed_addr] case bitc::MODULE_CODE_GLOBALVAR: { if (Record.size() < 6) return Error("Invalid MODULE_CODE_GLOBALVAR record"); @@ -1449,6 +1455,10 @@ bool BitcodeReader::ParseModule() { if (Record.size() > 7) isThreadLocal = Record[7]; + bool UnnamedAddr = false; + if (Record.size() > 8) + UnnamedAddr = Record[8]; + GlobalVariable *NewGV = new GlobalVariable(*TheModule, Ty, isConstant, Linkage, 0, "", 0, isThreadLocal, AddressSpace); @@ -1457,6 +1467,7 @@ bool BitcodeReader::ParseModule() { NewGV->setSection(Section); NewGV->setVisibility(Visibility); NewGV->setThreadLocal(isThreadLocal); + NewGV->setUnnamedAddr(UnnamedAddr); ValueList.push_back(NewGV); @@ -1466,7 +1477,7 @@ bool BitcodeReader::ParseModule() { break; } // FUNCTION: [type, callingconv, isproto, linkage, paramattr, - // alignment, section, visibility, gc] + // alignment, section, visibility, gc, unnamed_addr] case bitc::MODULE_CODE_FUNCTION: { if (Record.size() < 8) return Error("Invalid MODULE_CODE_FUNCTION record"); @@ -1499,6 +1510,10 @@ bool BitcodeReader::ParseModule() { return Error("Invalid GC ID"); Func->setGC(GCTable[Record[8]-1].c_str()); } + bool UnnamedAddr = false; + if (Record.size() > 9) + UnnamedAddr = Record[9]; + Func->setUnnamedAddr(UnnamedAddr); ValueList.push_back(Func); // If this is a function with a body, remember the prototype we are @@ -1889,13 +1904,17 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { if (OpNum < Record.size()) { if (Opc == Instruction::Add || Opc == Instruction::Sub || - Opc == Instruction::Mul) { + Opc == Instruction::Mul || + Opc == Instruction::Shl) { if (Record[OpNum] & (1 << bitc::OBO_NO_SIGNED_WRAP)) cast<BinaryOperator>(I)->setHasNoSignedWrap(true); if (Record[OpNum] & (1 << bitc::OBO_NO_UNSIGNED_WRAP)) cast<BinaryOperator>(I)->setHasNoUnsignedWrap(true); - } else if (Opc == Instruction::SDiv) { - if (Record[OpNum] & (1 << bitc::SDIV_EXACT)) + } else if (Opc == Instruction::SDiv || + Opc == Instruction::UDiv || + Opc == Instruction::LShr || + Opc == Instruction::AShr) { + if (Record[OpNum] & (1 << bitc::PEO_EXACT)) cast<BinaryOperator>(I)->setIsExact(true); } } diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 4e6e6d9..f8ef8c6 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -26,7 +26,8 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/System/Program.h" +#include "llvm/Support/Program.h" +#include <cctype> using namespace llvm; /// These are manifest constants used by the bitcode writer. They do not need to @@ -403,7 +404,8 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE, unsigned AbbrevToUse = 0; // GLOBALVAR: [type, isconst, initid, - // linkage, alignment, section, visibility, threadlocal] + // linkage, alignment, section, visibility, threadlocal, + // unnamed_addr] Vals.push_back(VE.getTypeID(GV->getType())); Vals.push_back(GV->isConstant()); Vals.push_back(GV->isDeclaration() ? 0 : @@ -412,9 +414,11 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE, Vals.push_back(Log2_32(GV->getAlignment())+1); Vals.push_back(GV->hasSection() ? SectionMap[GV->getSection()] : 0); if (GV->isThreadLocal() || - GV->getVisibility() != GlobalValue::DefaultVisibility) { + GV->getVisibility() != GlobalValue::DefaultVisibility || + GV->hasUnnamedAddr()) { Vals.push_back(getEncodedVisibility(GV)); Vals.push_back(GV->isThreadLocal()); + Vals.push_back(GV->hasUnnamedAddr()); } else { AbbrevToUse = SimpleGVarAbbrev; } @@ -426,7 +430,7 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE, // Emit the function proto information. for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) { // FUNCTION: [type, callingconv, isproto, paramattr, - // linkage, alignment, section, visibility, gc] + // linkage, alignment, section, visibility, gc, unnamed_addr] Vals.push_back(VE.getTypeID(F->getType())); Vals.push_back(F->getCallingConv()); Vals.push_back(F->isDeclaration()); @@ -436,6 +440,7 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE, Vals.push_back(F->hasSection() ? SectionMap[F->getSection()] : 0); Vals.push_back(getEncodedVisibility(F)); Vals.push_back(F->hasGC() ? GCMap[F->getGC()] : 0); + Vals.push_back(F->hasUnnamedAddr()); unsigned AbbrevToUse = 0; Stream.EmitRecord(bitc::MODULE_CODE_FUNCTION, Vals, AbbrevToUse); @@ -465,9 +470,10 @@ static uint64_t GetOptimizationFlags(const Value *V) { Flags |= 1 << bitc::OBO_NO_SIGNED_WRAP; if (OBO->hasNoUnsignedWrap()) Flags |= 1 << bitc::OBO_NO_UNSIGNED_WRAP; - } else if (const SDivOperator *Div = dyn_cast<SDivOperator>(V)) { - if (Div->isExact()) - Flags |= 1 << bitc::SDIV_EXACT; + } else if (const PossiblyExactOperator *PEO = + dyn_cast<PossiblyExactOperator>(V)) { + if (PEO->isExact()) + Flags |= 1 << bitc::PEO_EXACT; } return Flags; @@ -1642,9 +1648,12 @@ void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out) { /// WriteBitcodeToStream - Write the specified module to the specified output /// stream. void llvm::WriteBitcodeToStream(const Module *M, BitstreamWriter &Stream) { - // If this is darwin, emit a file header and trailer if needed. - bool isDarwin = M->getTargetTriple().find("-darwin") != std::string::npos; - if (isDarwin) + // If this is darwin or another generic macho target, emit a file header and + // trailer if needed. + bool isMacho = + M->getTargetTriple().find("-darwin") != std::string::npos || + M->getTargetTriple().find("-macho") != std::string::npos; + if (isMacho) EmitDarwinBCHeader(Stream, M->getTargetTriple()); // Emit the file header. @@ -1658,6 +1667,6 @@ void llvm::WriteBitcodeToStream(const Module *M, BitstreamWriter &Stream) { // Emit the module. WriteModule(M, Stream); - if (isDarwin) + if (isMacho) EmitDarwinBCTrailer(Stream, Stream.getBuffer().size()); } |