2 * Copyright 2011 Leiden University. All rights reserved.
3 * Copyright 2012 Ecole Normale Superieure. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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
40 #include <llvm/Support/raw_ostream.h>
41 #include <llvm/Support/ManagedStatic.h>
42 #include <llvm/Support/Host.h>
43 #include <clang/Basic/Version.h>
44 #include <clang/Basic/FileSystemOptions.h>
45 #include <clang/Basic/FileManager.h>
46 #include <clang/Basic/TargetOptions.h>
47 #include <clang/Basic/TargetInfo.h>
48 #include <clang/Driver/Compilation.h>
49 #include <clang/Driver/Driver.h>
50 #include <clang/Driver/Tool.h>
51 #include <clang/Frontend/CompilerInstance.h>
52 #include <clang/Frontend/CompilerInvocation.h>
53 #ifdef HAVE_BASIC_DIAGNOSTICOPTIONS_H
54 #include <clang/Basic/DiagnosticOptions.h>
56 #include <clang/Frontend/DiagnosticOptions.h>
58 #include <clang/Frontend/TextDiagnosticPrinter.h>
59 #ifdef HAVE_LEX_HEADERSEARCHOPTIONS_H
60 #include <clang/Lex/HeaderSearchOptions.h>
62 #include <clang/Frontend/HeaderSearchOptions.h>
64 #include <clang/Frontend/LangStandard.h>
65 #ifdef HAVE_LEX_PREPROCESSOROPTIONS_H
66 #include <clang/Lex/PreprocessorOptions.h>
68 #include <clang/Frontend/PreprocessorOptions.h>
70 #include <clang/Frontend/FrontendOptions.h>
71 #include <clang/Frontend/Utils.h>
72 #include <clang/Lex/HeaderSearch.h>
73 #include <clang/Lex/Preprocessor.h>
74 #include <clang/Lex/Pragma.h>
75 #include <clang/AST/ASTContext.h>
76 #include <clang/AST/ASTConsumer.h>
77 #include <clang/Sema/Sema.h>
78 #include <clang/Sema/SemaDiagnostic.h>
79 #include <clang/Parse/Parser.h>
80 #include <clang/Parse/ParseAST.h>
83 #include <isl/constraint.h>
88 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
91 using namespace clang
;
92 using namespace clang::driver
;
94 /* Called if we found something we didn't expect in one of the pragmas.
95 * We'll provide more informative warnings later.
97 static void unsupported(Preprocessor
&PP
, SourceLocation loc
)
99 DiagnosticsEngine
&diag
= PP
.getDiagnostics();
100 unsigned id
= diag
.getCustomDiagID(DiagnosticsEngine::Warning
,
102 DiagnosticBuilder B
= diag
.Report(loc
, id
);
105 static int get_int(const char *s
)
107 return s
[0] == '"' ? atoi(s
+ 1) : atoi(s
);
110 static ValueDecl
*get_value_decl(Sema
&sema
, Token
&token
)
112 IdentifierInfo
*name
;
115 if (token
.isNot(tok::identifier
))
118 name
= token
.getIdentifierInfo();
119 decl
= sema
.LookupSingleName(sema
.TUScope
, name
,
120 token
.getLocation(), Sema::LookupOrdinaryName
);
121 return decl
? cast_or_null
<ValueDecl
>(decl
) : NULL
;
124 /* Handle pragmas of the form
126 * #pragma value_bounds identifier lower_bound upper_bound
128 * For each such pragma, add a mapping
129 * { identifier[] -> [i] : lower_bound <= i <= upper_bound }
132 struct PragmaValueBoundsHandler
: public PragmaHandler
{
135 isl_union_map
*value_bounds
;
137 PragmaValueBoundsHandler(isl_ctx
*ctx
, Sema
&sema
) :
138 PragmaHandler("value_bounds"), ctx(ctx
), sema(sema
) {
139 isl_space
*space
= isl_space_params_alloc(ctx
, 0);
140 value_bounds
= isl_union_map_empty(space
);
143 ~PragmaValueBoundsHandler() {
144 isl_union_map_free(value_bounds
);
147 virtual void HandlePragma(Preprocessor
&PP
,
148 PragmaIntroducerKind Introducer
,
159 vd
= get_value_decl(sema
, token
);
161 unsupported(PP
, token
.getLocation());
166 if (!token
.isLiteral()) {
167 unsupported(PP
, token
.getLocation());
171 lb
= get_int(token
.getLiteralData());
174 if (!token
.isLiteral()) {
175 unsupported(PP
, token
.getLocation());
179 ub
= get_int(token
.getLiteralData());
181 dim
= isl_space_alloc(ctx
, 0, 0, 1);
182 map
= isl_map_universe(dim
);
183 map
= isl_map_lower_bound_si(map
, isl_dim_out
, 0, lb
);
184 map
= isl_map_upper_bound_si(map
, isl_dim_out
, 0, ub
);
185 id
= isl_id_alloc(ctx
, vd
->getName().str().c_str(), vd
);
186 map
= isl_map_set_tuple_id(map
, isl_dim_in
, id
);
188 value_bounds
= isl_union_map_add_map(value_bounds
, map
);
192 /* Given a variable declaration, check if it has an integer initializer
193 * and if so, add a parameter corresponding to the variable to "value"
194 * with its value fixed to the integer initializer and return the result.
196 static __isl_give isl_set
*extract_initialization(__isl_take isl_set
*value
,
208 vd
= cast
<VarDecl
>(decl
);
211 if (!vd
->getType()->isIntegerType())
213 expr
= vd
->getInit();
216 il
= cast
<IntegerLiteral
>(expr
);
220 ctx
= isl_set_get_ctx(value
);
221 id
= isl_id_alloc(ctx
, vd
->getName().str().c_str(), vd
);
222 space
= isl_space_params_alloc(ctx
, 1);
223 space
= isl_space_set_dim_id(space
, isl_dim_param
, 0, id
);
224 set
= isl_set_universe(space
);
227 PetScan::extract_int(il
, &v
);
228 set
= isl_set_fix(set
, isl_dim_param
, 0, v
);
231 return isl_set_intersect(value
, set
);
234 /* Handle pragmas of the form
236 * #pragma parameter identifier lower_bound
238 * #pragma parameter identifier lower_bound upper_bound
240 * For each such pragma, intersect the context with the set
241 * [identifier] -> { [] : lower_bound <= identifier <= upper_bound }
243 struct PragmaParameterHandler
: public PragmaHandler
{
246 isl_set
*&context_value
;
248 PragmaParameterHandler(Sema
&sema
, isl_set
*&context
,
249 isl_set
*&context_value
) :
250 PragmaHandler("parameter"), sema(sema
), context(context
),
251 context_value(context_value
) {}
253 virtual void HandlePragma(Preprocessor
&PP
,
254 PragmaIntroducerKind Introducer
,
257 isl_ctx
*ctx
= isl_set_get_ctx(context
);
267 vd
= get_value_decl(sema
, token
);
269 unsupported(PP
, token
.getLocation());
274 if (!token
.isLiteral()) {
275 unsupported(PP
, token
.getLocation());
279 lb
= get_int(token
.getLiteralData());
282 if (token
.isLiteral()) {
284 ub
= get_int(token
.getLiteralData());
285 } else if (token
.isNot(tok::eod
)) {
286 unsupported(PP
, token
.getLocation());
290 id
= isl_id_alloc(ctx
, vd
->getName().str().c_str(), vd
);
291 dim
= isl_space_params_alloc(ctx
, 1);
292 dim
= isl_space_set_dim_id(dim
, isl_dim_param
, 0, id
);
294 set
= isl_set_universe(dim
);
296 set
= isl_set_lower_bound_si(set
, isl_dim_param
, 0, lb
);
298 set
= isl_set_upper_bound_si(set
, isl_dim_param
, 0, ub
);
300 context
= isl_set_intersect(context
, set
);
302 context_value
= extract_initialization(context_value
, vd
);
306 #ifdef HAVE_TRANSLATELINECOL
308 /* Return a SourceLocation for line "line", column "col" of file "FID".
310 SourceLocation
translateLineCol(SourceManager
&SM
, FileID FID
, unsigned line
,
313 return SM
.translateLineCol(FID
, line
, col
);
318 /* Return a SourceLocation for line "line", column "col" of file "FID".
320 SourceLocation
translateLineCol(SourceManager
&SM
, FileID FID
, unsigned line
,
323 return SM
.getLocation(SM
.getFileEntryForID(FID
), line
, col
);
328 /* Handle pragmas of the form
332 * In particular, store the location of the line containing
333 * the pragma in loc.start.
335 struct PragmaScopHandler
: public PragmaHandler
{
338 PragmaScopHandler(ScopLoc
&loc
) : PragmaHandler("scop"), loc(loc
) {}
340 virtual void HandlePragma(Preprocessor
&PP
,
341 PragmaIntroducerKind Introducer
,
343 SourceManager
&SM
= PP
.getSourceManager();
344 SourceLocation sloc
= ScopTok
.getLocation();
345 int line
= SM
.getExpansionLineNumber(sloc
);
346 sloc
= translateLineCol(SM
, SM
.getFileID(sloc
), line
, 1);
347 loc
.start
= SM
.getFileOffset(sloc
);
351 /* Handle pragmas of the form
355 * In particular, store the location of the line following the one containing
356 * the pragma in loc.end.
358 struct PragmaEndScopHandler
: public PragmaHandler
{
361 PragmaEndScopHandler(ScopLoc
&loc
) :
362 PragmaHandler("endscop"), loc(loc
) {}
364 virtual void HandlePragma(Preprocessor
&PP
,
365 PragmaIntroducerKind Introducer
,
367 SourceManager
&SM
= PP
.getSourceManager();
368 SourceLocation sloc
= EndScopTok
.getLocation();
369 int line
= SM
.getExpansionLineNumber(sloc
);
370 sloc
= translateLineCol(SM
, SM
.getFileID(sloc
), line
+ 1, 1);
371 loc
.end
= SM
.getFileOffset(sloc
);
375 /* Handle pragmas of the form
377 * #pragma live-out identifier, identifier, ...
379 * Each identifier on the line is stored in live_out.
381 struct PragmaLiveOutHandler
: public PragmaHandler
{
383 set
<ValueDecl
*> &live_out
;
385 PragmaLiveOutHandler(Sema
&sema
, set
<ValueDecl
*> &live_out
) :
386 PragmaHandler("live"), sema(sema
), live_out(live_out
) {}
388 virtual void HandlePragma(Preprocessor
&PP
,
389 PragmaIntroducerKind Introducer
,
394 if (token
.isNot(tok::minus
))
397 if (token
.isNot(tok::identifier
) ||
398 !token
.getIdentifierInfo()->isStr("out"))
402 while (token
.isNot(tok::eod
)) {
405 vd
= get_value_decl(sema
, token
);
407 unsupported(PP
, token
.getLocation());
412 if (token
.is(tok::comma
))
418 /* Extract a pet_scop from the appropriate function.
419 * If "function" is not NULL, then we only extract a pet_scop if the
420 * name of the function matches.
421 * If "autodetect" is false, then we only extract if we have seen
422 * scop and endscop pragmas and if these are situated inside the function
425 struct PetASTConsumer
: public ASTConsumer
{
427 ASTContext
&ast_context
;
429 const char *function
;
430 pet_options
*options
;
432 struct pet_scop
*scop
;
433 PragmaValueBoundsHandler
*vb_handler
;
435 PetASTConsumer(isl_ctx
*ctx
, Preprocessor
&PP
, ASTContext
&ast_context
,
436 ScopLoc
&loc
, const char *function
, pet_options
*options
) :
437 ctx(ctx
), PP(PP
), ast_context(ast_context
), loc(loc
),
438 scop(NULL
), function(function
), options(options
),
441 void handle_value_bounds(Sema
*sema
) {
442 vb_handler
= new PragmaValueBoundsHandler(ctx
, *sema
);
443 PP
.AddPragmaHandler(vb_handler
);
446 __isl_give isl_union_map
*get_value_bounds() {
447 return isl_union_map_copy(vb_handler
->value_bounds
);
450 virtual HandleTopLevelDeclReturn
HandleTopLevelDecl(DeclGroupRef dg
) {
451 DeclGroupRef::iterator it
;
454 return HandleTopLevelDeclContinue
;
455 for (it
= dg
.begin(); it
!= dg
.end(); ++it
) {
456 isl_union_map
*vb
= vb_handler
->value_bounds
;
457 FunctionDecl
*fd
= dyn_cast
<clang::FunctionDecl
>(*it
);
463 fd
->getNameInfo().getAsString() != function
)
465 if (options
->autodetect
) {
466 PetScan
ps(PP
, ast_context
, loc
, options
,
467 isl_union_map_copy(vb
));
476 SourceManager
&SM
= PP
.getSourceManager();
477 if (SM
.getFileOffset(fd
->getLocStart()) > loc
.end
)
479 if (SM
.getFileOffset(fd
->getLocEnd()) < loc
.start
)
481 PetScan
ps(PP
, ast_context
, loc
, options
,
482 isl_union_map_copy(vb
));
487 return HandleTopLevelDeclContinue
;
491 static const char *ResourceDir
= CLANG_PREFIX
"/lib/clang/"CLANG_VERSION_STRING
;
493 static const char *implicit_functions
[] = {
494 "min", "max", "ceild", "floord"
497 static bool is_implicit(const IdentifierInfo
*ident
)
499 const char *name
= ident
->getNameStart();
500 for (int i
= 0; i
< ARRAY_SIZE(implicit_functions
); ++i
)
501 if (!strcmp(name
, implicit_functions
[i
]))
506 /* Ignore implicit function declaration warnings on
507 * "min", "max", "ceild" and "floord" as we detect and handle these
510 struct MyDiagnosticPrinter
: public TextDiagnosticPrinter
{
511 const DiagnosticOptions
*DiagOpts
;
512 #ifdef HAVE_BASIC_DIAGNOSTICOPTIONS_H
513 MyDiagnosticPrinter(DiagnosticOptions
*DO
) :
514 TextDiagnosticPrinter(llvm::errs(), DO
) {}
515 virtual DiagnosticConsumer
*clone(DiagnosticsEngine
&Diags
) const {
516 return new MyDiagnosticPrinter(&Diags
.getDiagnosticOptions());
519 MyDiagnosticPrinter(const DiagnosticOptions
&DO
) :
520 DiagOpts(&DO
), TextDiagnosticPrinter(llvm::errs(), DO
) {}
521 virtual DiagnosticConsumer
*clone(DiagnosticsEngine
&Diags
) const {
522 return new MyDiagnosticPrinter(*DiagOpts
);
525 virtual void HandleDiagnostic(DiagnosticsEngine::Level level
,
526 const DiagnosticInfo
&info
) {
527 if (info
.getID() == diag::ext_implicit_function_decl
&&
528 info
.getNumArgs() == 1 &&
529 info
.getArgKind(0) == DiagnosticsEngine::ak_identifierinfo
&&
530 is_implicit(info
.getArgIdentifier(0)))
531 /* ignore warning */;
533 TextDiagnosticPrinter::HandleDiagnostic(level
, info
);
537 /* For each array in "scop", set its value_bounds property
538 * based on the infofrmation in "value_bounds" and
539 * mark it as live_out if it appears in "live_out".
541 static void update_arrays(struct pet_scop
*scop
,
542 __isl_take isl_union_map
*value_bounds
, set
<ValueDecl
*> &live_out
)
544 set
<ValueDecl
*>::iterator lo_it
;
545 isl_ctx
*ctx
= isl_union_map_get_ctx(value_bounds
);
548 isl_union_map_free(value_bounds
);
552 for (int i
= 0; i
< scop
->n_array
; ++i
) {
557 pet_array
*array
= scop
->arrays
[i
];
559 id
= isl_set_get_tuple_id(array
->extent
);
560 decl
= (ValueDecl
*)isl_id_get_user(id
);
562 space
= isl_space_alloc(ctx
, 0, 0, 1);
563 space
= isl_space_set_tuple_id(space
, isl_dim_in
, id
);
565 bounds
= isl_union_map_extract_map(value_bounds
, space
);
566 if (!isl_map_plain_is_empty(bounds
))
567 array
->value_bounds
= isl_map_range(bounds
);
569 isl_map_free(bounds
);
571 lo_it
= live_out
.find(decl
);
572 if (lo_it
!= live_out
.end())
576 isl_union_map_free(value_bounds
);
581 #ifdef HAVE_CXXISPRODUCTION
582 static Driver
*construct_driver(const char *binary
, DiagnosticsEngine
&Diags
)
584 return new Driver(binary
, llvm::sys::getDefaultTargetTriple(),
585 "", false, false, Diags
);
587 #elif defined(HAVE_ISPRODUCTION)
588 static Driver
*construct_driver(const char *binary
, DiagnosticsEngine
&Diags
)
590 return new Driver(binary
, llvm::sys::getDefaultTargetTriple(),
594 static Driver
*construct_driver(const char *binary
, DiagnosticsEngine
&Diags
)
596 return new Driver(binary
, llvm::sys::getDefaultTargetTriple(),
601 /* Create a CompilerInvocation object that stores the command line
602 * arguments constructed by the driver.
603 * The arguments are mainly useful for setting up the system include
604 * paths on newer clangs and on some platforms.
606 static CompilerInvocation
*construct_invocation(const char *filename
,
607 DiagnosticsEngine
&Diags
)
609 const char *binary
= CLANG_PREFIX
"/bin/clang";
610 const llvm::OwningPtr
<Driver
> driver(construct_driver(binary
, Diags
));
611 std::vector
<const char *> Argv
;
612 Argv
.push_back(binary
);
613 Argv
.push_back(filename
);
614 const llvm::OwningPtr
<Compilation
> compilation(
615 driver
->BuildCompilation(llvm::ArrayRef
<const char *>(Argv
)));
616 JobList
&Jobs
= compilation
->getJobs();
620 Command
*cmd
= cast
<Command
>(*Jobs
.begin());
621 if (strcmp(cmd
->getCreator().getName(), "clang"))
624 const ArgStringList
*args
= &cmd
->getArguments();
626 CompilerInvocation
*invocation
= new CompilerInvocation
;
627 CompilerInvocation::CreateFromArgs(*invocation
, args
->data() + 1,
628 args
->data() + args
->size(),
635 static CompilerInvocation
*construct_invocation(const char *filename
,
636 DiagnosticsEngine
&Diags
)
643 #ifdef HAVE_BASIC_DIAGNOSTICOPTIONS_H
645 static MyDiagnosticPrinter
*construct_printer(CompilerInstance
*Clang
)
647 return new MyDiagnosticPrinter(new DiagnosticOptions());
652 static MyDiagnosticPrinter
*construct_printer(CompilerInstance
*Clang
)
654 return new MyDiagnosticPrinter(Clang
->getDiagnosticOpts());
659 #ifdef CREATETARGETINFO_TAKES_POINTER
661 static TargetInfo
*create_target_info(CompilerInstance
*Clang
,
662 DiagnosticsEngine
&Diags
)
664 TargetOptions
&TO
= Clang
->getTargetOpts();
665 TO
.Triple
= llvm::sys::getDefaultTargetTriple();
666 return TargetInfo::CreateTargetInfo(Diags
, &TO
);
671 static TargetInfo
*create_target_info(CompilerInstance
*Clang
,
672 DiagnosticsEngine
&Diags
)
674 TargetOptions
&TO
= Clang
->getTargetOpts();
675 TO
.Triple
= llvm::sys::getDefaultTargetTriple();
676 return TargetInfo::CreateTargetInfo(Diags
, TO
);
681 #ifdef CREATEDIAGNOSTICS_TAKES_ARG
683 static void create_diagnostics(CompilerInstance
*Clang
)
685 Clang
->createDiagnostics(0, NULL
);
690 static void create_diagnostics(CompilerInstance
*Clang
)
692 Clang
->createDiagnostics();
697 #ifdef ADDPATH_TAKES_4_ARGUMENTS
699 void add_path(HeaderSearchOptions
&HSO
, string Path
)
701 HSO
.AddPath(Path
, frontend::Angled
, false, false);
706 void add_path(HeaderSearchOptions
&HSO
, string Path
)
708 HSO
.AddPath(Path
, frontend::Angled
, true, false, false);
713 /* Extract a pet_scop from the C source file called "filename".
714 * If "function" is not NULL, extract the pet_scop from the function
716 * If "autodetect" is set, extract any pet_scop we can find.
717 * Otherwise, extract the pet_scop from the region delimited
718 * by "scop" and "endscop" pragmas.
720 * We first set up the clang parser and then try to extract the
721 * pet_scop from the appropriate function in PetASTConsumer.
722 * If we have found a pet_scop, we add the context and value_bounds
723 * constraints specified through pragmas.
725 static struct pet_scop
*scop_extract_from_C_source(isl_ctx
*ctx
,
726 const char *filename
, const char *function
, pet_options
*options
)
730 isl_set
*context_value
;
732 set
<ValueDecl
*> live_out
;
733 isl_union_map
*value_bounds
;
735 CompilerInstance
*Clang
= new CompilerInstance();
736 create_diagnostics(Clang
);
737 DiagnosticsEngine
&Diags
= Clang
->getDiagnostics();
738 Diags
.setSuppressSystemWarnings(true);
739 CompilerInvocation
*invocation
= construct_invocation(filename
, Diags
);
741 Clang
->setInvocation(invocation
);
742 Diags
.setClient(construct_printer(Clang
));
743 Clang
->createFileManager();
744 Clang
->createSourceManager(Clang
->getFileManager());
745 TargetInfo
*target
= create_target_info(Clang
, Diags
);
746 Clang
->setTarget(target
);
747 CompilerInvocation::setLangDefaults(Clang
->getLangOpts(), IK_C
,
748 LangStandard::lang_unspecified
);
749 HeaderSearchOptions
&HSO
= Clang
->getHeaderSearchOpts();
750 HSO
.ResourceDir
= ResourceDir
;
751 for (int i
= 0; i
< options
->n_path
; ++i
)
752 add_path(HSO
, options
->paths
[i
]);
753 PreprocessorOptions
&PO
= Clang
->getPreprocessorOpts();
754 for (int i
= 0; i
< options
->n_define
; ++i
)
755 PO
.addMacroDef(options
->defines
[i
]);
756 Clang
->createPreprocessor();
757 Preprocessor
&PP
= Clang
->getPreprocessor();
761 const FileEntry
*file
= Clang
->getFileManager().getFile(filename
);
763 isl_die(ctx
, isl_error_unknown
, "unable to open file",
764 do { delete Clang
; return NULL
; } while (0));
765 Clang
->getSourceManager().createMainFileID(file
);
767 Clang
->createASTContext();
768 PetASTConsumer
consumer(ctx
, PP
, Clang
->getASTContext(),
769 loc
, function
, options
);
770 Sema
*sema
= new Sema(PP
, Clang
->getASTContext(), consumer
);
772 if (!options
->autodetect
) {
773 PP
.AddPragmaHandler(new PragmaScopHandler(loc
));
774 PP
.AddPragmaHandler(new PragmaEndScopHandler(loc
));
775 PP
.AddPragmaHandler(new PragmaLiveOutHandler(*sema
, live_out
));
778 dim
= isl_space_params_alloc(ctx
, 0);
779 context
= isl_set_universe(isl_space_copy(dim
));
780 context_value
= isl_set_universe(dim
);
781 PP
.AddPragmaHandler(new PragmaParameterHandler(*sema
, context
,
783 consumer
.handle_value_bounds(sema
);
785 Diags
.getClient()->BeginSourceFile(Clang
->getLangOpts(), &PP
);
787 Diags
.getClient()->EndSourceFile();
789 scop
= consumer
.scop
;
790 if (Diags
.hasErrorOccurred()) {
796 scop
->context
= isl_set_intersect(context
, scop
->context
);
797 scop
->context_value
= isl_set_intersect(context_value
,
798 scop
->context_value
);
800 isl_set_free(context
);
801 isl_set_free(context_value
);
804 update_arrays(scop
, consumer
.get_value_bounds(), live_out
);
806 scop
= pet_scop_anonymize(scop
);
814 struct pet_scop
*pet_scop_extract_from_C_source(isl_ctx
*ctx
,
815 const char *filename
, const char *function
)
818 pet_options
*options
;
819 bool allocated
= false;
821 options
= isl_ctx_peek_pet_options(ctx
);
823 options
= pet_options_new_with_defaults();
827 scop
= scop_extract_from_C_source(ctx
, filename
, function
, options
);
828 llvm::llvm_shutdown();
831 pet_options_free(options
);