Any entity from LLVM IR can be easily converted into an alias token that acts like a unified abstraction.
For example the operands of an instruction, x = load y
can be abstracted into two alias tokens x
and y
.
$ git clone this_repository.git
$ cd this_repository
$ mkdir build; cd build
$ cmake .. && make
$ make install
- Path to shared libary and headers should be searchable by the compiler
- In your LLVM IR pass:
- Include the header file,
AliasToken/AliasToken.h
- Use namespace
AliasUtil
- Include the header file,
- Load libAliasToken.so before your pass's shared library
opt -load /usr/local/lib/libAliasToken.so -load yourPass.so ...
Alias Tokens can be generated for any LLVM IR's entity, below are some common use cases.
Directly creating new alias tokens from the entities is supported but not recommended until required as it requires to the alias token bank to avoid duplication of tokens. There are cases where we need to explicitly create a alias token example GEP instructions.
...
#include "AliasToken/AliasToken.h"
...
using namespace AliasUtil
...
for(llvm::StoreInst* SI = llvm::dyn_cast<llvm::StoreInst>(Inst)){
Alias * X = new Alias(SI -> getPointerOperand());
X = AT.getAliasToken(X);
}
AT
is an object ofAliasTokens
class and should be unique to a module. It store all the tokens for a single modulegetAliasToken
returns alias token fromAliasTokens
either by creating a new one or using the already existing one.
LibAliasToken provides abstraction for common LLVM IR instructions that can be used to generate alias tokens with out explicitly handling each operand.
...
#include "AliasToken/AliasToken.h"
...
using namespace AliasUtil
...
for(llvm::StoreInst* SI = llvm::dyn_cast<llvm::StoreInst>(Inst)){
auto StoreAliasVec = AT.extractAliasToken(SI);
// StoreAliasVec[0] is the alias token for SI -> getValueOperand()
// StoreAliasVec[1] is the alias token for SI -> getPointerOperand()
}
Creating of dummy alias token can be useful in few use cases. LibAliasToken supports generation of dummy alias token.
...
#include "AliasToken/AliasToken.h"
...
using namespace AliasUtil
...
AT.getAliasToken("?", nullptr) // Creates a dummy alias token with name ? and with global scope
Some commonly used instructions are supported directly and can be used as follows:
...
#include "AliasToken/AliasToken.h"
...
using namespace AliasUtil
...
auto AliasVec = AT.extractAliasToken(Inst);
// AT is the object of AliasTokens
// Inst is a pointer to llvm::Instruction
LoadInst
of syntax x = load y
can be extracted into {X, Y}
StoreInst
of syntax store x y
can be extracted into {X, Y}
BitCastInst
of syntax x = bitcast y
can be extracted into {X, Y}
AllocaInst
of syntax x = alloca
can be extracted into {X, Y}
where Y is a dummy node
ReturnInst
of syntax return X
can be extracted into {X}