retdec
llvm_support.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_LLVMIR2HLL_LLVM_LLVM_SUPPORT_H
8 #define RETDEC_LLVMIR2HLL_LLVM_LLVM_SUPPORT_H
9 
10 #include <cstdint>
11 #include <set>
12 #include <string>
13 
15 
16 namespace llvm {
17 
18 class AllocaInst;
19 class BasicBlock;
20 class ConstantArray;
21 class GlobalVariable;
22 class Instruction;
23 class Module;
24 class Value;
25 
26 } // namespace llvm
27 
28 namespace retdec {
29 namespace llvmir2hll {
30 
37 class LLVMSupport {
38 public:
39  static std::size_t getNumberOfUniquePredecessors(llvm::BasicBlock *bb);
40  static bool isPredecessorOf(llvm::BasicBlock *pred, llvm::BasicBlock *bb);
41  static bool isInlineAsm(const llvm::Instruction *i);
42  static bool isInlinableInst(const llvm::Instruction *i);
43  static const llvm::AllocaInst *isDirectAlloca(const llvm::Value *v);
44  static bool endsWithRetOrUnreach(llvm::BasicBlock *bb, bool indirect = true);
45  static bool endWithSameUncondBranch(llvm::BasicBlock *bb1, llvm::BasicBlock *bb2);
46  static const llvm::Module *getModuleFromValue(const llvm::Value *v);
47  static std::string getBasicBlockLabelPrefix();
48  static bool isBasicBlockLabel(const std::string &str);
49  static Address getInstAddress(const llvm::Instruction *i);
50 
51 public:
52  // Disable both constructors, destructor, and assignment operator.
53  // They are declared public to make diagnostics messages more precise.
54  LLVMSupport() = delete;
55  LLVMSupport(const LLVMSupport &) = delete;
56  ~LLVMSupport() = delete;
57  LLVMSupport &operator=(const LLVMSupport &) = delete;
58 
59 private:
61  using BasicBlockSet = std::set<llvm::BasicBlock *>;
62 
63 private:
64 
65  static bool endsWithRetOrUnreachImpl(llvm::BasicBlock *bb, bool indirect);
66 
67 private:
71 };
72 
73 } // namespace llvmir2hll
74 } // namespace retdec
75 
76 #endif
Definition: address.h:21
Supportive functions regarding LLVM IR.
Definition: llvm_support.h:37
static bool isPredecessorOf(llvm::BasicBlock *pred, llvm::BasicBlock *bb)
Returns true if pred is a predecessor of bb, false otherwise.
Definition: llvm_support.cpp:57
static bool isBasicBlockLabel(const std::string &str)
Returns true if str has the format of a basic block's label in LLVM IR, false otherwise.
Definition: llvm_support.cpp:293
static bool endWithSameUncondBranch(llvm::BasicBlock *bb1, llvm::BasicBlock *bb2)
Returns true if both bb1 and bb2 end with an unconditional branch to the same basic block,...
Definition: llvm_support.cpp:241
static const llvm::Module * getModuleFromValue(const llvm::Value *v)
Returns the LLVM module corresponding to the given value v.
Definition: llvm_support.cpp:259
static std::size_t getNumberOfUniquePredecessors(llvm::BasicBlock *bb)
Returns the number of unique predecessors of the given basic block.
Definition: llvm_support.cpp:40
std::set< llvm::BasicBlock * > BasicBlockSet
Set of basic blocks.
Definition: llvm_support.h:61
static std::string getBasicBlockLabelPrefix()
Returns the used prefix of labels in LLVM IR.
Definition: llvm_support.cpp:285
static bool isInlinableInst(const llvm::Instruction *i)
Returns true if the given LLVM instruction i is inlinable, false otherwise.
Definition: llvm_support.cpp:96
static const llvm::AllocaInst * isDirectAlloca(const llvm::Value *v)
If v is a direct alloca, it returns v converted into an alloca instruction. Otherwise,...
Definition: llvm_support.cpp:168
static Address getInstAddress(const llvm::Instruction *i)
Get instruction's ASM address from metadata.
Definition: llvm_support.cpp:308
static bool endsWithRetOrUnreachImpl(llvm::BasicBlock *bb, bool indirect)
Implementation of endsWithRetOrUnreach().
Definition: llvm_support.cpp:210
static BasicBlockSet endsWithRetOrUnreachBBSet
Definition: llvm_support.h:70
static bool isInlineAsm(const llvm::Instruction *i)
Returns true if the given LLVM instruction i is a call to an inline asm chunk, false otherwise.
Definition: llvm_support.cpp:76
LLVMSupport & operator=(const LLVMSupport &)=delete
static bool endsWithRetOrUnreach(llvm::BasicBlock *bb, bool indirect=true)
Returns true if bb (indirectly) ends with a return or an unreachable instruction, false otherwise.
Definition: llvm_support.cpp:193
LLVMSupport(const LLVMSupport &)=delete
Definition: itanium_ast_ctypes_parser.h:12
A library providing API for working with back-end IR.
Definition: archive_wrapper.h:19
Aliases for several useful types.