Skip to content

Commit e09a454

Browse files
authored
Merge pull request microsoft#3684 from tex3d/refactor-exectest-setup-on-release
Merge fixes for release - refactor setup, -Zi and PDB fixes
2 parents 1071f1f + f53085e commit e09a454

File tree

9 files changed

+243
-52
lines changed

9 files changed

+243
-52
lines changed

include/llvm/IR/BasicBlock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ class BasicBlock : public Value, // Basic blocks are data objects also
245245
inline const Instruction &back() const { return InstList.back(); }
246246
inline Instruction &back() { return InstList.back(); }
247247

248+
size_t compute_size_no_dbg() const; // HLSL Change - Get the size of the block without the debug insts
249+
248250
/// \brief Return the underlying instruction list container.
249251
///
250252
/// Currently you need to access the underlying instruction list container

include/llvm/Option/OptTable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ class OptTable {
133133
unsigned FlagsToInclude = 0,
134134
unsigned FlagsToExclude = 0) const;
135135

136+
Option findOption(const char *normalizedName, unsigned FlagsToInclude = 0, unsigned FlagsToExclude = 0) const; // HLSL Change
137+
136138
/// \brief Parse an list of arguments into an InputArgList.
137139
///
138140
/// The resulting InputArgList will reference the strings in [\p ArgBegin,

lib/IR/BasicBlock.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ CallInst *BasicBlock::getTerminatingMustTailCall() {
168168
return nullptr;
169169
}
170170

171+
// HLSL Change - begin
172+
size_t BasicBlock::compute_size_no_dbg() const {
173+
size_t ret = 0;
174+
for (auto it = InstList.begin(), E = InstList.end(); it != E; it++) {
175+
if (isa<DbgInfoIntrinsic>(&*it))
176+
continue;
177+
ret++;
178+
}
179+
return ret;
180+
}
181+
// HLSL Change - end
182+
171183
Instruction* BasicBlock::getFirstNonPHI() {
172184
for (Instruction &I : *this)
173185
if (!isa<PHINode>(I))

lib/Option/OptTable.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,35 @@ static unsigned matchOption(const OptTable::Info *I, StringRef Str,
188188
return 0;
189189
}
190190

191+
// HLSL Change - begin
192+
Option OptTable::findOption(const char *normalizedName, unsigned FlagsToInclude, unsigned FlagsToExclude) const {
193+
const Info *Start = OptionInfos + FirstSearchableIndex;
194+
const Info *End = OptionInfos + getNumOptions();
195+
196+
StringRef Str(normalizedName);
197+
198+
for (; Start != End; ++Start) {
199+
// Scan for first option which is a proper prefix.
200+
for (; Start != End; ++Start)
201+
if (Str.startswith(Start->Name))
202+
break;
203+
if (Start == End)
204+
break;
205+
206+
Option Opt(Start, this);
207+
208+
if (FlagsToInclude && !Opt.hasFlag(FlagsToInclude))
209+
continue;
210+
if (Opt.hasFlag(FlagsToExclude))
211+
continue;
212+
213+
return Opt;
214+
}
215+
216+
return Option(nullptr, this);
217+
}
218+
// HLSL Change - end
219+
191220
Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index,
192221
unsigned FlagsToInclude,
193222
unsigned FlagsToExclude) const {

lib/Transforms/Scalar/MergedLoadStoreMotion.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ bool MergedLoadStoreMotion::mergeLoads(BasicBlock *BB) {
359359
BasicBlock *Succ0 = BI->getSuccessor(0);
360360
BasicBlock *Succ1 = BI->getSuccessor(1);
361361
// #Instructions in Succ1 for Compile Time Control
362-
int Size1 = Succ1->size();
362+
// int Size1 = Succ1->size(); // HLSL Change
363+
int Size1 = Succ1->compute_size_no_dbg(); // HLSL Change
363364
int NLoads = 0;
364365
for (BasicBlock::iterator BBI = Succ0->begin(), BBE = Succ0->end();
365366
BBI != BBE;) {
@@ -529,7 +530,8 @@ bool MergedLoadStoreMotion::mergeStores(BasicBlock *T) {
529530
return false; // No. More than 2 predecessors.
530531

531532
// #Instructions in Succ1 for Compile Time Control
532-
int Size1 = Pred1->size();
533+
// int Size1 = Succ1->size(); // HLSL Change
534+
int Size1 = Pred1->compute_size_no_dbg(); // HLSL Change
533535
int NStores = 0;
534536

535537
for (BasicBlock::reverse_iterator RBI = Pred0->rbegin(), RBE = Pred0->rend();

tools/clang/tools/dxcompiler/dxcpdbutils.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,29 @@ struct DxcPdbUtils : public IDxcPdbUtils, public IDxcPixDxilDebugInfoFactory
543543
}
544544

545545
void AddArgPair(ArgPair &&newPair) {
546+
const llvm::opt::OptTable *optTable = hlsl::options::getHlslOptTable();
547+
548+
if (newPair.Name.size() && newPair.Value.size()) {
549+
// Handling case where old positional arguments used to have
550+
// <input> written as the option name.
551+
if (newPair.Name == L"<input>") {
552+
newPair.Name.clear();
553+
}
554+
// Check if the option and its value must be merged. Newer compiler
555+
// pre-merge them before writing them to the PDB, but older PDBs might
556+
// have them separated.
557+
else {
558+
std::string NameUtf8 = ToUtf8String(newPair.Name);
559+
llvm::opt::Option opt = optTable->findOption(NameUtf8.c_str());
560+
if (opt.isValid()) {
561+
if (opt.getKind() == llvm::opt::Option::JoinedClass) {
562+
newPair.Name += newPair.Value;
563+
newPair.Value.clear();
564+
}
565+
}
566+
}
567+
}
568+
546569
bool excludeFromFlags = false;
547570
if (newPair.Name == L"E") {
548571
m_EntryPoint = newPair.Value;

tools/clang/tools/dxcompiler/dxcshadersourceinfo.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ void SourceInfoWriter::Write(llvm::StringRef targetProfile, llvm::StringRef entr
426426
const llvm::opt::OptTable *optTable = hlsl::options::getHlslOptTable();
427427
llvm::opt::InputArgList argList = optTable->ParseArgs(optPointers, missingIndex, missingCount);
428428

429+
llvm::SmallString<64> argumentStorage;
429430
const size_t argumentsOffset = m_Buffer.size();
430431
for (llvm::opt::Arg *arg : argList) {
431432
llvm::StringRef name = arg->getOption().getName();
@@ -435,6 +436,23 @@ void SourceInfoWriter::Write(llvm::StringRef targetProfile, llvm::StringRef entr
435436
value = arg->getValue();
436437
}
437438

439+
440+
// If this is a positional argument, set the name to ""
441+
// explicitly.
442+
if (arg->getOption().getKind() == llvm::opt::Option::InputClass) {
443+
name = "";
444+
}
445+
// If the argument must be merged (eg. -Wx, where W is the option and x is
446+
// the value), merge them right now.
447+
else if (arg->getOption().getKind() == llvm::opt::Option::JoinedClass) {
448+
argumentStorage.clear();
449+
argumentStorage.append(name);
450+
argumentStorage.append(value);
451+
452+
name = argumentStorage;
453+
value = nullptr;
454+
}
455+
438456
// Name
439457
Append(&m_Buffer, name.data(), name.size());
440458
Append(&m_Buffer, 0); // Null term

tools/clang/unittests/HLSL/CompilerTest.cpp

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class CompilerTest : public ::testing::Test {
128128
TEST_METHOD(CompileWhenWorksThenAddRemovePrivate)
129129
TEST_METHOD(CompileThenAddCustomDebugName)
130130
TEST_METHOD(CompileThenTestPdbUtils)
131+
TEST_METHOD(CompileThenTestPdbUtilsWarningOpt)
131132
TEST_METHOD(CompileThenTestPdbInPrivate)
132133
TEST_METHOD(CompileThenTestPdbUtilsStripped)
133134
TEST_METHOD(CompileThenTestPdbUtilsEmptyEntry)
@@ -1632,6 +1633,113 @@ TEST_F(CompilerTest, CompileThenTestPdbUtils) {
16321633
TestPdbUtils(/*bSlim*/false, /*bSourceInDebugModule*/false, /*strip*/true); // Full PDB, where source info is stored in its own part, and debug module is present
16331634
}
16341635

1636+
1637+
TEST_F(CompilerTest, CompileThenTestPdbUtilsWarningOpt) {
1638+
CComPtr<IDxcCompiler> pCompiler;
1639+
VERIFY_SUCCEEDED(CreateCompiler(&pCompiler));
1640+
1641+
std::string main_source = R"x(
1642+
cbuffer MyCbuffer : register(b1) {
1643+
float4 my_cbuf_foo;
1644+
}
1645+
1646+
[RootSignature("CBV(b1)")]
1647+
float4 main() : SV_Target {
1648+
return my_cbuf_foo;
1649+
}
1650+
)x";
1651+
1652+
CComPtr<IDxcUtils> pUtils;
1653+
VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcUtils, &pUtils));
1654+
1655+
1656+
1657+
CComPtr<IDxcCompiler3> pCompiler3;
1658+
VERIFY_SUCCEEDED(pCompiler.QueryInterface(&pCompiler3));
1659+
1660+
const WCHAR *args[] = {
1661+
L"/Zs",
1662+
L".\redundant_input",
1663+
L"-Wno-parentheses-equality",
1664+
L"hlsl.hlsl",
1665+
L"/Tps_6_0",
1666+
L"/Emain",
1667+
};
1668+
1669+
DxcBuffer buf = {};
1670+
buf.Ptr = main_source.c_str();
1671+
buf.Size = main_source.size();
1672+
buf.Encoding = CP_UTF8;
1673+
1674+
CComPtr<IDxcResult> pResult;
1675+
VERIFY_SUCCEEDED(pCompiler3->Compile(&buf, args, _countof(args), nullptr, IID_PPV_ARGS(&pResult)));
1676+
1677+
CComPtr<IDxcBlob> pPdb;
1678+
VERIFY_SUCCEEDED(pResult->GetOutput(DXC_OUT_PDB, IID_PPV_ARGS(&pPdb), nullptr));
1679+
1680+
auto TestPdb = [](IDxcPdbUtils *pPdbUtils) {
1681+
UINT32 uArgsCount = 0;
1682+
VERIFY_SUCCEEDED(pPdbUtils->GetArgCount(&uArgsCount));
1683+
bool foundArg = false;
1684+
for (UINT32 i = 0; i < uArgsCount; i++) {
1685+
CComBSTR pArg;
1686+
VERIFY_SUCCEEDED(pPdbUtils->GetArg(i, &pArg));
1687+
if (pArg) {
1688+
std::wstring arg(pArg);
1689+
if (arg == L"-Wno-parentheses-equality" || arg == L"/Wno-parentheses-equality") {
1690+
foundArg = true;
1691+
}
1692+
else {
1693+
// Make sure arg value "no-parentheses-equality" doesn't show up
1694+
// as its own argument token.
1695+
VERIFY_ARE_NOT_EQUAL(arg, L"no-parentheses-equality");
1696+
1697+
// Make sure the presence of the argument ".\redundant_input"
1698+
// doesn't cause "<input>" to show up.
1699+
VERIFY_ARE_NOT_EQUAL(arg, L"<input>");
1700+
}
1701+
}
1702+
}
1703+
VERIFY_IS_TRUE(foundArg);
1704+
1705+
UINT32 uFlagsCount = 0;
1706+
VERIFY_SUCCEEDED(pPdbUtils->GetFlagCount(&uFlagsCount));
1707+
bool foundFlag = false;
1708+
for (UINT32 i = 0; i < uFlagsCount; i++) {
1709+
CComBSTR pFlag;
1710+
VERIFY_SUCCEEDED(pPdbUtils->GetFlag(i, &pFlag));
1711+
if (pFlag) {
1712+
std::wstring arg(pFlag);
1713+
if (arg == L"-Wno-parentheses-equality" || arg == L"/Wno-parentheses-equality") {
1714+
foundFlag = true;
1715+
}
1716+
else {
1717+
// Make sure arg value "no-parentheses-equality" doesn't show up
1718+
// as its own flag token.
1719+
VERIFY_ARE_NOT_EQUAL(arg, L"no-parentheses-equality");
1720+
}
1721+
}
1722+
}
1723+
VERIFY_IS_TRUE(foundFlag);
1724+
1725+
CComBSTR pMainFileName;
1726+
VERIFY_SUCCEEDED(pPdbUtils->GetMainFileName(&pMainFileName));
1727+
std::wstring mainFileName = pMainFileName;
1728+
VERIFY_ARE_EQUAL(mainFileName, L"hlsl.hlsl");
1729+
};
1730+
1731+
CComPtr<IDxcPdbUtils> pPdbUtils;
1732+
VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcPdbUtils, &pPdbUtils));
1733+
1734+
VERIFY_SUCCEEDED(pPdbUtils->Load(pPdb));
1735+
TestPdb(pPdbUtils);
1736+
1737+
CComPtr<IDxcBlob> pFullPdb;
1738+
VERIFY_SUCCEEDED(pPdbUtils->GetFullPDB(&pFullPdb));
1739+
VERIFY_SUCCEEDED(pPdbUtils->Load(pFullPdb));
1740+
TestPdb(pPdbUtils);
1741+
}
1742+
16351743
TEST_F(CompilerTest, CompileThenTestPdbInPrivate) {
16361744
CComPtr<IDxcCompiler> pCompiler;
16371745
VERIFY_SUCCEEDED(CreateCompiler(&pCompiler));

0 commit comments

Comments
 (0)