Skip to content

Commit 7a2f900

Browse files
committed
Removed global flag
1 parent 403a4d9 commit 7a2f900

File tree

10 files changed

+29
-38
lines changed

10 files changed

+29
-38
lines changed

tools/clang/include/clang/AST/ASTContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2408,7 +2408,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
24082408
/// It is normally invoked after ASTContext construction.
24092409
///
24102410
/// \param Target The target
2411-
void InitBuiltinTypes(const TargetInfo &Target);
2411+
void InitBuiltinTypes(const TargetInfo &Target, bool ignoreHLSLIntrinsics);
24122412

24132413
private:
24142414
void InitBuiltinType(CanQualType &R, BuiltinType::Kind K);

tools/clang/include/clang/AST/HlslTypes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ namespace hlsl {
5151

5252
/// <summary>Initializes the specified context to support HLSL
5353
/// compilation.</summary>
54-
void InitializeASTContextForHLSL(clang::ASTContext &context);
54+
void InitializeASTContextForHLSL(clang::ASTContext &context,
55+
bool ignoreHLSLIntrinsics);
5556

5657
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5758
// Type system enumerations.

tools/clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ class CompilerInstance : public ModuleLoader {
669669
std::string getSpecificModuleCachePath();
670670

671671
/// Create the AST context.
672-
void createASTContext();
672+
void createASTContext(bool ignoreHLSLIntrinsics = false);
673673

674674
/// Create an external AST source to read a PCH file and attach it to the AST
675675
/// context.

tools/clang/include/clang/Frontend/FrontendAction.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ class FrontendAction {
208208
///
209209
/// \return True on success; on failure the compilation of this file should
210210
/// be aborted and neither Execute() nor EndSourceFile() should be called.
211-
bool BeginSourceFile(CompilerInstance &CI, const FrontendInputFile &Input);
211+
bool BeginSourceFile(CompilerInstance &CI, const FrontendInputFile &Input,
212+
bool ignoreHLSLIntrinsics = false);
212213

213214
/// \brief Set the source manager's main input file, and run the action.
214215
bool Execute();

tools/clang/include/clang/Sema/SemaHLSL.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,6 @@
2424
#include "clang/Sema/Template.h"
2525
#include "clang/Sema/TemplateDeduction.h"
2626

27-
#include <optional>
28-
extern std::optional<bool> disableHLSLIntrinsicsGlobalVariableBecauseIDontCare;
29-
30-
inline bool shouldDisableHLSLIntrinsics()
31-
{
32-
assert(disableHLSLIntrinsicsGlobalVariableBecauseIDontCare.has_value());
33-
34-
if (!disableHLSLIntrinsicsGlobalVariableBecauseIDontCare.has_value())
35-
exit(-1);
36-
37-
return disableHLSLIntrinsicsGlobalVariableBecauseIDontCare.value();
38-
}
39-
4027
// Forward declarations.
4128
struct IDxcIntrinsicTable;
4229
namespace clang {

tools/clang/lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ void ASTContext::InitBuiltinType(CanQualType &R, BuiltinType::Kind K) {
958958
Types.push_back(Ty);
959959
}
960960

961-
void ASTContext::InitBuiltinTypes(const TargetInfo &Target) {
961+
void ASTContext::InitBuiltinTypes(const TargetInfo &Target, bool ignoreHLSLIntrinsics) {
962962
assert((!this->Target || this->Target == &Target) &&
963963
"Incorrect target reinitialization");
964964
assert(VoidTy.isNull() && "Context reinitialized?");
@@ -1108,7 +1108,7 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target) {
11081108

11091109
HLSLStringTy = this->getPointerType(CharTy);
11101110

1111-
hlsl::InitializeASTContextForHLSL(*this); // Previously in constructor, guarded by !DelayInitialization
1111+
hlsl::InitializeASTContextForHLSL(*this, ignoreHLSLIntrinsics); // Previously in constructor, guarded by !DelayInitialization
11121112
}
11131113
// HLSL Change Ends
11141114
}

tools/clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,12 @@ std::string CompilerInstance::getSpecificModuleCachePath() {
409409

410410
// ASTContext
411411

412-
void CompilerInstance::createASTContext() {
412+
void CompilerInstance::createASTContext(bool ignoreHLSLIntrinsics) {
413413
Preprocessor &PP = getPreprocessor();
414414
Context = new ASTContext(getLangOpts(), PP.getSourceManager(),
415415
PP.getIdentifierTable(), PP.getSelectorTable(),
416416
PP.getBuiltinInfo());
417-
Context->InitBuiltinTypes(getTarget());
417+
Context->InitBuiltinTypes(getTarget(), ignoreHLSLIntrinsics);
418418
}
419419

420420
// ExternalASTSource

tools/clang/lib/Frontend/FrontendAction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI,
173173
}
174174

175175
bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
176-
const FrontendInputFile &Input) {
176+
const FrontendInputFile &Input,
177+
bool ignoreHLSLIntrinsics) {
177178
assert(!Instance && "Already processing a source file!");
178179
assert(!Input.isEmpty() && "Unexpected empty filename!");
179180
setCurrentInput(Input);
@@ -323,7 +324,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
323324
if (!usesPreprocessorOnly()) {
324325
// Parsing a model file should reuse the existing ASTContext.
325326
if (!isModelParsingAction())
326-
CI.createASTContext();
327+
CI.createASTContext(ignoreHLSLIntrinsics);
327328

328329
std::unique_ptr<ASTConsumer> Consumer =
329330
CreateWrappedASTConsumer(CI, InputFile);

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@
5353
#include <bitset>
5454
#include <float.h>
5555

56-
std::optional<bool> disableHLSLIntrinsicsGlobalVariableBecauseIDontCare = std::nullopt;
57-
5856
enum ArBasicKind {
5957
AR_BASIC_BOOL,
6058
AR_BASIC_LITERAL_FLOAT,
@@ -2996,6 +2994,9 @@ static TypedefDecl *CreateGlobalTypedef(ASTContext *context, const char *ident,
29962994

29972995
class HLSLExternalSource : public ExternalSemaSource {
29982996
private:
2997+
2998+
const bool m_disableHLSLIntrinsics;
2999+
29993000
// Inner types.
30003001
struct FindStructBasicTypeResult {
30013002
ArBasicKind Kind; // Kind of struct (eg, AR_OBJECT_TEXTURE2D)
@@ -4115,13 +4116,14 @@ class HLSLExternalSource : public ExternalSemaSource {
41154116
}
41164117

41174118
public:
4118-
HLSLExternalSource()
4119+
HLSLExternalSource(bool disableHLSLIntrinsics)
41194120
: m_matrixTemplateDecl(nullptr), m_vectorTemplateDecl(nullptr),
41204121
m_vkIntegralConstantTemplateDecl(nullptr),
41214122
m_vkLiteralTemplateDecl(nullptr),
41224123
m_vkBufferPointerTemplateDecl(nullptr), m_hlslNSDecl(nullptr),
41234124
m_vkNSDecl(nullptr), m_dxNSDecl(nullptr), m_context(nullptr),
4124-
m_sema(nullptr), m_hlslStringTypedef(nullptr) {
4125+
m_sema(nullptr), m_hlslStringTypedef(nullptr),
4126+
m_disableHLSLIntrinsics(disableHLSLIntrinsics) {
41254127
memset(m_matrixTypes, 0, sizeof(m_matrixTypes));
41264128
memset(m_matrixShorthandTypes, 0, sizeof(m_matrixShorthandTypes));
41274129
memset(m_vectorTypes, 0, sizeof(m_vectorTypes));
@@ -5133,8 +5135,11 @@ class HLSLExternalSource : public ExternalSemaSource {
51335135
bool IsValidObjectElement(LPCSTR tableName, IntrinsicOp op,
51345136
QualType objectElement);
51355137

5136-
static bool checkIfIntrinsicIsAllowed(StringRef intrinsicNameIdentifier)
5138+
bool checkIfIntrinsicIsAllowed(StringRef intrinsicNameIdentifier)
51375139
{
5140+
if (!m_disableHLSLIntrinsics)
5141+
return true;
5142+
51385143
static const std::unordered_set<std::string> allowedHLSLIntrinsics = {
51395144
"Abort",
51405145
"AcceptHitAndEndSearch",
@@ -5220,10 +5225,7 @@ class HLSLExternalSource : public ExternalSemaSource {
52205225
"TraceRay",
52215226
"TraceRayInline",
52225227
"WorldRayDirection",
5223-
"WorldRayOrigin",
5224-
"WorldToObject",
5225-
"WorldToObject3x4",
5226-
"WorldToObject4x3"
5228+
"WorldRayOrigin"
52275229
};
52285230

52295231
auto it = allowedHLSLIntrinsics.find(std::string(intrinsicNameIdentifier));
@@ -5237,7 +5239,7 @@ class HLSLExternalSource : public ExternalSemaSource {
52375239
StringRef nameIdentifier,
52385240
size_t argumentCount) {
52395241
// TODO: only check if the flag "devsh-disable-hlsl-intrinsics" is enabled
5240-
if (shouldDisableHLSLIntrinsics() && !checkIfIntrinsicIsAllowed(nameIdentifier))
5242+
if (!checkIfIntrinsicIsAllowed(nameIdentifier))
52415243
{
52425244
return IntrinsicDefIter::CreateStart(
52435245
table, tableSize, table + tableSize,
@@ -13560,8 +13562,8 @@ hlsl::TrySubscriptIndexInitialization(clang::Sema *self, clang::Expr *SrcExpr,
1356013562

1356113563
/// <summary>Performs HLSL-specific initialization on the specified
1356213564
/// context.</summary>
13563-
void hlsl::InitializeASTContextForHLSL(ASTContext &context) {
13564-
HLSLExternalSource *hlslSource = new HLSLExternalSource();
13565+
void hlsl::InitializeASTContextForHLSL(ASTContext &context, bool ignoreHLSLIntrinsics) {
13566+
HLSLExternalSource *hlslSource = new HLSLExternalSource(ignoreHLSLIntrinsics);
1356513567
IntrusiveRefCntPtr<ExternalASTSource> externalSource(hlslSource);
1356613568
if (hlslSource->Initialize(context)) {
1356713569
context.setExternalSource(externalSource);

tools/clang/tools/dxcompiler/dxcompilerobj.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,6 @@ class DxcCompiler : public IDxcCompiler3,
628628
static_cast<const char *>(pOrigUtf8Source->GetStringPointer()),
629629
pOrigUtf8Source->GetStringLength());
630630

631-
disableHLSLIntrinsicsGlobalVariableBecauseIDontCare = opts.SpirvOptions.devshDisableHLSLIntrinsics;
632-
633631
CComPtr<IDxcResult> pSrcCodeResult;
634632
std::vector<LPCWSTR> PreprocessArgs;
635633
PreprocessArgs.reserve(argCount + 1);
@@ -968,7 +966,8 @@ class DxcCompiler : public IDxcCompiler3,
968966
compiler.getCodeGenOpts().SpirvOptions = opts.SpirvOptions;
969967
clang::EmitSpirvAction action;
970968
FrontendInputFile file(pUtf8SourceName, IK_HLSL);
971-
action.BeginSourceFile(compiler, file);
969+
action.BeginSourceFile(
970+
compiler, file, opts.SpirvOptions.devshDisableHLSLIntrinsics);
972971
action.Execute();
973972
action.EndSourceFile();
974973
outStream.flush();

0 commit comments

Comments
 (0)