forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Instrumentor] Add counter IDs #16
Open
EthanLuisMcDonough
wants to merge
37
commits into
jdoerfert:instrumentor_dev_rewrite
Choose a base branch
from
EthanLuisMcDonough:inst_dev_counters
base: instrumentor_dev_rewrite
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Instrumentor] Add counter IDs #16
EthanLuisMcDonough
wants to merge
37
commits into
jdoerfert:instrumentor_dev_rewrite
from
EthanLuisMcDonough:inst_dev_counters
Conversation
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
Both internally and externally we instrument code all the time. Usually, those are hand written traversals that look for some specific instructions or program points and then provide information to a runtime. Since the real difference is in the runtime, and the instrumentation is basically always the same, people can use this Instrumentor pass and configure it to their needs. Initial implementation only instruments alloca instructions but shows the setup, and configurability via a JSON file.
Following the alloca example, this adds store instruction instrumentation support. The following properties are captured: ``` void __instrumentor_store_pre(void* PointerOperand, int32_t PointerOperandAddressSpace, int64_t ValueOperand, int64_t ValueOperandSize, int32_t ValueOperandTypeId, int64_t Alignment, int32_t AtomicityOrdering, int8_t SyncScopeId, int8_t IsVolatile); void __instrumentor_store_pre_ind(void* PointerOperand, int32_t PointerOperandAddressSpace, void* ValueOperandStorage, int64_t ValueOperandSize, int32_t ValueOperandTypeId, int64_t Alignment, int32_t AtomicityOrdering, int8_t SyncScopeId, int8_t IsVolatile); ```
Following the store example, this adds load instruction instrumentation support. The following properties are captured: ``` void __instrumentor_pre_load(void* PointerOperand, int32_t PointerOperandAddressSpace, int64_t ValueSize, int32_t ValueTypeId, int64_t Alignment, int32_t AtomicityOrdering, int8_t SyncScopeId, int8_t IsVolatile); int64_t __instrumentor_post_load(void* PointerOperand, int32_t PointerOperandAddressSpace, int64_t Value, int64_t ValueSize, int32_t ValueTypeId, int64_t Alignment, int32_t AtomicityOrdering, int8_t SyncScopeId, int8_t IsVolatile); void __instrumentor_post_load_ind(void* PointerOperand, int32_t PointerOperandAddressSpace, void* ValueStorage, int64_t ValueSize, int32_t ValueTypeId, int64_t Alignment, int32_t AtomicityOrdering, int8_t SyncScopeId, int8_t IsVolatile); ```
This adds allocation call instrumentation support by exposing more of the memory builtin information, notably, non constant information. The following properties are captured: ``` void __instrumentor_post_allocation_call(void* MemoryPointer, int64_t MemorySize, int32_t Alignment, void /*char*/ * Family, int8_t InitialValue); void* __instrumentor_post_allocation_call(void* MemoryPointer, int64_t MemorySize, int32_t Alignment, void /*char*/ * Family, int8_t InitialValue); ```
Passing the arguments -Xclang -finstrumentor enables the instrumentor pass when compiling with Clang.
Features and optimizations: - Instrumentation of call arguments (pointers) - Instrumentation of base pointers - Instrumentation of globals - Skip loads and stores that are known to be safe at compile time - Passing base pointer info to load and store instrumentation calls
The arguments of the main function instrumentation are both pointers. We call the instrumentation function passing the pointers to the argc and argv arguments, so the instrumentation implementation can modify them.
A instrumentor database file contains the names of the functions and global variables that have been instrumented for a particular LLVM module. The database file is named as "<module-name>.instrdb". The -mllvm -instrumentor-read-database-dir=DIR allows loading the database files of other instrumented modules that are stored in the directory DIR. The -mllvm -instrumentor-write-database-dir=DIR allows writing the instrumented functions and globals from the current module in a database file in the directory DIR. If these flags are not specified, no database is read or written.
The call instrumentation was not working properly for globals and accesses that were marked as compile-time safe (e.g., constant offset on a alloca). This commit fixes that and removes the need for annotations. The option OnlyReplacedPointerValues in the call instrumentation is an optimzation to avoid passing non-pointer arguments and pointer arguments that were not replaced by another runtime call. This is very useful for the use case of the address sanitizer.
The reuse of temporary allocas for runtime calls did not consider when a call can use more than one alloca with the same total size. In that case, both were trying to use the same allocas, producing invalid IR. Now, we allow more than one alloca for each size. Each RTArgumentPack holds the temporary allocas that are used for a particular runtime call. Once the object is destroyed, these allocas are returned for reuse.
The OperandValueSize parameter is the number of bytes being stored instead of the number of bits.
b92a11a
to
dfa9b6a
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces the
add_call_counters
base configuration option. When enabled, this option will add an ID parameter to the end of each instrumentor function. Each instrumentation opportunity will have its own unique ID associated with it.