diff --git a/lib/HLSL/DxilSemantic.cpp b/lib/HLSL/DxilSemantic.cpp index 4a73b636f..df99e38a8 100644 --- a/lib/HLSL/DxilSemantic.cpp +++ b/lib/HLSL/DxilSemantic.cpp @@ -76,13 +76,8 @@ const Semantic *Semantic::GetArbitrary() { } bool Semantic::HasSVPrefix(llvm::StringRef Name) { - if (Name.size() >= 3) - if (Name[0] == 'S' || Name[0] == 's') - if (Name[1] == 'V' || Name[1] == 'v') - if (Name[2] == '_') - return true; - - return false; + return Name.size() >= 3 && (Name[0] == 'S' || Name[0] == 's') && + (Name[1] == 'V' || Name[1] == 'v') && Name[2] == '_'; } void Semantic::DecomposeNameAndIndex(llvm::StringRef FullName, llvm::StringRef *pName, unsigned *pIndex) { diff --git a/lib/HLSL/DxilSignature.cpp b/lib/HLSL/DxilSignature.cpp index 4643a6679..61dd151db 100644 --- a/lib/HLSL/DxilSignature.cpp +++ b/lib/HLSL/DxilSignature.cpp @@ -11,6 +11,7 @@ #include "dxc/HLSL/DxilSignature.h" #include "dxc/HLSL/DxilSignatureAllocator.h" #include "dxc/HLSL/DxilSigPoint.h" +#include "llvm/ADT/STLExtras.h" using std::vector; using std::unique_ptr; @@ -53,7 +54,7 @@ bool DxilSignature::IsOutput() const { } unique_ptr DxilSignature::CreateElement() { - return unique_ptr(new DxilSignatureElement(m_sigPointKind)); + return llvm::make_unique(m_sigPointKind); } unsigned DxilSignature::AppendElement(std::unique_ptr pSE, bool bSetID) { @@ -67,11 +68,11 @@ unsigned DxilSignature::AppendElement(std::unique_ptr pSE, } DxilSignatureElement &DxilSignature::GetElement(unsigned idx) { - return *m_Elements[idx].get(); + return *m_Elements[idx]; } const DxilSignatureElement &DxilSignature::GetElement(unsigned idx) const { - return *m_Elements[idx].get(); + return *m_Elements[idx]; } const std::vector > &DxilSignature::GetElements() const { diff --git a/tools/clang/lib/CodeGen/CGHLSLMS.cpp b/tools/clang/lib/CodeGen/CGHLSLMS.cpp index a6e2ff208..c3a20a452 100644 --- a/tools/clang/lib/CodeGen/CGHLSLMS.cpp +++ b/tools/clang/lib/CodeGen/CGHLSLMS.cpp @@ -25,6 +25,7 @@ #include "clang/Frontend/CodeGenOptions.h" #include "clang/Lex/HLSLMacroExpander.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/IR/Constants.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/GetElementPtrTypeIterator.h" @@ -425,13 +426,11 @@ SourceLocation CGMSHLSLRuntime::SetSemantic(const NamedDecl *decl, DxilParameterAnnotation ¶mInfo) { for (const hlsl::UnusualAnnotation *it : decl->getUnusualAnnotations()) { - switch (it->getKind()) { - case hlsl::UnusualAnnotation::UA_SemanticDecl: { + if (it->getKind() == hlsl::UnusualAnnotation::UA_SemanticDecl) { const hlsl::SemanticDecl *sd = cast(it); paramInfo.SetSemanticString(sd->SemanticName); return it->Loc; } - } } return SourceLocation(); } @@ -674,10 +673,7 @@ static void ConstructFieldAttributedAnnotation(DxilFieldAnnotation &fieldAnnotat } } - unsigned row, col; - hlsl::GetHLSLMatRowColCount(Ty, row, col); - Matrix.Cols = col; - Matrix.Rows = row; + hlsl::GetHLSLMatRowColCount(Ty, Matrix.Rows, Matrix.Cols); fieldAnnotation.SetMatrixAnnotation(Matrix); EltTy = hlsl::GetHLSLMatElementType(Ty); } @@ -972,16 +968,13 @@ static DxilResource::Kind KeywordToKind(StringRef keyword) { return DxilResource::Kind::Invalid; } -static DxilSampler::SamplerKind KeywordToSamplerKind(const std::string &keyword) { +static DxilSampler::SamplerKind KeywordToSamplerKind(llvm::StringRef keyword) { // TODO: refactor for faster search (switch by 1/2/3 first letters, then // compare) - if (keyword == "SamplerState") - return DxilSampler::SamplerKind::Default; - - if (keyword == "SamplerComparisonState") - return DxilSampler::SamplerKind::Comparison; - - return DxilSampler::SamplerKind::Invalid; + return llvm::StringSwitch(keyword) + .Case("SamplerState", DxilSampler::SamplerKind::Default) + .Case("SamplerComparisonState", DxilSampler::SamplerKind::Comparison) + .Default(DxilSampler::SamplerKind::Invalid); } void CGMSHLSLRuntime::AddHLSLFunctionInfo(Function *F, const FunctionDecl *FD) { @@ -1351,19 +1344,7 @@ void CGMSHLSLRuntime::AddHLSLFunctionInfo(Function *F, const FunctionDecl *FD) { funcProps->shaderKind = DXIL::ShaderKind::Pixel; } - unsigned profileAttributes = 0; - if (isCS) - profileAttributes++; - if (isHS) - profileAttributes++; - if (isDS) - profileAttributes++; - if (isGS) - profileAttributes++; - if (isVS) - profileAttributes++; - if (isPS) - profileAttributes++; + const unsigned profileAttributes = isCS + isHS + isDS + isGS + isVS + isPS; // TODO: check this in front-end and report error. DXASSERT(profileAttributes < 2, "profile attributes are mutual exclusive");