Skip to content

Commit cf6749e

Browse files
add setJumpBufSize() and setJumpBufAlignment() to target-lowering.
Call these from your backend to enjoy setjmp/longjmp goodness, see lib/Target/IA64/IA64ISelLowering.cpp for an example llvm-svn: 30095
1 parent a59bee7 commit cf6749e

File tree

5 files changed

+47
-14
lines changed

5 files changed

+47
-14
lines changed

llvm/include/llvm/Target/TargetLowering.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,18 @@ class TargetLowering {
327327
return StackPointerRegisterToSaveRestore;
328328
}
329329

330+
/// getJumpBufSize - returns the target's jmp_buf size in bytes (if never
331+
/// set, the default is 200)
332+
unsigned getJumpBufSize() const {
333+
return JumpBufSize;
334+
}
335+
336+
/// getJumpBufAlignment - returns the target's jmp_buf alignment in bytes
337+
/// (if never set, the default is 0)
338+
unsigned getJumpBufAlignment() const {
339+
return JumpBufAlignment;
340+
}
341+
330342
//===--------------------------------------------------------------------===//
331343
// TargetLowering Optimization Methods
332344
//
@@ -537,6 +549,18 @@ class TargetLowering {
537549
TargetDAGCombineArray[NT >> 3] |= 1 << (NT&7);
538550
}
539551

552+
/// setJumpBufSize - Set the target's required jmp_buf buffer size (in
553+
/// bytes); default is 200
554+
void setJumpBufSize(unsigned Size) {
555+
JumpBufSize = Size;
556+
}
557+
558+
/// setJumpBufAlignment - Set the target's required jmp_buf buffer
559+
/// alignment (in bytes); default is 0
560+
void setJumpBufAlignment(unsigned Align) {
561+
JumpBufAlignment = Align;
562+
}
563+
540564
public:
541565

542566
//===--------------------------------------------------------------------===//
@@ -718,6 +742,13 @@ class TargetLowering {
718742
/// _longjmp to implement llvm.setjmp/llvm.longjmp. Defaults to false.
719743
bool UseUnderscoreSetJmpLongJmp;
720744

745+
/// JumpBufSize - The size, in bytes, of the target's jmp_buf buffers
746+
unsigned JumpBufSize;
747+
748+
/// JumpBufAlignment - The alignment, in bytes, of the target's jmp_buf
749+
/// buffers
750+
unsigned JumpBufAlignment;
751+
721752
/// StackPointerRegisterToSaveRestore - If set to a physical register, this
722753
/// specifies the register that llvm.savestack/llvm.restorestack should save
723754
/// and restore.

llvm/include/llvm/Transforms/Scalar.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ FunctionPass *createLowerPackedPass();
286286
// "my LLVM-to-LLVM pass doesn't support the invoke instruction yet" lowering
287287
// pass.
288288
//
289-
FunctionPass *createLowerInvokePass(unsigned JumBufSize = 200,
290-
unsigned JumpBufAlign = 0);
289+
FunctionPass *createLowerInvokePass(const TargetLowering *TLI = NULL);
291290
extern const PassInfo *LowerInvokePassID;
292291

293292

llvm/lib/CodeGen/LLVMTargetMachine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ bool LLVMTargetMachine::addPassesToEmitFile(FunctionPassManager &PM,
3333
PM.add(createLowerGCPass());
3434

3535
// FIXME: Implement the invoke/unwind instructions!
36-
PM.add(createLowerInvokePass());
36+
PM.add(createLowerInvokePass(getTargetLowering()));
3737

3838
// Make sure that no unreachable blocks are instruction selected.
3939
PM.add(createUnreachableBlockEliminationPass());
@@ -107,7 +107,7 @@ bool LLVMTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
107107
PM.add(createLowerGCPass());
108108

109109
// FIXME: Implement the invoke/unwind instructions!
110-
PM.add(createLowerInvokePass());
110+
PM.add(createLowerInvokePass(getTargetLowering()));
111111

112112
// Make sure that no unreachable blocks are instruction selected.
113113
PM.add(createUnreachableBlockEliminationPass());

llvm/lib/Target/IA64/IA64ISelLowering.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ IA64TargetLowering::IA64TargetLowering(TargetMachine &TM)
109109

110110
setStackPointerRegisterToSaveRestore(IA64::r12);
111111

112+
setJumpBufSize(704); // on ia64-linux, jmp_bufs are 704 bytes..
113+
setJumpBufAlignment(16); // ...and must be 16-byte aligned
114+
112115
computeRegisterProperties();
113116

114117
setOperationAction(ISD::ConstantFP, MVT::f64, Expand);

llvm/lib/Transforms/Utils/LowerInvoke.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "llvm/ADT/Statistic.h"
4646
#include "llvm/Support/CommandLine.h"
4747
#include "llvm/Support/Compiler.h"
48+
#include "llvm/Target/TargetLowering.h"
4849
#include <csetjmp>
4950
using namespace llvm;
5051

@@ -67,9 +68,12 @@ namespace {
6768
const Type *JBLinkTy;
6869
GlobalVariable *JBListHead;
6970
Function *SetJmpFn, *LongJmpFn;
71+
72+
// We peek in TLI to grab the target's jmp_buf size and alignment
73+
const TargetLowering *TLI;
74+
7075
public:
71-
LowerInvoke(unsigned Size = 200, unsigned Align = 0) : JumpBufSize(Size),
72-
JumpBufAlign(Align) {}
76+
LowerInvoke(const TargetLowering *tli = NULL) : TLI(tli) { }
7377
bool doInitialization(Module &M);
7478
bool runOnFunction(Function &F);
7579

@@ -89,9 +93,6 @@ namespace {
8993
void rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
9094
AllocaInst *InvokeNum, SwitchInst *CatchSwitch);
9195
bool insertExpensiveEHSupport(Function &F);
92-
93-
unsigned JumpBufSize;
94-
unsigned JumpBufAlign;
9596
};
9697

9798
RegisterPass<LowerInvoke>
@@ -101,9 +102,8 @@ namespace {
101102
const PassInfo *llvm::LowerInvokePassID = X.getPassInfo();
102103

103104
// Public Interface To the LowerInvoke pass.
104-
FunctionPass *llvm::createLowerInvokePass(unsigned JumpBufSize,
105-
unsigned JumpBufAlign) {
106-
return new LowerInvoke(JumpBufSize, JumpBufAlign);
105+
FunctionPass *llvm::createLowerInvokePass(const TargetLowering *TLI) {
106+
return new LowerInvoke(TLI);
107107
}
108108

109109
// doInitialization - Make sure that there is a prototype for abort in the
@@ -113,7 +113,7 @@ bool LowerInvoke::doInitialization(Module &M) {
113113
AbortMessage = 0;
114114
if (ExpensiveEHSupport) {
115115
// Insert a type for the linked list of jump buffers.
116-
const Type *JmpBufTy = ArrayType::get(VoidPtrTy, JumpBufSize);
116+
const Type *JmpBufTy = ArrayType::get(VoidPtrTy, TLI->getJumpBufSize());
117117

118118
{ // The type is recursive, so use a type holder.
119119
std::vector<const Type*> Elements;
@@ -453,7 +453,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
453453
// that needs to be restored on all exits from the function. This is an
454454
// alloca because the value needs to be live across invokes.
455455
AllocaInst *JmpBuf =
456-
new AllocaInst(JBLinkTy, 0, JumpBufAlign, "jblink", F.begin()->begin());
456+
new AllocaInst(JBLinkTy, 0, TLI->getJumpBufAlignment(), "jblink", F.begin()->begin());
457457

458458
std::vector<Value*> Idx;
459459
Idx.push_back(Constant::getNullValue(Type::IntTy));

0 commit comments

Comments
 (0)