[llvm-commits] CVS: llvm/include/llvm/CodeGen/MachineJumpTableInfo.h AsmPrinter.h MachineCodeEmitter.h MachineFunction.h MachineInstr.h ScheduleDAG.h SelectionDAG.h SelectionDAGISel.h SelectionDAGNodes.h
Nate Begeman
natebegeman at mac.com
Sat Apr 22 11:54:03 PDT 2006
Changes in directory llvm/include/llvm/CodeGen:
MachineJumpTableInfo.h added (r1.1)
AsmPrinter.h updated: 1.31 -> 1.32
MachineCodeEmitter.h updated: 1.28 -> 1.29
MachineFunction.h updated: 1.58 -> 1.59
MachineInstr.h updated: 1.167 -> 1.168
ScheduleDAG.h updated: 1.22 -> 1.23
SelectionDAG.h updated: 1.100 -> 1.101
SelectionDAGISel.h updated: 1.12 -> 1.13
SelectionDAGNodes.h updated: 1.129 -> 1.130
---
Log message:
JumpTable support! What this represents is working asm and jit support for
x86 and ppc for 100% dense switch statements when relocations are non-PIC.
This support will be extended and enhanced in the coming days to support
PIC, and less dense forms of jump tables.
---
Diffs of the changes: (+181 -4)
AsmPrinter.h | 14 +++++++++
MachineCodeEmitter.h | 18 ++++++++++++
MachineFunction.h | 10 ++++++
MachineInstr.h | 18 +++++++++++-
MachineJumpTableInfo.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++++
ScheduleDAG.h | 1
SelectionDAG.h | 5 ++-
SelectionDAGISel.h | 20 ++++++++++++-
SelectionDAGNodes.h | 26 ++++++++++++++++-
9 files changed, 181 insertions(+), 4 deletions(-)
Index: llvm/include/llvm/CodeGen/MachineJumpTableInfo.h
diff -c /dev/null llvm/include/llvm/CodeGen/MachineJumpTableInfo.h:1.1
*** /dev/null Sat Apr 22 13:53:55 2006
--- llvm/include/llvm/CodeGen/MachineJumpTableInfo.h Sat Apr 22 13:53:45 2006
***************
*** 0 ****
--- 1,73 ----
+ //===-- CodeGen/MachineJumpTableInfo.h - Abstract Jump Tables --*- C++ -*-===//
+ //
+ // The LLVM Compiler Infrastructure
+ //
+ // This file was developed by Nate Begeman and is distributed under the
+ // University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // The MachineJumpTableInfo class keeps track of jump tables referenced by
+ // lowered switch instructions in the MachineFunction.
+ //
+ // Instructions reference the address of these jump tables through the use of
+ // MO_JumpTableIndex values. When emitting assembly or machine code, these
+ // virtual address references are converted to refer to the address of the
+ // function jump tables.
+ //
+ //===----------------------------------------------------------------------===//
+
+ #ifndef LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
+ #define LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
+
+ #include "llvm/Target/TargetData.h"
+ #include <vector>
+ #include <iosfwd>
+
+ namespace llvm {
+
+ class MachineBasicBlock;
+
+ /// MachineJumpTableEntry - One jump table in the jump table info.
+ ///
+ struct MachineJumpTableEntry {
+ /// MBBs - The vector of basic blocks from which to create the jump table.
+ std::vector<MachineBasicBlock*> MBBs;
+
+ MachineJumpTableEntry(std::vector<MachineBasicBlock*> &M) : MBBs(M) {}
+ };
+
+ class MachineJumpTableInfo {
+ const TargetData &TD;
+ std::vector<MachineJumpTableEntry> JumpTables;
+ public:
+ MachineJumpTableInfo(const TargetData &td) : TD(td) {}
+
+ /// getJumpTableIndex - Create a new jump table or return an existing one.
+ ///
+ unsigned getJumpTableIndex(std::vector<MachineBasicBlock*> &DestBBs);
+
+ /// isEmpty - Return true if there are no jump tables.
+ ///
+ bool isEmpty() const { return JumpTables.empty(); }
+
+ const std::vector<MachineJumpTableEntry> &getJumpTables() const {
+ return JumpTables;
+ }
+
+ unsigned getEntrySize() const { return TD.getPointerSize(); }
+ unsigned getAlignment() const { return TD.getPointerAlignment(); }
+
+ /// print - Used by the MachineFunction printer to print information about
+ /// jump tables. Implemented in MachineFunction.cpp
+ ///
+ void print(std::ostream &OS) const;
+
+ /// dump - Call print(std::cerr) to be called from the debugger.
+ ///
+ void dump() const;
+ };
+
+ } // End llvm namespace
+
+ #endif
Index: llvm/include/llvm/CodeGen/AsmPrinter.h
diff -u llvm/include/llvm/CodeGen/AsmPrinter.h:1.31 llvm/include/llvm/CodeGen/AsmPrinter.h:1.32
--- llvm/include/llvm/CodeGen/AsmPrinter.h:1.31 Fri Feb 24 14:21:12 2006
+++ llvm/include/llvm/CodeGen/AsmPrinter.h Sat Apr 22 13:53:45 2006
@@ -140,6 +140,10 @@
/// before emitting the constant pool for a function.
const char *ConstantPoolSection; // Defaults to "\t.section .rodata\n"
+ /// JumpTableSection - This is the section that we SwitchToSection right
+ /// before emitting the jump tables for a function.
+ const char *JumpTableSection; // Defaults to "\t.section .rodata\n"
+
/// StaticCtorsSection - This is the directive that is emitted to switch to
/// a section to emit the static constructor list.
/// Defaults to "\t.section .ctors,\"aw\", at progbits".
@@ -231,6 +235,11 @@
///
void EmitConstantPool(MachineConstantPool *MCP);
+ /// EmitJumpTableInfo - Print assembly representations of the jump tables
+ /// used by the current function to the current output stream.
+ ///
+ void EmitJumpTableInfo(MachineJumpTableInfo *MJTI);
+
/// EmitSpecialLLVMGlobal - Check to see if the specified global is a
/// special global used by LLVM. If so, emit it and return true, otherwise
/// do nothing and return false.
@@ -257,6 +266,11 @@
/// printInlineAsm - This method formats and prints the specified machine
/// instruction that is an inline asm.
void printInlineAsm(const MachineInstr *MI) const;
+
+ /// printBasicBlockLabel - This method prints the label for the specified
+ /// MachineBasicBlock
+ virtual void printBasicBlockLabel(const MachineBasicBlock *MBB) const;
+
private:
void EmitXXStructorList(Constant *List);
Index: llvm/include/llvm/CodeGen/MachineCodeEmitter.h
diff -u llvm/include/llvm/CodeGen/MachineCodeEmitter.h:1.28 llvm/include/llvm/CodeGen/MachineCodeEmitter.h:1.29
--- llvm/include/llvm/CodeGen/MachineCodeEmitter.h:1.28 Thu Jul 28 13:13:59 2005
+++ llvm/include/llvm/CodeGen/MachineCodeEmitter.h Sat Apr 22 13:53:45 2006
@@ -18,11 +18,13 @@
#define LLVM_CODEGEN_MACHINECODEEMITTER_H
#include "llvm/Support/DataTypes.h"
+#include <map>
namespace llvm {
class MachineBasicBlock;
class MachineConstantPool;
+class MachineJumpTableInfo;
class MachineFunction;
class MachineRelocation;
class Value;
@@ -47,6 +49,17 @@
/// for the function.
virtual void emitConstantPool(MachineConstantPool *MCP) {}
+ /// initJumpTableInfo - This callback is invoked by the JIT to allocate the
+ /// necessary memory to hold the jump tables.
+ virtual void initJumpTableInfo(MachineJumpTableInfo *MJTI) {}
+
+ /// emitJumpTableInfo - This callback is invoked to output the jump tables
+ /// for the function. In addition to a pointer to the MachineJumpTableInfo,
+ /// this function also takes a map of MBBs to addresses, so that the final
+ /// addresses of the MBBs can be written to the jump tables.
+ virtual void emitJumpTableInfo(MachineJumpTableInfo *MJTI,
+ std::map<MachineBasicBlock*,uint64_t> &MBBM) {}
+
/// startFunctionStub - This callback is invoked when the JIT needs the
/// address of a function that has not been code generated yet. The StubSize
/// specifies the total size required by the stub. Stubs are not allowed to
@@ -94,6 +107,11 @@
//
virtual uint64_t getConstantPoolEntryAddress(unsigned Index) = 0;
+ // getJumpTablelEntryAddress - Return the address of the jump table with index
+ // 'Index' in the function that last called initJumpTableInfo.
+ //
+ virtual uint64_t getJumpTableEntryAddress(unsigned Index) = 0;
+
// allocateGlobal - Allocate some space for a global variable.
virtual unsigned char* allocateGlobal(unsigned size, unsigned alignment) = 0;
Index: llvm/include/llvm/CodeGen/MachineFunction.h
diff -u llvm/include/llvm/CodeGen/MachineFunction.h:1.58 llvm/include/llvm/CodeGen/MachineFunction.h:1.59
--- llvm/include/llvm/CodeGen/MachineFunction.h:1.58 Mon Apr 10 20:09:25 2006
+++ llvm/include/llvm/CodeGen/MachineFunction.h Sat Apr 22 13:53:45 2006
@@ -29,6 +29,7 @@
class SSARegMap;
class MachineFrameInfo;
class MachineConstantPool;
+class MachineJumpTableInfo;
// ilist_traits
template <>
@@ -93,6 +94,9 @@
// Keep track of constants which are spilled to memory
MachineConstantPool *ConstantPool;
+
+ // Keep track of jump tables for switch instructions
+ MachineJumpTableInfo *JumpTableInfo;
// Function-level unique numbering for MachineBasicBlocks. When a
// MachineBasicBlock is inserted into a MachineFunction is it automatically
@@ -138,6 +142,12 @@
///
MachineFrameInfo *getFrameInfo() const { return FrameInfo; }
+ /// getJumpTableInfo - Return the jump table info object for the current
+ /// function. This object contains information about jump tables for switch
+ /// instructions in the current function.
+ ///
+ MachineJumpTableInfo *getJumpTableInfo() const { return JumpTableInfo; }
+
/// getConstantPool - Return the constant pool object for the current
/// function.
///
Index: llvm/include/llvm/CodeGen/MachineInstr.h
diff -u llvm/include/llvm/CodeGen/MachineInstr.h:1.167 llvm/include/llvm/CodeGen/MachineInstr.h:1.168
--- llvm/include/llvm/CodeGen/MachineInstr.h:1.167 Thu Apr 20 13:09:13 2006
+++ llvm/include/llvm/CodeGen/MachineInstr.h Sat Apr 22 13:53:45 2006
@@ -105,6 +105,7 @@
MO_MachineBasicBlock, // MachineBasicBlock reference
MO_FrameIndex, // Abstract Stack Frame Index
MO_ConstantPoolIndex, // Address of indexed Constant in Constant Pool
+ MO_JumpTableIndex, // Address of indexed Jump Table for switch
MO_ExternalSymbol, // Name of external global symbol
MO_GlobalAddress // Address of a global value
};
@@ -242,6 +243,7 @@
}
bool isFrameIndex() const { return opType == MO_FrameIndex; }
bool isConstantPoolIndex() const { return opType == MO_ConstantPoolIndex; }
+ bool isJumpTableIndex() const { return opType == MO_JumpTableIndex; }
bool isGlobalAddress() const { return opType == MO_GlobalAddress; }
bool isExternalSymbol() const { return opType == MO_ExternalSymbol; }
@@ -285,6 +287,10 @@
assert(isConstantPoolIndex() && "Wrong MachineOperand accessor");
return (unsigned)contents.immedVal;
}
+ unsigned getJumpTableIndex() const {
+ assert(isJumpTableIndex() && "Wrong MachineOperand accessor");
+ return (unsigned)contents.immedVal;
+ }
GlobalValue *getGlobal() const {
assert(isGlobalAddress() && "Wrong MachineOperand accessor");
return (GlobalValue*)contents.value;
@@ -348,7 +354,8 @@
}
void setOffset(int Offset) {
- assert((isGlobalAddress() || isExternalSymbol() || isConstantPoolIndex()) &&
+ assert((isGlobalAddress() || isExternalSymbol() || isConstantPoolIndex() ||
+ isJumpTableIndex()) &&
"Wrong MachineOperand accessor");
extra.offset = Offset;
}
@@ -611,6 +618,15 @@
operands.push_back(MachineOperand(I, MachineOperand::MO_ConstantPoolIndex));
}
+ /// addJumpTableIndexOperand - Add a jump table object index to the
+ /// instruction.
+ ///
+ void addJumpTableIndexOperand(unsigned I) {
+ assert(!OperandsComplete() &&
+ "Trying to add an operand to a machine instr that is already done!");
+ operands.push_back(MachineOperand(I, MachineOperand::MO_JumpTableIndex));
+ }
+
void addGlobalAddressOperand(GlobalValue *GV, bool isPCRelative, int Offset) {
assert(!OperandsComplete() &&
"Trying to add an operand to a machine instr that is already done!");
Index: llvm/include/llvm/CodeGen/ScheduleDAG.h
diff -u llvm/include/llvm/CodeGen/ScheduleDAG.h:1.22 llvm/include/llvm/CodeGen/ScheduleDAG.h:1.23
--- llvm/include/llvm/CodeGen/ScheduleDAG.h:1.22 Fri Mar 10 01:51:12 2006
+++ llvm/include/llvm/CodeGen/ScheduleDAG.h Sat Apr 22 13:53:45 2006
@@ -100,6 +100,7 @@
if (isa<BasicBlockSDNode>(Node)) return true;
if (isa<FrameIndexSDNode>(Node)) return true;
if (isa<ConstantPoolSDNode>(Node)) return true;
+ if (isa<JumpTableSDNode>(Node)) return true;
if (isa<ExternalSymbolSDNode>(Node)) return true;
return false;
}
Index: llvm/include/llvm/CodeGen/SelectionDAG.h
diff -u llvm/include/llvm/CodeGen/SelectionDAG.h:1.100 llvm/include/llvm/CodeGen/SelectionDAG.h:1.101
--- llvm/include/llvm/CodeGen/SelectionDAG.h:1.100 Sat Feb 25 03:52:55 2006
+++ llvm/include/llvm/CodeGen/SelectionDAG.h Sat Apr 22 13:53:45 2006
@@ -120,6 +120,8 @@
int offset = 0);
SDOperand getFrameIndex(int FI, MVT::ValueType VT);
SDOperand getTargetFrameIndex(int FI, MVT::ValueType VT);
+ SDOperand getJumpTable(int JTI, MVT::ValueType VT);
+ SDOperand getTargetJumpTable(int JTI, MVT::ValueType VT);
SDOperand getConstantPool(Constant *C, MVT::ValueType VT,
unsigned Alignment=0, int offset = 0);
SDOperand getTargetConstantPool(Constant *C, MVT::ValueType VT,
@@ -468,7 +470,8 @@
std::map<std::pair<uint64_t, MVT::ValueType>, SDNode*> TargetConstants;
std::map<std::pair<uint64_t, MVT::ValueType>, SDNode*> ConstantFPs;
std::map<std::pair<uint64_t, MVT::ValueType>, SDNode*> TargetConstantFPs;
- std::map<int, SDNode*> FrameIndices, TargetFrameIndices;
+ std::map<int, SDNode*> FrameIndices, TargetFrameIndices, JumpTableIndices,
+ TargetJumpTableIndices;
std::map<std::pair<Constant *,
std::pair<int, unsigned> >, SDNode*> ConstantPoolIndices;
std::map<std::pair<Constant *,
Index: llvm/include/llvm/CodeGen/SelectionDAGISel.h
diff -u llvm/include/llvm/CodeGen/SelectionDAGISel.h:1.12 llvm/include/llvm/CodeGen/SelectionDAGISel.h:1.13
--- llvm/include/llvm/CodeGen/SelectionDAGISel.h:1.12 Sun Mar 26 19:32:24 2006
+++ llvm/include/llvm/CodeGen/SelectionDAGISel.h Sat Apr 22 13:53:45 2006
@@ -18,6 +18,7 @@
#include "llvm/Pass.h"
#include "llvm/Constant.h"
#include "llvm/CodeGen/SelectionDAGNodes.h"
+#include <set>
namespace llvm {
class SelectionDAG;
@@ -40,7 +41,7 @@
SelectionDAG *CurDAG;
MachineBasicBlock *BB;
- SelectionDAGISel(TargetLowering &tli) : TLI(tli) {}
+ SelectionDAGISel(TargetLowering &tli) : TLI(tli), JT(0,0,0) {}
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
@@ -87,6 +88,20 @@
// ThisBB - the blcok into which to emit the code for the setcc and branches
MachineBasicBlock *ThisBB;
};
+ struct JumpTable {
+ JumpTable(unsigned R, unsigned J, MachineBasicBlock *me) : Reg(R), JTI(J),
+ MBB(me) {}
+ // Reg - the virtual register containing the index of the jump table entry
+ // to jump to.
+ unsigned Reg;
+ // JTI - the JumpTableIndex for this jump table in the function.
+ unsigned JTI;
+ // MBB - the MBB into which to emit the code for the indirect jump.
+ MachineBasicBlock *MBB;
+ // SuccMBBs - a vector of unique successor MBBs used for updating CFG info
+ // and PHI nodes.
+ std::set<MachineBasicBlock*> SuccMBBs;
+ };
protected:
/// Pick a safe ordering and emit instructions for each target node in the
@@ -114,6 +129,9 @@
/// SwitchCases - Vector of CaseBlock structures used to communicate
/// SwitchInst code generation information.
std::vector<CaseBlock> SwitchCases;
+
+ /// JT - Record which holds necessary information for emitting a jump table
+ JumpTable JT;
};
}
Index: llvm/include/llvm/CodeGen/SelectionDAGNodes.h
diff -u llvm/include/llvm/CodeGen/SelectionDAGNodes.h:1.129 llvm/include/llvm/CodeGen/SelectionDAGNodes.h:1.130
--- llvm/include/llvm/CodeGen/SelectionDAGNodes.h:1.129 Wed Apr 12 11:44:15 2006
+++ llvm/include/llvm/CodeGen/SelectionDAGNodes.h Sat Apr 22 13:53:45 2006
@@ -65,7 +65,7 @@
// Various leaf nodes.
STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
Constant, ConstantFP,
- GlobalAddress, FrameIndex, ConstantPool, ExternalSymbol,
+ GlobalAddress, FrameIndex, JumpTable, ConstantPool, ExternalSymbol,
// TargetConstant* - Like Constant*, but the DAG does not do any folding or
// simplification of the constant.
@@ -77,6 +77,7 @@
// dag, turning into a GlobalAddress operand.
TargetGlobalAddress,
TargetFrameIndex,
+ TargetJumpTable,
TargetConstantPool,
TargetExternalSymbol,
@@ -388,6 +389,11 @@
// operand, the second is the MBB to branch to.
BR,
+ // BRIND - Indirect branch. The first operand is the chain, the second
+ // is the value to branch to, which must be of the same type as the target's
+ // pointer type.
+ BRIND,
+
// BRCOND - Conditional branch. The first operand is the chain,
// the second is the condition, the third is the block to branch
// to if the condition is true.
@@ -1165,6 +1171,24 @@
}
};
+class JumpTableSDNode : public SDNode {
+ int JTI;
+protected:
+ friend class SelectionDAG;
+ JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
+ : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, VT),
+ JTI(jti) {}
+public:
+
+ int getIndex() const { return JTI; }
+
+ static bool classof(const JumpTableSDNode *) { return true; }
+ static bool classof(const SDNode *N) {
+ return N->getOpcode() == ISD::JumpTable ||
+ N->getOpcode() == ISD::TargetJumpTable;
+ }
+};
+
class ConstantPoolSDNode : public SDNode {
Constant *C;
int Offset;
More information about the llvm-commits
mailing list