Skip to content

Commit 2724b05

Browse files
committed
codegen: compile generated code with debug symbols in debug builds
Relates to #373. This commit adjusts the compilation command for generated code to compile code with debug symbols when TACO is built in debug mode. Conveniently, this allows for debuggers (like the integrated one in CLion) to automatically display the generated source code when a segfault occurs (along with other things the IDE supports).
1 parent f59a6e5 commit 2724b05

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/codegen/module.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,15 @@ string Module::compile() {
121121
}
122122
else {
123123
cc = util::getFromEnv(target.compiler_env, target.compiler);
124-
cflags = util::getFromEnv("TACO_CFLAGS",
125-
"-O3 -ffast-math -std=c99") + " -shared -fPIC";
124+
#ifdef TACO_DEBUG
125+
// In debug mode, compile the generated code with debug symbols and a
126+
// low optimization level.
127+
string defaultFlags = "-g -O0 -std=c99";
128+
#else
129+
// Otherwise, use the standard set of optimizing flags.
130+
string defaultFlags = "-O3 -ffast-math -std=c99";
131+
#endif
132+
cflags = util::getFromEnv("TACO_CFLAGS", defaultFlags) + " -shared -fPIC";
126133
#if USE_OPENMP
127134
cflags += " -fopenmp";
128135
#endif

test/tests-qcd.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ TEST(qcd, mul1) {
3434
tau = z(i) * z(j) * theta(i,j) * theta(i,j);
3535

3636
tau.evaluate();
37+
// Using -O0 to compile the generated kernel yields a slightly different
38+
// answer than using -O3.
39+
#ifdef TACO_DEBUG
40+
ASSERT_DOUBLE_EQ(0.41212798763234648, getScalarValue(tau));
41+
#else
3742
ASSERT_DOUBLE_EQ(0.41212798763234737, getScalarValue(tau));
43+
#endif
3844
}
3945

4046
TEST(qcd, mul2) {

0 commit comments

Comments
 (0)