Skip to content

Commit 7cd2f29

Browse files
authored
Merge pull request #382 from rohany/debug-symbols
codegen: compile generated code with debug symbols in debug builds
2 parents 0ede002 + 2724b05 commit 7cd2f29

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
@@ -125,8 +125,15 @@ string Module::compile() {
125125
}
126126
else {
127127
cc = util::getFromEnv(target.compiler_env, target.compiler);
128-
cflags = util::getFromEnv("TACO_CFLAGS",
129-
"-O3 -ffast-math -std=c99") + " -shared -fPIC";
128+
#ifdef TACO_DEBUG
129+
// In debug mode, compile the generated code with debug symbols and a
130+
// low optimization level.
131+
string defaultFlags = "-g -O0 -std=c99";
132+
#else
133+
// Otherwise, use the standard set of optimizing flags.
134+
string defaultFlags = "-O3 -ffast-math -std=c99";
135+
#endif
136+
cflags = util::getFromEnv("TACO_CFLAGS", defaultFlags) + " -shared -fPIC";
130137
#if USE_OPENMP
131138
cflags += " -fopenmp";
132139
#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)