Skip to content

Commit 0f6ab8b

Browse files
committed
Merge branch 'main' into devshFixes
2 parents 29a5e12 + 0d8a809 commit 0f6ab8b

File tree

279 files changed

+14640
-7202
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

279 files changed

+14640
-7202
lines changed

CMakeLists.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,17 @@
33

44
cmake_minimum_required(VERSION 3.17.2) # HLSL Change - Require CMake 3.17.2.
55
cmake_policy(SET CMP0091 NEW)
6-
message(CMAKE_BUILD_TYPE0!!!!!="${CMAKE_BUILD_TYPE}")
7-
message(CMAKE_CONFIGURATION_TYPES!!!!!="${CMAKE_CONFIGURATION_TYPES}")
8-
message(CMAKE_CXX_FLAGS_RELEASE!!!!!="${CMAKE_CXX_FLAGS_RELEASE}")
96
set(CMAKE_CXX_STANDARD 17)
107
set(CMAKE_CXX_STANDARD_REQUIRED ON)
118

129
if (NOT "${DXC_CMAKE_BEGINS_INCLUDE}" STREQUAL "")
1310
include(${DXC_CMAKE_BEGINS_INCLUDE})
1411
endif()
1512

16-
1713
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
1814
message(STATUS "No build type selected, default to Debug")
1915
set(CMAKE_BUILD_TYPE "Debug")
2016
endif()
21-
message(CMAKE_BUILD_TYPE1!!!!!="${CMAKE_BUILD_TYPE}")
2217

2318
if(POLICY CMP0022)
2419
cmake_policy(SET CMP0022 NEW) # automatic when 2.8.12 is required
@@ -322,15 +317,11 @@ option(LLVM_ENABLE_LIBCXXABI "Use libc++abi when using libc++." OFF)
322317
option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
323318
option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
324319

325-
message(uppercase_CMAKE_BUILD_TYPE!!!!!="${CMAKE_BUILD_TYPE}")
326320
if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
327-
message(assertions OFF)
328321
option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
329322
else()
330-
message(assertions ON)
331323
option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
332324
endif()
333-
message(LLVM_ENABLE_ASSERTIONS!!!!!="${LLVM_ENABLE_ASSERTIONS}")
334325

335326
set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
336327
"Enable abi-breaking checks. Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")

azure-pipelines.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ stages:
3434
call utils\hct\hctstart.cmd %HLSL_SRC_DIR% %HLSL_BLD_DIR%
3535
call utils\hct\hcttest.cmd -$(configuration) noexec
3636
displayName: 'DXIL Tests'
37-
- script: |
38-
call utils\hct\hctstart.cmd %HLSL_SRC_DIR% %HLSL_BLD_DIR%
39-
call utils\hct\hcttest.cmd -$(configuration) spirv_only
40-
displayName: 'SPIRV Tests'
4137
4238
- job: Nix
4339
timeoutInMinutes: 90

cmake/modules/HandleLLVMOptions.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ int main() { return (float)x; }"
5656
endif()
5757

5858
if( LLVM_ENABLE_ASSERTIONS )
59-
message(how did I get here?)
6059
# MSVC doesn't like _DEBUG on release builds. See PR 4379.
6160
# HLSL Note: the above comment referrs to llvm.org problem, not pull request:
6261
# https://bugs.llvm.org/show_bug.cgi?id=4379

include/llvm/ADT/Triple.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,12 @@ class Triple {
509509
getOS() == Triple::PS4;
510510
}
511511

512+
// HLSL Change Begin - Add DXIL Triple.
513+
bool isDXIL() const {
514+
return getArch() == Triple::dxil || getArch() == Triple::dxil64;
515+
}
516+
// HLSL Change End - Add DXIL Triple.
517+
512518
/// @}
513519
/// @name Mutators
514520
/// @{

include/llvm/IR/Operator.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,26 @@ class BitCastOperator
501501
}
502502
};
503503

504+
// HLSL CHANGE: Add this helper class from upstream.
505+
class AddrSpaceCastOperator
506+
: public ConcreteOperator<Operator, Instruction::AddrSpaceCast> {
507+
friend class AddrSpaceCastInst;
508+
friend class ConstantExpr;
509+
510+
public:
511+
Value *getPointerOperand() { return getOperand(0); }
512+
513+
const Value *getPointerOperand() const { return getOperand(0); }
514+
515+
unsigned getSrcAddressSpace() const {
516+
return getPointerOperand()->getType()->getPointerAddressSpace();
517+
}
518+
519+
unsigned getDestAddressSpace() const {
520+
return getType()->getPointerAddressSpace();
521+
}
522+
};
523+
504524
} // End llvm namespace
505525

506526
#endif

lib/DXIL/DxilOperations.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
685685
"SampleCmp",
686686
OCC::SampleCmp,
687687
"sampleCmp",
688-
{false, true, true, false, false, false, true, true, false, false,
688+
{false, true, true, false, false, false, false, false, false, false,
689689
false},
690690
Attribute::ReadOnly,
691691
},
@@ -694,7 +694,7 @@ const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
694694
"SampleCmpLevelZero",
695695
OCC::SampleCmpLevelZero,
696696
"sampleCmpLevelZero",
697-
{false, true, true, false, false, false, true, true, false, false,
697+
{false, true, true, false, false, false, false, false, false, false,
698698
false},
699699
Attribute::ReadOnly,
700700
},

lib/DXIL/DxilSignatureElement.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ void DxilSignatureElement::Initialize(llvm::StringRef Name,
5151
m_SemanticStartIndex = IndexVector[0];
5252
// Find semantic in the table.
5353
m_pSemantic = Semantic::GetByName(m_SemanticName, m_sigPointKind);
54+
// Replace semantic name with canonical name if it's a system value.
55+
if (!m_pSemantic->IsInvalid() && !m_pSemantic->IsArbitrary())
56+
m_SemanticName = m_pSemantic->GetName();
5457
SetCompType(ElementType);
5558
m_InterpMode = InterpMode;
5659
m_SemanticIndex = IndexVector;

lib/DXIL/DxilUtilDbgInfoAndMisc.cpp

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,18 @@ using namespace hlsl;
3737

3838
namespace {
3939

40-
Value *MergeGEP(GEPOperator *SrcGEP, GEPOperator *GEP) {
40+
// Attempt to merge the two GEPs into a single GEP.
41+
//
42+
// If `AsCast` is non-null the merged GEP will be wrapped
43+
// in an addrspacecast before replacing users. This allows
44+
// merging GEPs of the form
45+
//
46+
// gep(addrspacecast(gep(p0, gep_args0) to p1*), gep_args1)
47+
// into
48+
// addrspacecast(gep(p0, gep_args0+gep_args1) to p1*)
49+
//
50+
Value *MergeGEP(GEPOperator *SrcGEP, GEPOperator *GEP,
51+
AddrSpaceCastOperator *AsCast) {
4152
IRBuilder<> Builder(GEP->getContext());
4253
StringRef Name = "";
4354
if (Instruction *I = dyn_cast<Instruction>(GEP)) {
@@ -75,7 +86,7 @@ Value *MergeGEP(GEPOperator *SrcGEP, GEPOperator *GEP) {
7586
}
7687

7788
// Update the GEP in place if possible.
78-
if (SrcGEP->getNumOperands() == 2) {
89+
if (SrcGEP->getNumOperands() == 2 && !AsCast) {
7990
GEP->setOperand(0, SrcGEP->getOperand(0));
8091
GEP->setOperand(1, Sum);
8192
return GEP;
@@ -94,12 +105,64 @@ Value *MergeGEP(GEPOperator *SrcGEP, GEPOperator *GEP) {
94105
DXASSERT(!Indices.empty(), "must merge");
95106
Value *newGEP =
96107
Builder.CreateInBoundsGEP(nullptr, SrcGEP->getOperand(0), Indices, Name);
108+
109+
// Wrap the new gep in an addrspacecast if needed.
110+
if (AsCast)
111+
newGEP = Builder.CreateAddrSpaceCast(
112+
newGEP, PointerType::get(GEP->getType()->getPointerElementType(),
113+
AsCast->getDestAddressSpace()));
97114
GEP->replaceAllUsesWith(newGEP);
98115
if (Instruction *I = dyn_cast<Instruction>(GEP))
99116
I->eraseFromParent();
100117
return newGEP;
101118
}
102119

120+
// Examine the gep and try to merge it when the input pointer is
121+
// itself a gep. We handle two forms here:
122+
//
123+
// gep(gep(p))
124+
// gep(addrspacecast(gep(p)))
125+
//
126+
// If the gep was merged successfully then return the updated value, otherwise
127+
// return nullptr.
128+
//
129+
// When the gep is sucessfully merged we will delete the gep and also try to
130+
// delete the nested gep and addrspacecast.
131+
static Value *TryMegeWithNestedGEP(GEPOperator *GEP) {
132+
// Sentinal value to return when we fail to merge.
133+
Value *FailedToMerge = nullptr;
134+
135+
Value *Ptr = GEP->getPointerOperand();
136+
GEPOperator *prevGEP = dyn_cast<GEPOperator>(Ptr);
137+
AddrSpaceCastOperator *AsCast = nullptr;
138+
139+
// If there is no directly nested gep try looking through an addrspacecast to
140+
// find one.
141+
if (!prevGEP) {
142+
AsCast = dyn_cast<AddrSpaceCastOperator>(Ptr);
143+
if (AsCast)
144+
prevGEP = dyn_cast<GEPOperator>(AsCast->getPointerOperand());
145+
}
146+
147+
// Not a nested gep expression.
148+
if (!prevGEP)
149+
return FailedToMerge;
150+
151+
// Try merging the two geps.
152+
Value *newGEP = MergeGEP(prevGEP, GEP, AsCast);
153+
if (!newGEP)
154+
return FailedToMerge;
155+
156+
// Delete the nested gep and addrspacecast if no more users.
157+
if (AsCast && AsCast->user_empty() && isa<AddrSpaceCastInst>(AsCast))
158+
cast<AddrSpaceCastInst>(AsCast)->eraseFromParent();
159+
160+
if (prevGEP->user_empty() && isa<GetElementPtrInst>(prevGEP))
161+
cast<GetElementPtrInst>(prevGEP)->eraseFromParent();
162+
163+
return newGEP;
164+
}
165+
103166
} // namespace
104167

105168
namespace hlsl {
@@ -130,23 +193,14 @@ bool MergeGepUse(Value *V) {
130193
// merge any GEP users of the untranslated bitcast
131194
addUsersToWorklist(V);
132195
}
196+
} else if (isa<AddrSpaceCastOperator>(V)) {
197+
addUsersToWorklist(V);
133198
} else if (GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {
134-
if (GEPOperator *prevGEP =
135-
dyn_cast<GEPOperator>(GEP->getPointerOperand())) {
136-
// merge the 2 GEPs, returns nullptr if couldn't merge
137-
if (Value *newGEP = MergeGEP(prevGEP, GEP)) {
138-
changed = true;
139-
worklist.push_back(newGEP);
140-
// delete prevGEP if no more users
141-
if (prevGEP->user_empty() && isa<GetElementPtrInst>(prevGEP)) {
142-
cast<GetElementPtrInst>(prevGEP)->eraseFromParent();
143-
}
144-
} else {
145-
addUsersToWorklist(GEP);
146-
}
199+
if (Value *newGEP = TryMegeWithNestedGEP(GEP)) {
200+
changed = true;
201+
worklist.push_back(newGEP);
147202
} else {
148-
// nothing to merge yet, add GEP users
149-
addUsersToWorklist(V);
203+
addUsersToWorklist(GEP);
150204
}
151205
}
152206
}

lib/HLSL/DxilValidation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ static void ValidateSampleInst(CallInst *CI, Value *srvHandle,
975975
isSampleCompTy |= compTy == DXIL::ComponentType::SNormF16;
976976
isSampleCompTy |= compTy == DXIL::ComponentType::UNormF16;
977977
const ShaderModel *pSM = ValCtx.DxilMod.GetShaderModel();
978-
if (pSM->IsSM67Plus()) {
978+
if (pSM->IsSM67Plus() && !IsSampleC) {
979979
isSampleCompTy |= compTy == DXIL::ComponentType::I16;
980980
isSampleCompTy |= compTy == DXIL::ComponentType::U16;
981981
isSampleCompTy |= compTy == DXIL::ComponentType::I32;

lib/Support/Unix/Signals.inc

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@ static void RemoveFilesToRemove() {
144144
// memory.
145145
std::vector<std::string>& FilesToRemoveRef = *FilesToRemove;
146146
for (unsigned i = 0, e = FilesToRemoveRef.size(); i != e; ++i) {
147-
// We rely on a std::string implementation for which repeated calls to
148-
// 'c_str()' don't allocate memory. We pre-call 'c_str()' on all of these
149-
// strings to try to ensure this is safe.
150147
const char *path = FilesToRemoveRef[i].c_str();
151148

152149
// Get the status so we can determine if it's a file or directory. If we
@@ -235,21 +232,7 @@ bool llvm::sys::RemoveFileOnSignal(StringRef Filename,
235232
std::string* ErrMsg) {
236233
{
237234
sys::SmartScopedLock<true> Guard(*SignalsMutex);
238-
std::vector<std::string>& FilesToRemoveRef = *FilesToRemove;
239-
std::string *OldPtr =
240-
FilesToRemoveRef.empty() ? nullptr : &FilesToRemoveRef[0];
241-
FilesToRemoveRef.push_back(Filename);
242-
243-
// We want to call 'c_str()' on every std::string in this vector so that if
244-
// the underlying implementation requires a re-allocation, it happens here
245-
// rather than inside of the signal handler. If we see the vector grow, we
246-
// have to call it on every entry. If it remains in place, we only need to
247-
// call it on the latest one.
248-
if (OldPtr == &FilesToRemoveRef[0])
249-
FilesToRemoveRef.back().c_str();
250-
else
251-
for (unsigned i = 0, e = FilesToRemoveRef.size(); i != e; ++i)
252-
FilesToRemoveRef[i].c_str();
235+
FilesToRemove->push_back(Filename);
253236
}
254237

255238
RegisterHandlers();
@@ -264,13 +247,6 @@ void llvm::sys::DontRemoveFileOnSignal(StringRef Filename) {
264247
std::vector<std::string>::iterator I = FilesToRemove->end();
265248
if (RI != FilesToRemove->rend())
266249
I = FilesToRemove->erase(RI.base()-1);
267-
268-
// We need to call c_str() on every element which would have been moved by
269-
// the erase. These elements, in a C++98 implementation where c_str()
270-
// requires a reallocation on the first call may have had the call to c_str()
271-
// made on insertion become invalid by being copied down an element.
272-
for (std::vector<std::string>::iterator E = FilesToRemove->end(); I != E; ++I)
273-
I->c_str();
274250
}
275251

276252
/// AddSignalHandler - Add a function to be called when a signal is delivered

0 commit comments

Comments
 (0)