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

Commit 3c7137a

Browse files
committed
Added peloton::codegen::CppProxyMember that allows loading and storing proxy members without using GEP. Beefed up proxies.
1 parent c42df7f commit 3c7137a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+247
-277
lines changed

src/codegen/buffer_accessor.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ void BufferAccessor::Append(CodeGen &codegen, llvm::Value *buffer_ptr,
4848

4949
void BufferAccessor::Iterate(CodeGen &codegen, llvm::Value *buffer_ptr,
5050
BufferAccessor::IterateCallback &callback) const {
51-
auto *start = GetStartPosition(codegen, buffer_ptr);
52-
auto *end = GetEndPosition(codegen, buffer_ptr);
51+
auto *start = codegen.Load(BufferProxy::buffer_start, buffer_ptr);
52+
auto *end = codegen.Load(BufferProxy::buffer_pos, buffer_ptr);
5353
lang::Loop loop(codegen, codegen->CreateICmpNE(start, end), {{"pos", start}});
5454
{
5555
auto *pos = loop.GetLoopVar(0);
@@ -83,30 +83,14 @@ void BufferAccessor::Destroy(CodeGen &codegen, llvm::Value *buffer_ptr) const {
8383

8484
llvm::Value *BufferAccessor::NumTuples(CodeGen &codegen,
8585
llvm::Value *buffer_ptr) const {
86-
llvm::Value *start = GetStartPosition(codegen, buffer_ptr);
87-
llvm::Value *end = GetEndPosition(codegen, buffer_ptr);
86+
auto *start = codegen.Load(BufferProxy::buffer_start, buffer_ptr);
87+
auto *end = codegen.Load(BufferProxy::buffer_pos, buffer_ptr);
8888
start = codegen->CreatePtrToInt(start, codegen.Int64Type());
8989
end = codegen->CreatePtrToInt(end, codegen.Int64Type());
9090
auto *diff = codegen->CreateSub(end, start);
9191
diff = codegen->CreateAShr(diff, 3, "numTuples", true);
9292
return codegen->CreateTrunc(diff, codegen.Int32Type());
9393
}
9494

95-
llvm::Value *BufferAccessor::GetStartPosition(CodeGen &codegen,
96-
llvm::Value *buffer_ptr) const {
97-
auto *buffer_type = BufferProxy::GetType(codegen);
98-
auto *addr =
99-
codegen->CreateConstInBoundsGEP2_32(buffer_type, buffer_ptr, 0, 0);
100-
return codegen->CreateLoad(addr);
101-
}
102-
103-
llvm::Value *BufferAccessor::GetEndPosition(CodeGen &codegen,
104-
llvm::Value *buffer_ptr) const {
105-
auto *buffer_type = BufferProxy::GetType(codegen);
106-
auto *addr =
107-
codegen->CreateConstInBoundsGEP2_32(buffer_type, buffer_ptr, 0, 1);
108-
return codegen->CreateLoad(addr);
109-
}
110-
11195
} // namespace codegen
11296
} // namespace peloton

src/codegen/codegen.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,5 +292,19 @@ uint64_t CodeGen::ElementOffset(llvm::Type *type, uint32_t element_idx) const {
292292
return struct_layout->getElementOffset(element_idx);
293293
}
294294

295+
////////////////////////////////////////////////////////////////////////////////
296+
///
297+
/// CPP Proxy Compiled Member
298+
///
299+
////////////////////////////////////////////////////////////////////////////////
300+
301+
llvm::Value *CppProxyMember::Load(CodeGen &codegen,
302+
llvm::Value *ptr) const {
303+
llvm::SmallVector<llvm::Value *, 2> indexes{codegen.Const32(0),
304+
codegen.Const32(slot)};
305+
llvm::Value *addr = codegen->CreateInBoundsGEP(ptr, indexes);
306+
return codegen->CreateLoad(addr);
307+
}
308+
295309
} // namespace codegen
296310
} // namespace peloton

src/codegen/oa_hash_table.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,6 @@ llvm::Value *OAHashTable::HashKey(
5858
return Hash::HashValues(codegen, key);
5959
}
6060

61-
// Load the value of a field from the given hash table instance.
62-
// NOTE: the type returned is the actual type registered in HashTable type
63-
llvm::Value *OAHashTable::LoadHashTableField(CodeGen &codegen,
64-
llvm::Value *hash_table,
65-
uint32_t field_id) const {
66-
llvm::Type *hash_table_type = OAHashTableProxy::GetType(codegen);
67-
return codegen->CreateLoad(codegen->CreateConstInBoundsGEP2_32(
68-
hash_table_type, hash_table, 0, field_id));
69-
}
70-
7161
// Return the element stored in a specified field of a HashEntry struct. Since
7262
// we also need to access data field, the offset is an extra argument
7363
llvm::Value *OAHashTable::LoadHashEntryField(CodeGen &codegen,
@@ -115,7 +105,8 @@ OAHashTable::HashTablePos OAHashTable::GetNextEntry(CodeGen &codegen,
115105
llvm::Value *entry_ptr,
116106
llvm::Value *index) const {
117107
// hash_table_size = hash_table->num_buckets_
118-
llvm::Value *hash_table_size = LoadHashTableField(codegen, hash_table, 1);
108+
llvm::Value *hash_table_size =
109+
codegen.Load(OAHashTableProxy::num_buckets, hash_table);
119110
// next_index = index + 1
120111
llvm::Value *next_index = codegen->CreateAdd(index, codegen.Const64(1));
121112
// next_entry_p = entry_p + HashEntrySize()
@@ -128,7 +119,7 @@ OAHashTable::HashTablePos OAHashTable::GetNextEntry(CodeGen &codegen,
128119
codegen->CreateICmpEQ(next_index, hash_table_size)};
129120
{
130121
wrap_back_index = codegen.Const64(0);
131-
wrap_back_entry_ptr = LoadHashTableField(codegen, hash_table, 0);
122+
wrap_back_entry_ptr = codegen.Load(OAHashTableProxy::buckets, hash_table);
132123
}
133124
wrap_back.EndIf();
134125

@@ -144,7 +135,7 @@ llvm::Value *OAHashTable::GetEntry(CodeGen &codegen, llvm::Value *hash_table,
144135
llvm::Value *byte_offset = codegen->CreateMul(
145136
codegen.Const64(hash_entry_size_),
146137
codegen->CreateZExtOrBitCast(index, codegen.Int64Type()));
147-
llvm::Value *base_ptr = LoadHashTableField(codegen, hash_table, 0);
138+
llvm::Value *base_ptr = codegen.Load(OAHashTableProxy::buckets, hash_table);
148139
return AdvancePointer(codegen, base_ptr, byte_offset);
149140
}
150141

@@ -154,7 +145,8 @@ OAHashTable::HashTablePos OAHashTable::GetEntryByHash(
154145
// We need both to judge whether to wrap back
155146

156147
// Load bucket mask from the hash table field #2 (3rd)
157-
llvm::Value *bucket_mask = LoadHashTableField(codegen, hash_table, 2);
148+
llvm::Value *bucket_mask =
149+
codegen.Load(OAHashTableProxy::bucket_mask, hash_table);
158150
llvm::Value *index = codegen->CreateAnd(bucket_mask, hash_value);
159151
llvm::Value *entry_ptr = GetEntry(codegen, hash_table, index);
160152
return HashTablePos{index, entry_ptr};
@@ -540,14 +532,15 @@ void OAHashTable::Insert(CodeGen &codegen, llvm::Value *ht_ptr,
540532
void OAHashTable::Iterate(CodeGen &codegen, llvm::Value *hash_table,
541533
IterateCallback &callback) const {
542534
// Load the size of the array
543-
llvm::Value *num_buckets = LoadHashTableField(codegen, hash_table, 1);
535+
llvm::Value *num_buckets =
536+
codegen.Load(OAHashTableProxy::num_buckets, hash_table);
544537

545538
// Create a constant number from entry size
546539
llvm::Value *entry_size = codegen.Const64(HashEntrySize());
547540

548541
// This is the first entry in the hash table
549542
// The type of this pointer is HashEntry without key and value field
550-
llvm::Value *entry_ptr = LoadHashTableField(codegen, hash_table, 0);
543+
llvm::Value *entry_ptr = codegen.Load(OAHashTableProxy::buckets, hash_table);
551544

552545
// Create an uint64_t variable which is the current index in the array
553546
// and initialize it with cosntant number 0
@@ -627,10 +620,11 @@ void OAHashTable::VectorizedIterate(
627620
PELOTON_ASSERT((size & (size - 1)) == 0);
628621

629622
// The start of the buckets array
630-
llvm::Value *entry_ptr = LoadHashTableField(codegen, hash_table, 0);
623+
llvm::Value *entry_ptr = codegen.Load(OAHashTableProxy::buckets, hash_table);
631624

632625
// Load the size of the array
633-
llvm::Value *num_buckets = LoadHashTableField(codegen, hash_table, 1);
626+
llvm::Value *num_buckets =
627+
codegen.Load(OAHashTableProxy::num_buckets, hash_table);
634628
num_buckets = codegen->CreateTruncOrBitCast(num_buckets, codegen.Int32Type());
635629

636630
lang::VectorizedLoop vector_loop(codegen, num_buckets, size,

src/codegen/operator/table_scan_translator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "codegen/type/boolean_type.h"
2222
#include "codegen/vector.h"
2323
#include "planner/seq_scan_plan.h"
24+
#include "storage/data_table.h"
2425

2526
namespace peloton {
2627
namespace codegen {

src/codegen/pipeline.cpp

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,46 @@ namespace codegen {
2525

2626
////////////////////////////////////////////////////////////////////////////////
2727
///
28-
/// PipelineContext
28+
/// LoopOverStates
29+
///
30+
////////////////////////////////////////////////////////////////////////////////
31+
32+
PipelineContext::LoopOverStates::LoopOverStates(PipelineContext &pipeline_ctx)
33+
: ctx_(pipeline_ctx) {}
34+
35+
void PipelineContext::LoopOverStates::Do(
36+
const std::function<void(llvm::Value *)> &body) const {
37+
auto &compilation_ctx = ctx_.GetPipeline().GetCompilationContext();
38+
auto &exec_consumer = compilation_ctx.GetExecutionConsumer();
39+
auto *thread_states = exec_consumer.GetThreadStatesPtr(compilation_ctx);
40+
41+
CodeGen &codegen = compilation_ctx.GetCodeGen();
42+
43+
llvm::Value *num_threads =
44+
codegen.Load(ThreadStatesProxy::num_threads, thread_states);
45+
llvm::Value *state_size =
46+
codegen.Load(ThreadStatesProxy::state_size, thread_states);
47+
llvm::Value *states = codegen.Load(ThreadStatesProxy::states, thread_states);
48+
49+
llvm::Value *state_end = codegen->CreateInBoundsGEP(
50+
states, {codegen->CreateMul(num_threads, state_size)});
51+
52+
llvm::Value *loop_cond = codegen->CreateICmpNE(states, state_end);
53+
lang::Loop state_loop(codegen, loop_cond, {{"threadState", states}});
54+
{
55+
// Pull out state in this iteration
56+
llvm::Value *curr_state = state_loop.GetLoopVar(0);
57+
// Invoke caller
58+
body(curr_state);
59+
// Wrap up
60+
states = codegen->CreateInBoundsGEP(states, {state_size});
61+
state_loop.LoopEnd(codegen->CreateICmpNE(states, state_end), {states});
62+
}
63+
}
64+
65+
////////////////////////////////////////////////////////////////////////////////
66+
///
67+
/// Pipeline context
2968
///
3069
////////////////////////////////////////////////////////////////////////////////
3170

@@ -343,46 +382,17 @@ void Pipeline::CompletePipeline(PipelineContext &pipeline_context) {
343382
return;
344383
}
345384

346-
auto &exec_consumer = compilation_ctx_.GetExecutionConsumer();
347-
auto *thread_states = exec_consumer.GetThreadStatesPtr(compilation_ctx_);
348-
349-
CodeGen &codegen = compilation_ctx_.GetCodeGen();
350-
351-
auto *thread_states_type = ThreadStatesProxy::GetType(codegen);
352-
353-
llvm::Value *num_threads =
354-
codegen->CreateLoad(codegen->CreateConstInBoundsGEP2_32(
355-
thread_states_type, thread_states, 0, 1));
356-
357-
llvm::Value *state_size =
358-
codegen->CreateLoad(codegen->CreateConstInBoundsGEP2_32(
359-
thread_states_type, thread_states, 0, 2));
360-
361-
llvm::Value *state = codegen->CreateLoad(codegen->CreateConstInBoundsGEP2_32(
362-
thread_states_type, thread_states, 0, 3));
363-
364-
llvm::Value *state_end = codegen->CreateInBoundsGEP(
365-
state, {codegen->CreateMul(num_threads, state_size)});
366-
367-
llvm::Value *loop_cond = codegen->CreateICmpNE(state, state_end);
368-
lang::Loop worker_loop(codegen, loop_cond, {{"threadState", state}});
369-
{
370-
state = worker_loop.GetLoopVar(0);
371-
llvm::Value *thread_state = codegen->CreateBitOrPointerCast(
372-
state, pipeline_context.GetThreadStateType()->getPointerTo());
385+
// Loop over all states
386+
PipelineContext::LoopOverStates loop_state(pipeline_context);
387+
loop_state.Do([this, &pipeline_context](llvm::Value *thread_state) {
373388
PipelineContext::ScopedStateAccess state_access(pipeline_context,
374389
thread_state);
375-
376390
// Let operators in the pipeline clean up any pipeline state
377391
for (auto riter = pipeline_.rbegin(), rend = pipeline_.rend();
378392
riter != rend; ++riter) {
379393
(*riter)->TearDownPipelineState(pipeline_context);
380394
}
381-
382-
// Wrap up
383-
state = codegen->CreateInBoundsGEP(state, {state_size});
384-
worker_loop.LoopEnd(codegen->CreateICmpNE(state, state_end), {state});
385-
}
395+
});
386396
}
387397

388398
void Pipeline::RunSerial(const std::function<void(ConsumerContext &)> &body) {

src/codegen/proxy/bloom_filter_proxy.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// Identification: src/codegen/proxy/bloom_filter_proxy.cpp
88
//
9-
// Copyright (c) 2015-2017, Carnegie Mellon University Database Group
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
1010
//
1111
//===----------------------------------------------------------------------===//
1212

@@ -15,9 +15,8 @@
1515
namespace peloton {
1616
namespace codegen {
1717

18-
DEFINE_TYPE(BloomFilter, "peloton::BloomFilter", MEMBER(num_hash_funcs),
19-
MEMBER(bytes), MEMBER(num_bits), MEMBER(num_misses),
20-
MEMBER(num_probes));
18+
DEFINE_TYPE(BloomFilter, "peloton::BloomFilter", num_hash_funcs, bytes,
19+
num_bits, num_misses, num_probes);
2120

2221
DEFINE_METHOD(peloton::codegen::util, BloomFilter, Init);
2322
DEFINE_METHOD(peloton::codegen::util, BloomFilter, Destroy);

src/codegen/proxy/buffer_proxy.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
namespace peloton {
1919
namespace codegen {
2020

21-
DEFINE_TYPE(Buffer, "peloton::Buffer", MEMBER(buffer_start), MEMBER(buffer_pos),
22-
MEMBER(buffer_end));
21+
DEFINE_TYPE(Buffer, "peloton::Buffer", buffer_start, buffer_pos, buffer_end);
2322

2423
DEFINE_METHOD(peloton::codegen::util, Buffer, Init);
2524
DEFINE_METHOD(peloton::codegen::util, Buffer, Destroy);

src/codegen/proxy/cc_hash_table_proxy.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// Identification: src/codegen/proxy/cc_hash_table_proxy.cpp
88
//
9-
// Copyright (c) 2015-2017, Carnegie Mellon University Database Group
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
1010
//
1111
//===----------------------------------------------------------------------===//
1212

@@ -37,8 +37,8 @@ llvm::Type *HashEntryProxy::GetType(CodeGen &codegen) {
3737
return hash_entry_type;
3838
}
3939

40-
DEFINE_TYPE(CCHashTable, "peloton::CCHashTable", MEMBER(buckets),
41-
MEMBER(num_buckets), MEMBER(bucket_mask), MEMBER(num_elements));
40+
DEFINE_TYPE(CCHashTable, "peloton::CCHashTable", buckets, num_buckets,
41+
bucket_mask, num_elements);
4242

4343
DEFINE_METHOD(peloton::codegen::util, CCHashTable, Init);
4444
DEFINE_METHOD(peloton::codegen::util, CCHashTable, StoreTuple);

src/codegen/proxy/data_table_proxy.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// Identification: src/codegen/proxy/data_table_proxy.cpp
88
//
9-
// Copyright (c) 2015-2017, Carnegie Mellon University Database Group
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
1010
//
1111
//===----------------------------------------------------------------------===//
1212

@@ -15,7 +15,8 @@
1515
namespace peloton {
1616
namespace codegen {
1717

18-
DEFINE_TYPE(DataTable, "storage::DataTable", MEMBER(opaque));
18+
DEFINE_TYPE(DataTable, "storage::DataTable", opaque);
19+
1920
DEFINE_METHOD(peloton::storage, DataTable, GetTileGroupCount);
2021

2122
} // namespace codegen

src/codegen/proxy/decimal_functions_proxy.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// Identification: src/codegen/proxy/decimal_functions_proxy.cpp
88
//
9-
// Copyright (c) 2015-2017, Carnegie Mellon University Database Group
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
1010
//
1111
//===----------------------------------------------------------------------===//
1212

@@ -17,12 +17,14 @@
1717

1818
namespace peloton {
1919
namespace codegen {
20+
2021
DEFINE_METHOD(peloton::function, DecimalFunctions, Abs);
2122

2223
DEFINE_METHOD(peloton::function, DecimalFunctions, Floor);
2324

2425
DEFINE_METHOD(peloton::function, DecimalFunctions, Round);
2526

2627
DEFINE_METHOD(peloton::function, DecimalFunctions, Ceil);
28+
2729
} // namespace codegen
2830
} // namespace peloton

0 commit comments

Comments
 (0)