Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit c99abdc

Browse files
committed
Address reviews
1 parent 63bcbe4 commit c99abdc

File tree

4 files changed

+35
-30
lines changed

4 files changed

+35
-30
lines changed

src/codegen/codegen.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,6 @@ llvm::Value *CodeGen::ConstString(const std::string &str_val,
6969
return GetBuilder().CreateInBoundsGEP(global_var, {Const32(0), Const32(0)});
7070
}
7171

72-
llvm::Value *CodeGen::ConstType(const type::Type &type) {
73-
auto iter = type_variables_.find(type);
74-
if (iter != type_variables_.end()) {
75-
return iter->second;
76-
}
77-
const type::Type t = type;
78-
llvm::Value *ret = ConstGenericBytes(&type, sizeof(type), "type");
79-
type_variables_.insert(std::make_pair(t, ret));
80-
return ret;
81-
}
82-
8372
llvm::Value *CodeGen::ConstGenericBytes(const void *data, uint32_t length,
8473
const std::string &name) const {
8574
// Create the constant data array that wraps the input data
@@ -156,6 +145,14 @@ llvm::Value *CodeGen::Printf(const std::string &format,
156145
auto *printf_fn = LookupBuiltin("printf");
157146
if (printf_fn == nullptr) {
158147
#if GCC_AT_LEAST_6
148+
// In newer GCC versions (i.e., GCC 6+), function attributes are part of the
149+
// type system and are attached to the function signature. For example, printf()
150+
// comes with the "noexcept" attribute. Moreover, GCC 6+ will complain when
151+
// attributes attached to a function (e.g., noexcept()) are not used at
152+
// their call-site. Below, we use decltype(printf) to get the C/C++ function
153+
// type of printf(...), but we discard the attributes since we don't need
154+
// them. Hence, on GCC 6+, compilation will fail without adding the
155+
// "-Wignored-attributes" flag. So, we add it here only.
159156
#pragma GCC diagnostic push
160157
#pragma GCC diagnostic ignored "-Wignored-attributes"
161158
#endif
@@ -181,6 +178,14 @@ llvm::Value *CodeGen::Memcmp(llvm::Value *ptr1, llvm::Value *ptr2,
181178
auto *memcmp_fn = LookupBuiltin(kMemcmpFnName);
182179
if (memcmp_fn == nullptr) {
183180
#if GCC_AT_LEAST_6
181+
// In newer GCC versions (i.e., GCC 6+), function attributes are part of the
182+
// type system and are attached to the function signature. For example, memcmp()
183+
// comes with the "throw()" attribute, among many others. Moreover, GCC 6+ will
184+
// complain when attributes attached to a function are not used at their
185+
// call-site. Below, we use decltype(memcmp) to get the C/C++ function type
186+
// of memcmp(...), but we discard the attributes since we don't need them.
187+
// Hence, on GCC 6+, compilation will fail without adding the
188+
// "-Wignored-attributes" flag. So, we add it here only.
184189
#pragma GCC diagnostic push
185190
#pragma GCC diagnostic ignored "-Wignored-attributes"
186191
#endif

src/include/codegen/codegen.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ class CppProxyMember {
5959
uint32_t slot_;
6060
};
6161

62-
//===----------------------------------------------------------------------===//
63-
// The main wrapper around LLVM's IR Builder to generate IR
64-
//===----------------------------------------------------------------------===//
62+
/**
63+
* The main API used to generate code in Peloton. Provides a thin wrapper around
64+
* LLVM's IR Builder to generate IR.
65+
*/
6566
class CodeGen {
6667
public:
6768
/// Constructor and destructor
@@ -89,7 +90,8 @@ class CodeGen {
8990
}
9091
llvm::Type *ArrayType(llvm::Type *type, uint32_t num_elements) const;
9192

92-
/// Constant wrappers for bool, int8, int16, int32, int64, strings, and null
93+
/// Functions to return LLVM values for constant boolean, int8, int16, int32,
94+
// int64, strings, and null values.
9395
llvm::Constant *ConstBool(bool val) const;
9496
llvm::Constant *Const8(int8_t val) const;
9597
llvm::Constant *Const16(int16_t val) const;
@@ -98,7 +100,6 @@ class CodeGen {
98100
llvm::Constant *ConstDouble(double val) const;
99101
llvm::Value *ConstString(const std::string &str_val,
100102
const std::string &name) const;
101-
llvm::Value *ConstType(const type::Type &type);
102103
llvm::Value *ConstGenericBytes(const void *data, uint32_t length,
103104
const std::string &name) const;
104105
llvm::Constant *Null(llvm::Type *type) const;
@@ -195,9 +196,6 @@ class CodeGen {
195196
private:
196197
// The context/module where all the code this class produces goes
197198
CodeContext &code_context_;
198-
199-
std::unordered_map<type::Type, llvm::Value *, type::TypeHasher,
200-
type::TypeEquality> type_variables_;
201199
};
202200

203201
} // namespace codegen

test/function/numeric_functions_test.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ using ::testing::Return;
2828
namespace peloton {
2929
namespace test {
3030

31-
class NumericFunctionsTest : public PelotonTest {};
31+
class NumericFunctionsTests : public PelotonTest {};
3232

33-
TEST_F(NumericFunctionsTest, SqrtTest) {
33+
TEST_F(NumericFunctionsTests, SqrtTest) {
3434
const double column_val = 9.0;
3535
const double expected = sqrt(9.0);
3636
std::vector<type::Value> args = {
@@ -46,7 +46,7 @@ TEST_F(NumericFunctionsTest, SqrtTest) {
4646
EXPECT_TRUE(result.IsNull());
4747
}
4848

49-
TEST_F(NumericFunctionsTest, FloorTest) {
49+
TEST_F(NumericFunctionsTests, FloorTest) {
5050
// Testing Floor with DecimalTypes
5151
std::vector<double> inputs = {9.5, 3.3, -4.4, 0.0};
5252
std::vector<type::Value> args;
@@ -88,7 +88,7 @@ TEST_F(NumericFunctionsTest, FloorTest) {
8888
EXPECT_TRUE(result.IsNull());
8989
}
9090

91-
TEST_F(NumericFunctionsTest, RoundTest) {
91+
TEST_F(NumericFunctionsTests, RoundTest) {
9292
std::vector<double> column_vals = {9.5, 3.3, -4.4, -5.5, 0.0};
9393
std::vector<type::Value> args;
9494
for (double val : column_vals) {
@@ -104,7 +104,7 @@ TEST_F(NumericFunctionsTest, RoundTest) {
104104
EXPECT_TRUE(result.IsNull());
105105
}
106106

107-
TEST_F(NumericFunctionsTest,AbsTestDouble) {
107+
TEST_F(NumericFunctionsTests,AbsTestDouble) {
108108
std::vector<double> doubleTestInputs = {9.5, -2.5, -4.4, 0.0};
109109
std::vector<type::Value> args;
110110
for (double in : doubleTestInputs) {
@@ -120,7 +120,7 @@ TEST_F(NumericFunctionsTest,AbsTestDouble) {
120120
EXPECT_TRUE(result.IsNull());
121121
}
122122

123-
TEST_F(NumericFunctionsTest, AbsTestInt) {
123+
TEST_F(NumericFunctionsTests, AbsTestInt) {
124124
std::vector<int64_t> bigIntTestInputs = {-20, -15, -10, 0, 10, 20};
125125
std::vector<int32_t> intTestInputs = {-20, -15, -10, 0, 10, 20};
126126
std::vector<int16_t> smallIntTestInputs = {-20, -15, -10, 0, 10, 20};
@@ -157,7 +157,7 @@ TEST_F(NumericFunctionsTest, AbsTestInt) {
157157
}
158158
}
159159

160-
TEST_F(NumericFunctionsTest, CeilTestDouble) {
160+
TEST_F(NumericFunctionsTests, CeilTestDouble) {
161161
std::vector<double> doubleTestInputs = {-36.0, -35.222, -0.7, -0.5, -0.2,
162162
0.0, 0.2, 0.5, 0.7, 35.2, 36.0,
163163
37.2222};
@@ -174,7 +174,7 @@ TEST_F(NumericFunctionsTest, CeilTestDouble) {
174174
EXPECT_TRUE(result.IsNull());
175175
}
176176

177-
TEST_F(NumericFunctionsTest, CeilTestInt) {
177+
TEST_F(NumericFunctionsTests, CeilTestInt) {
178178
std::vector<int64_t> bigIntTestInputs = {-20, -15, -10, 0, 10, 20};
179179
std::vector<int32_t> intTestInputs = {-20, -15, -10, 0, 10, 20};
180180
std::vector<int16_t> smallIntTestInputs = {-20, -15, -10, 0, 10, 20};

test/include/codegen/testing_codegen_util.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ struct TempFileHandle {
5252
};
5353

5454
/**
55-
* Common base class for all codegen tests. This class four test tables that all
56-
* the codegen components use. Their ID's are available through the oid_t
57-
* enumeration.
55+
* Common base class for all codegen tests. This class has four test tables
56+
* whose IDs and names are stored in test_table_oids and test_table_names,
57+
* respectively. The test tables all have the exact schema: column "a" and "b"
58+
* are integers, column "c" is a decimal, and column "d" is a varchar. The table
59+
* with the highest OID also has a primary key on column "a".
5860
*/
5961
class PelotonCodeGenTest : public PelotonTest {
6062
public:

0 commit comments

Comments
 (0)