Skip to content

Commit

Permalink
wip: Using the symbol address space for pointers to Map/Set/List
Browse files Browse the repository at this point in the history
  • Loading branch information
theo25 committed Jul 20, 2022
1 parent 0b969ac commit e022389
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 60 deletions.
26 changes: 13 additions & 13 deletions lib/codegen/CreateTerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ llvm::Type *getParamType(ValueType sort, llvm::Module *Module) {
case SortCategory::MapIterator:
case SortCategory::Map:
case SortCategory::List:
case SortCategory::Set: type = llvm::PointerType::get(type, (unsigned)sort.cat); break;
case SortCategory::Set: type = llvm::PointerType::get(type, (unsigned)SortCategory::Symbol); break;
default: break;
}
return type;
Expand Down Expand Up @@ -284,7 +284,7 @@ llvm::Value *allocateTerm(
return malloc;
}
auto cast = new llvm::BitCastInst(
malloc, llvm::PointerType::get(AllocType, (unsigned)Cat.cat), "", block);
malloc, llvm::PointerType::get(AllocType, malloc->getType()->getPointerAddressSpace()), "", block);
return cast;
}

Expand Down Expand Up @@ -906,7 +906,7 @@ llvm::Value *CreateTerm::createFunctionCall(
types.insert(types.begin(), AllocSret->getType());
returnType = llvm::Type::getVoidTy(Ctx);
} else if (collection) {
returnType = llvm::PointerType::get(returnType, (unsigned)returnCat.cat);
returnType = llvm::PointerType::get(returnType, (unsigned)SortCategory::Symbol);
}

llvm::FunctionType *funcType
Expand Down Expand Up @@ -1166,7 +1166,7 @@ bool makeFunction(
case SortCategory::Map:
case SortCategory::List:
case SortCategory::Set:
paramType = llvm::PointerType::get(paramType, (unsigned)cat.cat);
paramType = llvm::PointerType::get(paramType, (unsigned)SortCategory::Symbol);
break;
default: break;
}
Expand All @@ -1181,7 +1181,7 @@ bool makeFunction(
case SortCategory::Map:
case SortCategory::List:
case SortCategory::Set:
returnType = llvm::PointerType::get(returnType, (unsigned)returnCat.cat);
returnType = llvm::PointerType::get(returnType, (unsigned)SortCategory::Symbol);
break;
default: break;
}
Expand Down Expand Up @@ -1219,13 +1219,13 @@ bool makeFunction(

CreateTerm creator = CreateTerm(subst, definition, block, Module, false);
llvm::Value *retval = creator(pattern).first;
if (funcType->getReturnType()
== llvm::PointerType::get(retval->getType(), (unsigned)returnCat.cat)) {
auto tempAlloc = allocateTerm(
returnCat, retval->getType(), creator.getCurrentBlock(),
"koreAllocAlwaysGC");
new llvm::StoreInst(retval, tempAlloc, creator.getCurrentBlock());
retval = tempAlloc;
if (funcType->getReturnType()->isPointerTy())
if (funcType->getReturnType()->getPointerElementType() == retval->getType()) {
auto tempAlloc = allocateTerm(
returnCat, retval->getType(), creator.getCurrentBlock(),
"koreAllocAlwaysGC");
new llvm::StoreInst(retval, tempAlloc, creator.getCurrentBlock());
retval = tempAlloc;
}
if (bigStep) {
llvm::Type *blockType = getValueType({SortCategory::Symbol, 0}, Module);
Expand Down Expand Up @@ -1284,7 +1284,7 @@ std::string makeApplyRuleFunction(
case SortCategory::Map:
case SortCategory::List:
case SortCategory::Set:
paramType = llvm::PointerType::get(paramType, (unsigned)cat.cat);
paramType = llvm::PointerType::get(paramType, (unsigned)SortCategory::Symbol);
break;
default: break;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/codegen/Decision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ void makeEvalOrAnywhereFunction(
case SortCategory::Map:
case SortCategory::List:
case SortCategory::Set:
args.push_back(llvm::PointerType::get(getValueType(cat, module), (unsigned)cat.cat));
args.push_back(llvm::PointerType::get(getValueType(cat, module), (unsigned)SortCategory::Symbol));
cats.push_back(cat);
break;
default:
Expand Down Expand Up @@ -990,7 +990,7 @@ void makeStepFunction(
case SortCategory::Map:
case SortCategory::List:
case SortCategory::Set:
argTypes.push_back(llvm::PointerType::get(getValueType(cat, module), (unsigned)cat.cat));
argTypes.push_back(llvm::PointerType::get(getValueType(cat, module), (unsigned)SortCategory::Symbol));
break;
default: argTypes.push_back(getValueType(cat, module)); break;
}
Expand Down
16 changes: 8 additions & 8 deletions lib/codegen/DecisionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ class DTPreprocessor {
auto child = (*this)(get(node, "next"));

assert(cat == "SET.Set" || cat == "MAP.Map");
unsigned addrspace =
(unsigned)(cat == "SET.Set" ? SortCategory::SetIterator
: SortCategory::MapIterator);
// unsigned addrspace =
// (unsigned)(cat == "SET.Set" ? SortCategory::SetIterator
// : SortCategory::MapIterator);

return MakeIteratorNode::Create(
name, type, name + "_iter",
llvm::PointerType::get(
getTypeByName(mod, cat == "SET.Set" ? "setiter" : "mapiter"), addrspace),
getTypeByName(mod, cat == "SET.Set" ? "setiter" : "mapiter"), (unsigned)SortCategory::Symbol),
function, child);
}

Expand All @@ -229,16 +229,16 @@ class DTPreprocessor {
auto child = (*this)(get(node, "next"));

assert(function == "set_iterator_next" || function == "map_iterator_next");
unsigned addrspace =
(unsigned)(function == "set_iterator_next" ? SortCategory::SetIterator
: SortCategory::MapIterator);
// unsigned addrspace =
// (unsigned)(function == "set_iterator_next" ? SortCategory::SetIterator
// : SortCategory::MapIterator);

return IterNextNode::Create(
iterator,
llvm::PointerType::get(
getTypeByName(
mod, function == "set_iterator_next" ? "setiter" : "mapiter"),
addrspace),
(unsigned)SortCategory::Symbol),
name, type, function, child);
}

Expand Down
18 changes: 9 additions & 9 deletions lib/codegen/EmitConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ static llvm::Value *getArgValue(
case SortCategory::List:
case SortCategory::Set:
arg = new llvm::BitCastInst(
addrspaceCast(arg, CaseBlock, 0, (unsigned)cat.cat),
llvm::PointerType::get(getValueType(cat, mod), (unsigned)cat.cat), "", CaseBlock);
addrspaceCast(arg, CaseBlock, 0, (unsigned)SortCategory::Symbol),
llvm::PointerType::get(getValueType(cat, mod), (unsigned)SortCategory::Symbol), "", CaseBlock);
break;
case SortCategory::Int:
case SortCategory::Float:
Expand Down Expand Up @@ -351,17 +351,17 @@ static std::pair<llvm::Value *, llvm::BasicBlock *> getEval(
case SortCategory::Int:
case SortCategory::Float:
case SortCategory::StringBuffer:
case SortCategory::Symbol:
case SortCategory::Map:
case SortCategory::List:
case SortCategory::Set:
retval = addrspaceCast(
new llvm::BitCastInst(
result, llvm::Type::getInt8PtrTy(Ctx, (unsigned)cat.cat), "",
creator.getCurrentBlock()),
creator.getCurrentBlock(), (unsigned)cat.cat, 0);
break;
case SortCategory::Symbol:
case SortCategory::Variable:
case SortCategory::Map:
case SortCategory::List:
case SortCategory::Set:
retval = addrspaceCast(
new llvm::BitCastInst(
result, llvm::Type::getInt8PtrTy(Ctx, (unsigned)SortCategory::Symbol), "",
Expand Down Expand Up @@ -708,17 +708,17 @@ makePackedVisitorStructureType(llvm::LLVMContext &Ctx, llvm::Module *module) {
makeVisitorType(
Ctx, file,
llvm::PointerType::get(
getValueType({SortCategory::Map, 0}, module), (unsigned)SortCategory::Map),
getValueType({SortCategory::Map, 0}, module), (unsigned)SortCategory::Symbol),
3, 0),
makeVisitorType(
Ctx, file,
llvm::PointerType::get(
getValueType({SortCategory::List, 0}, module), (unsigned)SortCategory::List),
getValueType({SortCategory::List, 0}, module), (unsigned)SortCategory::Symbol),
3, 0),
makeVisitorType(
Ctx, file,
llvm::PointerType::get(
getValueType({SortCategory::Set, 0}, module), (unsigned)SortCategory::Set),
getValueType({SortCategory::Set, 0}, module), (unsigned)SortCategory::Symbol),
3, 0),
makeVisitorType(
Ctx, file, getValueType({SortCategory::Int, 0}, module), 1, 0),
Expand Down
10 changes: 5 additions & 5 deletions runtime/alloc/alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,27 @@ __attribute__((always_inline)) void *koreAllocAlwaysGC(size_t requested) {
}

__attribute__((always_inline)) map *
koreAllocAlwaysGC_p1s_maps(size_t requested) {
koreAllocAlwaysGC_p8s_maps(size_t requested) {
return (map *)koreAllocAlwaysGC(requested);
}

__attribute__((always_inline)) set *
koreAllocAlwaysGC_p3s_sets(size_t requested) {
koreAllocAlwaysGC_p8s_sets(size_t requested) {
return (set *)koreAllocAlwaysGC(requested);
}

__attribute__((always_inline)) list *
koreAllocAlwaysGC_p2s_lists(size_t requested) {
koreAllocAlwaysGC_p8s_lists(size_t requested) {
return (list *)koreAllocAlwaysGC(requested);
}

__attribute__((always_inline)) setiter *
koreAllocAlwaysGC_p11s_setiters(size_t requested) {
koreAllocAlwaysGC_p8s_setiters(size_t requested) {
return (setiter *)koreAllocAlwaysGC(requested);
}

__attribute__((always_inline)) mapiter *
koreAllocAlwaysGC_p12s_mapiters(size_t requested) {
koreAllocAlwaysGC_p8s_mapiters(size_t requested) {
return (mapiter *)koreAllocAlwaysGC(requested);
}

Expand Down
101 changes: 78 additions & 23 deletions runtime/opaque/opaque.ll
Original file line number Diff line number Diff line change
Expand Up @@ -43,48 +43,103 @@ define %floating addrspace(5)* @addrspace_0_to_5_s_floatings(%floating* %in) #0
ret %floating addrspace(5)* %out
}

define %map addrspace(1)* @addrspace_0_to_1_s_maps(%map* %in) #0 {
%out = addrspacecast %map* %in to %map addrspace(1)*
ret %map addrspace(1)* %out
define %map addrspace(8)* @addrspace_0_to_8_s_maps(%map* %in) #0 {
%out = addrspacecast %map* %in to %map addrspace(8)*
ret %map addrspace(8)* %out
}

define %list addrspace(2)* @addrspace_0_to_2_s_lists(%list* %in) #0 {
%out = addrspacecast %list* %in to %list addrspace(2)*
ret %list addrspace(2)* %out
define %list addrspace(8)* @addrspace_0_to_2_s_lists(%list* %in) #0 {
%out = addrspacecast %list* %in to %list addrspace(8)*
ret %list addrspace(8)* %out
}

define %set addrspace(3)* @addrspace_0_to_3_s_sets(%set* %in) #0 {
%out = addrspacecast %set* %in to %set addrspace(3)*
ret %set addrspace(3)* %out
define %set addrspace(8)* @addrspace_0_to_3_s_sets(%set* %in) #0 {
%out = addrspacecast %set* %in to %set addrspace(8)*
ret %set addrspace(8)* %out
}

define %string addrspace(1)* @addrspace_0_to_1_s_strings(%string* %in) #0 {
%out = addrspacecast %string* %in to %string addrspace(1)*
ret %string addrspace(1)* %out
}

define i8 addrspace(1)* @addrspace_0_to_1_i8(i8* %in) #0 {
%out = addrspacecast i8* %in to i8 addrspace(1)*
ret i8 addrspace(1)* %out
define i8 addrspace(4)* @addrspace_0_to_4_i8(i8* %in) #0 {
%out = addrspacecast i8* %in to i8 addrspace(4)*
ret i8 addrspace(4)* %out
}

define i1 addrspace(1)* @addrspace_0_to_1_i1(i1* %in) #0 {
%out = addrspacecast i1* %in to i1 addrspace(1)*
ret i1 addrspace(1)* %out
define i8 addrspace(5)* @addrspace_0_to_5_i8(i8* %in) #0 {
%out = addrspacecast i8* %in to i8 addrspace(5)*
ret i8 addrspace(5)* %out
}

define i32 addrspace(1)* @addrspace_0_to_1_i32(i32* %in) #0 {
%out = addrspacecast i32* %in to i32 addrspace(1)*
ret i32 addrspace(1)* %out
define i8 addrspace(6)* @addrspace_0_to_6_i8(i8* %in) #0 {
%out = addrspacecast i8* %in to i8 addrspace(6)*
ret i8 addrspace(6)* %out
}

define i64 addrspace(1)* @addrspace_0_to_1_i64(i64* %in) #0 {
%out = addrspacecast i64* %in to i64 addrspace(1)*
ret i64 addrspace(1)* %out
define i8 addrspace(7)* @addrspace_0_to_7_i8(i8* %in) #0 {
%out = addrspacecast i8* %in to i8 addrspace(7)*
ret i8 addrspace(7)* %out
}

define i8* @addrspace_1_to_0_i8(i8 addrspace(1)* %in) #0 {
%out = addrspacecast i8 addrspace(1)* %in to i8*
define i8 addrspace(8)* @addrspace_0_to_8_i8(i8* %in) #0 {
%out = addrspacecast i8* %in to i8 addrspace(8)*
ret i8 addrspace(8)* %out
}

define i8 addrspace(10)* @addrspace_0_to_10_i8(i8* %in) #0 {
%out = addrspacecast i8* %in to i8 addrspace(10)*
ret i8 addrspace(10)* %out
}

define i1 addrspace(4)* @addrspace_0_to_4_i1(i1* %in) #0 {
%out = addrspacecast i1* %in to i1 addrspace(4)*
ret i1 addrspace(4)* %out
}

define i1 addrspace(5)* @addrspace_0_to_5_i1(i1* %in) #0 {
%out = addrspacecast i1* %in to i1 addrspace(5)*
ret i1 addrspace(5)* %out
}

define i32 addrspace(4)* @addrspace_0_to_4_i32(i32* %in) #0 {
%out = addrspacecast i32* %in to i32 addrspace(4)*
ret i32 addrspace(4)* %out
}

define i32 addrspace(5)* @addrspace_0_to_5_i32(i32* %in) #0 {
%out = addrspacecast i32* %in to i32 addrspace(5)*
ret i32 addrspace(5)* %out
}

define i64 addrspace(4)* @addrspace_0_to_4_i64(i64* %in) #0 {
%out = addrspacecast i64* %in to i64 addrspace(4)*
ret i64 addrspace(4)* %out
}

define i64 addrspace(5)* @addrspace_0_to_5_i64(i64* %in) #0 {
%out = addrspacecast i64* %in to i64 addrspace(5)*
ret i64 addrspace(5)* %out
}

define i8* @addrspace_4_to_0_i8(i8 addrspace(4)* %in) #0 {
%out = addrspacecast i8 addrspace(4)* %in to i8*
ret i8* %out
}

define i8* @addrspace_5_to_0_i8(i8 addrspace(5)* %in) #0 {
%out = addrspacecast i8 addrspace(5)* %in to i8*
ret i8* %out
}

define i8* @addrspace_6_to_0_i8(i8 addrspace(6)* %in) #0 {
%out = addrspacecast i8 addrspace(6)* %in to i8*
ret i8* %out
}

define i8* @addrspace_8_to_0_i8(i8 addrspace(8)* %in) #0 {
%out = addrspacecast i8 addrspace(8)* %in to i8*
ret i8* %out
}

Expand Down

0 comments on commit e022389

Please sign in to comment.