Merge "Skip reflection of resize() when building for the compatibility library."
diff --git a/Android.mk b/Android.mk
index 93cdbd6..caf8852 100644
--- a/Android.mk
+++ b/Android.mk
@@ -43,8 +43,8 @@
 	libclangAnalysis \
 	libclangCodeGen \
 	libclangAST \
-	libclangLex \
 	libclangEdit \
+	libclangLex \
 	libclangFrontend \
 	libclangBasic \
 	libclangSerialization \
diff --git a/BitWriter_2_9/BitcodeWriter.cpp b/BitWriter_2_9/BitcodeWriter.cpp
index 4cfba10..037bd42 100644
--- a/BitWriter_2_9/BitcodeWriter.cpp
+++ b/BitWriter_2_9/BitcodeWriter.cpp
@@ -12,21 +12,21 @@
 //===----------------------------------------------------------------------===//
 
 #include "ReaderWriter_2_9.h"
+#include "ValueEnumerator.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/Bitcode/BitstreamWriter.h"
 #include "llvm/Bitcode/LLVMBitCodes.h"
-#include "ValueEnumerator.h"
-#include "llvm/Constants.h"
-#include "llvm/DerivedTypes.h"
-#include "llvm/InlineAsm.h"
-#include "llvm/Instructions.h"
-#include "llvm/Module.h"
-#include "llvm/Operator.h"
-#include "llvm/ValueSymbolTable.h"
-#include "llvm/ADT/Triple.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/InlineAsm.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Operator.h"
+#include "llvm/IR/ValueSymbolTable.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/Program.h"
+#include "llvm/Support/raw_ostream.h"
 #include <cctype>
 #include <map>
 using namespace llvm;
@@ -134,18 +134,19 @@
 // Emit information about parameter attributes.
 static void WriteAttributeTable(const llvm_2_9::ValueEnumerator &VE,
                                 BitstreamWriter &Stream) {
-  const std::vector<AttrListPtr> &Attrs = VE.getAttributes();
+  const std::vector<AttributeSet> &Attrs = VE.getAttributes();
   if (Attrs.empty()) return;
 
   Stream.EnterSubblock(bitc::PARAMATTR_BLOCK_ID, 3);
 
   SmallVector<uint64_t, 64> Record;
   for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
-    const AttrListPtr &A = Attrs[i];
+    const AttributeSet &A = Attrs[i];
     for (unsigned i = 0, e = A.getNumSlots(); i != e; ++i) {
       const AttributeWithIndex &PAWI = A.getSlot(i);
       Record.push_back(PAWI.Index);
-
+      Record.push_back(Attribute::encodeLLVMAttributesForBitcode(PAWI.Attrs));
+#if 0
       // FIXME: remove in LLVM 3.0
       // Store the alignment in the bitcode as a 16-bit raw value instead of a
       // 5-bit log2 encoded value. Shift the bits above the alignment up by
@@ -157,6 +158,7 @@
       FauxAttr |= (PAWI.Attrs.Raw() & (0x3FFull << 21)) << 11;
 
       Record.push_back(FauxAttr);
+#endif
     }
 
     Stream.EmitRecord(bitc::PARAMATTR_CODE_ENTRY, Record);
@@ -433,10 +435,6 @@
 static void WriteModuleInfo(const Module *M,
                             const llvm_2_9::ValueEnumerator &VE,
                             BitstreamWriter &Stream) {
-  // Emit the list of dependent libraries for the Module.
-  for (Module::lib_iterator I = M->lib_begin(), E = M->lib_end(); I != E; ++I)
-    WriteStringRecord(bitc::MODULE_CODE_DEPLIB, *I, 0/*TODO*/, Stream);
-
   // Emit various pieces of data attached to a module.
   if (!M->getTargetTriple().empty())
     WriteStringRecord(bitc::MODULE_CODE_TRIPLE, M->getTargetTriple(),
@@ -907,12 +905,12 @@
         if (isCStrChar6)
           isCStrChar6 = BitCodeAbbrevOp::isChar6(V);
       }
-      
+
       if (isCStrChar6)
         AbbrevToUse = CString6Abbrev;
       else if (isCStr7)
         AbbrevToUse = CString7Abbrev;
-    } else if (const ConstantDataSequential *CDS = 
+    } else if (const ConstantDataSequential *CDS =
                   dyn_cast<ConstantDataSequential>(C)) {
       // We must replace ConstantDataSequential's representation with the
       // legacy ConstantArray/ConstantVector/ConstantStruct version.
diff --git a/BitWriter_2_9/BitcodeWriterPass.cpp b/BitWriter_2_9/BitcodeWriterPass.cpp
index 1ae4556..dfacc54 100644
--- a/BitWriter_2_9/BitcodeWriterPass.cpp
+++ b/BitWriter_2_9/BitcodeWriterPass.cpp
@@ -12,9 +12,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "ReaderWriter_2_9.h"
-#include "llvm/Function.h"
-#include "llvm/Instructions.h"
-#include "llvm/Module.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
 #include "llvm/Pass.h"
 using namespace llvm;
 
diff --git a/BitWriter_2_9/ValueEnumerator.cpp b/BitWriter_2_9/ValueEnumerator.cpp
index b1cbbe9..a07c54c 100644
--- a/BitWriter_2_9/ValueEnumerator.cpp
+++ b/BitWriter_2_9/ValueEnumerator.cpp
@@ -12,13 +12,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "ValueEnumerator.h"
-#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/Constants.h"
-#include "llvm/DerivedTypes.h"
-#include "llvm/Module.h"
-#include "llvm/ValueSymbolTable.h"
-#include "llvm/Instructions.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/ValueSymbolTable.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
@@ -97,7 +97,7 @@
         I->getAllMetadataOtherThanDebugLoc(MDs);
         for (unsigned i = 0, e = MDs.size(); i != e; ++i)
           EnumerateMetadata(MDs[i].second);
-        
+
         if (!I->getDebugLoc().isUnknown()) {
           MDNode *Scope, *IA;
           I->getDebugLoc().getScopeAndInlinedAt(Scope, IA, I->getContext());
@@ -374,16 +374,16 @@
   if (StructType *STy = dyn_cast<StructType>(Ty))
     if (!STy->isLiteral())
       *TypeID = ~0U;
-  
+
   // Enumerate all of the subtypes before we enumerate this type.  This ensures
   // that the type will be enumerated in an order that can be directly built.
   for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
        I != E; ++I)
     EnumerateType(*I);
-  
+
   // Refresh the TypeID pointer in case the table rehashed.
   TypeID = &TypeMap[Ty];
-  
+
   // Check to see if we got the pointer another way.  This can happen when
   // enumerating recursive types that hit the base case deeper than they start.
   //
@@ -391,10 +391,10 @@
   // then emit the definition now that all of its contents are available.
   if (*TypeID && *TypeID != ~0U)
     return;
-  
+
   // Add this type now that its contents are all happily enumerated.
   Types.push_back(Ty);
-  
+
   *TypeID = Types.size();
 }
 
@@ -402,7 +402,7 @@
 // walk through it, enumerating the types of the constant.
 void ValueEnumerator::EnumerateOperandType(const Value *V) {
   EnumerateType(V->getType());
-  
+
   if (const Constant *C = dyn_cast<Constant>(V)) {
     // If this constant is already enumerated, ignore it, we know its type must
     // be enumerated.
@@ -412,11 +412,11 @@
     // them.
     for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) {
       const Value *Op = C->getOperand(i);
-      
+
       // Don't enumerate basic blocks here, this happens as operands to
       // blockaddress.
       if (isa<BasicBlock>(Op)) continue;
-      
+
       EnumerateOperandType(Op);
     }
 
@@ -429,14 +429,14 @@
     EnumerateMetadata(V);
 }
 
-void ValueEnumerator::EnumerateAttributes(const AttrListPtr &PAL) {
+void ValueEnumerator::EnumerateAttributes(const AttributeSet &PAL) {
   if (PAL.isEmpty()) return;  // null is always 0.
   // Do a lookup.
   unsigned &Entry = AttributeMap[PAL.getRawPointer()];
   if (Entry == 0) {
     // Never saw this before, add it.
-    Attributes.push_back(PAL);
-    Entry = Attributes.size();
+    Attribute.push_back(PAL);
+    Entry = Attribute.size();
   }
 }
 
@@ -493,7 +493,7 @@
         if (N->isFunctionLocal() && N->getFunction())
           FnLocalMDVector.push_back(N);
       }
-        
+
       if (!I->getType()->isVoidTy())
         EnumerateValue(I);
     }
diff --git a/BitWriter_2_9/ValueEnumerator.h b/BitWriter_2_9/ValueEnumerator.h
index 9e21775..6711e4b 100644
--- a/BitWriter_2_9/ValueEnumerator.h
+++ b/BitWriter_2_9/ValueEnumerator.h
@@ -16,7 +16,7 @@
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/Attributes.h"
+#include "llvm/IR/Attributes.h"
 #include <vector>
 
 namespace llvm {
@@ -29,7 +29,7 @@
 class Module;
 class MDNode;
 class NamedMDNode;
-class AttrListPtr;
+class AttributeSet;
 class ValueSymbolTable;
 class MDSymbolTable;
 class raw_ostream;
@@ -55,15 +55,15 @@
   ValueList MDValues;
   llvm::SmallVector<const llvm::MDNode *, 8> FunctionLocalMDs;
   ValueMapType MDValueMap;
-  
+
   typedef llvm::DenseMap<void*, unsigned> AttributeMapType;
   AttributeMapType AttributeMap;
-  std::vector<llvm::AttrListPtr> Attributes;
-  
+  std::vector<llvm::AttributeSet> Attribute;
+
   /// GlobalBasicBlockIDs - This map memoizes the basic block ID's referenced by
   /// the "getGlobalBasicBlockID" method.
   mutable llvm::DenseMap<const llvm::BasicBlock*, unsigned> GlobalBasicBlockIDs;
-  
+
   typedef llvm::DenseMap<const llvm::Instruction*, unsigned> InstructionMapType;
   InstructionMapType InstructionMap;
   unsigned InstructionCount;
@@ -71,7 +71,7 @@
   /// BasicBlocks - This contains all the basic blocks for the currently
   /// incorporated function.  Their reverse mapping is stored in ValueMap.
   std::vector<const llvm::BasicBlock*> BasicBlocks;
-  
+
   /// When a function is incorporated, this is the size of the Values list
   /// before incorporation.
   unsigned NumModuleValues;
@@ -82,7 +82,7 @@
 
   unsigned FirstFuncConstantID;
   unsigned FirstInstID;
-  
+
   ValueEnumerator(const ValueEnumerator &);  // DO NOT IMPLEMENT
   void operator=(const ValueEnumerator &);   // DO NOT IMPLEMENT
 public:
@@ -102,7 +102,7 @@
   unsigned getInstructionID(const llvm::Instruction *I) const;
   void setInstructionID(const llvm::Instruction *I);
 
-  unsigned getAttributeID(const llvm::AttrListPtr &PAL) const {
+  unsigned getAttributeID(const llvm::AttributeSet &PAL) const {
     if (PAL.isEmpty()) return 0;  // Null maps to zero.
     AttributeMapType::const_iterator I = AttributeMap.find(PAL.getRawPointer());
     assert(I != AttributeMap.end() && "Attribute not in ValueEnumerator!");
@@ -115,20 +115,20 @@
     Start = FirstFuncConstantID;
     End = FirstInstID;
   }
-  
+
   const ValueList &getValues() const { return Values; }
   const ValueList &getMDValues() const { return MDValues; }
-  const llvm::SmallVector<const llvm::MDNode *, 8> &getFunctionLocalMDValues() const { 
+  const llvm::SmallVector<const llvm::MDNode *, 8> &getFunctionLocalMDValues() const {
     return FunctionLocalMDs;
   }
   const TypeList &getTypes() const { return Types; }
   const std::vector<const llvm::BasicBlock*> &getBasicBlocks() const {
-    return BasicBlocks; 
+    return BasicBlocks;
   }
-  const std::vector<llvm::AttrListPtr> &getAttributes() const {
-    return Attributes;
+  const std::vector<llvm::AttributeSet> &getAttributes() const {
+    return Attribute;
   }
-  
+
   /// getGlobalBasicBlockID - This returns the function-specific ID for the
   /// specified basic block.  This is relatively expensive information, so it
   /// should only be used by rare constructs such as address-of-label.
@@ -142,7 +142,7 @@
 
 private:
   void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
-    
+
   void EnumerateMDNodeOperands(const llvm::MDNode *N);
   void EnumerateMetadata(const llvm::Value *MD);
   void EnumerateFunctionLocalMetadata(const llvm::MDNode *N);
@@ -150,8 +150,8 @@
   void EnumerateValue(const llvm::Value *V);
   void EnumerateType(llvm::Type *T);
   void EnumerateOperandType(const llvm::Value *V);
-  void EnumerateAttributes(const llvm::AttrListPtr &PAL);
-  
+  void EnumerateAttributes(const llvm::AttributeSet &PAL);
+
   void EnumerateValueSymbolTable(const llvm::ValueSymbolTable &ST);
   void EnumerateNamedMetadata(const llvm::Module *M);
 };
diff --git a/BitWriter_2_9_func/BitcodeWriter.cpp b/BitWriter_2_9_func/BitcodeWriter.cpp
index a8a0750..23b3883 100644
--- a/BitWriter_2_9_func/BitcodeWriter.cpp
+++ b/BitWriter_2_9_func/BitcodeWriter.cpp
@@ -12,21 +12,21 @@
 //===----------------------------------------------------------------------===//
 
 #include "ReaderWriter_2_9_func.h"
+#include "ValueEnumerator.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/Bitcode/BitstreamWriter.h"
 #include "llvm/Bitcode/LLVMBitCodes.h"
-#include "ValueEnumerator.h"
-#include "llvm/Constants.h"
-#include "llvm/DerivedTypes.h"
-#include "llvm/InlineAsm.h"
-#include "llvm/Instructions.h"
-#include "llvm/Module.h"
-#include "llvm/Operator.h"
-#include "llvm/ValueSymbolTable.h"
-#include "llvm/ADT/Triple.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/InlineAsm.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Operator.h"
+#include "llvm/IR/ValueSymbolTable.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/Program.h"
+#include "llvm/Support/raw_ostream.h"
 #include <cctype>
 #include <map>
 using namespace llvm;
@@ -58,6 +58,7 @@
   FUNCTION_INST_UNREACHABLE_ABBREV
 };
 
+
 static unsigned GetEncodedCastOpcode(unsigned Opcode) {
   switch (Opcode) {
   default: llvm_unreachable("Unknown cast instruction!");
@@ -156,18 +157,19 @@
 // Emit information about parameter attributes.
 static void WriteAttributeTable(const llvm_2_9_func::ValueEnumerator &VE,
                                 BitstreamWriter &Stream) {
-  const std::vector<AttrListPtr> &Attrs = VE.getAttributes();
+  const std::vector<AttributeSet> &Attrs = VE.getAttributes();
   if (Attrs.empty()) return;
 
   Stream.EnterSubblock(bitc::PARAMATTR_BLOCK_ID, 3);
 
   SmallVector<uint64_t, 64> Record;
   for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
-    const AttrListPtr &A = Attrs[i];
+    const AttributeSet &A = Attrs[i];
     for (unsigned i = 0, e = A.getNumSlots(); i != e; ++i) {
       const AttributeWithIndex &PAWI = A.getSlot(i);
       Record.push_back(PAWI.Index);
-
+      Record.push_back(Attribute::encodeLLVMAttributesForBitcode(PAWI.Attrs));
+#if 0
       // FIXME: remove in LLVM 3.0
       // Store the alignment in the bitcode as a 16-bit raw value instead of a
       // 5-bit log2 encoded value. Shift the bits above the alignment up by
@@ -179,6 +181,7 @@
       FauxAttr |= (PAWI.Attrs.Raw() & (0x3FFull << 21)) << 11;
 
       Record.push_back(FauxAttr);
+#endif
     }
 
     Stream.EmitRecord(bitc::PARAMATTR_CODE_ENTRY, Record);
@@ -238,7 +241,7 @@
   Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
                             Log2_32_Ceil(VE.getTypes().size()+1)));
   unsigned StructNamedAbbrev = Stream.EmitAbbrev(Abbv);
-  
+
   // Abbrev for TYPE_CODE_ARRAY.
   Abbv = new BitCodeAbbrev();
   Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_ARRAY));
@@ -386,10 +389,6 @@
 static void WriteModuleInfo(const Module *M,
                             const llvm_2_9_func::ValueEnumerator &VE,
                             BitstreamWriter &Stream) {
-  // Emit the list of dependent libraries for the Module.
-  for (Module::lib_iterator I = M->lib_begin(), E = M->lib_end(); I != E; ++I)
-    WriteStringRecord(bitc::MODULE_CODE_DEPLIB, *I, 0/*TODO*/, Stream);
-
   // Emit various pieces of data attached to a module.
   if (!M->getTargetTriple().empty())
     WriteStringRecord(bitc::MODULE_CODE_TRIPLE, M->getTargetTriple(),
@@ -411,15 +410,14 @@
        GV != E; ++GV) {
     MaxAlignment = std::max(MaxAlignment, GV->getAlignment());
     MaxGlobalType = std::max(MaxGlobalType, VE.getTypeID(GV->getType()));
-    if (GV->hasSection()) {
-      // Give section names unique ID's.
-      unsigned &Entry = SectionMap[GV->getSection()];
-      if (!Entry) {
-        WriteStringRecord(bitc::MODULE_CODE_SECTIONNAME, GV->getSection(),
-                          0/*TODO*/, Stream);
-        Entry = SectionMap.size();
-      }
-    }
+
+    if (!GV->hasSection()) continue;
+    // Give section names unique ID's.
+    unsigned &Entry = SectionMap[GV->getSection()];
+    if (Entry != 0) continue;
+    WriteStringRecord(bitc::MODULE_CODE_SECTIONNAME, GV->getSection(),
+                      0/*TODO*/, Stream);
+    Entry = SectionMap.size();
   }
   for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) {
     MaxAlignment = std::max(MaxAlignment, F->getAlignment());
@@ -651,7 +649,7 @@
         }
         WriteMDNode(N, VE, Stream, Record);
       }
-      
+
   if (StartedMetadataBlock)
     Stream.ExitBlock();
 }
@@ -666,18 +664,18 @@
   // Write metadata attachments
   // METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]]
   SmallVector<std::pair<unsigned, MDNode*>, 4> MDs;
-  
+
   for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
     for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
          I != E; ++I) {
       MDs.clear();
       I->getAllMetadataOtherThanDebugLoc(MDs);
-      
+
       // If no metadata, ignore instruction.
       if (MDs.empty()) continue;
 
       Record.push_back(VE.getInstructionID(I));
-      
+
       for (unsigned i = 0, e = MDs.size(); i != e; ++i) {
         Record.push_back(MDs[i].first);
         Record.push_back(VE.getValueID(MDs[i].second));
@@ -696,16 +694,16 @@
   // METADATA_KIND - [n x [id, name]]
   SmallVector<StringRef, 4> Names;
   M->getMDKindNames(Names);
-  
+
   if (Names.empty()) return;
 
   Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
-  
+
   for (unsigned MDKindID = 0, e = Names.size(); MDKindID != e; ++MDKindID) {
     Record.push_back(MDKindID);
     StringRef KName = Names[MDKindID];
     Record.append(KName.begin(), KName.end());
-    
+
     Stream.EmitRecord(bitc::METADATA_KIND, Record, 0);
     Record.clear();
   }
@@ -861,12 +859,12 @@
         if (isCStrChar6)
           isCStrChar6 = BitCodeAbbrevOp::isChar6(V);
       }
-      
+
       if (isCStrChar6)
         AbbrevToUse = CString6Abbrev;
       else if (isCStr7)
         AbbrevToUse = CString7Abbrev;
-    } else if (const ConstantDataSequential *CDS = 
+    } else if (const ConstantDataSequential *CDS =
                   dyn_cast<ConstantDataSequential>(C)) {
       // We must replace ConstantDataSequential's representation with the
       // legacy ConstantArray/ConstantVector/ConstantStruct version.
@@ -1152,7 +1150,7 @@
     for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i)
       Vals.push_back(VE.getValueID(I.getOperand(i)));
     break;
-      
+
   case Instruction::Invoke: {
     const InvokeInst *II = cast<InvokeInst>(&I);
     const Value *Callee(II->getCalledValue());
@@ -1399,21 +1397,21 @@
   unsigned InstID = CstEnd;
 
   bool NeedsMetadataAttachment = false;
-  
+
   DebugLoc LastDL;
-  
+
   // Finally, emit all the instructions, in order.
   for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
     for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
          I != E; ++I) {
       WriteInstruction(*I, InstID, VE, Stream, Vals);
-      
+
       if (!I->getType()->isVoidTy())
         ++InstID;
-      
+
       // If the instruction has metadata, write a metadata attachment later.
       NeedsMetadataAttachment |= I->hasMetadataOtherThanDebugLoc();
-      
+
       // If the instruction has a debug location, emit it.
       DebugLoc DL = I->getDebugLoc();
       if (DL.isUnknown()) {
@@ -1424,14 +1422,14 @@
       } else {
         MDNode *Scope, *IA;
         DL.getScopeAndInlinedAt(Scope, IA, I->getContext());
-        
+
         Vals.push_back(DL.getLine());
         Vals.push_back(DL.getCol());
         Vals.push_back(Scope ? VE.getValueID(Scope)+1 : 0);
         Vals.push_back(IA ? VE.getValueID(IA)+1 : 0);
         Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals);
         Vals.clear();
-        
+
         LastDL = DL;
       }
     }
diff --git a/BitWriter_2_9_func/BitcodeWriterPass.cpp b/BitWriter_2_9_func/BitcodeWriterPass.cpp
index 1bd6cd0..14eb2ff 100644
--- a/BitWriter_2_9_func/BitcodeWriterPass.cpp
+++ b/BitWriter_2_9_func/BitcodeWriterPass.cpp
@@ -12,9 +12,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "ReaderWriter_2_9_func.h"
-#include "llvm/Function.h"
-#include "llvm/Instructions.h"
-#include "llvm/Module.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
 #include "llvm/Pass.h"
 using namespace llvm;
 
diff --git a/BitWriter_2_9_func/ValueEnumerator.cpp b/BitWriter_2_9_func/ValueEnumerator.cpp
index 88c406f..9bdd5e9 100644
--- a/BitWriter_2_9_func/ValueEnumerator.cpp
+++ b/BitWriter_2_9_func/ValueEnumerator.cpp
@@ -12,13 +12,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "ValueEnumerator.h"
-#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/Constants.h"
-#include "llvm/DerivedTypes.h"
-#include "llvm/Module.h"
-#include "llvm/ValueSymbolTable.h"
-#include "llvm/Instructions.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/ValueSymbolTable.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
@@ -97,7 +97,7 @@
         I->getAllMetadataOtherThanDebugLoc(MDs);
         for (unsigned i = 0, e = MDs.size(); i != e; ++i)
           EnumerateMetadata(MDs[i].second);
-        
+
         if (!I->getDebugLoc().isUnknown()) {
           MDNode *Scope, *IA;
           I->getDebugLoc().getScopeAndInlinedAt(Scope, IA, I->getContext());
@@ -374,16 +374,16 @@
   if (StructType *STy = dyn_cast<StructType>(Ty))
     if (!STy->isLiteral())
       *TypeID = ~0U;
-  
+
   // Enumerate all of the subtypes before we enumerate this type.  This ensures
   // that the type will be enumerated in an order that can be directly built.
   for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
        I != E; ++I)
     EnumerateType(*I);
-  
+
   // Refresh the TypeID pointer in case the table rehashed.
   TypeID = &TypeMap[Ty];
-  
+
   // Check to see if we got the pointer another way.  This can happen when
   // enumerating recursive types that hit the base case deeper than they start.
   //
@@ -391,10 +391,10 @@
   // then emit the definition now that all of its contents are available.
   if (*TypeID && *TypeID != ~0U)
     return;
-  
+
   // Add this type now that its contents are all happily enumerated.
   Types.push_back(Ty);
-  
+
   *TypeID = Types.size();
 }
 
@@ -402,7 +402,7 @@
 // walk through it, enumerating the types of the constant.
 void ValueEnumerator::EnumerateOperandType(const Value *V) {
   EnumerateType(V->getType());
-  
+
   if (const Constant *C = dyn_cast<Constant>(V)) {
     // If this constant is already enumerated, ignore it, we know its type must
     // be enumerated.
@@ -412,11 +412,11 @@
     // them.
     for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) {
       const Value *Op = C->getOperand(i);
-      
+
       // Don't enumerate basic blocks here, this happens as operands to
       // blockaddress.
       if (isa<BasicBlock>(Op)) continue;
-      
+
       EnumerateOperandType(Op);
     }
 
@@ -429,14 +429,14 @@
     EnumerateMetadata(V);
 }
 
-void ValueEnumerator::EnumerateAttributes(const AttrListPtr &PAL) {
+void ValueEnumerator::EnumerateAttributes(const AttributeSet &PAL) {
   if (PAL.isEmpty()) return;  // null is always 0.
   // Do a lookup.
   unsigned &Entry = AttributeMap[PAL.getRawPointer()];
   if (Entry == 0) {
     // Never saw this before, add it.
-    Attributes.push_back(PAL);
-    Entry = Attributes.size();
+    Attribute.push_back(PAL);
+    Entry = Attribute.size();
   }
 }
 
@@ -493,7 +493,7 @@
         if (N->isFunctionLocal() && N->getFunction())
           FnLocalMDVector.push_back(N);
       }
-        
+
       if (!I->getType()->isVoidTy())
         EnumerateValue(I);
     }
diff --git a/BitWriter_2_9_func/ValueEnumerator.h b/BitWriter_2_9_func/ValueEnumerator.h
index bfcc8da..8636358 100644
--- a/BitWriter_2_9_func/ValueEnumerator.h
+++ b/BitWriter_2_9_func/ValueEnumerator.h
@@ -16,7 +16,7 @@
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/Attributes.h"
+#include "llvm/IR/Attributes.h"
 #include <vector>
 
 namespace llvm {
@@ -29,7 +29,7 @@
 class Module;
 class MDNode;
 class NamedMDNode;
-class AttrListPtr;
+class AttributeSet;
 class ValueSymbolTable;
 class MDSymbolTable;
 class raw_ostream;
@@ -55,15 +55,15 @@
   ValueList MDValues;
   llvm::SmallVector<const llvm::MDNode *, 8> FunctionLocalMDs;
   ValueMapType MDValueMap;
-  
+
   typedef llvm::DenseMap<void*, unsigned> AttributeMapType;
   AttributeMapType AttributeMap;
-  std::vector<llvm::AttrListPtr> Attributes;
-  
+  std::vector<llvm::AttributeSet> Attribute;
+
   /// GlobalBasicBlockIDs - This map memoizes the basic block ID's referenced by
   /// the "getGlobalBasicBlockID" method.
   mutable llvm::DenseMap<const llvm::BasicBlock*, unsigned> GlobalBasicBlockIDs;
-  
+
   typedef llvm::DenseMap<const llvm::Instruction*, unsigned> InstructionMapType;
   InstructionMapType InstructionMap;
   unsigned InstructionCount;
@@ -71,7 +71,7 @@
   /// BasicBlocks - This contains all the basic blocks for the currently
   /// incorporated function.  Their reverse mapping is stored in ValueMap.
   std::vector<const llvm::BasicBlock*> BasicBlocks;
-  
+
   /// When a function is incorporated, this is the size of the Values list
   /// before incorporation.
   unsigned NumModuleValues;
@@ -82,7 +82,7 @@
 
   unsigned FirstFuncConstantID;
   unsigned FirstInstID;
-  
+
   ValueEnumerator(const ValueEnumerator &);  // DO NOT IMPLEMENT
   void operator=(const ValueEnumerator &);   // DO NOT IMPLEMENT
 public:
@@ -102,7 +102,7 @@
   unsigned getInstructionID(const llvm::Instruction *I) const;
   void setInstructionID(const llvm::Instruction *I);
 
-  unsigned getAttributeID(const llvm::AttrListPtr &PAL) const {
+  unsigned getAttributeID(const llvm::AttributeSet &PAL) const {
     if (PAL.isEmpty()) return 0;  // Null maps to zero.
     AttributeMapType::const_iterator I = AttributeMap.find(PAL.getRawPointer());
     assert(I != AttributeMap.end() && "Attribute not in ValueEnumerator!");
@@ -115,20 +115,20 @@
     Start = FirstFuncConstantID;
     End = FirstInstID;
   }
-  
+
   const ValueList &getValues() const { return Values; }
   const ValueList &getMDValues() const { return MDValues; }
-  const llvm::SmallVector<const llvm::MDNode *, 8> &getFunctionLocalMDValues() const { 
+  const llvm::SmallVector<const llvm::MDNode *, 8> &getFunctionLocalMDValues() const {
     return FunctionLocalMDs;
   }
   const TypeList &getTypes() const { return Types; }
   const std::vector<const llvm::BasicBlock*> &getBasicBlocks() const {
-    return BasicBlocks; 
+    return BasicBlocks;
   }
-  const std::vector<llvm::AttrListPtr> &getAttributes() const {
-    return Attributes;
+  const std::vector<llvm::AttributeSet> &getAttributes() const {
+    return Attribute;
   }
-  
+
   /// getGlobalBasicBlockID - This returns the function-specific ID for the
   /// specified basic block.  This is relatively expensive information, so it
   /// should only be used by rare constructs such as address-of-label.
@@ -142,7 +142,7 @@
 
 private:
   void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
-    
+
   void EnumerateMDNodeOperands(const llvm::MDNode *N);
   void EnumerateMetadata(const llvm::Value *MD);
   void EnumerateFunctionLocalMetadata(const llvm::MDNode *N);
@@ -150,8 +150,8 @@
   void EnumerateValue(const llvm::Value *V);
   void EnumerateType(llvm::Type *T);
   void EnumerateOperandType(const llvm::Value *V);
-  void EnumerateAttributes(const llvm::AttrListPtr &PAL);
-  
+  void EnumerateAttributes(const llvm::AttributeSet &PAL);
+
   void EnumerateValueSymbolTable(const llvm::ValueSymbolTable &ST);
   void EnumerateNamedMetadata(const llvm::Module *M);
 };
diff --git a/BitWriter_3_2/BitcodeWriter.cpp b/BitWriter_3_2/BitcodeWriter.cpp
index dd24512..a7f7234 100644
--- a/BitWriter_3_2/BitcodeWriter.cpp
+++ b/BitWriter_3_2/BitcodeWriter.cpp
@@ -12,22 +12,22 @@
 //===----------------------------------------------------------------------===//
 
 #include "ReaderWriter_3_2.h"
+#include "ValueEnumerator.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/Bitcode/BitstreamWriter.h"
 #include "llvm/Bitcode/LLVMBitCodes.h"
-#include "ValueEnumerator.h"
-#include "llvm/Constants.h"
-#include "llvm/DerivedTypes.h"
-#include "llvm/InlineAsm.h"
-#include "llvm/Instructions.h"
-#include "llvm/Module.h"
-#include "llvm/Operator.h"
-#include "llvm/ValueSymbolTable.h"
-#include "llvm/ADT/Triple.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/InlineAsm.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Operator.h"
+#include "llvm/IR/ValueSymbolTable.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/Program.h"
+#include "llvm/Support/raw_ostream.h"
 #include <cctype>
 #include <map>
 using namespace llvm;
@@ -63,7 +63,7 @@
   FUNCTION_INST_RET_VOID_ABBREV,
   FUNCTION_INST_RET_VAL_ABBREV,
   FUNCTION_INST_UNREACHABLE_ABBREV,
-  
+
   // SwitchInst Magic
   SWITCH_INST_MAGIC = 0x4B5 // May 2012 => 1205 => Hex
 };
@@ -166,14 +166,14 @@
 // Emit information about parameter attributes.
 static void WriteAttributeTable(const llvm_3_2::ValueEnumerator &VE,
                                 BitstreamWriter &Stream) {
-  const std::vector<AttrListPtr> &Attrs = VE.getAttributes();
+  const std::vector<AttributeSet> &Attrs = VE.getAttributes();
   if (Attrs.empty()) return;
 
   Stream.EnterSubblock(bitc::PARAMATTR_BLOCK_ID, 3);
 
   SmallVector<uint64_t, 64> Record;
   for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
-    const AttrListPtr &A = Attrs[i];
+    const AttributeSet &A = Attrs[i];
     for (unsigned i = 0, e = A.getNumSlots(); i != e; ++i) {
       const AttributeWithIndex &PAWI = A.getSlot(i);
       Record.push_back(PAWI.Index);
@@ -237,7 +237,7 @@
   Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits));
 
   unsigned StructNamedAbbrev = Stream.EmitAbbrev(Abbv);
-  
+
   // Abbrev for TYPE_CODE_ARRAY.
   Abbv = new BitCodeAbbrev();
   Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_ARRAY));
@@ -303,7 +303,7 @@
       for (StructType::element_iterator I = ST->element_begin(),
            E = ST->element_end(); I != E; ++I)
         TypeVals.push_back(VE.getTypeID(*I));
-      
+
       if (ST->isLiteral()) {
         Code = bitc::TYPE_CODE_STRUCT_ANON;
         AbbrevToUse = StructAnonAbbrev;
@@ -396,10 +396,6 @@
 static void WriteModuleInfo(const Module *M,
                             const llvm_3_2::ValueEnumerator &VE,
                             BitstreamWriter &Stream) {
-  // Emit the list of dependent libraries for the Module.
-  for (Module::lib_iterator I = M->lib_begin(), E = M->lib_end(); I != E; ++I)
-    WriteStringRecord(bitc::MODULE_CODE_DEPLIB, *I, 0/*TODO*/, Stream);
-
   // Emit various pieces of data attached to a module.
   if (!M->getTargetTriple().empty())
     WriteStringRecord(bitc::MODULE_CODE_TRIPLE, M->getTargetTriple(),
@@ -662,7 +658,7 @@
         }
         WriteMDNode(N, VE, Stream, Record);
       }
-      
+
   if (StartedMetadataBlock)
     Stream.ExitBlock();
 }
@@ -677,18 +673,18 @@
   // Write metadata attachments
   // METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]]
   SmallVector<std::pair<unsigned, MDNode*>, 4> MDs;
-  
+
   for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
     for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
          I != E; ++I) {
       MDs.clear();
       I->getAllMetadataOtherThanDebugLoc(MDs);
-      
+
       // If no metadata, ignore instruction.
       if (MDs.empty()) continue;
 
       Record.push_back(VE.getInstructionID(I));
-      
+
       for (unsigned i = 0, e = MDs.size(); i != e; ++i) {
         Record.push_back(MDs[i].first);
         Record.push_back(VE.getValueID(MDs[i].second));
@@ -707,16 +703,16 @@
   // METADATA_KIND - [n x [id, name]]
   SmallVector<StringRef, 4> Names;
   M->getMDKindNames(Names);
-  
+
   if (Names.empty()) return;
 
   Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
-  
+
   for (unsigned MDKindID = 0, e = Names.size(); MDKindID != e; ++MDKindID) {
     Record.push_back(MDKindID);
     StringRef KName = Names[MDKindID];
     Record.append(KName.begin(), KName.end());
-    
+
     Stream.EmitRecord(bitc::METADATA_KIND, Record, 0);
     Record.clear();
   }
@@ -743,10 +739,10 @@
     // format it is likely that the high bits are going to be zero.
     // So, we only write the number of active words.
     unsigned NWords = Val.getActiveWords();
-    
+
     if (EmitSizeForWideNumbers)
       Vals.push_back(NWords);
-    
+
     const uint64_t *RawWords = Val.getRawData();
     for (unsigned i = 0; i != NWords; ++i) {
       int64_t V = RawWords[i];
@@ -885,12 +881,12 @@
         if (isCStrChar6)
           isCStrChar6 = BitCodeAbbrevOp::isChar6(V);
       }
-      
+
       if (isCStrChar6)
         AbbrevToUse = CString6Abbrev;
       else if (isCStr7)
         AbbrevToUse = CString7Abbrev;
-    } else if (const ConstantDataSequential *CDS = 
+    } else if (const ConstantDataSequential *CDS =
                   dyn_cast<ConstantDataSequential>(C)) {
       Code = bitc::CST_CODE_DATA;
       Type *EltTy = CDS->getType()->getElementType();
@@ -1159,13 +1155,13 @@
       // Redefine Vals, since here we need to use 64 bit values
       // explicitly to store large APInt numbers.
       SmallVector<uint64_t, 128> Vals64;
-      
+
       Code = bitc::FUNC_CODE_INST_SWITCH;
       SwitchInst &SI = cast<SwitchInst>(I);
-      
-      uint32_t SwitchRecordHeader = SI.hash() | (SWITCH_INST_MAGIC << 16); 
-      Vals64.push_back(SwitchRecordHeader);      
-      
+
+      uint32_t SwitchRecordHeader = SI.hash() | (SWITCH_INST_MAGIC << 16);
+      Vals64.push_back(SwitchRecordHeader);
+
       Vals64.push_back(VE.getTypeID(SI.getCondition()->getType()));
       Vals64.push_back(VE.getValueID(SI.getCondition()));
       Vals64.push_back(VE.getValueID(SI.getDefaultDest()));
@@ -1174,21 +1170,21 @@
            i != e; ++i) {
         IntegersSubset& CaseRanges = i.getCaseValueEx();
         unsigned Code, Abbrev; // will unused.
-        
+
         if (CaseRanges.isSingleNumber()) {
           Vals64.push_back(1/*NumItems = 1*/);
           Vals64.push_back(true/*IsSingleNumber = true*/);
           EmitAPInt(Vals64, Code, Abbrev, CaseRanges.getSingleNumber(0), true);
         } else {
-          
+
           Vals64.push_back(CaseRanges.getNumItems());
-          
+
           if (CaseRanges.isSingleNumbersOnly()) {
             for (unsigned ri = 0, rn = CaseRanges.getNumItems();
                  ri != rn; ++ri) {
-              
+
               Vals64.push_back(true/*IsSingleNumber = true*/);
-              
+
               EmitAPInt(Vals64, Code, Abbrev,
                         CaseRanges.getSingleNumber(ri), true);
             }
@@ -1197,9 +1193,9 @@
                  ri != rn; ++ri) {
               IntegersSubset::Range r = CaseRanges.getItem(ri);
               bool IsSingleNumber = CaseRanges.isSingleNumber(ri);
-    
+
               Vals64.push_back(IsSingleNumber);
-              
+
               EmitAPInt(Vals64, Code, Abbrev, r.getLow(), true);
               if (!IsSingleNumber)
                 EmitAPInt(Vals64, Code, Abbrev, r.getHigh(), true);
@@ -1207,9 +1203,9 @@
         }
         Vals64.push_back(VE.getValueID(i.getCaseSuccessor()));
       }
-      
+
       Stream.EmitRecord(Code, Vals64, AbbrevToUse);
-      
+
       // Also do expected action - clear external Vals collection:
       Vals.clear();
       return;
@@ -1221,7 +1217,7 @@
     for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i)
       Vals.push_back(VE.getValueID(I.getOperand(i)));
     break;
-      
+
   case Instruction::Invoke: {
     const InvokeInst *II = cast<InvokeInst>(&I);
     const Value *Callee(II->getCalledValue());
@@ -1468,21 +1464,21 @@
   unsigned InstID = CstEnd;
 
   bool NeedsMetadataAttachment = false;
-  
+
   DebugLoc LastDL;
-  
+
   // Finally, emit all the instructions, in order.
   for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
     for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
          I != E; ++I) {
       WriteInstruction(*I, InstID, VE, Stream, Vals);
-      
+
       if (!I->getType()->isVoidTy())
         ++InstID;
-      
+
       // If the instruction has metadata, write a metadata attachment later.
       NeedsMetadataAttachment |= I->hasMetadataOtherThanDebugLoc();
-      
+
       // If the instruction has a debug location, emit it.
       DebugLoc DL = I->getDebugLoc();
       if (DL.isUnknown()) {
@@ -1493,14 +1489,14 @@
       } else {
         MDNode *Scope, *IA;
         DL.getScopeAndInlinedAt(Scope, IA, I->getContext());
-        
+
         Vals.push_back(DL.getLine());
         Vals.push_back(DL.getCol());
         Vals.push_back(Scope ? VE.getValueID(Scope)+1 : 0);
         Vals.push_back(IA ? VE.getValueID(IA)+1 : 0);
         Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals);
         Vals.clear();
-        
+
         LastDL = DL;
       }
     }
@@ -1676,7 +1672,7 @@
   Stream.ExitBlock();
 }
 
-// Sort the Users based on the order in which the reader parses the bitcode 
+// Sort the Users based on the order in which the reader parses the bitcode
 // file.
 static bool bitcodereader_order(const User *lhs, const User *rhs) {
   // TODO: Implement.
@@ -1746,9 +1742,9 @@
   for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
        I != E; ++I)
     I->removeDeadConstantUsers();
-  
+
   // Write the global variables.
-  for (Module::const_global_iterator GI = M->global_begin(), 
+  for (Module::const_global_iterator GI = M->global_begin(),
          GE = M->global_end(); GI != GE; ++GI) {
     WriteUseList(GI, VE, Stream);
 
diff --git a/BitWriter_3_2/ValueEnumerator.cpp b/BitWriter_3_2/ValueEnumerator.cpp
index dc7f604..556f06a 100644
--- a/BitWriter_3_2/ValueEnumerator.cpp
+++ b/BitWriter_3_2/ValueEnumerator.cpp
@@ -12,13 +12,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "ValueEnumerator.h"
-#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/Constants.h"
-#include "llvm/DerivedTypes.h"
-#include "llvm/Module.h"
-#include "llvm/ValueSymbolTable.h"
-#include "llvm/Instructions.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/ValueSymbolTable.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
@@ -97,7 +97,7 @@
         I->getAllMetadataOtherThanDebugLoc(MDs);
         for (unsigned i = 0, e = MDs.size(); i != e; ++i)
           EnumerateMetadata(MDs[i].second);
-        
+
         if (!I->getDebugLoc().isUnknown()) {
           MDNode *Scope, *IA;
           I->getDebugLoc().getScopeAndInlinedAt(Scope, IA, I->getContext());
@@ -364,16 +364,16 @@
   if (StructType *STy = dyn_cast<StructType>(Ty))
     if (!STy->isLiteral())
       *TypeID = ~0U;
-  
+
   // Enumerate all of the subtypes before we enumerate this type.  This ensures
   // that the type will be enumerated in an order that can be directly built.
   for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
        I != E; ++I)
     EnumerateType(*I);
-  
+
   // Refresh the TypeID pointer in case the table rehashed.
   TypeID = &TypeMap[Ty];
-  
+
   // Check to see if we got the pointer another way.  This can happen when
   // enumerating recursive types that hit the base case deeper than they start.
   //
@@ -381,10 +381,10 @@
   // then emit the definition now that all of its contents are available.
   if (*TypeID && *TypeID != ~0U)
     return;
-  
+
   // Add this type now that its contents are all happily enumerated.
   Types.push_back(Ty);
-  
+
   *TypeID = Types.size();
 }
 
@@ -392,7 +392,7 @@
 // walk through it, enumerating the types of the constant.
 void ValueEnumerator::EnumerateOperandType(const Value *V) {
   EnumerateType(V->getType());
-  
+
   if (const Constant *C = dyn_cast<Constant>(V)) {
     // If this constant is already enumerated, ignore it, we know its type must
     // be enumerated.
@@ -402,11 +402,11 @@
     // them.
     for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) {
       const Value *Op = C->getOperand(i);
-      
+
       // Don't enumerate basic blocks here, this happens as operands to
       // blockaddress.
       if (isa<BasicBlock>(Op)) continue;
-      
+
       EnumerateOperandType(Op);
     }
 
@@ -419,14 +419,14 @@
     EnumerateMetadata(V);
 }
 
-void ValueEnumerator::EnumerateAttributes(const AttrListPtr &PAL) {
+void ValueEnumerator::EnumerateAttributes(const AttributeSet &PAL) {
   if (PAL.isEmpty()) return;  // null is always 0.
   // Do a lookup.
   unsigned &Entry = AttributeMap[PAL.getRawPointer()];
   if (Entry == 0) {
     // Never saw this before, add it.
-    Attributes.push_back(PAL);
-    Entry = Attributes.size();
+    Attribute.push_back(PAL);
+    Entry = Attribute.size();
   }
 }
 
@@ -483,7 +483,7 @@
         if (N->isFunctionLocal() && N->getFunction())
           FnLocalMDVector.push_back(N);
       }
-        
+
       if (!I->getType()->isVoidTy())
         EnumerateValue(I);
     }
diff --git a/BitWriter_3_2/ValueEnumerator.h b/BitWriter_3_2/ValueEnumerator.h
index ff15527..de64da4 100644
--- a/BitWriter_3_2/ValueEnumerator.h
+++ b/BitWriter_3_2/ValueEnumerator.h
@@ -16,7 +16,7 @@
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/Attributes.h"
+#include "llvm/IR/Attributes.h"
 #include <vector>
 
 namespace llvm {
@@ -29,7 +29,7 @@
 class Module;
 class MDNode;
 class NamedMDNode;
-class AttrListPtr;
+class AttributeSet;
 class ValueSymbolTable;
 class MDSymbolTable;
 class raw_ostream;
@@ -55,15 +55,15 @@
   ValueList MDValues;
   llvm::SmallVector<const llvm::MDNode *, 8> FunctionLocalMDs;
   ValueMapType MDValueMap;
-  
+
   typedef llvm::DenseMap<void*, unsigned> AttributeMapType;
   AttributeMapType AttributeMap;
-  std::vector<llvm::AttrListPtr> Attributes;
-  
+  std::vector<llvm::AttributeSet> Attribute;
+
   /// GlobalBasicBlockIDs - This map memoizes the basic block ID's referenced by
   /// the "getGlobalBasicBlockID" method.
   mutable llvm::DenseMap<const llvm::BasicBlock*, unsigned> GlobalBasicBlockIDs;
-  
+
   typedef llvm::DenseMap<const llvm::Instruction*, unsigned> InstructionMapType;
   InstructionMapType InstructionMap;
   unsigned InstructionCount;
@@ -71,7 +71,7 @@
   /// BasicBlocks - This contains all the basic blocks for the currently
   /// incorporated function.  Their reverse mapping is stored in ValueMap.
   std::vector<const llvm::BasicBlock*> BasicBlocks;
-  
+
   /// When a function is incorporated, this is the size of the Values list
   /// before incorporation.
   unsigned NumModuleValues;
@@ -82,7 +82,7 @@
 
   unsigned FirstFuncConstantID;
   unsigned FirstInstID;
-  
+
   ValueEnumerator(const ValueEnumerator &);  // DO NOT IMPLEMENT
   void operator=(const ValueEnumerator &);   // DO NOT IMPLEMENT
 public:
@@ -102,7 +102,7 @@
   unsigned getInstructionID(const llvm::Instruction *I) const;
   void setInstructionID(const llvm::Instruction *I);
 
-  unsigned getAttributeID(const llvm::AttrListPtr &PAL) const {
+  unsigned getAttributeID(const llvm::AttributeSet &PAL) const {
     if (PAL.isEmpty()) return 0;  // Null maps to zero.
     AttributeMapType::const_iterator I = AttributeMap.find(PAL.getRawPointer());
     assert(I != AttributeMap.end() && "Attribute not in ValueEnumerator!");
@@ -115,20 +115,20 @@
     Start = FirstFuncConstantID;
     End = FirstInstID;
   }
-  
+
   const ValueList &getValues() const { return Values; }
   const ValueList &getMDValues() const { return MDValues; }
-  const llvm::SmallVector<const llvm::MDNode *, 8> &getFunctionLocalMDValues() const { 
+  const llvm::SmallVector<const llvm::MDNode *, 8> &getFunctionLocalMDValues() const {
     return FunctionLocalMDs;
   }
   const TypeList &getTypes() const { return Types; }
   const std::vector<const llvm::BasicBlock*> &getBasicBlocks() const {
-    return BasicBlocks; 
+    return BasicBlocks;
   }
-  const std::vector<llvm::AttrListPtr> &getAttributes() const {
-    return Attributes;
+  const std::vector<llvm::AttributeSet> &getAttributes() const {
+    return Attribute;
   }
-  
+
   /// getGlobalBasicBlockID - This returns the function-specific ID for the
   /// specified basic block.  This is relatively expensive information, so it
   /// should only be used by rare constructs such as address-of-label.
@@ -142,7 +142,7 @@
 
 private:
   void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
-    
+
   void EnumerateMDNodeOperands(const llvm::MDNode *N);
   void EnumerateMetadata(const llvm::Value *MD);
   void EnumerateFunctionLocalMetadata(const llvm::MDNode *N);
@@ -150,8 +150,8 @@
   void EnumerateValue(const llvm::Value *V);
   void EnumerateType(llvm::Type *T);
   void EnumerateOperandType(const llvm::Value *V);
-  void EnumerateAttributes(const llvm::AttrListPtr &PAL);
-  
+  void EnumerateAttributes(const llvm::AttributeSet &PAL);
+
   void EnumerateValueSymbolTable(const llvm::ValueSymbolTable &ST);
   void EnumerateNamedMetadata(const llvm::Module *M);
 };
diff --git a/RSCCOptions.td b/RSCCOptions.td
index caeba16..76bb497 100644
--- a/RSCCOptions.td
+++ b/RSCCOptions.td
@@ -27,69 +27,69 @@
 // Target Options
 //===----------------------------------------------------------------------===//
 
-def target_api : Separate<"-target-api">,
+def target_api : Separate<["-"], "target-api">,
   HelpText<"Specify target API level (e.g. 14)">;
-def target_api_EQ : Joined<"-target-api=">, Alias<target_api>;
+def target_api_EQ : Joined<["-"], "target-api=">, Alias<target_api>;
 
 //===----------------------------------------------------------------------===//
 // Header Search Options
 //===----------------------------------------------------------------------===//
 
-def I : JoinedOrSeparate<"-I">, MetaVarName<"<directory>">,
+def I : JoinedOrSeparate<["-"], "I">, MetaVarName<"<directory>">,
   HelpText<"Add directory to include search path">;
-def _I : Separate<"include-path">, MetaVarName<"<directory>">, Alias<I>;
+def _I : Separate<["-", "--"], "include-path">, MetaVarName<"<directory>">, Alias<I>;
 
 //===----------------------------------------------------------------------===//
 // Frontend Options
 //===----------------------------------------------------------------------===//
 
-def o : Separate<"-o">, MetaVarName<"<directory>">,
+def o : Separate<["-"], "o">, MetaVarName<"<directory>">,
   HelpText<"Specify output directory">;
 
 def Output_Type_Group : OptionGroup<"<output type group>">;
 let Group = Output_Type_Group in {
 
-def emit_asm : Flag<"-emit-asm">,
+def emit_asm : Flag<["-"], "emit-asm">,
   HelpText<"Emit target assembly files">;
-def _emit_asm : Flag<"-S">, Alias<emit_asm>;
-def emit_llvm : Flag<"-emit-llvm">,
+def _emit_asm : Flag<["-"], "S">, Alias<emit_asm>;
+def emit_llvm : Flag<["-"], "emit-llvm">,
   HelpText<"Build ASTs then convert to LLVM, emit .ll file">;
-def emit_bc : Flag<"-emit-bc">,
+def emit_bc : Flag<["-"], "emit-bc">,
   HelpText<"Build ASTs then convert to LLVM, emit .bc file">;
-def emit_nothing : Flag<"-emit-nothing">,
+def emit_nothing : Flag<["-"], "emit-nothing">,
   HelpText<"Build ASTs then convert to LLVM, but emit nothing">;
 }
 
-def emit_g : Flag<"-g">,
+def emit_g : Flag<["-"], "g">,
   HelpText<"Emit LLVM Debug Metadata">;
 
-def optimization_level : Separate<"-O">, MetaVarName<"<optimization-level>">,
+def optimization_level : Separate<["-"], "O">, MetaVarName<"<optimization-level>">,
   HelpText<"<optimization-level> can be one of '0' or '3' (default)">;
 
-def allow_rs_prefix : Flag<"-allow-rs-prefix">,
+def allow_rs_prefix : Flag<["-"], "allow-rs-prefix">,
   HelpText<"Allow user-defined function prefixed with 'rs'">;
 
-def java_reflection_path_base : Separate<"-java-reflection-path-base">,
+def java_reflection_path_base : Separate<["-"], "java-reflection-path-base">,
   MetaVarName<"<directory>">,
   HelpText<"Base directory for output reflected Java files">;
-def _java_reflection_path_base : Separate<"-p">,
+def _java_reflection_path_base : Separate<["-"], "p">,
   Alias<java_reflection_path_base>;
-def java_reflection_package_name : Separate<"-java-reflection-package-name">,
+def java_reflection_package_name : Separate<["-"], "java-reflection-package-name">,
   HelpText<"Specify the package name that reflected Java files belong to">;
-def _java_reflection_package_name : Separate<"-j">,
+def _java_reflection_package_name : Separate<["-"], "j">,
   Alias<java_reflection_package_name>;
 
-def bitcode_storage : Separate<"-bitcode-storage">,
+def bitcode_storage : Separate<["-"], "bitcode-storage">,
   MetaVarName<"<value>">, HelpText<"<value> should be 'ar' or 'jc'">;
-def _bitcode_storage : Separate<"-s">, Alias<bitcode_storage>;
+def _bitcode_storage : Separate<["-"], "s">, Alias<bitcode_storage>;
 
-def rs_package_name : Separate<"-rs-package-name">,
+def rs_package_name : Separate<["-"], "rs-package-name">,
   MetaVarName<"<package_name>">,
   HelpText<"package name for referencing RS classes">;
-def rs_package_name_EQ : Joined<"-rs-package-name=">, Alias<rs_package_name>;
+def rs_package_name_EQ : Joined<["-"], "rs-package-name=">, Alias<rs_package_name>;
 
-def W : Joined<"-W">;
-def w : Flag<"-w">, HelpText<"Suppress all warnings">;
+def W : Joined<["-"], "W">;
+def w : Flag<["-"], "w">, HelpText<"Suppress all warnings">;
 
 //===----------------------------------------------------------------------===//
 // Dependency Output Options
@@ -98,39 +98,39 @@
 def M_Group : OptionGroup<"M group>">;
 let Group = M_Group in {
 
-  def MD : Flag<"-MD">;
+  def MD : Flag<["-"], "MD">;
 
-  def M : Flag<"-M">;
-  def emit_dep : Flag<"-emit-dep">, Alias<M>;
+  def M : Flag<["-"], "M">;
+  def emit_dep : Flag<["-"], "emit-dep">, Alias<M>;
 }
 
-def output_dep_dir : Separate<"-output-dep-dir">, MetaVarName<"<directory>">,
+def output_dep_dir : Separate<["-"], "output-dep-dir">, MetaVarName<"<directory>">,
   HelpText<"Specify output directory for dependencies output">;
-def _output_dep_dir : Separate<"-d">, Alias<output_dep_dir>;
+def _output_dep_dir : Separate<["-"], "d">, Alias<output_dep_dir>;
 
-def additional_dep_target: Separate<"-additional-dep-target">,
+def additional_dep_target: Separate<["-"], "additional-dep-target">,
   HelpText<"Additional targets to show up in dependencies output">;
-def _additional_dep_target : Separate<"-a">, Alias<additional_dep_target>;
+def _additional_dep_target : Separate<["-"], "a">, Alias<additional_dep_target>;
 
 //===----------------------------------------------------------------------===//
 // Reflection Options
 //===----------------------------------------------------------------------===//
 
-def reflect_cpp : Flag<"-reflect-c++">,
+def reflect_cpp : Flag<["-"], "reflect-c++">,
   HelpText<"Reflect C++ classes">;
 
 //===----------------------------------------------------------------------===//
 // Misc Options
 //===----------------------------------------------------------------------===//
 
-def help : Flag<"-help">,
+def help : Flag<["-"], "help">,
   HelpText<"Print this help text">;
-def _help : Flag<"--help">, Alias<help>;
-def __help : Flag<"-h">, Alias<help>;
+def _help : Flag<["--"], "help">, Alias<help>;
+def __help : Flag<["-"], "h">, Alias<help>;
 
-def version : Flag<"-version">,
+def version : Flag<["-"], "version">,
   HelpText<"Print the assembler version">;
-def _version : Flag<"--version">, Alias<version>;
+def _version : Flag<["--"], "version">, Alias<version>;
 
 // Compatible with old slang
-def no_link : Flag<"-no-link">;  // currently no effect
+def no_link : Flag<["-"], "no-link">;  // currently no effect
diff --git a/llvm-rs-cc.cpp b/llvm-rs-cc.cpp
index 1e60c6e..cc77b7a 100644
--- a/llvm-rs-cc.cpp
+++ b/llvm-rs-cc.cpp
@@ -27,7 +27,7 @@
 #include "clang/Driver/Option.h"
 #include "clang/Driver/OptTable.h"
 
-#include "clang/Frontend/DiagnosticOptions.h"
+#include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Frontend/Utils.h"
 
@@ -75,19 +75,31 @@
 
 enum {
   OPT_INVALID = 0,  // This is not an option ID.
-#define OPTION(NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM, \
+#define PREFIX(NAME, VALUE)
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM, \
                HELPTEXT, METAVAR) OPT_##ID,
 #include "RSCCOptions.inc"
   LastOption
 #undef OPTION
+#undef PREFIX
 };
 
-static const OptTable::Info RSCCInfoTable[] = {
-#define OPTION(NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM, \
-               HELPTEXT, METAVAR)   \
-  { NAME, HELPTEXT, METAVAR, Option::KIND##Class, PARAM, FLAGS, \
-    OPT_##GROUP, OPT_##ALIAS },
+#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE;
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM, \
+               HELPTEXT, METAVAR)
 #include "RSCCOptions.inc"
+#undef OPTION
+#undef PREFIX
+
+static const OptTable::Info RSCCInfoTable[] = {
+#define PREFIX(NAME, VALUE)
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM, \
+               HELPTEXT, METAVAR)   \
+  { PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, PARAM, \
+    FLAGS, OPT_##GROUP, OPT_##ALIAS },
+#include "RSCCOptions.inc"
+#undef OPTION
+#undef PREFIX
 };
 
 class RSCCOptTable : public OptTable {
@@ -202,7 +214,7 @@
         it != ie; ++it) {
       const Arg *A = *it;
       if (A->getOption().getKind() == Option::InputClass)
-        Inputs.push_back(A->getValue(*Args));
+        Inputs.push_back(A->getValue());
     }
 
     Opts.mIncludePaths = Args->getAllArgValues(OPT_I);
@@ -403,7 +415,9 @@
   llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> DiagIDs(
     new clang::DiagnosticIDs());
 
-  clang::DiagnosticsEngine DiagEngine(DiagIDs, DiagClient, true);
+  llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> DiagOpts(
+    new clang::DiagnosticOptions());
+  clang::DiagnosticsEngine DiagEngine(DiagIDs, &*DiagOpts, DiagClient, true);
 
   slang::Slang::GlobalInitialization();
 
diff --git a/llvm-rs-link.cpp b/llvm-rs-link.cpp
index 8dec206..cf77481 100644
--- a/llvm-rs-link.cpp
+++ b/llvm-rs-link.cpp
@@ -24,9 +24,9 @@
 #include "llvm/Bitcode/ReaderWriter.h"
 
 #include "llvm/Linker.h"
-#include "llvm/LLVMContext.h"
-#include "llvm/Metadata.h"
-#include "llvm/Module.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Module.h"
 
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
@@ -39,7 +39,7 @@
 #include "llvm/Transforms/IPO.h"
 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
 
-#include "llvm/Target/TargetData.h"
+#include "llvm/IR/DataLayout.h"
 
 #include "slang_rs_metadata.h"
 
@@ -220,8 +220,8 @@
 
   const std::string &ModuleDataLayout = M->getDataLayout();
   if (!ModuleDataLayout.empty())
-    if (llvm::TargetData *TD = new llvm::TargetData(ModuleDataLayout))
-      Passes.add(TD);
+    if (llvm::DataLayout *DL = new llvm::DataLayout(ModuleDataLayout))
+      Passes.add(DL);
 
   // Some symbols must not be internalized
   std::vector<const char *> ExportList;
diff --git a/slang.cpp b/slang.cpp
index 1775563..d0a6744 100644
--- a/slang.cpp
+++ b/slang.cpp
@@ -25,6 +25,7 @@
 #include "clang/AST/ASTContext.h"
 
 #include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/FileSystemOptions.h"
 #include "clang/Basic/LangOptions.h"
@@ -33,14 +34,15 @@
 #include "clang/Basic/TargetOptions.h"
 
 #include "clang/Frontend/CodeGenOptions.h"
-#include "clang/Frontend/DiagnosticOptions.h"
 #include "clang/Frontend/DependencyOutputOptions.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Frontend/Utils.h"
 
 #include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/HeaderSearchOptions.h"
 
 #include "clang/Parse/ParseAST.h"
 
@@ -84,7 +86,7 @@
 
     // llvm-rs-cc need this.
     new clang::TextDiagnosticPrinter(llvm::errs(),
-                                     clang::DiagnosticOptions());
+                                     new clang::DiagnosticOptions());
   }
 } ForceSlangLinking;
 
@@ -174,18 +176,18 @@
 void Slang::createTarget(const std::string &Triple, const std::string &CPU,
                          const std::vector<std::string> &Features) {
   if (!Triple.empty())
-    mTargetOpts.Triple = Triple;
+    mTargetOpts->Triple = Triple;
   else
-    mTargetOpts.Triple = DEFAULT_TARGET_TRIPLE_STRING;
+    mTargetOpts->Triple = DEFAULT_TARGET_TRIPLE_STRING;
 
   if (!CPU.empty())
-    mTargetOpts.CPU = CPU;
+    mTargetOpts->CPU = CPU;
 
   if (!Features.empty())
-    mTargetOpts.Features = Features;
+    mTargetOpts->FeaturesAsWritten = Features;
 
   mTarget.reset(clang::TargetInfo::CreateTargetInfo(*mDiagEngine,
-                                                    mTargetOpts));
+                                                    mTargetOpts.getPtr()));
 }
 
 void Slang::createFileManager() {
@@ -199,12 +201,18 @@
 
 void Slang::createPreprocessor() {
   // Default only search header file in current dir
-  clang::HeaderSearch *HeaderInfo = new clang::HeaderSearch(*mFileMgr,
+  llvm::IntrusiveRefCntPtr<clang::HeaderSearchOptions> HSOpts =
+      new clang::HeaderSearchOptions();
+  clang::HeaderSearch *HeaderInfo = new clang::HeaderSearch(HSOpts,
+                                                            *mFileMgr,
                                                             *mDiagEngine,
                                                             LangOpts,
                                                             mTarget.get());
 
-  mPP.reset(new clang::Preprocessor(*mDiagEngine,
+  llvm::IntrusiveRefCntPtr<clang::PreprocessorOptions> PPOpts =
+      new clang::PreprocessorOptions();
+  mPP.reset(new clang::Preprocessor(PPOpts,
+                                    *mDiagEngine,
                                     LangOpts,
                                     mTarget.get(),
                                     *mSourceMgr,
@@ -249,11 +257,12 @@
 clang::ASTConsumer *
 Slang::createBackend(const clang::CodeGenOptions& CodeGenOpts,
                      llvm::raw_ostream *OS, OutputType OT) {
-  return new Backend(mDiagEngine, CodeGenOpts, mTargetOpts,
+  return new Backend(mDiagEngine, CodeGenOpts, getTargetOptions(),
                      &mPragmas, OS, OT);
 }
 
 Slang::Slang() : mInitialized(false), mDiagClient(NULL), mOT(OT_Default) {
+  mTargetOpts = new clang::TargetOptions();
   GlobalInitialization();
 }
 
@@ -277,12 +286,13 @@
   mInitialized = true;
 }
 
-clang::Module *Slang::loadModule(clang::SourceLocation ImportLoc,
-                                 clang::ModuleIdPath Path,
-                                 clang::Module::NameVisibilityKind Visibility,
-                                 bool IsInclusionDirective) {
+clang::ModuleLoadResult Slang::loadModule(
+    clang::SourceLocation ImportLoc,
+    clang::ModuleIdPath Path,
+    clang::Module::NameVisibilityKind Visibility,
+    bool IsInclusionDirective) {
   slangAssert(0 && "Not implemented");
-  return NULL;
+  return clang::ModuleLoadResult();
 }
 
 bool Slang::setInputSource(llvm::StringRef InputFile,
@@ -454,9 +464,9 @@
 
 void Slang::setDebugMetadataEmission(bool EmitDebug) {
   if (EmitDebug)
-    CodeGenOpts.DebugInfo = clang::CodeGenOptions::FullDebugInfo;
+    CodeGenOpts.setDebugInfo(clang::CodeGenOptions::FullDebugInfo);
   else
-    CodeGenOpts.DebugInfo = clang::CodeGenOptions::NoDebugInfo;
+    CodeGenOpts.setDebugInfo(clang::CodeGenOptions::NoDebugInfo);
 }
 
 void Slang::setOptimizationLevel(llvm::CodeGenOpt::Level OptimizationLevel) {
diff --git a/slang.h b/slang.h
index 16f851e..c33f5c8 100644
--- a/slang.h
+++ b/slang.h
@@ -21,10 +21,13 @@
 #include <string>
 #include <vector>
 
+// Terrible workaround for TargetOptions.h not using llvm::RefCountedBase!
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+using llvm::RefCountedBase;
+
 #include "clang/Basic/TargetOptions.h"
 #include "clang/Lex/ModuleLoader.h"
 
-#include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/StringRef.h"
 
@@ -50,7 +53,6 @@
   class Preprocessor;
   class SourceManager;
   class TargetInfo;
-  class TargetOptions;
 }  // namespace clang
 
 namespace slang {
@@ -89,7 +91,7 @@
   DiagnosticBuffer *mDiagClient;
 
   // The target being compiled for
-  clang::TargetOptions mTargetOpts;
+  llvm::IntrusiveRefCntPtr<clang::TargetOptions> mTargetOpts;
   llvm::OwningPtr<clang::TargetInfo> mTarget;
   void createTarget(std::string const &Triple, std::string const &CPU,
                     std::vector<std::string> const &Features);
@@ -150,7 +152,7 @@
   clang::ASTContext &getASTContext() { return *mASTContext; }
 
   inline clang::TargetOptions const &getTargetOptions() const
-    { return mTargetOpts; }
+    { return *mTargetOpts.getPtr(); }
 
   virtual void initDiagnostic() {}
   virtual void initPreprocessor() {}
@@ -173,10 +175,11 @@
             clang::DiagnosticsEngine *DiagEngine,
             DiagnosticBuffer *DiagClient);
 
-  virtual clang::Module *loadModule(clang::SourceLocation ImportLoc,
-                                    clang::ModuleIdPath Path,
-                                    clang::Module::NameVisibilityKind VK,
-                                    bool IsInclusionDirective);
+  virtual clang::ModuleLoadResult loadModule(
+      clang::SourceLocation ImportLoc,
+      clang::ModuleIdPath Path,
+      clang::Module::NameVisibilityKind VK,
+      bool IsInclusionDirective);
 
   bool setInputSource(llvm::StringRef InputFile, const char *Text,
                       size_t TextLength);
diff --git a/slang_backend.cpp b/slang_backend.cpp
index 58593ed..1e692ee 100644
--- a/slang_backend.cpp
+++ b/slang_backend.cpp
@@ -41,13 +41,13 @@
 #include "llvm/CodeGen/RegAllocRegistry.h"
 #include "llvm/CodeGen/SchedulerRegistry.h"
 
-#include "llvm/LLVMContext.h"
-#include "llvm/Module.h"
-#include "llvm/Metadata.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Metadata.h"
 
 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
 
-#include "llvm/Target/TargetData.h"
+#include "llvm/IR/DataLayout.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Support/TargetRegistry.h"
@@ -64,7 +64,7 @@
 void Backend::CreateFunctionPasses() {
   if (!mPerFunctionPasses) {
     mPerFunctionPasses = new llvm::FunctionPassManager(mpModule);
-    mPerFunctionPasses->add(new llvm::TargetData(mpModule));
+    mPerFunctionPasses->add(new llvm::DataLayout(mpModule));
 
     llvm::PassManagerBuilder PMBuilder;
     PMBuilder.OptLevel = mCodeGenOpts.OptimizationLevel;
@@ -76,7 +76,7 @@
 void Backend::CreateModulePasses() {
   if (!mPerModulePasses) {
     mPerModulePasses = new llvm::PassManager();
-    mPerModulePasses->add(new llvm::TargetData(mpModule));
+    mPerModulePasses->add(new llvm::DataLayout(mpModule));
 
     llvm::PassManagerBuilder PMBuilder;
     PMBuilder.OptLevel = mCodeGenOpts.OptimizationLevel;
@@ -109,7 +109,7 @@
     return true;
   } else {
     mCodeGenPasses = new llvm::FunctionPassManager(mpModule);
-    mCodeGenPasses->add(new llvm::TargetData(mpModule));
+    mCodeGenPasses->add(new llvm::DataLayout(mpModule));
   }
 
   // Create the TargetMachine for generating code.
diff --git a/slang_rs_backend.cpp b/slang_rs_backend.cpp
index c643908..3fb9f1a 100644
--- a/slang_rs_backend.cpp
+++ b/slang_rs_backend.cpp
@@ -25,13 +25,13 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/ADT/StringExtras.h"
 
-#include "llvm/Constant.h"
-#include "llvm/Constants.h"
-#include "llvm/DerivedTypes.h"
-#include "llvm/Function.h"
-#include "llvm/IRBuilder.h"
-#include "llvm/Metadata.h"
-#include "llvm/Module.h"
+#include "llvm/IR/Constant.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Module.h"
 
 #include "llvm/Support/DebugLoc.h"
 
diff --git a/slang_rs_context.cpp b/slang_rs_context.cpp
index 04f5d99..84c7181 100644
--- a/slang_rs_context.cpp
+++ b/slang_rs_context.cpp
@@ -27,8 +27,8 @@
 #include "clang/Basic/Linkage.h"
 #include "clang/Basic/TargetInfo.h"
 
-#include "llvm/LLVMContext.h"
-#include "llvm/Target/TargetData.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/DataLayout.h"
 
 #include "slang.h"
 #include "slang_assert.h"
@@ -54,7 +54,7 @@
       mPragmas(Pragmas),
       mTargetAPI(TargetAPI),
       mGeneratedFileNames(GeneratedFileNames),
-      mTargetData(NULL),
+      mDataLayout(NULL),
       mLLVMContext(llvm::getGlobalContext()),
       mLicenseNote(NULL),
       mRSPackageName("android.renderscript"),
@@ -79,7 +79,7 @@
   PP.AddPragmaHandler(RSPragmaHandler::CreatePragmaVersionHandler(this));
 
   // Prepare target data
-  mTargetData = new llvm::TargetData(Target.getTargetDescription());
+  mDataLayout = new llvm::DataLayout(Target.getTargetDescription());
 
   return;
 }
@@ -154,7 +154,7 @@
   clang::DeclContext::lookup_const_result R = TUDecl->lookup(II);
   RSExportType *ET = NULL;
 
-  for (clang::DeclContext::lookup_const_iterator I = R.first, E = R.second;
+  for (clang::DeclContext::lookup_const_iterator I = R.begin(), E = R.end();
        I != E;
        I++) {
     clang::NamedDecl *const ND = *I;
@@ -322,7 +322,7 @@
 
 RSContext::~RSContext() {
   delete mLicenseNote;
-  delete mTargetData;
+  delete mDataLayout;
   for (ExportableList::iterator I = mExportables.begin(),
           E = mExportables.end();
        I != E;
diff --git a/slang_rs_context.h b/slang_rs_context.h
index 8e616bc..946393b 100644
--- a/slang_rs_context.h
+++ b/slang_rs_context.h
@@ -33,7 +33,7 @@
 
 namespace llvm {
   class LLVMContext;
-  class TargetData;
+  class DataLayout;
 }   // namespace llvm
 
 namespace clang {
@@ -71,7 +71,7 @@
   unsigned int mTargetAPI;
   std::vector<std::string> *mGeneratedFileNames;
 
-  llvm::TargetData *mTargetData;
+  llvm::DataLayout *mDataLayout;
   llvm::LLVMContext &mLLVMContext;
 
   ExportableList mExportables;
@@ -114,7 +114,7 @@
   inline clang::MangleContext &getMangleContext() const {
     return *mMangleCtx;
   }
-  inline const llvm::TargetData *getTargetData() const { return mTargetData; }
+  inline const llvm::DataLayout *getDataLayout() const { return mDataLayout; }
   inline llvm::LLVMContext &getLLVMContext() const { return mLLVMContext; }
   inline const clang::SourceManager *getSourceManager() const {
     return &mPP.getSourceManager();
diff --git a/slang_rs_export_foreach.cpp b/slang_rs_export_foreach.cpp
index 8462099..b2e82af 100644
--- a/slang_rs_export_foreach.cpp
+++ b/slang_rs_export_foreach.cpp
@@ -19,11 +19,11 @@
 #include <string>
 
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/TypeLoc.h"
 
-#include "llvm/DerivedTypes.h"
-#include "llvm/Target/TargetData.h"
+#include "llvm/IR/DerivedTypes.h"
 
 #include "slang_assert.h"
 #include "slang_rs_context.h"
diff --git a/slang_rs_export_func.cpp b/slang_rs_export_func.cpp
index e03ccc6..8c9cd9b 100644
--- a/slang_rs_export_func.cpp
+++ b/slang_rs_export_func.cpp
@@ -21,8 +21,8 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 
-#include "llvm/DerivedTypes.h"
-#include "llvm/Target/TargetData.h"
+#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DerivedTypes.h"
 
 #include "slang_assert.h"
 #include "slang_rs_context.h"
@@ -141,7 +141,7 @@
     return false;
 
   const llvm::StructLayout *ParamTySL =
-      getRSContext()->getTargetData()->getStructLayout(ParamTy);
+      getRSContext()->getDataLayout()->getStructLayout(ParamTy);
 
   unsigned Index = 0;
   for (RSExportRecordType::const_field_iterator FI = ERT->fields_begin(),
@@ -164,7 +164,7 @@
 
     // Check size
     size_t T1Size = RSExportType::GetTypeAllocSize(F->getType());
-    size_t T2Size = getRSContext()->getTargetData()->getTypeAllocSize(T2);
+    size_t T2Size = getRSContext()->getDataLayout()->getTypeAllocSize(T2);
 
     if (T1Size != T2Size)
       return false;
diff --git a/slang_rs_export_type.cpp b/slang_rs_export_type.cpp
index ba37860..e7e5b0d 100644
--- a/slang_rs_export_type.cpp
+++ b/slang_rs_export_type.cpp
@@ -20,15 +20,13 @@
 #include <vector>
 
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Attr.h"
 #include "clang/AST/RecordLayout.h"
 
 #include "llvm/ADT/StringExtras.h"
-
-#include "llvm/DerivedTypes.h"
-
-#include "llvm/Target/TargetData.h"
-
-#include "llvm/Type.h"
+#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Type.h"
 
 #include "slang_assert.h"
 #include "slang_rs_context.h"
@@ -798,7 +796,7 @@
 }
 
 size_t RSExportType::GetTypeStoreSize(const RSExportType *ET) {
-  return ET->getRSContext()->getTargetData()->getTypeStoreSize(
+  return ET->getRSContext()->getDataLayout()->getTypeStoreSize(
       ET->getLLVMType());
 }
 
@@ -806,7 +804,7 @@
   if (ET->getClass() == RSExportType::ExportClassRecord)
     return static_cast<const RSExportRecordType*>(ET)->getAllocSize();
   else
-    return ET->getRSContext()->getTargetData()->getTypeAllocSize(
+    return ET->getRSContext()->getDataLayout()->getTypeAllocSize(
         ET->getLLVMType());
 }
 
diff --git a/slang_rs_object_ref_count.cpp b/slang_rs_object_ref_count.cpp
index 246ae83..7506b53 100644
--- a/slang_rs_object_ref_count.cpp
+++ b/slang_rs_object_ref_count.cpp
@@ -106,11 +106,8 @@
   }
   slangAssert(CompoundStmtCount == NewStmtCount);
 
-  clang::CompoundStmt *CS = new(C) clang::CompoundStmt(C,
-                                                       CompoundStmtList,
-                                                       CompoundStmtCount,
-                                                       Loc,
-                                                       Loc);
+  clang::CompoundStmt *CS = new(C) clang::CompoundStmt(
+      C, llvm::makeArrayRef(CompoundStmtList, CompoundStmtCount), Loc, Loc);
 
   delete [] CompoundStmtList;
 
@@ -535,7 +532,8 @@
                                    C.IntTy,
                                    clang::VK_RValue,
                                    clang::OK_Ordinary,
-                                   Loc);
+                                   Loc,
+                                   false);
 
   // Cond -> "rsIntIter < NumArrayElements"
   clang::Expr *NumArrayElementsExpr = clang::IntegerLiteral::Create(C,
@@ -548,7 +546,8 @@
                                    C.IntTy,
                                    clang::VK_RValue,
                                    clang::OK_Ordinary,
-                                   Loc);
+                                   Loc,
+                                   false);
 
   // Inc -> "rsIntIter++"
   clang::UnaryOperator *Inc =
@@ -606,8 +605,8 @@
   StmtArray[StmtCtr++] = DestructorLoop;
   slangAssert(StmtCtr == 2);
 
-  clang::CompoundStmt *CS =
-      new(C) clang::CompoundStmt(C, StmtArray, StmtCtr, Loc, Loc);
+  clang::CompoundStmt *CS = new(C) clang::CompoundStmt(
+      C, llvm::makeArrayRef(StmtArray, StmtCtr), Loc, Loc);
 
   return CS;
 }
@@ -773,8 +772,8 @@
   }
 
   slangAssert(StmtCount > 0);
-  clang::CompoundStmt *CS =
-      new(C) clang::CompoundStmt(C, StmtArray, StmtCount, Loc, Loc);
+  clang::CompoundStmt *CS = new(C) clang::CompoundStmt(
+      C, llvm::makeArrayRef(StmtArray, StmtCount), Loc, Loc);
 
   delete [] StmtArray;
 
@@ -1100,11 +1099,12 @@
   // the proper RS object reference counts).
   clang::BinaryOperator *CopyStruct =
       new(C) clang::BinaryOperator(LHS, RHS, clang::BO_Assign, QT,
-                                   clang::VK_RValue, clang::OK_Ordinary, Loc);
+                                   clang::VK_RValue, clang::OK_Ordinary, Loc,
+                                   false);
   StmtArray[StmtCount++] = CopyStruct;
 
-  clang::CompoundStmt *CS =
-      new(C) clang::CompoundStmt(C, StmtArray, StmtCount, Loc, Loc);
+  clang::CompoundStmt *CS = new(C) clang::CompoundStmt(
+      C, llvm::makeArrayRef(StmtArray, StmtCount), Loc, Loc);
 
   delete [] StmtArray;
 
diff --git a/slang_rs_pragma_handler.cpp b/slang_rs_pragma_handler.cpp
index 597136d..7d44495 100644
--- a/slang_rs_pragma_handler.cpp
+++ b/slang_rs_pragma_handler.cpp
@@ -292,8 +292,10 @@
   PP.LexUnexpandedToken(PragmaToken);
 
   if (PragmaToken.is(clang::tok::numeric_constant)) {
-    clang::NumericLiteralParser NumericLiteral(PragmaToken.getLiteralData(),
-        PragmaToken.getLiteralData() + PragmaToken.getLength(),
+    llvm::SmallString<128> SpellingBuffer;
+    SpellingBuffer.resize(PragmaToken.getLength() + 1);
+    llvm::StringRef TokSpelling = PP.getSpelling(PragmaToken, SpellingBuffer);
+    clang::NumericLiteralParser NumericLiteral(TokSpelling,
         PragmaToken.getLocation(), PP);
     if (NumericLiteral.hadError) {
       // Diagnostics will be generated automatically