diff options
| author | Roman Divacky <rdivacky@FreeBSD.org> | 2010-02-16 09:30:23 +0000 | 
|---|---|---|
| committer | Roman Divacky <rdivacky@FreeBSD.org> | 2010-02-16 09:30:23 +0000 | 
| commit | 6fe5c7aa327e188b7176daa5595bbf075a6b94df (patch) | |
| tree | 4cfca640904d1896e25032757a61f8959c066919 /lib/Bitcode/Writer/BitcodeWriter.cpp | |
| parent | 989df958a10f0beb90b89ccadd8351cbe51d90b1 (diff) | |
Notes
Diffstat (limited to 'lib/Bitcode/Writer/BitcodeWriter.cpp')
| -rw-r--r-- | lib/Bitcode/Writer/BitcodeWriter.cpp | 66 | 
1 files changed, 60 insertions, 6 deletions
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 5a4a1b2920d8..82e73b5cff25 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -181,6 +181,14 @@ static void WriteTypeTable(const ValueEnumerator &VE, BitstreamWriter &Stream) {                              Log2_32_Ceil(VE.getTypes().size()+1)));    unsigned StructAbbrev = Stream.EmitAbbrev(Abbv); +  // Abbrev for TYPE_CODE_UNION. +  Abbv = new BitCodeAbbrev(); +  Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_UNION)); +  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); +  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, +                            Log2_32_Ceil(VE.getTypes().size()+1))); +  unsigned UnionAbbrev = Stream.EmitAbbrev(Abbv); +    // Abbrev for TYPE_CODE_ARRAY.    Abbv = new BitCodeAbbrev();    Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_ARRAY)); @@ -250,6 +258,17 @@ static void WriteTypeTable(const ValueEnumerator &VE, BitstreamWriter &Stream) {        AbbrevToUse = StructAbbrev;        break;      } +    case Type::UnionTyID: { +      const UnionType *UT = cast<UnionType>(T); +      // UNION: [eltty x N] +      Code = bitc::TYPE_CODE_UNION; +      // Output all of the element types. +      for (UnionType::element_iterator I = UT->element_begin(), +           E = UT->element_end(); I != E; ++I) +        TypeVals.push_back(VE.getTypeID(*I)); +      AbbrevToUse = UnionAbbrev; +      break; +    }      case Type::ArrayTyID: {        const ArrayType *AT = cast<ArrayType>(T);        // ARRAY: [numelts, eltty] @@ -280,7 +299,6 @@ static void WriteTypeTable(const ValueEnumerator &VE, BitstreamWriter &Stream) {  static unsigned getEncodedLinkage(const GlobalValue *GV) {    switch (GV->getLinkage()) {    default: llvm_unreachable("Invalid linkage!"); -  case GlobalValue::GhostLinkage:  // Map ghost linkage onto external.    case GlobalValue::ExternalLinkage:            return 0;    case GlobalValue::WeakAnyLinkage:             return 1;    case GlobalValue::AppendingLinkage:           return 2; @@ -499,7 +517,7 @@ static void WriteModuleMetadata(const ValueEnumerator &VE,    for (unsigned i = 0, e = Vals.size(); i != e; ++i) {      if (const MDNode *N = dyn_cast<MDNode>(Vals[i].first)) { -      if (!N->isFunctionLocal()) { +      if (!N->isFunctionLocal() || !N->getFunction()) {          if (!StartedMetadataBlock) {            Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);            StartedMetadataBlock = true; @@ -563,7 +581,7 @@ static void WriteFunctionLocalMetadata(const Function &F,    for (unsigned i = 0, e = Vals.size(); i != e; ++i)      if (const MDNode *N = dyn_cast<MDNode>(Vals[i].first)) -      if (N->getFunction() == &F) { +      if (N->isFunctionLocal() && N->getFunction() == &F) {          if (!StartedMetadataBlock) {            Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);            StartedMetadataBlock = true; @@ -790,7 +808,7 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,        else if (isCStr7)          AbbrevToUse = CString7Abbrev;      } else if (isa<ConstantArray>(C) || isa<ConstantStruct>(V) || -               isa<ConstantVector>(V)) { +               isa<ConstantUnion>(C) || isa<ConstantVector>(V)) {        Code = bitc::CST_CODE_AGGREGATE;        for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)          Record.push_back(VE.getValueID(C->getOperand(i))); @@ -1511,16 +1529,50 @@ enum {    DarwinBCHeaderSize = 5*4  }; +/// isARMTriplet - Return true if the triplet looks like: +/// arm-*, thumb-*, armv[0-9]-*, thumbv[0-9]-*, armv5te-*, or armv6t2-*. +static bool isARMTriplet(const std::string &TT) { +  size_t Pos = 0; +  size_t Size = TT.size(); +  if (Size >= 6 && +      TT[0] == 't' && TT[1] == 'h' && TT[2] == 'u' && +      TT[3] == 'm' && TT[4] == 'b') +    Pos = 5; +  else if (Size >= 4 && TT[0] == 'a' && TT[1] == 'r' && TT[2] == 'm') +    Pos = 3; +  else +    return false; + +  if (TT[Pos] == '-') +    return true; +  else if (TT[Pos] == 'v') { +    if (Size >= Pos+4 && +        TT[Pos+1] == '6' && TT[Pos+2] == 't' && TT[Pos+3] == '2') +      return true; +    else if (Size >= Pos+4 && +             TT[Pos+1] == '5' && TT[Pos+2] == 't' && TT[Pos+3] == 'e') +      return true; +  } else +    return false; +  while (++Pos < Size && TT[Pos] != '-') { +    if (!isdigit(TT[Pos])) +      return false; +  } +  return true; +} +  static void EmitDarwinBCHeader(BitstreamWriter &Stream,                                 const std::string &TT) {    unsigned CPUType = ~0U; -  // Match x86_64-*, i[3-9]86-*, powerpc-*, powerpc64-*.  The CPUType is a -  // magic number from /usr/include/mach/machine.h.  It is ok to reproduce the +  // Match x86_64-*, i[3-9]86-*, powerpc-*, powerpc64-*, arm-*, thumb-*, +  // armv[0-9]-*, thumbv[0-9]-*, armv5te-*, or armv6t2-*. The CPUType is a magic +  // number from /usr/include/mach/machine.h.  It is ok to reproduce the    // specific constants here because they are implicitly part of the Darwin ABI.    enum {      DARWIN_CPU_ARCH_ABI64      = 0x01000000,      DARWIN_CPU_TYPE_X86        = 7, +    DARWIN_CPU_TYPE_ARM        = 12,      DARWIN_CPU_TYPE_POWERPC    = 18    }; @@ -1533,6 +1585,8 @@ static void EmitDarwinBCHeader(BitstreamWriter &Stream,      CPUType = DARWIN_CPU_TYPE_POWERPC;    else if (TT.find("powerpc64-") == 0)      CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64; +  else if (isARMTriplet(TT)) +    CPUType = DARWIN_CPU_TYPE_ARM;    // Traditional Bitcode starts after header.    unsigned BCOffset = DarwinBCHeaderSize;  | 
