-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
--mutable-bytes
flag to enable possibly unsound optimizations (#…
…962) This PR adds a flag to `llvm-kompile` that enables semantics used by the LLVM backend that are unsound in certain scenarios, but are useful for performance (making objects of sort `Bytes` copy-on-write rather than mutable). The numerous edge cases from my initial attempt to fix this issue in #950 are retained as test cases here. Fixes #930 Blocked until we have propagated runtimeverification/k#3934 appropriately to downstream semantics.
- Loading branch information
Showing
37 changed files
with
16,160 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef KLLVM_CODEGEN_H | ||
#define KLLVM_CODEGEN_H | ||
|
||
#include <llvm/IR/LLVMContext.h> | ||
#include <llvm/IR/Module.h> | ||
|
||
#include <string> | ||
|
||
namespace kllvm { | ||
|
||
void addKompiledDirSymbol( | ||
llvm::Module &mod, std::string const &dir, bool debug); | ||
|
||
void addMutableBytesFlag(llvm::Module &mod, bool enabled, bool debug); | ||
|
||
} // namespace kllvm | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <kllvm/codegen/Debug.h> | ||
#include <kllvm/codegen/Metadata.h> | ||
|
||
#include <llvm/IR/Constants.h> | ||
#include <llvm/IR/LLVMContext.h> | ||
#include <llvm/IR/Module.h> | ||
#include <llvm/IR/Type.h> | ||
|
||
namespace kllvm { | ||
|
||
static std::string KOMPILED_DIR = "kompiled_directory"; | ||
static std::string STRICT_BYTES = "enable_mutable_bytes"; | ||
|
||
void addKompiledDirSymbol( | ||
llvm::Module &mod, std::string const &dir, bool debug) { | ||
auto &ctx = mod.getContext(); | ||
|
||
auto *str = llvm::ConstantDataArray::getString(ctx, dir, true); | ||
|
||
auto *global = mod.getOrInsertGlobal(KOMPILED_DIR, str->getType()); | ||
auto *global_var = llvm::cast<llvm::GlobalVariable>(global); | ||
|
||
if (!global_var->hasInitializer()) { | ||
global_var->setInitializer(str); | ||
} | ||
|
||
if (debug) { | ||
initDebugGlobal(KOMPILED_DIR, getCharDebugType(), global_var); | ||
} | ||
} | ||
|
||
void addMutableBytesFlag(llvm::Module &mod, bool enabled, bool debug) { | ||
auto &ctx = mod.getContext(); | ||
|
||
auto *i1_ty = llvm::Type::getInt1Ty(ctx); | ||
auto *enabled_cst = llvm::ConstantInt::getBool(ctx, enabled); | ||
|
||
auto *global = mod.getOrInsertGlobal(STRICT_BYTES, i1_ty); | ||
auto *global_var = llvm::cast<llvm::GlobalVariable>(global); | ||
|
||
if (!global_var->hasInitializer()) { | ||
global_var->setInitializer(enabled_cst); | ||
} | ||
|
||
if (debug) { | ||
initDebugGlobal(STRICT_BYTES, getBoolDebugType(), global_var); | ||
} | ||
} | ||
|
||
} // namespace kllvm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
add_library(strings STATIC | ||
strings.cpp | ||
bytes.cpp | ||
copy_on_write.cpp | ||
) | ||
|
||
target_link_libraries(strings | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <runtime/header.h> | ||
|
||
extern "C" bool enable_mutable_bytes; | ||
|
||
namespace { | ||
|
||
SortBytes copy_bytes(SortBytes b) { | ||
auto new_len = len(b); | ||
auto *ret = static_cast<string *>(koreAllocToken(sizeof(string) + new_len)); | ||
init_with_len(ret, new_len); | ||
memcpy(&(ret->data), &(b->data), new_len * sizeof(char)); | ||
return ret; | ||
} | ||
|
||
} // namespace | ||
|
||
extern "C" bool hook_BYTES_mutableBytesEnabled() { | ||
return enable_mutable_bytes; | ||
} | ||
|
||
void copy_if_needed(SortBytes &b) { | ||
if (!hook_BYTES_mutableBytesEnabled()) { | ||
b = copy_bytes(b); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.