PetScan::extract_for: explicitly keep track of when iterator is virtual
[pet.git] / pet.cc
blob4ba8076a44cb53d970a17640180ea2a4546d62bc
1 /*
2 * Copyright 2011 Leiden University. All rights reserved.
3 * Copyright 2012 Ecole Normale Superieure. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials provided
15 * with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY LEIDEN UNIVERSITY ''AS IS'' AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LEIDEN UNIVERSITY OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * The views and conclusions contained in the software and documentation
30 * are those of the authors and should not be interpreted as
31 * representing official policies, either expressed or implied, of
32 * Leiden University.
33 */
35 #include <stdlib.h>
36 #include <map>
37 #include <iostream>
38 #include <llvm/Support/raw_ostream.h>
39 #include <llvm/Support/ManagedStatic.h>
40 #include <llvm/Support/Host.h>
41 #include <clang/Basic/Version.h>
42 #include <clang/Basic/FileSystemOptions.h>
43 #include <clang/Basic/FileManager.h>
44 #include <clang/Basic/TargetOptions.h>
45 #include <clang/Basic/TargetInfo.h>
46 #include <clang/Driver/Compilation.h>
47 #include <clang/Driver/Driver.h>
48 #include <clang/Driver/Tool.h>
49 #include <clang/Frontend/CompilerInstance.h>
50 #include <clang/Frontend/CompilerInvocation.h>
51 #include <clang/Frontend/DiagnosticOptions.h>
52 #include <clang/Frontend/TextDiagnosticPrinter.h>
53 #include <clang/Frontend/HeaderSearchOptions.h>
54 #include <clang/Frontend/LangStandard.h>
55 #include <clang/Frontend/PreprocessorOptions.h>
56 #include <clang/Frontend/FrontendOptions.h>
57 #include <clang/Frontend/Utils.h>
58 #include <clang/Lex/HeaderSearch.h>
59 #include <clang/Lex/Preprocessor.h>
60 #include <clang/Lex/Pragma.h>
61 #include <clang/AST/ASTContext.h>
62 #include <clang/AST/ASTConsumer.h>
63 #include <clang/Sema/Sema.h>
64 #include <clang/Sema/SemaDiagnostic.h>
65 #include <clang/Parse/Parser.h>
66 #include <clang/Parse/ParseAST.h>
68 #include <isl/ctx.h>
69 #include <isl/constraint.h>
71 #include "options.h"
72 #include "scan.h"
74 #include "config.h"
76 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
78 using namespace std;
79 using namespace clang;
80 using namespace clang::driver;
82 /* Called if we found something we didn't expect in one of the pragmas.
83 * We'll provide more informative warnings later.
85 static void unsupported(Preprocessor &PP, SourceLocation loc)
87 DiagnosticsEngine &diag = PP.getDiagnostics();
88 unsigned id = diag.getCustomDiagID(DiagnosticsEngine::Warning,
89 "unsupported");
90 DiagnosticBuilder B = diag.Report(loc, id);
93 static int get_int(const char *s)
95 return s[0] == '"' ? atoi(s + 1) : atoi(s);
98 static ValueDecl *get_value_decl(Sema &sema, Token &token)
100 IdentifierInfo *name;
101 Decl *decl;
103 if (token.isNot(tok::identifier))
104 return NULL;
106 name = token.getIdentifierInfo();
107 decl = sema.LookupSingleName(sema.TUScope, name,
108 token.getLocation(), Sema::LookupOrdinaryName);
109 return decl ? cast_or_null<ValueDecl>(decl) : NULL;
112 /* Handle pragmas of the form
114 * #pragma value_bounds identifier lower_bound upper_bound
116 * For each such pragma, add a mapping
117 * { identifier[] -> [i] : lower_bound <= i <= upper_bound }
118 * to value_bounds.
120 struct PragmaValueBoundsHandler : public PragmaHandler {
121 Sema &sema;
122 isl_ctx *ctx;
123 isl_union_map *value_bounds;
125 PragmaValueBoundsHandler(isl_ctx *ctx, Sema &sema) :
126 PragmaHandler("value_bounds"), ctx(ctx), sema(sema) {
127 isl_space *space = isl_space_params_alloc(ctx, 0);
128 value_bounds = isl_union_map_empty(space);
131 ~PragmaValueBoundsHandler() {
132 isl_union_map_free(value_bounds);
135 virtual void HandlePragma(Preprocessor &PP,
136 PragmaIntroducerKind Introducer,
137 Token &ScopTok) {
138 isl_id *id;
139 isl_space *dim;
140 isl_map *map;
141 ValueDecl *vd;
142 Token token;
143 int lb;
144 int ub;
146 PP.Lex(token);
147 vd = get_value_decl(sema, token);
148 if (!vd) {
149 unsupported(PP, token.getLocation());
150 return;
153 PP.Lex(token);
154 if (!token.isLiteral()) {
155 unsupported(PP, token.getLocation());
156 return;
159 lb = get_int(token.getLiteralData());
161 PP.Lex(token);
162 if (!token.isLiteral()) {
163 unsupported(PP, token.getLocation());
164 return;
167 ub = get_int(token.getLiteralData());
169 dim = isl_space_alloc(ctx, 0, 0, 1);
170 map = isl_map_universe(dim);
171 map = isl_map_lower_bound_si(map, isl_dim_out, 0, lb);
172 map = isl_map_upper_bound_si(map, isl_dim_out, 0, ub);
173 id = isl_id_alloc(ctx, vd->getName().str().c_str(), vd);
174 map = isl_map_set_tuple_id(map, isl_dim_in, id);
176 value_bounds = isl_union_map_add_map(value_bounds, map);
180 /* Given a variable declaration, check if it has an integer initializer
181 * and if so, add a parameter corresponding to the variable to "value"
182 * with its value fixed to the integer initializer and return the result.
184 static __isl_give isl_set *extract_initialization(__isl_take isl_set *value,
185 ValueDecl *decl)
187 VarDecl *vd;
188 Expr *expr;
189 IntegerLiteral *il;
190 isl_int v;
191 isl_ctx *ctx;
192 isl_id *id;
193 isl_space *space;
194 isl_set *set;
196 vd = cast<VarDecl>(decl);
197 if (!vd)
198 return value;
199 if (!vd->getType()->isIntegerType())
200 return value;
201 expr = vd->getInit();
202 if (!expr)
203 return value;
204 il = cast<IntegerLiteral>(expr);
205 if (!il)
206 return value;
208 ctx = isl_set_get_ctx(value);
209 id = isl_id_alloc(ctx, vd->getName().str().c_str(), vd);
210 space = isl_space_params_alloc(ctx, 1);
211 space = isl_space_set_dim_id(space, isl_dim_param, 0, id);
212 set = isl_set_universe(space);
214 isl_int_init(v);
215 PetScan::extract_int(il, &v);
216 set = isl_set_fix(set, isl_dim_param, 0, v);
217 isl_int_clear(v);
219 return isl_set_intersect(value, set);
222 /* Handle pragmas of the form
224 * #pragma parameter identifier lower_bound
225 * and
226 * #pragma parameter identifier lower_bound upper_bound
228 * For each such pragma, intersect the context with the set
229 * [identifier] -> { [] : lower_bound <= identifier <= upper_bound }
231 struct PragmaParameterHandler : public PragmaHandler {
232 Sema &sema;
233 isl_set *&context;
234 isl_set *&context_value;
236 PragmaParameterHandler(Sema &sema, isl_set *&context,
237 isl_set *&context_value) :
238 PragmaHandler("parameter"), sema(sema), context(context),
239 context_value(context_value) {}
241 virtual void HandlePragma(Preprocessor &PP,
242 PragmaIntroducerKind Introducer,
243 Token &ScopTok) {
244 isl_id *id;
245 isl_ctx *ctx = isl_set_get_ctx(context);
246 isl_space *dim;
247 isl_set *set;
248 ValueDecl *vd;
249 Token token;
250 int lb;
251 int ub;
252 bool has_ub = false;
254 PP.Lex(token);
255 vd = get_value_decl(sema, token);
256 if (!vd) {
257 unsupported(PP, token.getLocation());
258 return;
261 PP.Lex(token);
262 if (!token.isLiteral()) {
263 unsupported(PP, token.getLocation());
264 return;
267 lb = get_int(token.getLiteralData());
269 PP.Lex(token);
270 if (token.isLiteral()) {
271 has_ub = true;
272 ub = get_int(token.getLiteralData());
273 } else if (token.isNot(tok::eod)) {
274 unsupported(PP, token.getLocation());
275 return;
278 id = isl_id_alloc(ctx, vd->getName().str().c_str(), vd);
279 dim = isl_space_params_alloc(ctx, 1);
280 dim = isl_space_set_dim_id(dim, isl_dim_param, 0, id);
282 set = isl_set_universe(dim);
284 set = isl_set_lower_bound_si(set, isl_dim_param, 0, lb);
285 if (has_ub)
286 set = isl_set_upper_bound_si(set, isl_dim_param, 0, ub);
288 context = isl_set_intersect(context, set);
290 context_value = extract_initialization(context_value, vd);
294 /* Handle pragmas of the form
296 * #pragma scop
298 * In particular, store the current location in loc.start.
300 struct PragmaScopHandler : public PragmaHandler {
301 ScopLoc &loc;
303 PragmaScopHandler(ScopLoc &loc) : PragmaHandler("scop"), loc(loc) {}
305 virtual void HandlePragma(Preprocessor &PP,
306 PragmaIntroducerKind Introducer,
307 Token &ScopTok) {
308 SourceManager &SM = PP.getSourceManager();
309 loc.start = SM.getFileOffset(ScopTok.getLocation());
313 /* Handle pragmas of the form
315 * #pragma endscop
317 * In particular, store the current location in loc.end.
319 struct PragmaEndScopHandler : public PragmaHandler {
320 ScopLoc &loc;
322 PragmaEndScopHandler(ScopLoc &loc) :
323 PragmaHandler("endscop"), loc(loc) {}
325 virtual void HandlePragma(Preprocessor &PP,
326 PragmaIntroducerKind Introducer,
327 Token &EndScopTok) {
328 SourceManager &SM = PP.getSourceManager();
329 loc.end = SM.getFileOffset(EndScopTok.getLocation());
333 /* Handle pragmas of the form
335 * #pragma live-out identifier, identifier, ...
337 * Each identifier on the line is stored in live_out.
339 struct PragmaLiveOutHandler : public PragmaHandler {
340 Sema &sema;
341 set<ValueDecl *> &live_out;
343 PragmaLiveOutHandler(Sema &sema, set<ValueDecl *> &live_out) :
344 PragmaHandler("live"), sema(sema), live_out(live_out) {}
346 virtual void HandlePragma(Preprocessor &PP,
347 PragmaIntroducerKind Introducer,
348 Token &ScopTok) {
349 Token token;
351 PP.Lex(token);
352 if (token.isNot(tok::minus))
353 return;
354 PP.Lex(token);
355 if (token.isNot(tok::identifier) ||
356 !token.getIdentifierInfo()->isStr("out"))
357 return;
359 PP.Lex(token);
360 while (token.isNot(tok::eod)) {
361 ValueDecl *vd;
363 vd = get_value_decl(sema, token);
364 if (!vd) {
365 unsupported(PP, token.getLocation());
366 return;
368 live_out.insert(vd);
369 PP.Lex(token);
370 if (token.is(tok::comma))
371 PP.Lex(token);
376 /* Extract a pet_scop from the appropriate function.
377 * If "function" is not NULL, then we only extract a pet_scop if the
378 * name of the function matches.
379 * If "autodetect" is false, then we only extract if we have seen
380 * scop and endscop pragmas and if these are situated inside the function
381 * body.
383 struct PetASTConsumer : public ASTConsumer {
384 Preprocessor &PP;
385 ASTContext &ast_context;
386 ScopLoc &loc;
387 const char *function;
388 bool autodetect;
389 isl_ctx *ctx;
390 struct pet_scop *scop;
391 PragmaValueBoundsHandler *vb_handler;
393 PetASTConsumer(isl_ctx *ctx, Preprocessor &PP, ASTContext &ast_context,
394 ScopLoc &loc, const char *function, bool autodetect) :
395 ctx(ctx), PP(PP), ast_context(ast_context), loc(loc),
396 scop(NULL), function(function), autodetect(autodetect),
397 vb_handler(NULL) { }
399 void handle_value_bounds(Sema *sema) {
400 vb_handler = new PragmaValueBoundsHandler(ctx, *sema);
401 PP.AddPragmaHandler(vb_handler);
404 __isl_give isl_union_map *get_value_bounds() {
405 return isl_union_map_copy(vb_handler->value_bounds);
408 virtual HandleTopLevelDeclReturn HandleTopLevelDecl(DeclGroupRef dg) {
409 DeclGroupRef::iterator it;
411 if (scop)
412 return HandleTopLevelDeclContinue;
413 for (it = dg.begin(); it != dg.end(); ++it) {
414 isl_union_map *vb = vb_handler->value_bounds;
415 FunctionDecl *fd = dyn_cast<clang::FunctionDecl>(*it);
416 if (!fd)
417 continue;
418 if (!fd->hasBody())
419 continue;
420 if (function &&
421 fd->getNameInfo().getAsString() != function)
422 continue;
423 if (autodetect) {
424 PetScan ps(PP, ast_context, loc, 1,
425 isl_union_map_copy(vb));
426 scop = ps.scan(fd);
427 if (scop)
428 break;
429 else
430 continue;
432 if (!loc.end)
433 continue;
434 SourceManager &SM = PP.getSourceManager();
435 if (SM.getFileOffset(fd->getLocStart()) > loc.end)
436 continue;
437 if (SM.getFileOffset(fd->getLocEnd()) < loc.start)
438 continue;
439 PetScan ps(PP, ast_context, loc, 0,
440 isl_union_map_copy(vb));
441 scop = ps.scan(fd);
442 break;
445 return HandleTopLevelDeclContinue;
449 static const char *ResourceDir = CLANG_PREFIX"/lib/clang/"CLANG_VERSION_STRING;
451 static const char *implicit_functions[] = {
452 "min", "max", "ceild", "floord"
455 static bool is_implicit(const IdentifierInfo *ident)
457 const char *name = ident->getNameStart();
458 for (int i = 0; i < ARRAY_SIZE(implicit_functions); ++i)
459 if (!strcmp(name, implicit_functions[i]))
460 return true;
461 return false;
464 /* Ignore implicit function declaration warnings on
465 * "min", "max", "ceild" and "floord" as we detect and handle these
466 * in PetScan.
468 * The cloned field keeps track of whether the clone method
469 * has ever been called. Newer clangs (by default) clone
470 * the DiagnosticConsumer passed to createDiagnostics and
471 * then take ownership of the clone, which means that
472 * the original has to be deleted by the calling code.
474 struct MyDiagnosticPrinter : public TextDiagnosticPrinter {
475 const DiagnosticOptions *DiagOpts;
476 static bool cloned;
477 MyDiagnosticPrinter(const DiagnosticOptions &DO) :
478 DiagOpts(&DO), TextDiagnosticPrinter(llvm::errs(), DO) {}
479 virtual DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const {
480 cloned = true;
481 return new MyDiagnosticPrinter(*DiagOpts);
483 virtual void HandleDiagnostic(DiagnosticsEngine::Level level,
484 const DiagnosticInfo &info) {
485 if (info.getID() == diag::ext_implicit_function_decl &&
486 info.getNumArgs() == 1 &&
487 info.getArgKind(0) == DiagnosticsEngine::ak_identifierinfo &&
488 is_implicit(info.getArgIdentifier(0)))
489 /* ignore warning */;
490 else
491 TextDiagnosticPrinter::HandleDiagnostic(level, info);
495 bool MyDiagnosticPrinter::cloned = false;
497 /* For each array in "scop", set its value_bounds property
498 * based on the infofrmation in "value_bounds" and
499 * mark it as live_out if it appears in "live_out".
501 static void update_arrays(struct pet_scop *scop,
502 __isl_take isl_union_map *value_bounds, set<ValueDecl *> &live_out)
504 set<ValueDecl *>::iterator lo_it;
505 isl_ctx *ctx = isl_union_map_get_ctx(value_bounds);
507 if (!scop) {
508 isl_union_map_free(value_bounds);
509 return;
512 for (int i = 0; i < scop->n_array; ++i) {
513 isl_id *id;
514 isl_space *space;
515 isl_map *bounds;
516 ValueDecl *decl;
517 pet_array *array = scop->arrays[i];
519 id = isl_set_get_tuple_id(array->extent);
520 decl = (ValueDecl *)isl_id_get_user(id);
522 space = isl_space_alloc(ctx, 0, 0, 1);
523 space = isl_space_set_tuple_id(space, isl_dim_in, id);
525 bounds = isl_union_map_extract_map(value_bounds, space);
526 if (!isl_map_plain_is_empty(bounds))
527 array->value_bounds = isl_map_range(bounds);
528 else
529 isl_map_free(bounds);
531 lo_it = live_out.find(decl);
532 if (lo_it != live_out.end())
533 array->live_out = 1;
536 isl_union_map_free(value_bounds);
539 #ifdef USE_ARRAYREF
541 #ifdef HAVE_CXXISPRODUCTION
542 static Driver *construct_driver(const char *binary, DiagnosticsEngine &Diags)
544 return new Driver(binary, llvm::sys::getDefaultTargetTriple(),
545 "", false, false, Diags);
547 #else
548 static Driver *construct_driver(const char *binary, DiagnosticsEngine &Diags)
550 return new Driver(binary, llvm::sys::getDefaultTargetTriple(),
551 "", false, Diags);
553 #endif
555 /* Create a CompilerInvocation object that stores the command line
556 * arguments constructed by the driver.
557 * The arguments are mainly useful for setting up the system include
558 * paths on newer clangs and on some platforms.
560 static CompilerInvocation *construct_invocation(const char *filename,
561 DiagnosticsEngine &Diags)
563 const char *binary = CLANG_PREFIX"/bin/clang";
564 const llvm::OwningPtr<Driver> driver(construct_driver(binary, Diags));
565 std::vector<const char *> Argv;
566 Argv.push_back(binary);
567 Argv.push_back(filename);
568 const llvm::OwningPtr<Compilation> compilation(
569 driver->BuildCompilation(llvm::ArrayRef<const char *>(Argv)));
570 JobList &Jobs = compilation->getJobs();
571 if (Jobs.size() < 1)
572 return NULL;
574 Command *cmd = cast<Command>(*Jobs.begin());
575 if (strcmp(cmd->getCreator().getName(), "clang"))
576 return NULL;
578 const ArgStringList *args = &cmd->getArguments();
580 CompilerInvocation *invocation = new CompilerInvocation;
581 CompilerInvocation::CreateFromArgs(*invocation, args->data() + 1,
582 args->data() + args->size(),
583 Diags);
584 return invocation;
587 #else
589 static CompilerInvocation *construct_invocation(const char *filename,
590 DiagnosticsEngine &Diags)
592 return NULL;
595 #endif
597 /* Extract a pet_scop from the C source file called "filename".
598 * If "function" is not NULL, extract the pet_scop from the function
599 * with that name.
600 * If "autodetect" is set, extract any pet_scop we can find.
601 * Otherwise, extract the pet_scop from the region delimited
602 * by "scop" and "endscop" pragmas.
604 * We first set up the clang parser and then try to extract the
605 * pet_scop from the appropriate function in PetASTConsumer.
606 * If we have found a pet_scop, we add the context and value_bounds
607 * constraints specified through pragmas.
609 static struct pet_scop *scop_extract_from_C_source(isl_ctx *ctx,
610 const char *filename, const char *function, pet_options *options)
612 isl_space *dim;
613 isl_set *context;
614 isl_set *context_value;
615 pet_scop *scop;
616 set<ValueDecl *> live_out;
617 isl_union_map *value_bounds;
619 CompilerInstance *Clang = new CompilerInstance();
620 DiagnosticOptions DO;
621 MyDiagnosticPrinter *printer = new MyDiagnosticPrinter(DO);
622 Clang->createDiagnostics(0, NULL, printer);
623 if (printer->cloned)
624 delete printer;
625 DiagnosticsEngine &Diags = Clang->getDiagnostics();
626 Diags.setSuppressSystemWarnings(true);
627 CompilerInvocation *invocation = construct_invocation(filename, Diags);
628 if (invocation)
629 Clang->setInvocation(invocation);
630 Clang->createFileManager();
631 Clang->createSourceManager(Clang->getFileManager());
632 TargetOptions TO;
633 TO.Triple = llvm::sys::getDefaultTargetTriple();
634 TargetInfo *target = TargetInfo::CreateTargetInfo(Diags, TO);
635 Clang->setTarget(target);
636 CompilerInvocation::setLangDefaults(Clang->getLangOpts(), IK_C,
637 LangStandard::lang_unspecified);
638 HeaderSearchOptions &HSO = Clang->getHeaderSearchOpts();
639 HSO.ResourceDir = ResourceDir;
640 for (int i = 0; i < options->n_path; ++i)
641 HSO.AddPath(options->paths[i],
642 frontend::Angled, true, false, false);
643 PreprocessorOptions &PO = Clang->getPreprocessorOpts();
644 for (int i = 0; i < options->n_define; ++i)
645 PO.addMacroDef(options->defines[i]);
646 Clang->createPreprocessor();
647 Preprocessor &PP = Clang->getPreprocessor();
649 ScopLoc loc;
651 const FileEntry *file = Clang->getFileManager().getFile(filename);
652 if (!file)
653 isl_die(ctx, isl_error_unknown, "unable to open file",
654 do { delete Clang; return NULL; } while (0));
655 Clang->getSourceManager().createMainFileID(file);
657 Clang->createASTContext();
658 PetASTConsumer consumer(ctx, PP, Clang->getASTContext(),
659 loc, function, options->autodetect);
660 Sema *sema = new Sema(PP, Clang->getASTContext(), consumer);
662 if (!options->autodetect) {
663 PP.AddPragmaHandler(new PragmaScopHandler(loc));
664 PP.AddPragmaHandler(new PragmaEndScopHandler(loc));
665 PP.AddPragmaHandler(new PragmaLiveOutHandler(*sema, live_out));
668 dim = isl_space_params_alloc(ctx, 0);
669 context = isl_set_universe(isl_space_copy(dim));
670 context_value = isl_set_universe(dim);
671 PP.AddPragmaHandler(new PragmaParameterHandler(*sema, context,
672 context_value));
673 consumer.handle_value_bounds(sema);
675 Diags.getClient()->BeginSourceFile(Clang->getLangOpts(), &PP);
676 ParseAST(*sema);
677 Diags.getClient()->EndSourceFile();
679 scop = consumer.scop;
680 if (Diags.hasErrorOccurred()) {
681 pet_scop_free(scop);
682 scop = NULL;
685 if (scop) {
686 scop->context = isl_set_intersect(context, scop->context);
687 scop->context_value = isl_set_intersect(context_value,
688 scop->context_value);
689 } else {
690 isl_set_free(context);
691 isl_set_free(context_value);
694 scop = pet_scop_anonymize(scop);
696 update_arrays(scop, consumer.get_value_bounds(), live_out);
698 delete sema;
699 delete Clang;
701 return scop;
704 struct pet_scop *pet_scop_extract_from_C_source(isl_ctx *ctx,
705 const char *filename, const char *function)
707 pet_scop *scop;
708 pet_options *options;
709 bool allocated = false;
711 options = isl_ctx_peek_pet_options(ctx);
712 if (!options) {
713 options = pet_options_new_with_defaults();
714 allocated = true;
717 scop = scop_extract_from_C_source(ctx, filename, function, options);
718 llvm::llvm_shutdown();
720 if (allocated)
721 pet_options_free(options);
723 return scop;