File tree Expand file tree Collapse file tree 11 files changed +139
-17
lines changed Expand file tree Collapse file tree 11 files changed +139
-17
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,9 @@ namespace types {
66
66
// / isAcceptedByClang - Can clang handle this input type.
67
67
bool isAcceptedByClang (ID Id);
68
68
69
+ // / isAcceptedByFlang - Can flang handle this input type.
70
+ bool isAcceptedByFlang (ID Id);
71
+
69
72
// / isDerivedFromC - Is the input derived from C.
70
73
// /
71
74
// / That is, does the lexer follow the rules of
@@ -92,9 +95,6 @@ namespace types {
92
95
// / isOpenCL - Is this an "OpenCL" input.
93
96
bool isOpenCL (ID Id);
94
97
95
- // / isFortran - Is this a Fortran input.
96
- bool isFortran (ID Id);
97
-
98
98
// / isSrcFile - Is this a source file, i.e. something that still has to be
99
99
// / preprocessed. The logic behind this is the same that decides if the first
100
100
// / compilation phase is a preprocessing one.
Original file line number Diff line number Diff line change @@ -6050,11 +6050,12 @@ bool Driver::ShouldUseClangCompiler(const JobAction &JA) const {
6050
6050
bool Driver::ShouldUseFlangCompiler (const JobAction &JA) const {
6051
6051
// Say "no" if there is not exactly one input of a type flang understands.
6052
6052
if (JA.size () != 1 ||
6053
- !types::isFortran ((*JA.input_begin ())->getType ()))
6053
+ !types::isAcceptedByFlang ((*JA.input_begin ())->getType ()))
6054
6054
return false ;
6055
6055
6056
6056
// And say "no" if this is not a kind of action flang understands.
6057
- if (!isa<PreprocessJobAction>(JA) && !isa<CompileJobAction>(JA) && !isa<BackendJobAction>(JA))
6057
+ if (!isa<PreprocessJobAction>(JA) && !isa<CompileJobAction>(JA) &&
6058
+ !isa<BackendJobAction>(JA))
6058
6059
return false ;
6059
6060
6060
6061
return true ;
Original file line number Diff line number Diff line change @@ -159,6 +159,20 @@ bool types::isAcceptedByClang(ID Id) {
159
159
}
160
160
}
161
161
162
+ bool types::isAcceptedByFlang (ID Id) {
163
+ switch (Id) {
164
+ default :
165
+ return false ;
166
+
167
+ case TY_Fortran:
168
+ case TY_PP_Fortran:
169
+ return true ;
170
+ case TY_LLVM_IR:
171
+ case TY_LLVM_BC:
172
+ return true ;
173
+ }
174
+ }
175
+
162
176
bool types::isDerivedFromC (ID Id) {
163
177
switch (Id) {
164
178
default :
@@ -272,16 +286,6 @@ bool types::isHIP(ID Id) {
272
286
}
273
287
}
274
288
275
- bool types::isFortran (ID Id) {
276
- switch (Id) {
277
- default :
278
- return false ;
279
-
280
- case TY_Fortran: case TY_PP_Fortran:
281
- return true ;
282
- }
283
- }
284
-
285
289
bool types::isSrcFile (ID Id) {
286
290
return Id != TY_Object && getPreprocessedType (Id) != TY_INVALID;
287
291
}
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ add_flang_library(flangFrontend
40
40
LINK_COMPONENTS
41
41
Passes
42
42
Analysis
43
+ IRReader
43
44
Option
44
45
Support
45
46
Target
Original file line number Diff line number Diff line change @@ -73,6 +73,19 @@ bool PrescanAndSemaDebugAction::BeginSourceFileAction() {
73
73
}
74
74
75
75
bool CodeGenAction::BeginSourceFileAction () {
76
+ llvmCtx = std::make_unique<llvm::LLVMContext>();
77
+
78
+ // If the input is an LLVM file, just parse it and return.
79
+ if (this ->currentInput ().kind ().GetLanguage () == Language::LLVM_IR) {
80
+ llvm::SMDiagnostic err;
81
+ llvmModule = llvm::parseIRFile (currentInput ().file (), err, *llvmCtx);
82
+
83
+ return (nullptr != llvmModule);
84
+ }
85
+
86
+ // Otherwise, generate an MLIR module from the input Fortran source
87
+ assert (currentInput ().kind ().GetLanguage () == Language::Fortran &&
88
+ " Invalid input type - expecting a Fortran file" );
76
89
bool res = RunPrescan () && RunParse () && RunSemanticChecks ();
77
90
if (!res)
78
91
return res;
@@ -448,7 +461,6 @@ void CodeGenAction::GenerateLLVMIR() {
448
461
449
462
// Translate to LLVM IR
450
463
llvm::Optional<llvm::StringRef> moduleName = mlirModule->getName ();
451
- llvmCtx = std::make_unique<llvm::LLVMContext>();
452
464
llvmModule = mlir::translateModuleToLLVMIR (
453
465
*mlirModule, *llvmCtx, moduleName ? *moduleName : " FIRModule" );
454
466
Original file line number Diff line number Diff line change @@ -35,5 +35,9 @@ InputKind FrontendOptions::GetInputKindForExtension(llvm::StringRef extension) {
35
35
if (isFixedFormSuffix (extension) || isFreeFormSuffix (extension)) {
36
36
return Language::Fortran;
37
37
}
38
+
39
+ if (extension == " bc" || extension == " ll" )
40
+ return Language::LLVM_IR;
41
+
38
42
return Language::Unknown;
39
43
}
Original file line number Diff line number Diff line change
1
+ ; Verify that the driver can consume LLVM BC files. The expected assembly is
2
+ ; fairly generic (tested on AArch64 and X86_64), but we may need to tweak when
3
+ ; testing on other platforms. Note that the actual output doesn't matter as
4
+ ; long as it's in Assembly format.
5
+
6
+ ;-------------
7
+ ; RUN COMMANDS
8
+ ;-------------
9
+ ; RUN: rm -f %t.bc
10
+ ; RUN: %flang_fc1 -emit-llvm-bc %s -o %t.bc
11
+ ; RUN: %flang_fc1 -S -o - %t.bc | FileCheck %s
12
+ ; RUN: rm -f %t.bc
13
+
14
+ ; RUN: rm -f %t.bc
15
+ ; RUN: %flang -c -emit-llvm %s -o %t.bc
16
+ ; RUN: %flang -S -o - %t.bc | FileCheck %s
17
+ ; RUN: rm -f %t.bc
18
+
19
+ ;----------------
20
+ ; EXPECTED OUTPUT
21
+ ;----------------
22
+ ; CHECK-LABEL: foo:
23
+ ; CHECK: ret
24
+
25
+ ;------
26
+ ; INPUT
27
+ ;------
28
+ define void @foo () {
29
+ ret void
30
+ }
Original file line number Diff line number Diff line change
1
+ ; Verify that the driver can consume LLVM IR files. The expected assembly is
2
+ ; fairly generic (verified on AArch64 and X86_64), but we may need to tweak when
3
+ ; testing on other platforms. Note that the actual output doesn't matter
4
+ ; as long as it's in Assembly format.
5
+
6
+ ;-------------
7
+ ; RUN COMMANDS
8
+ ;-------------
9
+ ; RUN: %flang_fc1 -S %s -o - | FileCheck %s
10
+ ; RUN: %flang -S %s -o - | FileCheck %s
11
+
12
+ ;----------------
13
+ ; EXPECTED OUTPUT
14
+ ;----------------
15
+ ; CHECK-LABEL: foo:
16
+ ; CHECK: ret
17
+
18
+ ;------
19
+ ; INPUT
20
+ ;------
21
+ define void @foo () {
22
+ ret void
23
+ }
Original file line number Diff line number Diff line change
1
+ ; Verify that the module triple is overridden by the driver - even when the
2
+ ; module triple is missing.
3
+ ; NOTE: At the time of writing, the tested behaviour was consistent with Clang
4
+
5
+ ;-------------
6
+ ; RUN COMMANDS
7
+ ;-------------
8
+ ; RUN: %flang_fc1 -S %s -o - 2>&1 | FileCheck %s
9
+ ; RUN: %flang -S %s -o - 2>&1 | FileCheck %s
10
+
11
+ ;----------------
12
+ ; EXPECTED OUTPUT
13
+ ;----------------
14
+ ; CHECK: warning: overriding the module target triple with {{.*}}
15
+
16
+ ;------
17
+ ; INPUT
18
+ ;------
19
+ define void @foo () {
20
+ ret void
21
+ }
Original file line number Diff line number Diff line change
1
+ ; Verify that the module triple is overridden by the driver - even in the presence
2
+ ; of a module triple.
3
+ ; NOTE: At the time of writing, the tested behaviour was consistent with Clang
4
+
5
+ ;-------------
6
+ ; RUN COMMANDS
7
+ ;-------------
8
+ ; RUN: %flang_fc1 -S %s -o - 2>&1 | FileCheck %s
9
+ ; RUN: %flang -S %s -o - 2>&1 | FileCheck %s
10
+
11
+ ;----------------
12
+ ; EXPECTED OUTPUT
13
+ ;----------------
14
+ ; CHECK: warning: overriding the module target triple with {{.*}}
15
+
16
+ ;------
17
+ ; INPUT
18
+ ;------
19
+ ; For the triple to be overridden by the driver, it needs to be different to the host triple.
20
+ ; Use a random string to guarantee that.
21
+ target triple = "invalid-triple"
22
+
23
+ define void @foo () {
24
+ ret void
25
+ }
You can’t perform that action at this time.
0 commit comments