1 //===-- JumpInstrTableInfo.h: Info for Jump-Instruction Tables --*- C++ -*-===// 2 // 3 // This file is distributed under the University of Illinois Open Source 4 // License. See LICENSE.TXT for details. 5 // 6 //===----------------------------------------------------------------------===// 7 /// 8 /// \file 9 /// \brief Information about jump-instruction tables that have been created by 10 /// JumpInstrTables pass. 11 /// 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_ANALYSIS_JUMPINSTRTABLEINFO_H 15 #define LLVM_ANALYSIS_JUMPINSTRTABLEINFO_H 16 17 #include "llvm/ADT/DenseMap.h" 18 #include "llvm/Pass.h" 19 #include <vector> 20 21 namespace llvm { 22 class Function; 23 class FunctionType; 24 25 /// This class stores information about jump-instruction tables created by the 26 /// JumpInstrTables pass (in lib/CodeGen/JumpInstrTables.cpp). Each table is a 27 /// map from a function type to a vector of pairs. The first element of each 28 /// pair is the function that has the jumptable annotation. The second element 29 /// is a function that was declared by JumpInstrTables and used to replace all 30 /// address-taking sites for the original function. 31 /// 32 /// The information in this pass is used in AsmPrinter 33 /// (lib/CodeGen/AsmPrinter/AsmPrinter.cpp) to generate the required assembly 34 /// for the jump-instruction tables. 35 class JumpInstrTableInfo : public ImmutablePass { 36 public: 37 static char ID; 38 39 /// The default byte alignment for jump tables is 16, which is large but 40 /// usually safe. 41 JumpInstrTableInfo(uint64_t ByteAlign = 16); 42 ~JumpInstrTableInfo() override; getPassName()43 const char *getPassName() const override { 44 return "Jump-Instruction Table Info"; 45 } 46 47 typedef std::pair<Function *, Function *> JumpPair; 48 typedef DenseMap<FunctionType *, std::vector<JumpPair> > JumpTables; 49 50 /// Inserts an entry in a table, adding the table if it doesn't exist. 51 void insertEntry(FunctionType *TableFunTy, Function *Target, Function *Jump); 52 53 /// Gets the tables. getTables()54 const JumpTables &getTables() const { return Tables; } 55 56 /// Gets the alignment in bytes of a jumptable entry. entryByteAlignment()57 uint64_t entryByteAlignment() const { return ByteAlignment; } 58 private: 59 JumpTables Tables; 60 61 /// A power-of-two alignment of a jumptable entry. 62 uint64_t ByteAlignment; 63 }; 64 65 /// Creates a JumpInstrTableInfo pass with the given bound on entry size. This 66 /// bound specifies the maximum number of bytes needed to represent an 67 /// unconditional jump or a trap instruction in the back end currently in use. 68 ModulePass *createJumpInstrTableInfoPass(unsigned Bound); 69 } 70 71 #endif /* LLVM_ANALYSIS_JUMPINSTRTABLEINFO_H */ 72