Apply changes to migrate to llvm upstream r135568.

- Remove the const qualifier of llvm::Type and
  llvm::PointerType due to the API change.

- Update the relocation model setup code, since
  llvm::TargetMachine changes the API.

- Qualify dyn_cast with llvm namespace.

Change-Id: I4820fb86effc3a62569e19a6a8753ba9e960f6b2
diff --git a/slang_backend.cpp b/slang_backend.cpp
index 55e7838..0eeaeaf 100644
--- a/slang_backend.cpp
+++ b/slang_backend.cpp
@@ -133,7 +133,7 @@
 
   // BCC needs all unknown symbols resolved at compilation time. So we don't
   // need any relocation model.
-  llvm::TargetMachine::setRelocationModel(llvm::Reloc::Static);
+  llvm::Reloc::Model RM = llvm::Reloc::Static;
 
 
   // This is set for the linker (specify how large of the virtual addresses we
@@ -159,7 +159,7 @@
     FeaturesStr = Features.getString();
   }
   llvm::TargetMachine *TM =
-      TargetInfo->createTargetMachine(Triple, mTargetOpts.CPU, FeaturesStr);
+      TargetInfo->createTargetMachine(Triple, mTargetOpts.CPU, FeaturesStr, RM);
 
   // Register scheduler
   llvm::RegisterScheduler::setDefault(llvm::createDefaultScheduler);
diff --git a/slang_rs_ast_replace.cpp b/slang_rs_ast_replace.cpp
index 7bcdd17..8ff3da5 100644
--- a/slang_rs_ast_replace.cpp
+++ b/slang_rs_ast_replace.cpp
@@ -18,6 +18,8 @@
 
 #include "slang_assert.h"
 
+#include "llvm/Support/Casting.h"
+
 namespace slang {
 
 void RSASTReplace::ReplaceStmt(
@@ -30,9 +32,9 @@
 
   // This simplifies use in various Stmt visitor passes where the only
   // valid type is an Expr.
-  mOldExpr = dyn_cast<clang::Expr>(OldStmt);
+  mOldExpr = llvm::dyn_cast<clang::Expr>(OldStmt);
   if (mOldExpr) {
-    mNewExpr = dyn_cast<clang::Expr>(NewStmt);
+    mNewExpr = llvm::dyn_cast<clang::Expr>(NewStmt);
   }
   Visit(mOuterStmt);
 }
diff --git a/slang_rs_backend.cpp b/slang_rs_backend.cpp
index 2d05ff0..f07be08 100644
--- a/slang_rs_backend.cpp
+++ b/slang_rs_backend.cpp
@@ -84,7 +84,7 @@
     // Iterate all function declarations in the program.
     for (clang::DeclGroupRef::iterator I = D.begin(), E = D.end();
          I != E; I++) {
-      clang::FunctionDecl *FD = dyn_cast<clang::FunctionDecl>(*I);
+      clang::FunctionDecl *FD = llvm::dyn_cast<clang::FunctionDecl>(*I);
       if (FD == NULL)
         continue;
       if (!FD->getName().startswith("rs"))  // Check prefix
@@ -100,7 +100,7 @@
 
   // Process any non-static function declarations
   for (clang::DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; I++) {
-    clang::FunctionDecl *FD = dyn_cast<clang::FunctionDecl>(*I);
+    clang::FunctionDecl *FD = llvm::dyn_cast<clang::FunctionDecl>(*I);
     if (FD && FD->isGlobal()) {
       AnnotateFunction(FD);
     }
@@ -139,7 +139,7 @@
           DE = TUDecl->decls_end();
        DI != DE;
        DI++) {
-    clang::VarDecl *VD = dyn_cast<clang::VarDecl>(*DI);
+    clang::VarDecl *VD = llvm::dyn_cast<clang::VarDecl>(*DI);
     if (VD && !ValidateVarDecl(VD)) {
       valid = false;
     }
@@ -172,7 +172,7 @@
           E = TUDecl->decls_end(); I != E; I++) {
     if ((I->getKind() >= clang::Decl::firstFunction) &&
         (I->getKind() <= clang::Decl::lastFunction)) {
-      clang::FunctionDecl *FD = dyn_cast<clang::FunctionDecl>(*I);
+      clang::FunctionDecl *FD = llvm::dyn_cast<clang::FunctionDecl>(*I);
       if (FD && !FD->isGlobal()) {
         AnnotateFunction(FD);
       }
diff --git a/slang_rs_export_func.cpp b/slang_rs_export_func.cpp
index 38811cd..d660594 100644
--- a/slang_rs_export_func.cpp
+++ b/slang_rs_export_func.cpp
@@ -128,7 +128,7 @@
 }
 
 bool
-RSExportFunc::checkParameterPacketType(const llvm::StructType *ParamTy) const {
+RSExportFunc::checkParameterPacketType(llvm::StructType *ParamTy) const {
   if (ParamTy == NULL)
     return !hasParam();
   else if (!hasParam())
@@ -149,8 +149,8 @@
        FE = ERT->fields_end(); FI != FE; FI++, Index++) {
     const RSExportRecordType::Field *F = *FI;
 
-    const llvm::Type *T1 = F->getType()->getLLVMType();
-    const llvm::Type *T2 = ParamTy->getTypeAtIndex(Index);
+    llvm::Type *T1 = F->getType()->getLLVMType();
+    llvm::Type *T2 = ParamTy->getTypeAtIndex(Index);
 
     // Fast check
     if (T1 == T2)
diff --git a/slang_rs_export_func.h b/slang_rs_export_func.h
index aedd3af..2ea0b92 100644
--- a/slang_rs_export_func.h
+++ b/slang_rs_export_func.h
@@ -101,7 +101,7 @@
   // Check whether the given ParamsPacket type (in LLVM type) is "size
   // equivalent" to the one obtained from getParamPacketType(). If the @Params
   // is NULL, means there must be no any parameters.
-  bool checkParameterPacketType(const llvm::StructType *ParamTy) const;
+  bool checkParameterPacketType(llvm::StructType *ParamTy) const;
 };  // RSExportFunc
 
 
diff --git a/slang_rs_object_ref_count.cpp b/slang_rs_object_ref_count.cpp
index 131a086..a54fdd0 100644
--- a/slang_rs_object_ref_count.cpp
+++ b/slang_rs_object_ref_count.cpp
@@ -227,7 +227,8 @@
       RSASTReplace R(mCtx);
       R.ReplaceStmt(mOuterStmt, S, CS);
     }
-    clang::CompoundStmt *CS = dyn_cast<clang::CompoundStmt>(mOuterStmt);
+    clang::CompoundStmt *CS =
+      llvm::dyn_cast<clang::CompoundStmt>(mOuterStmt);
     slangAssert(CS);
     if (CS) {
       AppendAfterStmt(mCtx, CS, NULL, mStmtList);