add interpreter support for indirect goto / blockaddress. The interpreter

now correctly runs clang's test/CodeGen/indirect-goto.c.  The JIT will abort
on it until someone feels compelled to implement this.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85488 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-10-29 05:26:09 +00:00
parent 7a8b33a9a4
commit f32a6a3091
5 changed files with 35 additions and 13 deletions

View File

@ -268,6 +268,12 @@ public:
///
virtual void *getPointerToFunction(Function *F) = 0;
/// getPointerToBasicBlock - The different EE's represent basic blocks in
/// different ways. Return the representation for a blockaddress of the
/// specified block.
///
virtual void *getPointerToBasicBlock(BasicBlock *BB) = 0;
/// getPointerToFunctionOrStub - If the specified function has been
/// code-gen'd, return a pointer to the function. If not, compile it, or use
/// a stub to implement lazy compilation if available. See

View File

@ -762,6 +762,9 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
Result = PTOGV(getPointerToFunctionOrStub(const_cast<Function*>(F)));
else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(C))
Result = PTOGV(getOrEmitGlobalVariable(const_cast<GlobalVariable*>(GV)));
else if (const BlockAddress *BA = dyn_cast<BlockAddress>(C))
Result = PTOGV(getPointerToBasicBlock(const_cast<BasicBlock*>(
BA->getBasicBlock())));
else
llvm_unreachable("Unknown constant pointer type!");
break;

View File

@ -678,6 +678,13 @@ void Interpreter::visitSwitchInst(SwitchInst &I) {
SwitchToNewBasicBlock(Dest, SF);
}
void Interpreter::visitIndirectBrInst(IndirectBrInst &I) {
ExecutionContext &SF = ECStack.back();
void *Dest = GVTOP(getOperandValue(I.getAddress(), SF));
SwitchToNewBasicBlock((BasicBlock*)Dest, SF);
}
// SwitchToNewBasicBlock - This method is used to jump to a new basic block.
// This function handles the actual updating of block and instruction iterators
// as well as execution of all of the PHI nodes in the destination block.

View File

@ -135,6 +135,7 @@ public:
void visitReturnInst(ReturnInst &I);
void visitBranchInst(BranchInst &I);
void visitSwitchInst(SwitchInst &I);
void visitIndirectBrInst(IndirectBrInst &I);
void visitBinaryOperator(BinaryOperator &I);
void visitICmpInst(ICmpInst &I);
@ -202,6 +203,7 @@ private: // Helper functions
void SwitchToNewBasicBlock(BasicBlock *Dest, ExecutionContext &SF);
void *getPointerToFunction(Function *F) { return (void*)F; }
void *getPointerToBasicBlock(BasicBlock *BB) { return (void*)BB; }
void initializeExecutionEngine() { }
void initializeExternalFunctions();

View File

@ -128,6 +128,10 @@ public:
///
void *getPointerToFunction(Function *F);
void *getPointerToBasicBlock(BasicBlock *BB) {
assert(0 && "JIT does not support address-of-label yet!");
}
/// getOrEmitGlobalVariable - Return the address of the specified global
/// variable, possibly emitting it to memory if needed. This is used by the
/// Emitter.