@@ -126,60 +126,29 @@ std::vector<char> makeVcOptPayload(uint64_t IR_size,
126
126
return VcPayload;
127
127
}
128
128
129
- void runFeInvocation (const InvocationInfo& Invocation,
130
- OclTranslationOutputBase& output) {
131
-
132
- auto & outputInterface = *output.GetImpl ();
133
- std::ifstream InputFile (Invocation.getInputFilename ());
134
- if (!InputFile.is_open ()) {
135
- outputInterface.SetError (TranslationErrorType::Internal,
136
- " CM frontend: could not read input file" );
137
- return ;
138
- }
139
-
140
- std::string InputText{std::istreambuf_iterator<char >(InputFile),
141
- std::istreambuf_iterator<char >()};
142
-
143
- if (Invocation.getOutputType () != InvocationInfo::OutputTypeT::SPIRV) {
144
- outputInterface.SetError (TranslationErrorType::Internal,
145
- " CM frontend: unsupported output request" );
146
- return ;
147
- }
148
-
149
- IGC::AdaptorCM::Frontend::InputArgs InputArgs;
150
- InputArgs.InputText = InputText;
151
- InputArgs.CompilationOpts = Invocation.getFEArgs ();
152
-
153
- using FEOutput = IGC::AdaptorCM::Frontend::IOutputArgs;
154
- auto FeDeleter = [](FEOutput* out) { out->discard (); };
155
- std::unique_ptr<FEOutput, decltype (FeDeleter)> Res (
156
- IGC::AdaptorCM::Frontend::translate (InputArgs),
157
- FeDeleter);
158
-
159
- if (!Res) {
160
- outputInterface.SetError (TranslationErrorType::Internal,
161
- " CM frontend null result errror" );
162
- return ;
163
- }
164
-
165
- const auto & ErrLog = Res->getLog ();
166
-
167
- if (Res->getStatus () ==
168
- Intel::CM::ClangFE::IOutputArgs::ErrT::COMPILE_PROGRAM_FAILURE) {
169
-
129
+ void finalizeFEOutput (const IGC::AdaptorCM::Frontend::IOutputArgs& FEOutput,
130
+ const InvocationInfo& Invocation,
131
+ OclTranslationOutputBase& Output)
132
+ {
133
+ auto & OutputInterface = *Output.GetImpl ();
134
+ const auto & ErrLog = FEOutput.getLog ();
135
+ if (FEOutput.getStatus () ==
136
+ Intel::CM::ClangFE::IOutputArgs::ErrT::COMPILE_PROGRAM_FAILURE)
137
+ {
170
138
if (ErrLog.empty ())
171
- outputInterface.SetError (TranslationErrorType::Internal,
172
- " unknown error during cm source compilation" );
139
+ OutputInterface.SetError (
140
+ TranslationErrorType::Internal,
141
+ " unknown error during cm source compilation" );
173
142
else
174
- outputInterface .SetError (TranslationErrorType::UnhandledInput,
143
+ OutputInterface .SetError (TranslationErrorType::UnhandledInput,
175
144
ErrLog.c_str ());
176
145
return ;
177
146
}
178
147
179
148
if (!ErrLog.empty ())
180
- outputInterface .AddWarning (ErrLog);
149
+ OutputInterface .AddWarning (ErrLog);
181
150
182
- const auto & IR = Res-> getIR ();
151
+ const auto & IR = FEOutput. getIR ();
183
152
// This is where the tricky part starts
184
153
// Right now we have no way to pass auxiliary options to vc-codegen backend
185
154
// So we introduce a temporary hack to incorporate the options
@@ -195,9 +164,10 @@ void runFeInvocation(const InvocationInfo& Invocation,
195
164
FinalOutput.insert (FinalOutput.end (), IR.begin (), IR.end ());
196
165
FinalOutput.insert (FinalOutput.end (), Payload.begin (), Payload.end ());
197
166
198
- if (!outputInterface.SetSuccessfulAndCloneOutput (FinalOutput.data (),
199
- FinalOutput.size ())) {
200
- outputInterface.SetError (TranslationErrorType::Internal, " OOM (cm FE)" );
167
+ if (!OutputInterface.SetSuccessfulAndCloneOutput (FinalOutput.data (),
168
+ FinalOutput.size ()))
169
+ {
170
+ OutputInterface.SetError (TranslationErrorType::Internal, " OOM (cm FE)" );
201
171
return ;
202
172
}
203
173
}
@@ -326,9 +296,9 @@ OclTranslationOutputBase* CIF_PIMPL(FclOclTranslationCtx)::TranslateCM(
326
296
uint32_t tracingOptionsCount) {
327
297
328
298
// Output
329
- auto outputInterface = CIF::RAII::UPtr (
330
- CIF::InterfaceCreator<OclTranslationOutput>::CreateInterfaceVer (outVersion,
331
- outType) );
299
+ auto * outputInterface =
300
+ CIF::InterfaceCreator<OclTranslationOutput>::CreateInterfaceVer (
301
+ outVersion, outType);
332
302
if (outputInterface == nullptr )
333
303
return nullptr ;
334
304
@@ -343,44 +313,54 @@ OclTranslationOutputBase* CIF_PIMPL(FclOclTranslationCtx)::TranslateCM(
343
313
(void )product;
344
314
(void )stepping;
345
315
346
- OclTranslationOutputBase& Out = *outputInterface. get () ;
316
+ OclTranslationOutputBase& Out = *outputInterface;
347
317
348
318
#if !defined(WDDM_LINUX) && (!defined(IGC_VC_DISABLED) || !IGC_VC_DISABLED)
349
- IGC::AdaptorCM::Frontend::AbiCompatibilityInfo AbiInfo;
350
- if (!IGC::AdaptorCM::Frontend::validateABICompatibility (&AbiInfo)) {
351
- const auto &ErrMsg =
352
- llvm::StringRef (" AdaptorCM: incompatible clangFEWrapper interface: " ) +
353
- " expected = " + llvm::Twine (AbiInfo.RequestedVersion ) +
354
- " , loaded = " + llvm::Twine (AbiInfo.AvailableVersion );
355
- Out.GetImpl ()->SetError (TranslationErrorType::Internal,
356
- ErrMsg.str ().c_str ());
357
- return outputInterface.release ();
358
- }
319
+ auto ErrFn = [&Out](const std::string& Err) {
320
+ Out.GetImpl ()->SetError (TranslationErrorType::Internal, Err.c_str ());
321
+ };
322
+ auto MaybeFE = IGC::AdaptorCM::Frontend::makeFEWrapper (ErrFn);
323
+ if (!MaybeFE)
324
+ return outputInterface;
359
325
360
326
auto OptSrc = MakeTemporaryCMSource (src, Out);
361
327
if (!OptSrc)
362
- return outputInterface. release () ; // proper error message is already set
328
+ return outputInterface; // proper error message is already set
363
329
364
330
llvm::BumpPtrAllocator A;
365
331
llvm::StringSaver Saver (A);
366
332
auto FeArgs = processFeOptions (OptSrc.getValue (), options, Saver);
367
333
368
- using IGC::AdaptorCM::Frontend::getDriverInvocation;
334
+ auto & FE = MaybeFE.getValue ();
335
+ auto Drv = FE.buildDriverInvocation (FeArgs);
336
+ if (!Drv)
337
+ {
338
+ ErrFn (" Null driver invocation in CMFE" );
339
+ return outputInterface;
340
+ }
341
+ if (Drv->getOutputType () != InvocationInfo::OutputTypeT::SPIRV)
342
+ {
343
+ ErrFn (" CM frontend: unsupported output request" );
344
+ return outputInterface;
345
+ }
346
+
347
+ IGC::AdaptorCM::Frontend::InputArgs InputArgs;
348
+ InputArgs.CompilationOpts = Drv->getFEArgs ();
349
+ auto FEOutput = FE.translate (InputArgs);
350
+ if (!FEOutput)
351
+ {
352
+ ErrFn (" Null output in CMFE" );
353
+ return outputInterface;
354
+ }
355
+
356
+ finalizeFEOutput (*FEOutput, *Drv, Out);
369
357
370
- auto Deleter = [](InvocationInfo* p) { delete p; };
371
- using InvokeInfo = std::unique_ptr<InvocationInfo, decltype (Deleter)>;
372
- InvokeInfo invoker (getDriverInvocation (FeArgs.size (), FeArgs.data ()), Deleter);
373
- if (invoker)
374
- runFeInvocation (*invoker, Out);
375
- else
376
- Out.GetImpl ()->SetError (TranslationErrorType::Internal,
377
- " could not create CM fronend invocation" );
378
358
#else
379
359
Out.GetImpl ()->SetError (TranslationErrorType::Internal,
380
360
" CM compilation is not supported in this configuration" );
381
361
#endif // !defined(WDDM_LINUX) && (!defined(IGC_VC_DISABLED) || !IGC_VC_DISABLED)
382
362
383
- return outputInterface. release () ;
363
+ return outputInterface;
384
364
}
385
365
386
366
}
0 commit comments