Forráskód Böngészése

Fix remaining Clang warnings (#3008)

Many of these take the form of removing unused member variables and
unused functions. Where they were truly unused, I removed them. Where
they were only used in asserts, I hid them for the release builds. Where
the code in question was original to LLVM, I didn't remove so much as
comment out the offending code. In most cases these changes are
counterparts to already excluded code for HLSL.

A few cases concern indexing or type matches. Where relevant, I lifted
the same solutions in the current source of the llvm project.

I altered the fix made recently to LinkAllPasses.h. Instead of just
disabling the warning, I used the temporary variables that the current
llvm project uses to avoid having to cast null pointers.
Greg Roth 5 éve
szülő
commit
29759a8942

+ 0 - 1
include/dxc/DXIL/DxilShaderModel.h

@@ -88,7 +88,6 @@ private:
   const char *m_pszName;
   unsigned m_NumInputRegs;
   unsigned m_NumOutputRegs;
-  bool     m_bUAVs;
   bool     m_bTypedUavs;
   unsigned m_NumUAVRegs;
 

+ 13 - 14
include/llvm/LinkAllPasses.h

@@ -16,6 +16,7 @@
 #define LLVM_LINKALLPASSES_H
 
 #include "llvm/ADT/Statistic.h"
+#include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/Analysis/AliasSetTracker.h"
 #include "llvm/Analysis/CallPrinter.h"
 #include "llvm/Analysis/DomPrinter.h"
@@ -42,10 +43,6 @@
 namespace {
   struct ForcePassLinking {
     ForcePassLinking() {
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wnull-dereference"
-#endif
       // We must reference the passes in such a way that compilers will not
       // delete it all as dead code, even with whole program optimization,
       // yet is effectively a NO-OP. As the compiler isn't smart enough
@@ -158,9 +155,13 @@ namespace {
       (void) llvm::createMetaRenamerPass();
       (void) llvm::createFunctionAttrsPass();
       (void) llvm::createMergeFunctionsPass();
-      (void) llvm::createPrintModulePass(*(llvm::raw_ostream*)nullptr);
-      (void) llvm::createPrintFunctionPass(*(llvm::raw_ostream*)nullptr);
-      (void) llvm::createPrintBasicBlockPass(*(llvm::raw_ostream*)nullptr);
+      // HLSL Change Begin - avoid casting nullptrs
+      std::string buf;
+      llvm::raw_string_ostream os(buf);
+      (void) llvm::createPrintModulePass(os);
+      (void) llvm::createPrintFunctionPass(os);
+      (void) llvm::createPrintBasicBlockPass(os);
+      // HLSL Change End - avoid casting nullptrs
       (void) llvm::createModuleDebugInfoPrinterPass();
       (void) llvm::createPartialInliningPass();
       (void) llvm::createLintPass();
@@ -184,16 +185,14 @@ namespace {
 
       (void)new llvm::IntervalPartition();
       (void)new llvm::ScalarEvolution();
-      ((llvm::Function*)nullptr)->viewCFGOnly();
-      llvm::RGPassManager RGM;
-      ((llvm::RegionPass*)nullptr)->runOnRegion((llvm::Region*)nullptr, RGM);
-      llvm::AliasSetTracker X(*(llvm::AliasAnalysis*)nullptr);
+      // HLSL Change Begin - avoid casting nullptrs
+      llvm::Function::Create(nullptr, llvm::GlobalValue::ExternalLinkage)->viewCFGOnly();
+      llvm::AliasAnalysis AA;
+      llvm::AliasSetTracker X(AA);
+      // HLSL Change End - avoid casting nullptrs
       X.add(nullptr, 0, llvm::AAMDNodes()); // for -print-alias-sets
       (void) llvm::AreStatisticsEnabled();
       (void) llvm::sys::RunningOnValgrind();
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
     }
   } ForcePassLinking; // Force link by creating a global definition.
 }

+ 2 - 2
include/llvm/Transforms/Scalar.h

@@ -116,8 +116,8 @@ void initializeHLExpandStoreIntrinsicsPass(PassRegistry&);
 // ScalarReplAggregatesHLSL - Break up alloca's of aggregates into multiple allocas
 // for hlsl. Array will not change, all structures will be broken up.
 //
-FunctionPass *createScalarReplAggregatesHLSLPass(bool UseDomTree = true,
-                                                 bool Promote = false);
+FunctionPass *createScalarReplAggregatesHLSLPass();
+
 void initializeSROA_DT_HLSLPass(PassRegistry&);
 //===----------------------------------------------------------------------===//
 //

+ 0 - 2
lib/Analysis/DxilValueCache.cpp

@@ -285,8 +285,6 @@ Value *DxilValueCache::SimplifyAndCacheResult(Instruction *I, DominatorTree *DT)
   return Simplified;
 }
 
-STATISTIC(StaleValuesEncountered, "Stale Values Encountered");
-
 bool DxilValueCache::WeakValueMap::Seen(Value *V) {
   auto FindIt = Map.find(V);
   if (FindIt == Map.end())

+ 0 - 28
lib/DXIL/DxilCounters.cpp

@@ -99,34 +99,6 @@ struct ValueInfo {
   }
 };
 
-typedef SmallDenseMap<Value*, ValueInfo, 16> ValueInfoMap;
-
-ValueInfo GetValueInfo(Value* V, ValueInfoMap &valueInfoMap) {
-  auto it = valueInfoMap.find(V);
-  if (it != valueInfoMap.end())
-    return it->second;
-
-  ValueInfo &VI = valueInfoMap[V];
-
-  if (Constant *C = dyn_cast<Constant>(V)) {
-    VI.isConstant = true;
-  } else if (CallInst *CI = dyn_cast<CallInst>(V)) {
-    if (hlsl::OP::IsDxilOpFuncCallInst(CI)) {
-      OpCode opcode = (OpCode)llvm::cast<llvm::ConstantInt>(CI->getOperand(0))->getZExtValue();
-      if (opcode == OpCode::CBufferLoad || opcode == OpCode::CBufferLoadLegacy)
-        VI.isCbuffer = true;
-    }
-  } else if (CmpInst *CMP = dyn_cast<CmpInst>(V)) {
-    VI = GetValueInfo(CMP->getOperand(0), valueInfoMap).Combine(
-         GetValueInfo(CMP->getOperand(1), valueInfoMap));
-  } else if (ExtractElementInst *EE = dyn_cast<ExtractElementInst>(V)) {
-    VI = GetValueInfo(EE->getVectorOperand(), valueInfoMap);
-  }
-  // TODO: fill out more as necessary
-
-  return VI;
-}
-
 /*<py>
 
 def tab_lines(text):

+ 5 - 1
lib/DXIL/DxilShaderFlags.cpp

@@ -54,7 +54,11 @@ ShaderFlags::ShaderFlags():
 , m_bSamplerFeedback(false)
 , m_align0(0)
 , m_align1(0)
-{}
+{
+  // Silence unused field warnings
+  (void)m_align0;
+  (void)m_align1;
+}
 
 uint64_t ShaderFlags::GetFeatureInfo() const {
   uint64_t Flags = 0;

+ 0 - 1
lib/DXIL/DxilShaderModel.cpp

@@ -26,7 +26,6 @@ ShaderModel::ShaderModel(Kind Kind, unsigned Major, unsigned Minor, const char *
 , m_pszName(pszName)
 , m_NumInputRegs(NumInputRegs)
 , m_NumOutputRegs(NumOutputRegs)
-, m_bUAVs(bUAVs)
 , m_bTypedUavs(bTypedUavs)
 , m_NumUAVRegs(NumUAVRegs) {
 }

+ 1 - 1
lib/DxcSupport/FileIOHelper.cpp

@@ -171,7 +171,7 @@ UINT32 DxcCodePageFromBytes(const char *bytes, size_t byteLen) throw() {
   return codePage;
 }
 
-static bool IsSizeWcharAligned(SIZE_T size) { return (size & (sizeof(wchar_t) - 1)) == 0; }
+#define IsSizeWcharAligned(size) (((size) & (sizeof(wchar_t) - 1)) == 0)
 
 template<typename _char>
 bool IsUtfBufferNullTerminated(LPCVOID pBuffer, SIZE_T size) {

+ 3 - 0
lib/DxilPIXPasses/DxilDbgValueToDbgDeclare.cpp

@@ -421,6 +421,7 @@ llvm::AllocaInst *VariableRegisters::GetRegisterForAlignedOffset(
   return it->second;
 }
 
+#ifndef NDEBUG
 // DITypePeelTypeAlias peels const, typedef, and other alias types off of Ty,
 // returning the unalised type.
 static llvm::DIType *DITypePeelTypeAlias(
@@ -443,6 +444,8 @@ static llvm::DIType *DITypePeelTypeAlias(
 
   return Ty;
 }
+#endif // NDEBUG
+
 
 VariableRegisters::VariableRegisters(
     llvm::DIVariable *Variable,

+ 1 - 1
lib/DxilPIXPasses/DxilPIXMeshShaderOutputInstrumentation.cpp

@@ -180,7 +180,7 @@ Value *DxilPIXMeshShaderOutputInstrumentation::reserveDebugEntrySpace(
   
   // Check that the caller didn't ask for so much memory that it will 
   // overwrite the offset counter:
-  assert(m_RemainingReservedSpaceInBytes < CounterOffsetBeyondUsefulData);
+  assert(m_RemainingReservedSpaceInBytes < (int)CounterOffsetBeyondUsefulData);
 
   m_RemainingReservedSpaceInBytes = SpaceInBytes;
 

+ 0 - 11
lib/HLSL/DxilNoops.cpp

@@ -124,17 +124,6 @@ static Constant *GetConstGep(Constant *Ptr, unsigned Idx0, unsigned Idx1) {
   return ConstantExpr::getGetElementPtr(nullptr, Ptr, Indices);
 }
 
-static bool ShouldPreserve(Value *V) {
-  if (isa<Constant>(V)) return true;
-  if (isa<Argument>(V)) return true;
-  if (isa<LoadInst>(V)) return true;
-  if (ExtractElementInst *GEP = dyn_cast<ExtractElementInst>(V)) {
-    return ShouldPreserve(GEP->getVectorOperand());
-  }
-  if (isa<CallInst>(V)) return true;
-  return false;
-}
-
 struct Store_Info {
   Instruction *StoreOrMC = nullptr;
   Value *Source = nullptr; // Alloca, GV, or Argument

+ 1 - 1
lib/Transforms/IPO/Inliner.cpp

@@ -39,7 +39,7 @@ using namespace llvm;
 STATISTIC(NumInlined, "Number of functions inlined");
 STATISTIC(NumCallsDeleted, "Number of call sites deleted, not inlined");
 STATISTIC(NumDeleted, "Number of functions deleted because all callers found");
-STATISTIC(NumMergedAllocas, "Number of allocas merged together");
+// STATISTIC(NumMergedAllocas, "Number of allocas merged together"); // HLSL Change - unused
 
 // This weirdly named statistic tracks the number of times that, when attempting
 // to inline a function A into B, we analyze the callers of B in order to see

+ 1 - 2
lib/Transforms/IPO/PassManagerBuilder.cpp

@@ -230,8 +230,7 @@ static void addHLSLPasses(bool HLSLHighLevel, unsigned OptLevel, hlsl::HLSLExten
   MPM.add(createSROA_Parameter_HLSL());
 
   // Split struct.
-  MPM.add(createScalarReplAggregatesHLSLPass(/*UseDomTree*/ true,
-                                             /*Promote*/ !NoOpt));
+  MPM.add(createScalarReplAggregatesHLSLPass());
 
   MPM.add(createHLMatrixLowerPass());
   // DCE should after SROA to remove unused element.

+ 0 - 15
lib/Transforms/Scalar/DxilEliminateVector.cpp

@@ -95,21 +95,6 @@ bool CollectVectorElements(Value *V, SmallVector<Value *, 4> &Elements) {
   return false;
 }
 
-static bool HasDebugValue(Value *V) {
-  Instruction *I = dyn_cast<Instruction>(V);
-  if (!I) return false;
-
-  MetadataAsValue *DebugI = GetAsMetadata(I);
-  if (!DebugI) return false;
-
-  for (User *U : DebugI->users()) {
-    if (isa<DbgValueInst>(U))
-      return true;
-  }
-
-  return false;
-}
-
 bool DxilEliminateVector::TryRewriteDebugInfoForVector(InsertElementInst *IE) {
 
   // If this is not ever used as meta-data, there's no debug

+ 8 - 303
lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp

@@ -70,8 +70,6 @@ using namespace hlsl;
 #define DEBUG_TYPE "scalarreplhlsl"
 
 STATISTIC(NumReplaced, "Number of allocas broken up");
-STATISTIC(NumPromoted, "Number of allocas promoted");
-STATISTIC(NumAdjusted, "Number of scalar allocas adjusted to allow promotion");
 
 namespace {
 
@@ -131,8 +129,8 @@ private:
 };
 
 struct SROA_HLSL : public FunctionPass {
-  SROA_HLSL(bool Promote, int T, bool hasDT, char &ID, int ST, int AT, int SLT)
-      : FunctionPass(ID), HasDomTree(hasDT), RunPromotion(Promote) {
+  SROA_HLSL(int T, char &ID, int ST, int AT, int SLT)
+      : FunctionPass(ID) {
 
     if (AT == -1)
       ArrayElementThreshold = 8;
@@ -151,8 +149,6 @@ struct SROA_HLSL : public FunctionPass {
   bool markPrecise(Function &F);
 
 private:
-  bool HasDomTree;
-  bool RunPromotion;
 
   /// DeadInsts - Keep track of instructions we have made dead, so that
   /// we can remove them after we are done working.
@@ -237,8 +233,8 @@ struct SROA_DT_HLSL : public SROA_HLSL {
   static char ID;
 
 public:
-  SROA_DT_HLSL(bool Promote = false, int T = -1, int ST = -1, int AT = -1, int SLT = -1)
-      : SROA_HLSL(Promote, T, true, ID, ST, AT, SLT) {
+  SROA_DT_HLSL(int T = -1, int ST = -1, int AT = -1, int SLT = -1)
+      : SROA_HLSL(T, ID, ST, AT, SLT) {
     initializeSROA_DTPass(*PassRegistry::getPassRegistry());
   }
 
@@ -256,8 +252,8 @@ struct SROA_SSAUp_HLSL : public SROA_HLSL {
   static char ID;
 
 public:
-  SROA_SSAUp_HLSL(bool Promote = false, int T = -1, int ST = -1, int AT = -1, int SLT = -1)
-      : SROA_HLSL(Promote, T, false, ID, ST, AT, SLT) {
+  SROA_SSAUp_HLSL(int T = -1, int ST = -1, int AT = -1, int SLT = -1)
+      : SROA_HLSL(T, ID, ST, AT, SLT) {
     initializeSROA_SSAUpPass(*PassRegistry::getPassRegistry());
   }
 
@@ -308,10 +304,8 @@ INITIALIZE_PASS_END(SROA_SSAUp_HLSL, "scalarreplhlsl-ssa",
                     false)
 
 // Public interface to the ScalarReplAggregates pass
-FunctionPass *llvm::createScalarReplAggregatesHLSLPass(bool UseDomTree, bool Promote) {
-  if (UseDomTree)
-    return new SROA_DT_HLSL(Promote);
-  return new SROA_SSAUp_HLSL(Promote);
+FunctionPass *llvm::createScalarReplAggregatesHLSLPass() {
+  return new SROA_DT_HLSL();
 }
 
 //===----------------------------------------------------------------------===//
@@ -422,295 +416,6 @@ public:
 };
 } // end anon namespace
 
-/// isSafeSelectToSpeculate - Select instructions that use an alloca and are
-/// subsequently loaded can be rewritten to load both input pointers and then
-/// select between the result, allowing the load of the alloca to be promoted.
-/// From this:
-///   %P2 = select i1 %cond, i32* %Alloca, i32* %Other
-///   %V = load i32* %P2
-/// to:
-///   %V1 = load i32* %Alloca      -> will be mem2reg'd
-///   %V2 = load i32* %Other
-///   %V = select i1 %cond, i32 %V1, i32 %V2
-///
-/// We can do this to a select if its only uses are loads and if the operand to
-/// the select can be loaded unconditionally.
-static bool isSafeSelectToSpeculate(SelectInst *SI) {
-  const DataLayout &DL = SI->getModule()->getDataLayout();
-  bool TDerefable = isDereferenceablePointer(SI->getTrueValue(), DL);
-  bool FDerefable = isDereferenceablePointer(SI->getFalseValue(), DL);
-
-  for (User *U : SI->users()) {
-    LoadInst *LI = dyn_cast<LoadInst>(U);
-    if (!LI || !LI->isSimple())
-      return false;
-
-    // Both operands to the select need to be dereferencable, either absolutely
-    // (e.g. allocas) or at this point because we can see other accesses to it.
-    if (!TDerefable &&
-        !isSafeToLoadUnconditionally(SI->getTrueValue(), LI,
-                                     LI->getAlignment()))
-      return false;
-    if (!FDerefable &&
-        !isSafeToLoadUnconditionally(SI->getFalseValue(), LI,
-                                     LI->getAlignment()))
-      return false;
-  }
-
-  return true;
-}
-
-/// isSafePHIToSpeculate - PHI instructions that use an alloca and are
-/// subsequently loaded can be rewritten to load both input pointers in the pred
-/// blocks and then PHI the results, allowing the load of the alloca to be
-/// promoted.
-/// From this:
-///   %P2 = phi [i32* %Alloca, i32* %Other]
-///   %V = load i32* %P2
-/// to:
-///   %V1 = load i32* %Alloca      -> will be mem2reg'd
-///   ...
-///   %V2 = load i32* %Other
-///   ...
-///   %V = phi [i32 %V1, i32 %V2]
-///
-/// We can do this to a select if its only uses are loads and if the operand to
-/// the select can be loaded unconditionally.
-static bool isSafePHIToSpeculate(PHINode *PN) {
-  // For now, we can only do this promotion if the load is in the same block as
-  // the PHI, and if there are no stores between the phi and load.
-  // TODO: Allow recursive phi users.
-  // TODO: Allow stores.
-  BasicBlock *BB = PN->getParent();
-  unsigned MaxAlign = 0;
-  for (User *U : PN->users()) {
-    LoadInst *LI = dyn_cast<LoadInst>(U);
-    if (!LI || !LI->isSimple())
-      return false;
-
-    // For now we only allow loads in the same block as the PHI.  This is a
-    // common case that happens when instcombine merges two loads through a PHI.
-    if (LI->getParent() != BB)
-      return false;
-
-    // Ensure that there are no instructions between the PHI and the load that
-    // could store.
-    for (BasicBlock::iterator BBI = PN; &*BBI != LI; ++BBI)
-      if (BBI->mayWriteToMemory())
-        return false;
-
-    MaxAlign = std::max(MaxAlign, LI->getAlignment());
-  }
-
-  const DataLayout &DL = PN->getModule()->getDataLayout();
-
-  // Okay, we know that we have one or more loads in the same block as the PHI.
-  // We can transform this if it is safe to push the loads into the predecessor
-  // blocks.  The only thing to watch out for is that we can't put a possibly
-  // trapping load in the predecessor if it is a critical edge.
-  for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
-    BasicBlock *Pred = PN->getIncomingBlock(i);
-    Value *InVal = PN->getIncomingValue(i);
-
-    // If the terminator of the predecessor has side-effects (an invoke),
-    // there is no safe place to put a load in the predecessor.
-    if (Pred->getTerminator()->mayHaveSideEffects())
-      return false;
-
-    // If the value is produced by the terminator of the predecessor
-    // (an invoke), there is no valid place to put a load in the predecessor.
-    if (Pred->getTerminator() == InVal)
-      return false;
-
-    // If the predecessor has a single successor, then the edge isn't critical.
-    if (Pred->getTerminator()->getNumSuccessors() == 1)
-      continue;
-
-    // If this pointer is always safe to load, or if we can prove that there is
-    // already a load in the block, then we can move the load to the pred block.
-    if (isDereferenceablePointer(InVal, DL) ||
-        isSafeToLoadUnconditionally(InVal, Pred->getTerminator(), MaxAlign))
-      continue;
-
-    return false;
-  }
-
-  return true;
-}
-
-/// tryToMakeAllocaBePromotable - This returns true if the alloca only has
-/// direct (non-volatile) loads and stores to it.  If the alloca is close but
-/// not quite there, this will transform the code to allow promotion.  As such,
-/// it is a non-pure predicate.
-static bool tryToMakeAllocaBePromotable(AllocaInst *AI, const DataLayout &DL) {
-  SetVector<Instruction *, SmallVector<Instruction *, 4>,
-            SmallPtrSet<Instruction *, 4>>
-      InstsToRewrite;
-  for (User *U : AI->users()) {
-    if (LoadInst *LI = dyn_cast<LoadInst>(U)) {
-      if (!LI->isSimple())
-        return false;
-      continue;
-    }
-
-    if (StoreInst *SI = dyn_cast<StoreInst>(U)) {
-      if (SI->getOperand(0) == AI || !SI->isSimple())
-        return false; // Don't allow a store OF the AI, only INTO the AI.
-      continue;
-    }
-
-    if (SelectInst *SI = dyn_cast<SelectInst>(U)) {
-      // If the condition being selected on is a constant, fold the select, yes
-      // this does (rarely) happen early on.
-      if (ConstantInt *CI = dyn_cast<ConstantInt>(SI->getCondition())) {
-        Value *Result = SI->getOperand(1 + CI->isZero());
-        SI->replaceAllUsesWith(Result);
-        SI->eraseFromParent();
-
-        // This is very rare and we just scrambled the use list of AI, start
-        // over completely.
-        return tryToMakeAllocaBePromotable(AI, DL);
-      }
-
-      // If it is safe to turn "load (select c, AI, ptr)" into a select of two
-      // loads, then we can transform this by rewriting the select.
-      if (!isSafeSelectToSpeculate(SI))
-        return false;
-
-      InstsToRewrite.insert(SI);
-      continue;
-    }
-
-    if (PHINode *PN = dyn_cast<PHINode>(U)) {
-      if (PN->use_empty()) { // Dead PHIs can be stripped.
-        InstsToRewrite.insert(PN);
-        continue;
-      }
-
-      // If it is safe to turn "load (phi [AI, ptr, ...])" into a PHI of loads
-      // in the pred blocks, then we can transform this by rewriting the PHI.
-      if (!isSafePHIToSpeculate(PN))
-        return false;
-
-      InstsToRewrite.insert(PN);
-      continue;
-    }
-
-    if (BitCastInst *BCI = dyn_cast<BitCastInst>(U)) {
-      if (onlyUsedByLifetimeMarkers(BCI)) {
-        InstsToRewrite.insert(BCI);
-        continue;
-      }
-    }
-
-    return false;
-  }
-
-  // If there are no instructions to rewrite, then all uses are load/stores and
-  // we're done!
-  if (InstsToRewrite.empty())
-    return true;
-
-  // If we have instructions that need to be rewritten for this to be promotable
-  // take care of it now.
-  for (unsigned i = 0, e = InstsToRewrite.size(); i != e; ++i) {
-    if (BitCastInst *BCI = dyn_cast<BitCastInst>(InstsToRewrite[i])) {
-      // This could only be a bitcast used by nothing but lifetime intrinsics.
-      for (BitCastInst::user_iterator I = BCI->user_begin(),
-                                      E = BCI->user_end();
-           I != E;)
-        cast<Instruction>(*I++)->eraseFromParent();
-      BCI->eraseFromParent();
-      continue;
-    }
-
-    if (SelectInst *SI = dyn_cast<SelectInst>(InstsToRewrite[i])) {
-      // Selects in InstsToRewrite only have load uses.  Rewrite each as two
-      // loads with a new select.
-      while (!SI->use_empty()) {
-        LoadInst *LI = cast<LoadInst>(SI->user_back());
-
-        IRBuilder<> Builder(LI);
-        LoadInst *TrueLoad =
-            Builder.CreateLoad(SI->getTrueValue(), LI->getName() + ".t");
-        LoadInst *FalseLoad =
-            Builder.CreateLoad(SI->getFalseValue(), LI->getName() + ".f");
-
-        // Transfer alignment and AA info if present.
-        TrueLoad->setAlignment(LI->getAlignment());
-        FalseLoad->setAlignment(LI->getAlignment());
-
-        AAMDNodes Tags;
-        LI->getAAMetadata(Tags);
-        if (Tags) {
-          TrueLoad->setAAMetadata(Tags);
-          FalseLoad->setAAMetadata(Tags);
-        }
-
-        Value *V =
-            Builder.CreateSelect(SI->getCondition(), TrueLoad, FalseLoad);
-        V->takeName(LI);
-        LI->replaceAllUsesWith(V);
-        LI->eraseFromParent();
-      }
-
-      // Now that all the loads are gone, the select is gone too.
-      SI->eraseFromParent();
-      continue;
-    }
-
-    // Otherwise, we have a PHI node which allows us to push the loads into the
-    // predecessors.
-    PHINode *PN = cast<PHINode>(InstsToRewrite[i]);
-    if (PN->use_empty()) {
-      PN->eraseFromParent();
-      continue;
-    }
-
-    Type *LoadTy = cast<PointerType>(PN->getType())->getElementType();
-    PHINode *NewPN = PHINode::Create(LoadTy, PN->getNumIncomingValues(),
-                                     PN->getName() + ".ld", PN);
-
-    // Get the AA tags and alignment to use from one of the loads.  It doesn't
-    // matter which one we get and if any differ, it doesn't matter.
-    LoadInst *SomeLoad = cast<LoadInst>(PN->user_back());
-
-    AAMDNodes AATags;
-    SomeLoad->getAAMetadata(AATags);
-    unsigned Align = SomeLoad->getAlignment();
-
-    // Rewrite all loads of the PN to use the new PHI.
-    while (!PN->use_empty()) {
-      LoadInst *LI = cast<LoadInst>(PN->user_back());
-      LI->replaceAllUsesWith(NewPN);
-      LI->eraseFromParent();
-    }
-
-    // Inject loads into all of the pred blocks.  Keep track of which blocks we
-    // insert them into in case we have multiple edges from the same block.
-    DenseMap<BasicBlock *, LoadInst *> InsertedLoads;
-
-    for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
-      BasicBlock *Pred = PN->getIncomingBlock(i);
-      LoadInst *&Load = InsertedLoads[Pred];
-      if (!Load) {
-        Load = new LoadInst(PN->getIncomingValue(i),
-                            PN->getName() + "." + Pred->getName(),
-                            Pred->getTerminator());
-        Load->setAlignment(Align);
-        if (AATags)
-          Load->setAAMetadata(AATags);
-      }
-
-      NewPN->addIncoming(Load, Pred);
-    }
-
-    PN->eraseFromParent();
-  }
-
-  ++NumAdjusted;
-  return true;
-}
 
 /// ShouldAttemptScalarRepl - Decide if an alloca is a good candidate for
 /// SROA.  It must be a struct or array type with a small number of elements.

+ 1 - 1
tools/clang/lib/CodeGen/CGCall.cpp

@@ -2979,7 +2979,7 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E,
           // RWBuffer<uint> buf;
           // InterlockedAdd(buf[0].r, 1);
           llvm::Value *V = LV.getAddress();
-          Ptr = Builder.CreateGEP(V, { Builder.getInt32(0) });
+          Ptr = Builder.CreateGEP(V, Builder.getInt32(0));
         } else {
           llvm::Value *V = LV.getExtVectorAddr();
           llvm::Constant *Elts = LV.getExtVectorElts();

+ 1 - 1
tools/clang/lib/CodeGen/CGDebugInfo.cpp

@@ -1041,7 +1041,7 @@ bool CGDebugInfo::TryCollectHLSLRecordElements(const RecordType *Ty,
     unsigned VecSize = hlsl::GetHLSLVecSize(QualTy);
     unsigned ElemSizeInBits = CGM.getContext().getTypeSize(ElemQualTy);
     for (unsigned ElemIdx = 0; ElemIdx < VecSize; ++ElemIdx) {
-      StringRef FieldName = StringRef("xyzw" + ElemIdx, 1);
+      StringRef FieldName = StringRef(&"xyzw"[ElemIdx], 1);
       unsigned OffsetInBits = ElemSizeInBits * ElemIdx;
       llvm::DIType *FieldType = createFieldType(FieldName, ElemQualTy, 0,
         SourceLocation(), AccessSpecifier::AS_public, OffsetInBits,

+ 0 - 8
tools/clang/lib/SPIRV/RawBufferMethods.cpp

@@ -190,10 +190,6 @@ SpirvInstruction *RawBufferHandler::processTemplatedLoadFromBuffer(
     const QualType targetType, uint32_t &bitOffset) {
   const auto loc = buffer->getSourceLocation();
   SpirvInstruction *result = nullptr;
-  auto *constUint0 =
-      spvBuilder.getConstantInt(astContext.UnsignedIntTy, llvm::APInt(32, 0));
-  auto *constUint1 =
-      spvBuilder.getConstantInt(astContext.UnsignedIntTy, llvm::APInt(32, 1));
 
   // TODO: If 8-bit types are to be supported in the future, we should also
   // add code to support bitOffset 8 and 24.
@@ -639,10 +635,6 @@ void RawBufferHandler::processTemplatedStoreToBuffer(SpirvInstruction *value,
                                                      uint32_t &bitOffset) {
   assert(bitOffset == 0 || bitOffset == 16);
   const auto loc = buffer->getSourceLocation();
-  auto *constUint0 =
-      spvBuilder.getConstantInt(astContext.UnsignedIntTy, llvm::APInt(32, 0));
-  auto *constUint1 =
-      spvBuilder.getConstantInt(astContext.UnsignedIntTy, llvm::APInt(32, 1));
 
   // Scalar types
   if (isScalarType(valueType)) {

+ 0 - 2
tools/clang/lib/SPIRV/SpirvEmitter.cpp

@@ -2138,7 +2138,6 @@ SpirvInstruction *SpirvEmitter::processCall(const CallExpr *callExpr) {
     }
 
     auto *argInst = doExpr(arg);
-    auto argType = arg->getType();
 
     // If argInfo is nullptr and argInst is a rvalue, we do not have a proper
     // pointer to pass to the function. we need a temporary variable in that
@@ -11656,7 +11655,6 @@ SpirvEmitter::processRayQueryIntrinsics(const CXXMemberCallExpr *expr,
         cast<ClassTemplateSpecializationDecl>(RT->getDecl());
     ClassTemplateDecl *templateDecl =
         templateSpecDecl->getSpecializedTemplate();
-    const auto retType = exprType;
     exprType = getHLSLMatrixType(astContext, theCompilerInstance.getSema(),
                                  templateDecl, astContext.FloatTy, 4, 3);
   }

+ 3 - 3
tools/clang/lib/Sema/SemaAccess.cpp

@@ -1762,9 +1762,9 @@ Sema::AccessResult Sema::CheckFriendAccess(NamedDecl *target) {
   // while the ParsingDeclarator is active.
   EffectiveContext EC(CurContext);
   switch (CheckEffectiveAccess(*this, EC, target->getLocation(), entity)) {
-  case AR_accessible: return Sema::AR_accessible;
-  case AR_inaccessible: return Sema::AR_inaccessible;
-  case AR_dependent: return Sema::AR_dependent;
+  case ::AR_accessible: return Sema::AR_accessible; // HLSL Change - disambiguate enum
+  case ::AR_inaccessible: return Sema::AR_inaccessible; // HLSL Change - disambiguate enum
+  case ::AR_dependent: return Sema::AR_dependent; // HLSL Change - disambiguate enum
   }
   llvm_unreachable("falling off end");
 }

+ 2 - 2
tools/clang/test/HLSLFileCheck/hlsl/intrinsics/atomic/umaxObjectAtomic.hlsl

@@ -47,7 +47,7 @@ float4 main(uint4 a : A, float4 b : B) : SV_Target
     uint4 r = a;
     uint comparevalue = r.w;
     uint newvalue = r.z;
-    uint origvalue;
+    uint origvalue = buf0[r.z];
 
     InterlockedAdd(buf0[r.z], newvalue);
     InterlockedMin(buf0[r.z], newvalue);
@@ -75,4 +75,4 @@ float4 main(uint4 a : A, float4 b : B) : SV_Target
     buf1.InterlockedCompareExchange(r.z, comparevalue, newvalue, origvalue); newvalue += origvalue;
 
     return newvalue;
-}
+}

+ 0 - 6
tools/clang/tools/dxclib/dxc.cpp

@@ -896,12 +896,6 @@ void DxcContext::Preprocess() {
   }
 }
 
-static void WriteString(HANDLE hFile, _In_z_ LPCSTR value, LPCWSTR pFileName) {
-  DWORD written;
-  if (FALSE == WriteFile(hFile, value, strlen(value) * sizeof(value[0]), &written, nullptr))
-    IFT_Data(HRESULT_FROM_WIN32(GetLastError()), pFileName);
-}
-
 void DxcContext::WriteHeader(IDxcBlobEncoding *pDisassembly, IDxcBlob *pCode,
                              llvm::Twine &pVariableName, LPCWSTR pFileName) {
   // Use older interface for compatibility with older DLL.

+ 0 - 20
tools/clang/tools/dxcompiler/dxcompilerobj.cpp

@@ -83,26 +83,6 @@ HRESULT RunInternalValidator(_In_ IDxcValidator *pValidator,
                              _In_ IDxcBlob *pShader, UINT32 Flags,
                              _In_ IDxcOperationResult **ppResult);
 
-static void CreateOperationResultFromOutputs(
-    IDxcBlob *pResultBlob, dxcutil::DxcArgsFileSystem *msfPtr,
-    const std::string &warnings, clang::DiagnosticsEngine &diags,
-    _COM_Outptr_ IDxcOperationResult **ppResult) {
-  CComPtr<IStream> pErrorStream;
-  msfPtr->GetStdOutpuHandleStream(&pErrorStream);
-  dxcutil::CreateOperationResultFromOutputs(pResultBlob, pErrorStream, warnings,
-                                            diags.hasErrorOccurred(), ppResult);
-}
-
-static void CreateOperationResultFromOutputs(
-    AbstractMemoryStream *pOutputStream, dxcutil::DxcArgsFileSystem *msfPtr,
-    const std::string &warnings, clang::DiagnosticsEngine &diags,
-    _COM_Outptr_ IDxcOperationResult **ppResult) {
-  CComPtr<IDxcBlob> pResultBlob;
-  IFT(pOutputStream->QueryInterface(&pResultBlob));
-  CreateOperationResultFromOutputs(pResultBlob, msfPtr, warnings, diags,
-                                   ppResult);
-}
-
 static bool ShouldPartBeIncludedInPDB(UINT32 FourCC) {
   switch (FourCC) {
   case hlsl::DFCC_ShaderDebugName:

+ 0 - 8
tools/clang/tools/libclang/dxcrewriteunused.cpp

@@ -223,14 +223,6 @@ public:
   }
 };
 
-static void raw_string_ostream_to_CoString(raw_string_ostream &o, _Outptr_result_z_ LPSTR *pResult) {
-  std::string& s = o.str(); // .str() will flush automatically
-  *pResult = (LPSTR)CoTaskMemAlloc(s.size() + 1);
-  if (*pResult == nullptr) 
-    throw std::bad_alloc();
-  strncpy(*pResult, s.c_str(), s.size() + 1);
-}
-
 static
 void SetupCompilerForRewrite(CompilerInstance &compiler,
                              _In_ DxcLangExtensionsHelper *helper,