@@ -22,7 +22,11 @@ using namespace llvm;
2222namespace {
2323
2424const unsigned OfflineLibMinor = 0xF ;
25- const unsigned MaxShaderModel6Minor = 7 ;
25+ const unsigned MaxDXILMajor = 1 ;
26+ const unsigned MaxDXILMinor = 7 ;
27+ const unsigned MaxShaderModel6Minor = MaxDXILMinor;
28+ // TODO:get default validator version from validator.
29+ const StringRef DefaultValidatorVer = " 1.7" ;
2630
2731bool isLegalVersion (VersionTuple Version, unsigned Major, unsigned MinMinor,
2832 unsigned MaxMinor) {
@@ -122,6 +126,30 @@ std::string tryParseProfile(StringRef Profile) {
122126 return " " ;
123127}
124128
129+ bool isLegalValidatorVersion (StringRef ValVersionStr, std::string &ErrorMsg) {
130+ auto VerPair = ValVersionStr.split (" ." );
131+ llvm::APInt APMajor, APMinor;
132+
133+ if (VerPair.first .getAsInteger (0 , APMajor) ||
134+ VerPair.second .getAsInteger (0 , APMinor)) {
135+ ErrorMsg =
136+ " Format of validator version is \" <major>.<minor>\" (ex:\" 1.4\" )." ;
137+ return false ;
138+ }
139+ uint64_t Major = APMajor.getLimitedValue ();
140+ uint64_t Minor = APMinor.getLimitedValue ();
141+ if (Major > MaxDXILMajor || (Major == MaxDXILMajor && Minor > MaxDXILMinor)) {
142+ ErrorMsg = " Validator version must be less than or equal to current "
143+ " internal version." ;
144+ return false ;
145+ }
146+ if (Major == 0 && Minor != 0 ) {
147+ ErrorMsg = " If validator major version is 0, minor version must also be 0." ;
148+ return false ;
149+ }
150+ return true ;
151+ }
152+
125153} // namespace
126154
127155// / DirectX Toolchain
@@ -145,3 +173,33 @@ HLSLToolChain::ComputeEffectiveClangTriple(const ArgList &Args,
145173 return ToolChain::ComputeEffectiveClangTriple (Args, InputType);
146174 }
147175}
176+
177+ DerivedArgList *
178+ HLSLToolChain::TranslateArgs (const DerivedArgList &Args, StringRef BoundArch,
179+ Action::OffloadKind DeviceOffloadKind) const {
180+ DerivedArgList *DAL = new DerivedArgList (Args.getBaseArgs ());
181+
182+ const OptTable &Opts = getDriver ().getOpts ();
183+
184+ for (Arg *A : Args) {
185+ if (A->getOption ().getID () == options::OPT_dxil_validator_version) {
186+ StringRef ValVerStr = A->getValue ();
187+ std::string ErrorMsg;
188+ if (!isLegalValidatorVersion (ValVerStr, ErrorMsg)) {
189+ getDriver ().Diag (diag::err_drv_invalid_dxil_validator_version)
190+ << ValVerStr << ErrorMsg;
191+
192+ continue ;
193+ }
194+ }
195+ DAL->append (A);
196+ }
197+ // Add default validator version if not set.
198+ // TODO: remove this once read validator version from validator.
199+ if (!DAL->hasArg (options::OPT_dxil_validator_version)) {
200+ DAL->AddSeparateArg (nullptr ,
201+ Opts.getOption (options::OPT_dxil_validator_version),
202+ DefaultValidatorVer);
203+ }
204+ return DAL;
205+ }
0 commit comments