blob: 7aae2a5592e96175e4d800b881c777a75050cc3f [file] [log] [blame]
Tom Roeder44cb65f2014-06-05 19:29:43 +00001//===-- JumpInstrTableInfo.cpp: Info for Jump-Instruction Tables ----------===//
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#define DEBUG_TYPE "jiti"
15
16#include "llvm/Analysis/JumpInstrTableInfo.h"
17#include "llvm/Analysis/Passes.h"
18#include "llvm/IR/Function.h"
19#include "llvm/IR/Type.h"
Tom Roedereb7a3032014-11-11 21:08:02 +000020#include "llvm/Support/MathExtras.h"
Tom Roeder44cb65f2014-06-05 19:29:43 +000021
22using namespace llvm;
23
24INITIALIZE_PASS(JumpInstrTableInfo, "jump-instr-table-info",
25 "Jump-Instruction Table Info", true, true)
26char JumpInstrTableInfo::ID = 0;
27
28ImmutablePass *llvm::createJumpInstrTableInfoPass() {
29 return new JumpInstrTableInfo();
30}
31
Tom Roedereb7a3032014-11-11 21:08:02 +000032ModulePass *llvm::createJumpInstrTableInfoPass(unsigned Bound) {
33 // This cast is always safe, since Bound is always in a subset of uint64_t.
34 uint64_t B = static_cast<uint64_t>(Bound);
35 return new JumpInstrTableInfo(B);
36}
37
38JumpInstrTableInfo::JumpInstrTableInfo(uint64_t ByteAlign)
39 : ImmutablePass(ID), Tables(), ByteAlignment(ByteAlign) {
40 if (!llvm::isPowerOf2_64(ByteAlign)) {
41 // Note that we don't explicitly handle overflow here, since we handle the 0
42 // case explicitly when a caller actually tries to create jumptable entries,
43 // and this is the return value on overflow.
44 ByteAlignment = llvm::NextPowerOf2(ByteAlign);
45 }
46
Tom Roeder44cb65f2014-06-05 19:29:43 +000047 initializeJumpInstrTableInfoPass(*PassRegistry::getPassRegistry());
48}
49
50JumpInstrTableInfo::~JumpInstrTableInfo() {}
51
52void JumpInstrTableInfo::insertEntry(FunctionType *TableFunTy, Function *Target,
53 Function *Jump) {
54 Tables[TableFunTy].push_back(JumpPair(Target, Jump));
55}