1 //===-- JumpInstrTables.h: Jump-Instruction Tables --------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
9 /// \brief An implementation of tables consisting of jump instructions
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CODEGEN_JUMPINSTRTABLES_H
14 #define LLVM_CODEGEN_JUMPINSTRTABLES_H
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/Pass.h"
18 #include "llvm/Target/TargetOptions.h"
24 class JumpInstrTableInfo;
27 /// A class to manage a set of jump tables indexed on function type. It looks at
28 /// each function in the module to find all the functions that have the
29 /// jumptable attribute set. For each such function, it creates a new
30 /// jump-instruction-table function and stores the mapping in the ImmutablePass
31 /// JumpInstrTableInfo.
33 /// These special functions get lowered in AsmPrinter to assembly of the form:
42 /// Support for an architecture depends on two functions in TargetInstrInfo:
43 /// getUnconditionalBranch, and getTrap. AsmPrinter uses these to generate the
44 /// appropriate instructions for the jump statement (an unconditional branch)
45 /// and for padding to make the table have a size that is a power of two. This
46 /// padding uses a trap instruction to ensure that calls to this area halt the
47 /// program. The default implementations of these functions call
49 class JumpInstrTables : public ModulePass {
54 JumpInstrTables(JumpTable::JumpTableType JTT);
55 virtual ~JumpInstrTables();
56 bool runOnModule(Module &M) override;
57 const char *getPassName() const override { return "Jump-Instruction Tables"; }
58 void getAnalysisUsage(AnalysisUsage &AU) const override;
60 /// Creates a jump-instruction table function for the Target and adds it to
62 Function *insertEntry(Module &M, Function *Target);
64 /// Checks to see if there is already a table for the given FunctionType.
65 bool hasTable(FunctionType *FunTy);
68 /// The metadata used while a jump table is being built
70 /// The number of this table
73 /// The current number of jump entries in the table.
77 typedef DenseMap<FunctionType *, struct TableMeta> JumpMap;
79 /// Maps the function into a subset of function types, depending on the
80 /// jump-instruction table style selected from JumpTableTypes in
81 /// JumpInstrTables.cpp. The choice of mapping determines the number of
82 /// jump-instruction tables generated by this pass. E.g., the simplest mapping
83 /// converts every function type into void f(); so, all functions end up in a
85 FunctionType *transformType(FunctionType *FunTy);
87 /// The current state of functions and jump entries in the table(s).
90 /// The ImmutablePass that stores information about the generated tables.
91 JumpInstrTableInfo *JITI;
93 /// The total number of tables.
96 /// The type of tables to build.
97 JumpTable::JumpTableType JTType;
100 /// Creates a JumpInstrTables pass for the given type of jump table.
101 ModulePass *createJumpInstrTablesPass(JumpTable::JumpTableType JTT);
104 #endif /* LLVM_CODEGEN_JUMPINSTRTABLES_H */