[llvm-branch-commits] [llvm-gcc-branch] r85926 - in /llvm-gcc-4.2/branches/Apple/Leela/gcc: llvm-convert.cpp llvm-internal.h
Bill Wendling
isanbard at gmail.com
Tue Nov 3 11:30:52 PST 2009
Author: void
Date: Tue Nov 3 13:30:52 2009
New Revision: 85926
URL: http://llvm.org/viewvc/llvm-project?rev=85926&view=rev
Log:
$ svn merge -c 85835 https://llvm.org/svn/llvm-project/llvm-gcc-4.2/trunk
--- Merging r85835 into '.':
U gcc/llvm-convert.cpp
U gcc/llvm-internal.h
$ svn merge -c 85837 https://llvm.org/svn/llvm-project/llvm-gcc-4.2/trunk
--- Merging r85837 into '.':
G gcc/llvm-convert.cpp
$ svn merge -c 85902 https://llvm.org/svn/llvm-project/llvm-gcc-4.2/trunk
--- Merging r85902 into '.':
G gcc/llvm-convert.cpp
Modified:
llvm-gcc-4.2/branches/Apple/Leela/gcc/llvm-convert.cpp
llvm-gcc-4.2/branches/Apple/Leela/gcc/llvm-internal.h
Modified: llvm-gcc-4.2/branches/Apple/Leela/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Leela/gcc/llvm-convert.cpp?rev=85926&r1=85925&r2=85926&view=diff
==============================================================================
--- llvm-gcc-4.2/branches/Apple/Leela/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/branches/Apple/Leela/gcc/llvm-convert.cpp Tue Nov 3 13:30:52 2009
@@ -181,9 +181,7 @@
FuncEHSelector = 0;
FuncEHGetTypeID = 0;
-#ifdef USEINDIRECTBRANCH
- IndirectBranch = 0;
-#else
+#ifndef USEINDIRECTBRANCH
NumAddressTakenBlocks = 0;
IndirectGotoBlock = 0;
#endif
@@ -730,22 +728,7 @@
EmitPostPads();
EmitUnwindBlock();
-#ifdef USEINDIRECTBRANCH
- // If someone did an indirect goto, emit the indirect goto block at the end of
- // the function.
- if (IndirectBranch) {
- EmitBlock(IndirectBranch->getParent());
- Builder.ClearInsertionPoint();
-
- // If someone took the address of a label but never did an indirect goto,
- // we made a zero entry PHI node, which is illegal. Zap it now.
- PHINode *PN = cast<PHINode>(IndirectBranch->getAddress());
- if (PN->getNumIncomingValues() == 0) {
- PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
- PN->eraseFromParent();
- }
- }
-#else
+#ifndef USEINDIRECTBRANCH
// If this function takes the address of a label, emit the indirect goto
// block.
if (IndirectGotoBlock) {
@@ -1076,8 +1059,12 @@
// Constants.
case LABEL_DECL: {
+#ifdef USEINDIRECTBRANCH
+ LV = LValue(EmitLV_LABEL_DECL(exp), 1);
+#else
Value *Ptr = TreeConstantToLLVM::EmitLV_LABEL_DECL(exp);
LV = LValue(Ptr, 1);
+#endif
break;
}
case COMPLEX_CST: {
@@ -1702,23 +1689,11 @@
}
}
+#ifndef USEINDIRECTBRANCH
//===----------------------------------------------------------------------===//
// ... Address Of Labels Extension Support ...
//===----------------------------------------------------------------------===//
-#ifdef USEINDIRECTBRANCH
-/// getBlockAddress - Create a BlockAddress and add it as a possible
-/// destination of the IndirectBranch.
-BlockAddress *TreeToLLVM::getBlockAddress(BasicBlock *BB) {
- // Make sure that there is a block for the indirect goto.
- if (IndirectBranch == 0)
- getIndirectGotoBlock();
-
- // Make sure the indirect branch includes all of the address-taken blocks.
- IndirectBranch->addDestination(BB);
- return BlockAddress::get(Fn, BB);
-}
-#else
/// getIndirectGotoBlockNumber - Return the unique ID of the specified basic
/// block for uses that take the address of it.
Constant *TreeToLLVM::getIndirectGotoBlockNumber(BasicBlock *BB) {
@@ -1734,26 +1709,10 @@
cast<SwitchInst>(getIndirectGotoBlock()->getTerminator())->addCase(Val, BB);
return Val;
}
-#endif
/// getIndirectGotoBlock - Get (and potentially lazily create) the indirect
/// goto block.
BasicBlock *TreeToLLVM::getIndirectGotoBlock() {
-#ifdef USEINDIRECTBRANCH
- // If we already made the indirect branch for indirect goto, return its block.
- if (IndirectBranch) return IndirectBranch->getParent();
-
- BasicBlock *IndirectGotoBlock = BasicBlock::Create(Context, "indirectgoto");
- LLVMBuilder TmpBuilder(IndirectGotoBlock, *TheFolder);
- const Type *Int8PtrTy = Type::getInt8PtrTy(Context);
-
- // Create the PHI node that indirect gotos will add entries to.
- Value *DestVal = TmpBuilder.CreatePHI(Int8PtrTy, "indirect.goto.dest");
-
- // Create the indirect branch instruction.
- IndirectBranch = TmpBuilder.CreateIndirectBr(DestVal);
- return IndirectBranch->getParent();
-#else
if (IndirectGotoBlock) return IndirectGotoBlock;
// Create a temporary for the value to be switched on.
@@ -1766,8 +1725,8 @@
// Finally, return it.
return IndirectGotoBlock;
-#endif
}
+#endif
//===----------------------------------------------------------------------===//
@@ -1782,32 +1741,38 @@
}
Value *TreeToLLVM::EmitGOTO_EXPR(tree exp) {
- if (TREE_CODE(TREE_OPERAND(exp, 0)) == LABEL_DECL) {
+ tree dest = GOTO_DESTINATION(exp);
+ if (TREE_CODE(dest) == LABEL_DECL) {
// Direct branch.
- Builder.CreateBr(getLabelDeclBlock(TREE_OPERAND(exp, 0)));
+ Builder.CreateBr(getLabelDeclBlock(dest));
} else {
+#ifdef USEINDIRECTBRANCH
+ // Indirect branch.
+ basic_block bb = bb_for_stmt(exp);
+ Value *V = Emit(dest, 0);
+ IndirectBrInst *Br = Builder.CreateIndirectBr(V, EDGE_COUNT(bb->succs));
+
+ // Add the list of possible destinations.
+ edge e;
+ edge_iterator ei;
+ FOR_EACH_EDGE (e, ei, bb->succs)
+ Br->addDestination(getLabelDeclBlock(tree_block_label(e->dest)));
+#else
// Otherwise we have an indirect goto.
BasicBlock *DestBB = getIndirectGotoBlock();
-#ifdef USEINDIRECTBRANCH
- Value *V = Emit(TREE_OPERAND(exp, 0), 0);
- V = Builder.CreateBitCast(V, Type::getInt8PtrTy(Context));
- // The first instruction in the indirect goto block has to be the PHI for
- // the indirect branch address; add an entry for this branch.
- cast<PHINode>(DestBB->begin())->addIncoming(V, Builder.GetInsertBlock());
-#else
// Store the destination block to the GotoValue alloca.
- Value *V = Emit(TREE_OPERAND(exp, 0), 0);
+ Value *V = Emit(dest, 0);
V = CastToType(Instruction::PtrToInt, V, TD.getIntPtrType(Context));
Builder.CreateStore(V, IndirectGotoValue);
-#endif
// NOTE: This is HORRIBLY INCORRECT in the presence of exception handlers.
// There should be one collector block per cleanup level! Note that
// standard GCC gets this wrong as well.
//
Builder.CreateBr(DestBB);
+#endif
}
EmitBlock(BasicBlock::Create(Context, ""));
return 0;
@@ -6974,6 +6939,11 @@
return LValue(Builder.CreateStructGEP(Ptr.Ptr, Idx), Alignment);
}
+#ifdef USEINDIRECTBRANCH
+Constant *TreeToLLVM::EmitLV_LABEL_DECL(tree exp) {
+ return BlockAddress::get(Fn, getLabelDeclBlock(exp));
+}
+#endif
//===----------------------------------------------------------------------===//
// ... Constant Expressions ...
@@ -8052,11 +8022,10 @@
"Taking the address of a label that isn't in the current fn!?");
}
- BasicBlock *BB = getLabelDeclBlock(exp);
#ifdef USEINDIRECTBRANCH
- Constant *Ptr = TheTreeToLLVM->getBlockAddress(BB);
- return TheFolder->CreateBitCast(Ptr, Type::getInt8PtrTy(Context));
+ return TheTreeToLLVM->EmitLV_LABEL_DECL(exp);
#else
+ BasicBlock *BB = getLabelDeclBlock(exp);
Constant *C = TheTreeToLLVM->getIndirectGotoBlockNumber(BB);
return TheFolder->CreateIntToPtr(C, Type::getInt8PtrTy(Context));
#endif
Modified: llvm-gcc-4.2/branches/Apple/Leela/gcc/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Leela/gcc/llvm-internal.h?rev=85926&r1=85925&r2=85926&view=diff
==============================================================================
--- llvm-gcc-4.2/branches/Apple/Leela/gcc/llvm-internal.h (original)
+++ llvm-gcc-4.2/branches/Apple/Leela/gcc/llvm-internal.h Tue Nov 3 13:30:52 2009
@@ -331,13 +331,7 @@
/// FuncEHGetTypeID - Function used to return type id for give typeinfo.
Function *FuncEHGetTypeID;
-#ifdef USEINDIRECTBRANCH
- /// IndirectBranch - The first time an indirect goto is seen we create a
- /// block with an indirect branch. Every time we see the address of a label
- /// taken, we add the label to the indirect goto. Every subsequent indirect
- /// goto is codegen'd as a jump to the IndirectBranch's basic block.
- IndirectBrInst *IndirectBranch;
-#else
+#ifndef USEINDIRECTBRANCH
/// NumAddressTakenBlocks - Count the number of labels whose addresses are
/// taken.
uint64_t NumAddressTakenBlocks;
@@ -370,11 +364,7 @@
/// the address of the result.
LValue EmitLV(tree_node *exp);
-#ifdef USEINDIRECTBRANCH
- /// getBlockAddress - Create a BlockAddress and add it as a possible
- /// destination of the IndirectBranch.
- BlockAddress *getBlockAddress(BasicBlock *BB);
-#else
+#ifndef USEINDIRECTBRANCH
/// getIndirectGotoBlockNumber - Return the unique ID of the specified basic
/// block for uses that take the address of it.
Constant *getIndirectGotoBlockNumber(BasicBlock *BB);
@@ -622,6 +612,12 @@
Value *&Result,
const Type *ResultType,
std::vector<Value*> &Ops);
+
+#ifdef USEINDIRECTBRANCH
+public:
+ // Helper for taking the address of a label.
+ Constant *EmitLV_LABEL_DECL(tree_node *exp);
+#endif
};
/// TreeConstantToLLVM - An instance of this class is created and used to
More information about the llvm-branch-commits
mailing list