2008-07-30 07:18:29 +08:00
|
|
|
//===-- CodeGenFunction.h - Per-Function state for LLVM CodeGen -*- C++ -*-===//
|
2007-05-24 14:29:05 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-05-24 14:29:05 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-02-09 07:14:22 +08:00
|
|
|
// This is the internal per-function state used for llvm translation.
|
2007-05-24 14:29:05 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-03-01 01:10:38 +08:00
|
|
|
#ifndef CLANG_CODEGEN_CODEGENFUNCTION_H
|
|
|
|
#define CLANG_CODEGEN_CODEGENFUNCTION_H
|
2007-05-24 14:29:05 +08:00
|
|
|
|
2008-03-31 07:03:07 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2007-05-30 08:13:02 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2007-07-17 05:28:45 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-01-12 03:40:10 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
This patch is motivated by numerous strict-aliasing warnings when compiling
clang as a Release build.
The big change is that all AST nodes (subclasses of Stmt) whose children are
Expr* store their children as Stmt* or arrays of Stmt*. This is to remove
strict-aliasing warnings when using StmtIterator. None of the interfaces of any
of the classes have changed (except those with arg_iterators, see below), as the
accessor methods introduce the needed casts (via cast<>). While this extra
casting may seem cumbersome, it actually adds some important sanity checks
throughout the codebase, as clients using StmtIterator can potentially overwrite
children that are expected to be Expr* with Stmt* (that aren't Expr*). The casts
provide extra sanity checks that are operational in debug builds to catch
invariant violations such as these.
For classes that have arg_iterators (e.g., CallExpr), the definition of
arg_iterator has been replaced. Instead of it being Expr**, it is an actual
class (called ExprIterator) that wraps a Stmt**, and provides the necessary
operators for iteration. The nice thing about this class is that it also uses
cast<> to type-checking, which introduces extra sanity checks throughout the
codebase that are useful for debugging.
A few of the CodeGen functions that use arg_iterator (especially from
OverloadExpr) have been modified to take begin and end iterators instead of a
base Expr** and the number of arguments. This matches more with the abstraction
of iteration. This still needs to be cleaned up a little bit, as clients expect
that ExprIterator is a RandomAccessIterator (which we may or may not wish to
allow for efficiency of representation).
This is a fairly large patch. It passes the tests (except CodeGen/bitfield.c,
which was already broken) on both a Debug and Release build, but it should
obviously be reviewed.
llvm-svn: 52378
2008-06-17 10:43:46 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
2008-09-10 10:36:38 +08:00
|
|
|
#include "clang/AST/ExprCXX.h"
|
This patch is motivated by numerous strict-aliasing warnings when compiling
clang as a Release build.
The big change is that all AST nodes (subclasses of Stmt) whose children are
Expr* store their children as Stmt* or arrays of Stmt*. This is to remove
strict-aliasing warnings when using StmtIterator. None of the interfaces of any
of the classes have changed (except those with arg_iterators, see below), as the
accessor methods introduce the needed casts (via cast<>). While this extra
casting may seem cumbersome, it actually adds some important sanity checks
throughout the codebase, as clients using StmtIterator can potentially overwrite
children that are expected to be Expr* with Stmt* (that aren't Expr*). The casts
provide extra sanity checks that are operational in debug builds to catch
invariant violations such as these.
For classes that have arg_iterators (e.g., CallExpr), the definition of
arg_iterator has been replaced. Instead of it being Expr**, it is an actual
class (called ExprIterator) that wraps a Stmt**, and provides the necessary
operators for iteration. The nice thing about this class is that it also uses
cast<> to type-checking, which introduces extra sanity checks throughout the
codebase that are useful for debugging.
A few of the CodeGen functions that use arg_iterator (especially from
OverloadExpr) have been modified to take begin and end iterators instead of a
base Expr** and the number of arguments. This matches more with the abstraction
of iteration. This still needs to be cleaned up a little bit, as clients expect
that ExprIterator is a RandomAccessIterator (which we may or may not wish to
allow for efficiency of representation).
This is a fairly large patch. It passes the tests (except CodeGen/bitfield.c,
which was already broken) on both a Debug and Release build, but it should
obviously be reviewed.
llvm-svn: 52378
2008-06-17 10:43:46 +08:00
|
|
|
#include "clang/AST/ExprObjC.h"
|
|
|
|
|
2007-06-16 08:16:26 +08:00
|
|
|
#include <vector>
|
2008-08-05 00:51:22 +08:00
|
|
|
#include <map>
|
2007-05-30 07:50:05 +08:00
|
|
|
|
2008-11-01 09:53:16 +08:00
|
|
|
#include "CGBuilder.h"
|
2008-09-09 05:33:45 +08:00
|
|
|
#include "CGCall.h"
|
2008-08-23 11:46:30 +08:00
|
|
|
#include "CGValue.h"
|
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace llvm {
|
2008-08-11 13:35:13 +08:00
|
|
|
class BasicBlock;
|
2007-05-24 14:29:05 +08:00
|
|
|
class Module;
|
2008-09-30 09:06:03 +08:00
|
|
|
class SwitchInst;
|
2008-11-19 17:36:46 +08:00
|
|
|
class Value;
|
2007-06-16 07:05:46 +08:00
|
|
|
}
|
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace clang {
|
|
|
|
class ASTContext;
|
2007-06-02 12:16:21 +08:00
|
|
|
class Decl;
|
2008-08-11 13:35:13 +08:00
|
|
|
class EnumConstantDecl;
|
2007-05-24 14:29:05 +08:00
|
|
|
class FunctionDecl;
|
2008-08-11 13:35:13 +08:00
|
|
|
class FunctionTypeProto;
|
|
|
|
class LabelStmt;
|
2009-01-11 05:06:09 +08:00
|
|
|
class ObjCContainerDecl;
|
2008-09-24 12:00:38 +08:00
|
|
|
class ObjCInterfaceDecl;
|
|
|
|
class ObjCIvarDecl;
|
2008-03-31 07:03:07 +08:00
|
|
|
class ObjCMethodDecl;
|
2008-12-10 04:23:04 +08:00
|
|
|
class ObjCImplementationDecl;
|
2008-08-26 16:29:31 +08:00
|
|
|
class ObjCPropertyImplDecl;
|
2007-06-16 08:16:26 +08:00
|
|
|
class TargetInfo;
|
2008-08-11 13:35:13 +08:00
|
|
|
class VarDecl;
|
This patch is motivated by numerous strict-aliasing warnings when compiling
clang as a Release build.
The big change is that all AST nodes (subclasses of Stmt) whose children are
Expr* store their children as Stmt* or arrays of Stmt*. This is to remove
strict-aliasing warnings when using StmtIterator. None of the interfaces of any
of the classes have changed (except those with arg_iterators, see below), as the
accessor methods introduce the needed casts (via cast<>). While this extra
casting may seem cumbersome, it actually adds some important sanity checks
throughout the codebase, as clients using StmtIterator can potentially overwrite
children that are expected to be Expr* with Stmt* (that aren't Expr*). The casts
provide extra sanity checks that are operational in debug builds to catch
invariant violations such as these.
For classes that have arg_iterators (e.g., CallExpr), the definition of
arg_iterator has been replaced. Instead of it being Expr**, it is an actual
class (called ExprIterator) that wraps a Stmt**, and provides the necessary
operators for iteration. The nice thing about this class is that it also uses
cast<> to type-checking, which introduces extra sanity checks throughout the
codebase that are useful for debugging.
A few of the CodeGen functions that use arg_iterator (especially from
OverloadExpr) have been modified to take begin and end iterators instead of a
base Expr** and the number of arguments. This matches more with the abstraction
of iteration. This still needs to be cleaned up a little bit, as clients expect
that ExprIterator is a RandomAccessIterator (which we may or may not wish to
allow for efficiency of representation).
This is a fairly large patch. It passes the tests (except CodeGen/bitfield.c,
which was already broken) on both a Debug and Release build, but it should
obviously be reviewed.
llvm-svn: 52378
2008-06-17 10:43:46 +08:00
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace CodeGen {
|
2007-05-28 09:07:47 +08:00
|
|
|
class CodeGenModule;
|
2007-10-23 10:10:49 +08:00
|
|
|
class CodeGenTypes;
|
2009-02-03 05:43:58 +08:00
|
|
|
class CGFunctionInfo;
|
2009-02-09 07:14:22 +08:00
|
|
|
class CGRecordLayout;
|
|
|
|
|
2007-05-28 09:07:47 +08:00
|
|
|
/// CodeGenFunction - This class organizes the per-function state that is used
|
|
|
|
/// while generating LLVM code.
|
|
|
|
class CodeGenFunction {
|
2007-08-27 07:13:56 +08:00
|
|
|
public:
|
2007-05-28 09:07:47 +08:00
|
|
|
CodeGenModule &CGM; // Per-module state.
|
2007-05-30 07:17:50 +08:00
|
|
|
TargetInfo &Target;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-08-22 00:57:55 +08:00
|
|
|
typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
|
2008-11-01 09:53:16 +08:00
|
|
|
CGBuilderTy Builder;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2008-04-04 12:07:35 +08:00
|
|
|
// Holds the Decl for the current function or method
|
2008-06-18 02:05:57 +08:00
|
|
|
const Decl *CurFuncDecl;
|
2009-02-03 06:03:45 +08:00
|
|
|
const CGFunctionInfo *CurFnInfo;
|
2008-03-31 07:03:07 +08:00
|
|
|
QualType FnRetTy;
|
2007-05-30 08:13:02 +08:00
|
|
|
llvm::Function *CurFn;
|
|
|
|
|
2008-09-10 05:00:17 +08:00
|
|
|
/// ReturnBlock - Unified return block.
|
|
|
|
llvm::BasicBlock *ReturnBlock;
|
2009-02-09 07:14:22 +08:00
|
|
|
/// ReturnValue - The temporary alloca to hold the return value. This is null
|
|
|
|
/// iff the function has no return value.
|
2008-09-10 05:00:17 +08:00
|
|
|
llvm::Instruction *ReturnValue;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-06-02 12:53:11 +08:00
|
|
|
/// AllocaInsertPoint - This is an instruction in the entry block before which
|
|
|
|
/// we prefer to insert allocas.
|
|
|
|
llvm::Instruction *AllocaInsertPt;
|
2008-08-05 00:51:22 +08:00
|
|
|
|
2007-06-03 06:49:07 +08:00
|
|
|
const llvm::Type *LLVMIntTy;
|
2007-10-17 23:00:17 +08:00
|
|
|
uint32_t LLVMPointerWidth;
|
2008-09-28 09:03:14 +08:00
|
|
|
|
|
|
|
public:
|
2009-02-09 07:14:22 +08:00
|
|
|
// FIXME: The following should be private once EH code is moved out of NeXT
|
|
|
|
// runtime.
|
2008-09-28 09:03:14 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
// ObjCEHStack - This keeps track of which object to rethrow from inside
|
|
|
|
// @catch blocks and which @finally block exits from an EH scope should be
|
|
|
|
// chained through.
|
2008-09-28 09:03:14 +08:00
|
|
|
struct ObjCEHEntry {
|
2009-02-08 05:26:04 +08:00
|
|
|
ObjCEHEntry(llvm::BasicBlock *fb, llvm::SwitchInst *fs, llvm::Value *dc)
|
2009-02-09 07:14:22 +08:00
|
|
|
: FinallyBlock(fb), FinallySwitch(fs),
|
2009-02-08 05:37:21 +08:00
|
|
|
DestCode(dc) {}
|
2008-09-28 09:03:14 +08:00
|
|
|
|
2008-09-30 09:06:03 +08:00
|
|
|
/// Entry point to the finally block.
|
2009-02-09 07:14:22 +08:00
|
|
|
llvm::BasicBlock *FinallyBlock;
|
2008-09-30 09:06:03 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// Switch instruction which runs at the end of the finally block to forward
|
|
|
|
/// jumps through the finally block.
|
|
|
|
llvm::SwitchInst *FinallySwitch;
|
2008-09-30 09:06:03 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// Variable holding the code for the destination of a jump through the
|
|
|
|
/// @finally block.
|
2008-09-30 09:06:03 +08:00
|
|
|
llvm::Value *DestCode;
|
2008-09-28 09:03:14 +08:00
|
|
|
};
|
2008-09-30 09:06:03 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// ObjCEHValueStack - Stack of exception objects being handled, during IR
|
|
|
|
/// generation for a @catch block.
|
2009-02-08 05:37:21 +08:00
|
|
|
llvm::SmallVector<llvm::Value*, 8> ObjCEHValueStack;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2008-09-30 09:06:03 +08:00
|
|
|
typedef llvm::SmallVector<ObjCEHEntry*, 8> ObjCEHStackType;
|
|
|
|
ObjCEHStackType ObjCEHStack;
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitJumpThroughFinally - Emit a branch from the current insert point
|
|
|
|
/// through the finally handling code for \arg Entry and then on to \arg
|
|
|
|
/// Dest. It is legal to call this function even if there is no current
|
|
|
|
/// insertion point.
|
2008-09-30 09:06:03 +08:00
|
|
|
///
|
2009-02-09 07:14:22 +08:00
|
|
|
/// \param ExecuteTryExit - When true, the try_exit runtime function should be
|
|
|
|
/// called prior to executing the finally code.
|
2009-02-09 06:25:30 +08:00
|
|
|
void EmitJumpThroughFinally(ObjCEHEntry *Entry, llvm::BasicBlock *Dest);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2009-02-09 06:25:30 +08:00
|
|
|
void EmitJumpThroughFinally(llvm::BasicBlock *Dest);
|
2007-06-03 06:49:07 +08:00
|
|
|
|
2009-02-08 11:22:36 +08:00
|
|
|
/// PushCleanupBlock - Push a new cleanup entry on the stack and set the
|
|
|
|
/// passed in block as the cleanup block.
|
|
|
|
void PushCleanupBlock(llvm::BasicBlock *CleanupBlock);
|
2009-02-08 15:46:24 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// CleanupBlockInfo - A struct representing a popped cleanup block.
|
2009-02-08 15:46:24 +08:00
|
|
|
struct CleanupBlockInfo {
|
|
|
|
/// CleanupBlock - the cleanup block
|
|
|
|
llvm::BasicBlock *CleanupBlock;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
|
|
|
/// SwitchBlock - the block (if any) containing the switch instruction used
|
|
|
|
/// for jumping to the final destination.
|
2009-02-08 15:46:24 +08:00
|
|
|
llvm::BasicBlock *SwitchBlock;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2009-02-08 15:46:24 +08:00
|
|
|
/// EndBlock - the default destination for the switch instruction.
|
|
|
|
llvm::BasicBlock *EndBlock;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
|
|
|
CleanupBlockInfo(llvm::BasicBlock *cb, llvm::BasicBlock *sb,
|
2009-02-08 15:46:24 +08:00
|
|
|
llvm::BasicBlock *eb)
|
|
|
|
: CleanupBlock(cb), SwitchBlock(sb), EndBlock(eb) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// PopCleanupBlock - Will pop the cleanup entry on the stack, process all
|
2009-02-09 07:14:22 +08:00
|
|
|
/// branch fixups and return a block info struct with the switch block and end
|
|
|
|
/// block.
|
2009-02-08 15:46:24 +08:00
|
|
|
CleanupBlockInfo PopCleanupBlock();
|
2009-02-09 07:14:22 +08:00
|
|
|
|
|
|
|
/// CleanupScope - RAII object that will create a cleanup block and set the
|
|
|
|
/// insert point to that block. When destructed, it sets the insert point to
|
|
|
|
/// the previous block and pushes a new cleanup entry on the stack.
|
2009-02-08 07:30:41 +08:00
|
|
|
class CleanupScope {
|
|
|
|
CodeGenFunction& CGF;
|
|
|
|
llvm::BasicBlock *CurBB;
|
2009-02-08 11:22:36 +08:00
|
|
|
llvm::BasicBlock *CleanupBB;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2009-02-08 07:30:41 +08:00
|
|
|
public:
|
|
|
|
CleanupScope(CodeGenFunction &cgf)
|
|
|
|
: CGF(cgf), CurBB(CGF.Builder.GetInsertBlock()) {
|
2009-02-08 11:22:36 +08:00
|
|
|
CleanupBB = CGF.createBasicBlock("cleanup");
|
|
|
|
CGF.Builder.SetInsertPoint(CleanupBB);
|
2009-02-08 07:30:41 +08:00
|
|
|
}
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2009-02-08 07:30:41 +08:00
|
|
|
~CleanupScope() {
|
2009-02-08 11:22:36 +08:00
|
|
|
CGF.PushCleanupBlock(CleanupBB);
|
2009-02-08 07:30:41 +08:00
|
|
|
CGF.Builder.SetInsertPoint(CurBB);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-02-08 07:50:39 +08:00
|
|
|
/// EmitCleanupBlocks - Takes the old cleanup stack size and emits the cleanup
|
|
|
|
/// blocks that have been added.
|
|
|
|
void EmitCleanupBlocks(size_t OldCleanupStackSize);
|
|
|
|
|
2009-02-08 08:50:42 +08:00
|
|
|
/// EmitBranchThroughCleanup - Emit a branch from the current insert block
|
|
|
|
/// through the cleanup handling code (if any) and then on to \arg Dest.
|
|
|
|
///
|
2009-02-09 07:14:22 +08:00
|
|
|
/// FIXME: Maybe this should really be in EmitBranch? Don't we always want
|
2009-02-08 08:50:42 +08:00
|
|
|
/// this behavior for branches?
|
|
|
|
void EmitBranchThroughCleanup(llvm::BasicBlock *Dest);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-08-24 13:35:26 +08:00
|
|
|
private:
|
2009-02-09 07:14:22 +08:00
|
|
|
/// LabelIDs - Track arbitrary ids assigned to labels for use in implementing
|
|
|
|
/// the GCC address-of-label extension and indirect goto. IDs are assigned to
|
|
|
|
/// labels inside getIDForAddrOfLabel().
|
2008-08-05 00:51:22 +08:00
|
|
|
std::map<const LabelStmt*, unsigned> LabelIDs;
|
|
|
|
|
|
|
|
/// IndirectSwitches - Record the list of switches for indirect
|
2009-02-09 07:14:22 +08:00
|
|
|
/// gotos. Emission of the actual switching code needs to be delayed until all
|
|
|
|
/// AddrLabelExprs have been seen.
|
2008-08-05 00:51:22 +08:00
|
|
|
std::vector<llvm::SwitchInst*> IndirectSwitches;
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
|
|
|
|
/// decls.
|
2007-06-16 07:05:46 +08:00
|
|
|
llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
|
2007-06-02 12:16:21 +08:00
|
|
|
|
2007-05-30 08:13:02 +08:00
|
|
|
/// LabelMap - This keeps track of the LLVM basic block for each C label.
|
2007-06-16 07:05:46 +08:00
|
|
|
llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
|
|
|
/// BreakContinuePush - Note a new break and continue level. This must be
|
|
|
|
/// called at the stack depth of the continue block. In particular, this must
|
|
|
|
/// not be called after the controlling condition has possibly started a vla.
|
2009-02-07 20:52:26 +08:00
|
|
|
void BreakContinuePush(llvm::BasicBlock *bb, llvm::BasicBlock *cb) {
|
|
|
|
BreakContinueStack.push_back(BreakContinue(bb, cb, StackDepth,
|
2009-02-08 07:02:10 +08:00
|
|
|
StackDepth,
|
|
|
|
ObjCEHStack.size()));
|
|
|
|
}
|
|
|
|
void BreakContinuePush(llvm::BasicBlock *bb, llvm::BasicBlock *cb,
|
|
|
|
llvm::Value *bsd, llvm::Value *csd) {
|
|
|
|
BreakContinueStack.push_back(BreakContinue(bb, cb, bsd, csd,
|
2009-02-07 20:52:26 +08:00
|
|
|
ObjCEHStack.size()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// BreakContinuePop - Note end of previous break and continue level.
|
|
|
|
void BreakContinuePop() {
|
|
|
|
BreakContinueStack.pop_back();
|
|
|
|
}
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
// BreakContinueStack - This keeps track of where break and continue
|
2009-02-07 20:52:26 +08:00
|
|
|
// statements should jump to, as well as the depth of the stack and the size
|
|
|
|
// of the eh stack.
|
2007-07-17 05:28:45 +08:00
|
|
|
struct BreakContinue {
|
2009-02-07 20:52:26 +08:00
|
|
|
BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb,
|
2009-02-08 07:02:10 +08:00
|
|
|
llvm::Value *bsd, llvm::Value *csd, size_t ehss)
|
|
|
|
: BreakBlock(bb), ContinueBlock(cb), SaveBreakStackDepth(bsd),
|
|
|
|
SaveContinueStackDepth(csd), EHStackSize(ehss) {}
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-07-17 05:28:45 +08:00
|
|
|
llvm::BasicBlock *BreakBlock;
|
|
|
|
llvm::BasicBlock *ContinueBlock;
|
2009-02-08 07:02:10 +08:00
|
|
|
llvm::Value *SaveBreakStackDepth;
|
|
|
|
llvm::Value *SaveContinueStackDepth;
|
2008-12-14 06:52:24 +08:00
|
|
|
size_t EHStackSize;
|
2009-02-09 07:14:22 +08:00
|
|
|
};
|
2007-07-17 05:28:45 +08:00
|
|
|
llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
|
2008-09-28 09:03:14 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// SwitchInsn - This is nearest current switch instruction. It is null if if
|
|
|
|
/// current context is not in a switch.
|
2007-10-05 07:45:31 +08:00
|
|
|
llvm::SwitchInst *SwitchInsn;
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// CaseRangeBlock - This block holds if condition check for last case
|
2007-10-10 01:08:50 +08:00
|
|
|
/// statement range in current switch instruction.
|
2007-10-09 04:57:48 +08:00
|
|
|
llvm::BasicBlock *CaseRangeBlock;
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
// VLASizeMap - This keeps track of the associated size for each VLA type.
|
|
|
|
// FIXME: Maybe this could be a stack of maps that is pushed/popped as we
|
|
|
|
// enter/leave scopes.
|
2008-12-12 15:19:02 +08:00
|
|
|
llvm::DenseMap<const VariableArrayType*, llvm::Value*> VLASizeMap;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
|
|
|
/// StackDepth - This keeps track of the stack depth. It is used to notice
|
|
|
|
/// when control flow results in a change in stack depth and to arrange for
|
|
|
|
/// the appropriate stack depth to be restored. VLAs are the primary means by
|
|
|
|
/// which the stack depth changes.
|
2009-02-07 20:52:26 +08:00
|
|
|
llvm::Value *StackDepth;
|
|
|
|
|
2008-12-12 13:52:00 +08:00
|
|
|
/// StackSaveValues - A stack(!) of stack save values. When a new scope is
|
2009-02-09 07:14:22 +08:00
|
|
|
/// entered, a null is pushed on this stack. If a VLA is emitted, then the
|
|
|
|
/// return value of llvm.stacksave() is stored at the top of this stack.
|
2008-12-12 13:52:00 +08:00
|
|
|
llvm::SmallVector<llvm::Value*, 8> StackSaveValues;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
|
|
|
/// StackDepthMap - A association of stack depth that will be in effect for
|
|
|
|
/// each label. If control flow is transferred to a label, we have to restore
|
|
|
|
/// the desired stack depth at the destination label, beore we transfer to
|
|
|
|
/// that label.
|
2009-02-08 17:22:19 +08:00
|
|
|
llvm::DenseMap<const void*, llvm::Value *> StackDepthMap;
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// StackFixupAtLabel - Routine to adjust the stack to the depth the stack
|
|
|
|
/// should be at by the time we transfer control flow to the label. This is
|
|
|
|
/// called as we emit destinations for control flow, such as user labels for
|
|
|
|
/// goto statements and compiler generated labels for break and continue
|
|
|
|
/// processsing. We return true, if for any reason we can't generate code for
|
|
|
|
/// the construct yet. See EmitStackUpdate for the paired routine to mark the
|
|
|
|
/// branch.
|
2009-02-08 17:22:19 +08:00
|
|
|
bool StackFixupAtLabel(const void *);
|
2009-02-07 20:52:26 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitStackUpdate - Routine to adjust the stack to the depth the stack
|
|
|
|
/// should be at by the time we transfer control flow to the label. This is
|
|
|
|
/// called just before emitting branches for user level goto processing,
|
|
|
|
/// branhes for break or continue processing. The llvm::value overload is
|
|
|
|
/// used when handling break and continue, as we know the stack depth
|
|
|
|
/// directly. We return true, if for any reason we can't generate code for
|
|
|
|
/// the construct yet. See StackFixupAtLabel for the paired routine to mark
|
|
|
|
/// the destinations.
|
2009-02-08 17:22:19 +08:00
|
|
|
bool EmitStackUpdate(llvm::Value *V);
|
|
|
|
bool EmitStackUpdate(const void *S);
|
2009-02-07 20:52:26 +08:00
|
|
|
|
2009-02-08 06:53:43 +08:00
|
|
|
struct CleanupEntry {
|
|
|
|
/// CleanupBlock - The block of code that does the actual cleanup.
|
|
|
|
llvm::BasicBlock *CleanupBlock;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2009-02-08 06:53:43 +08:00
|
|
|
/// Blocks - Basic blocks that were emitted in the current cleanup scope.
|
2009-02-08 15:46:24 +08:00
|
|
|
std::vector<llvm::BasicBlock *> Blocks;
|
2009-02-08 06:53:43 +08:00
|
|
|
|
|
|
|
/// BranchFixups - Branch instructions to basic blocks that haven't been
|
|
|
|
/// inserted into the current function yet.
|
2009-02-08 15:46:24 +08:00
|
|
|
std::vector<llvm::BranchInst *> BranchFixups;
|
2009-02-08 06:53:43 +08:00
|
|
|
|
|
|
|
explicit CleanupEntry(llvm::BasicBlock *cb)
|
|
|
|
: CleanupBlock(cb) {}
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2009-02-08 08:16:35 +08:00
|
|
|
~CleanupEntry() {
|
|
|
|
assert(Blocks.empty() && "Did not empty blocks!");
|
|
|
|
assert(BranchFixups.empty() && "Did not empty branch fixups!");
|
|
|
|
}
|
2009-02-08 06:53:43 +08:00
|
|
|
};
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2009-02-08 06:53:43 +08:00
|
|
|
/// CleanupEntries - Stack of cleanup entries.
|
|
|
|
llvm::SmallVector<CleanupEntry, 8> CleanupEntries;
|
|
|
|
|
2009-02-08 08:16:35 +08:00
|
|
|
typedef llvm::DenseMap<llvm::BasicBlock*, size_t> BlockScopeMap;
|
|
|
|
|
|
|
|
/// BlockScopes - Map of which "cleanup scope" scope basic blocks have.
|
|
|
|
BlockScopeMap BlockScopes;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-05-28 09:07:47 +08:00
|
|
|
public:
|
2007-05-30 07:17:50 +08:00
|
|
|
CodeGenFunction(CodeGenModule &cgm);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-06-03 06:49:07 +08:00
|
|
|
ASTContext &getContext() const;
|
|
|
|
|
2008-03-31 07:03:07 +08:00
|
|
|
void GenerateObjCMethod(const ObjCMethodDecl *OMD);
|
2008-08-26 16:29:31 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
void StartObjCMethod(const ObjCMethodDecl *MD,
|
2009-01-11 05:06:09 +08:00
|
|
|
const ObjCContainerDecl *CD);
|
2008-08-26 16:29:31 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// GenerateObjCGetter - Synthesize an Objective-C property getter function.
|
2008-12-10 04:23:04 +08:00
|
|
|
void GenerateObjCGetter(ObjCImplementationDecl *IMP,
|
|
|
|
const ObjCPropertyImplDecl *PID);
|
2008-08-26 16:29:31 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// GenerateObjCSetter - Synthesize an Objective-C property setter function
|
|
|
|
/// for the given property.
|
2008-12-10 04:23:04 +08:00
|
|
|
void GenerateObjCSetter(ObjCImplementationDecl *IMP,
|
|
|
|
const ObjCPropertyImplDecl *PID);
|
2008-08-26 16:29:31 +08:00
|
|
|
|
2008-07-30 07:18:29 +08:00
|
|
|
void GenerateCode(const FunctionDecl *FD,
|
|
|
|
llvm::Function *Fn);
|
2009-02-09 07:14:22 +08:00
|
|
|
void StartFunction(const Decl *D, QualType RetTy,
|
2008-09-10 07:14:03 +08:00
|
|
|
llvm::Function *Fn,
|
2008-10-19 02:22:23 +08:00
|
|
|
const FunctionArgList &Args,
|
|
|
|
SourceLocation StartLoc);
|
2008-11-12 07:11:34 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitReturnBlock - Emit the unified return block, trying to avoid its
|
|
|
|
/// emission when possible.
|
2009-01-27 07:27:52 +08:00
|
|
|
void EmitReturnBlock();
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// FinishFunction - Complete IR generation of the current function. It is
|
|
|
|
/// legal to call this function even if there is no current insertion point.
|
2008-08-26 16:29:31 +08:00
|
|
|
void FinishFunction(SourceLocation EndLoc=SourceLocation());
|
2008-09-10 07:27:19 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitFunctionProlog - Emit the target specific LLVM code to load the
|
|
|
|
/// arguments for the given function. This is also responsible for naming the
|
|
|
|
/// LLVM function arguments.
|
2009-02-03 06:03:45 +08:00
|
|
|
void EmitFunctionProlog(const CGFunctionInfo &FI,
|
|
|
|
llvm::Function *Fn,
|
2008-09-10 07:27:19 +08:00
|
|
|
const FunctionArgList &Args);
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitFunctionEpilog - Emit the target specific LLVM code to return the
|
|
|
|
/// given temporary.
|
2009-02-03 06:03:45 +08:00
|
|
|
void EmitFunctionEpilog(const CGFunctionInfo &FI, llvm::Value *ReturnValue);
|
2008-09-10 07:27:19 +08:00
|
|
|
|
2009-02-04 07:03:55 +08:00
|
|
|
const llvm::Type *ConvertTypeForMem(QualType T);
|
2007-06-23 03:05:19 +08:00
|
|
|
const llvm::Type *ConvertType(QualType T);
|
2008-04-04 12:07:35 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// LoadObjCSelf - Load the value of self. This function is only valid while
|
|
|
|
/// generating code for an Objective-C method.
|
2008-04-04 12:07:35 +08:00
|
|
|
llvm::Value *LoadObjCSelf();
|
2009-02-09 07:14:22 +08:00
|
|
|
|
|
|
|
/// TypeOfSelfObject - Return type of object that this self represents.
|
2009-02-03 08:09:52 +08:00
|
|
|
QualType TypeOfSelfObject();
|
2008-06-18 02:05:57 +08:00
|
|
|
|
|
|
|
/// isObjCPointerType - Return true if the specificed AST type will map onto
|
|
|
|
/// some Objective-C pointer type.
|
|
|
|
static bool isObjCPointerType(QualType T);
|
|
|
|
|
2007-06-23 06:02:34 +08:00
|
|
|
/// hasAggregateLLVMType - Return true if the specified AST type will map into
|
|
|
|
/// an aggregate LLVM type or is void.
|
|
|
|
static bool hasAggregateLLVMType(QualType T);
|
2008-11-11 10:29:29 +08:00
|
|
|
|
|
|
|
/// createBasicBlock - Create an LLVM basic block.
|
2009-02-09 07:14:22 +08:00
|
|
|
llvm::BasicBlock *createBasicBlock(const char *Name="",
|
2008-11-11 10:29:29 +08:00
|
|
|
llvm::Function *Parent=0,
|
|
|
|
llvm::BasicBlock *InsertBefore=0) {
|
2008-11-12 08:01:12 +08:00
|
|
|
#ifdef NDEBUG
|
|
|
|
return llvm::BasicBlock::Create("", Parent, InsertBefore);
|
|
|
|
#else
|
2008-11-11 10:29:29 +08:00
|
|
|
return llvm::BasicBlock::Create(Name, Parent, InsertBefore);
|
2008-11-12 08:01:12 +08:00
|
|
|
#endif
|
2008-11-11 10:29:29 +08:00
|
|
|
}
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-05-30 08:13:02 +08:00
|
|
|
/// getBasicBlockForLabel - Return the LLVM basicblock that the specified
|
|
|
|
/// label maps to.
|
|
|
|
llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
|
|
|
/// EmitBlock - Emit the given block \arg BB and set it as the insert point,
|
|
|
|
/// adding a fall-through branch from the current insert block if
|
|
|
|
/// necessary. It is legal to call this function even if there is no current
|
|
|
|
/// insertion point.
|
2008-11-13 09:24:05 +08:00
|
|
|
///
|
2009-02-09 07:14:22 +08:00
|
|
|
/// IsFinished - If true, indicates that the caller has finished emitting
|
|
|
|
/// branches to the given block and does not expect to emit code into it. This
|
|
|
|
/// means the block can be ignored if it is unreachable.
|
2008-11-13 09:24:05 +08:00
|
|
|
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false);
|
2008-11-11 12:34:23 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitBranch - Emit a branch to the specified basic block from the current
|
|
|
|
/// insert block, taking care to avoid creation of branches from dummy
|
|
|
|
/// blocks. It is legal to call this function even if there is no current
|
|
|
|
/// insertion point.
|
2008-11-12 06:06:59 +08:00
|
|
|
///
|
2009-02-09 07:14:22 +08:00
|
|
|
/// This function clears the current insertion point. The caller should follow
|
|
|
|
/// calls to this function with calls to Emit*Block prior to generation new
|
|
|
|
/// code.
|
2008-11-11 17:41:28 +08:00
|
|
|
void EmitBranch(llvm::BasicBlock *Block);
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// HaveInsertPoint - True if an insertion point is defined. If not, this
|
|
|
|
/// indicates that the current code being emitted is unreachable.
|
|
|
|
bool HaveInsertPoint() const {
|
2008-11-12 07:11:34 +08:00
|
|
|
return Builder.GetInsertBlock() != 0;
|
|
|
|
}
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EnsureInsertPoint - Ensure that an insertion point is defined so that
|
|
|
|
/// emitted IR has a place to go. Note that by definition, if this function
|
|
|
|
/// creates a block then that block is unreachable; callers may do better to
|
|
|
|
/// detect when no insertion point is defined and simply skip IR generation.
|
2008-11-12 07:11:34 +08:00
|
|
|
void EnsureInsertPoint() {
|
|
|
|
if (!HaveInsertPoint())
|
|
|
|
EmitBlock(createBasicBlock());
|
|
|
|
}
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2008-08-16 08:56:44 +08:00
|
|
|
/// ErrorUnsupported - Print out an error that codegen doesn't support the
|
2007-12-02 09:43:38 +08:00
|
|
|
/// specified stmt yet.
|
2008-09-04 11:43:08 +08:00
|
|
|
void ErrorUnsupported(const Stmt *S, const char *Type,
|
|
|
|
bool OmitOnError=false);
|
2007-06-02 12:16:21 +08:00
|
|
|
|
2007-06-23 05:44:33 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Helpers
|
|
|
|
//===--------------------------------------------------------------------===//
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-06-23 05:44:33 +08:00
|
|
|
/// CreateTempAlloca - This creates a alloca and inserts it into the entry
|
|
|
|
/// block.
|
|
|
|
llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
|
|
|
|
const char *Name = "tmp");
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-06-06 04:53:16 +08:00
|
|
|
/// EvaluateExprAsBool - Perform the usual unary conversions on the specified
|
|
|
|
/// expression and compare the result against zero, returning an Int1Ty value.
|
2007-06-16 07:05:46 +08:00
|
|
|
llvm::Value *EvaluateExprAsBool(const Expr *E);
|
2007-06-23 05:44:33 +08:00
|
|
|
|
2007-09-01 06:49:20 +08:00
|
|
|
/// EmitAnyExpr - Emit code to compute the specified expression which can have
|
|
|
|
/// any type. The result is returned as an RValue struct. If this is an
|
|
|
|
/// aggregate expression, the aggloc/agglocvolatile arguments indicate where
|
|
|
|
/// the result should be returned.
|
2009-02-09 07:14:22 +08:00
|
|
|
RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
|
2007-09-01 06:49:20 +08:00
|
|
|
bool isAggLocVolatile = false);
|
2007-09-29 05:49:18 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
// EmitVAListRef - Emit a "reference" to a va_list; this is either the address
|
|
|
|
// or the value of the expression, depending on how va_list is defined.
|
2009-01-21 01:46:04 +08:00
|
|
|
llvm::Value *EmitVAListRef(const Expr *E);
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will
|
|
|
|
/// always be accessible even if no aggregate location is provided.
|
|
|
|
RValue EmitAnyExprToTemp(const Expr *E, llvm::Value *AggLoc = 0,
|
2008-09-09 09:06:48 +08:00
|
|
|
bool isAggLocVolatile = false);
|
|
|
|
|
2008-09-10 04:49:46 +08:00
|
|
|
void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr,
|
|
|
|
QualType EltTy);
|
|
|
|
|
|
|
|
void EmitAggregateClear(llvm::Value *DestPtr, QualType Ty);
|
|
|
|
|
2007-10-05 07:45:31 +08:00
|
|
|
/// StartBlock - Start new block named N. If insert block is a dummy block
|
|
|
|
/// then reuse it.
|
|
|
|
void StartBlock(const char *N);
|
|
|
|
|
2007-11-02 03:11:01 +08:00
|
|
|
/// getCGRecordLayout - Return record layout info.
|
|
|
|
const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy);
|
2008-02-27 05:41:45 +08:00
|
|
|
|
|
|
|
/// GetAddrOfStaticLocalVar - Return the address of a static local variable.
|
2008-04-16 06:42:06 +08:00
|
|
|
llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
|
2008-05-22 08:50:06 +08:00
|
|
|
|
2008-09-11 17:15:33 +08:00
|
|
|
/// GetAddrOfLocalVar - Return the address of a local variable.
|
|
|
|
llvm::Value *GetAddrOfLocalVar(const VarDecl *VD);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2008-05-22 08:50:06 +08:00
|
|
|
/// getAccessedFieldNo - Given an encoded value and a result number, return
|
|
|
|
/// the input field number being accessed.
|
|
|
|
static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
|
|
|
|
|
2008-08-05 00:51:22 +08:00
|
|
|
unsigned GetIDForAddrOfLabel(const LabelStmt *L);
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitMemSetToZero - Generate code to memset a value of the given type to 0.
|
2008-08-31 03:51:14 +08:00
|
|
|
void EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty);
|
2008-11-04 13:30:00 +08:00
|
|
|
|
|
|
|
// EmitVAArg - Generate code to get an argument from the passed in pointer
|
|
|
|
// and update it accordingly. The return value is a pointer to the argument.
|
|
|
|
// FIXME: We should be able to get rid of this method and use the va_arg
|
2009-02-09 07:14:22 +08:00
|
|
|
// instruction in LLVM instead once it works well enough.
|
2008-11-04 13:30:00 +08:00
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty);
|
2008-12-21 04:27:15 +08:00
|
|
|
|
2008-12-21 04:46:34 +08:00
|
|
|
// EmitVLASize - Generate code for any VLA size expressions that might occur
|
|
|
|
// in a variably modified type. If Ty is a VLA, will return the value that
|
|
|
|
// corresponds to the size in bytes of the VLA type. Will return 0 otherwise.
|
|
|
|
llvm::Value *EmitVLASize(QualType Ty);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2008-12-12 15:19:02 +08:00
|
|
|
// GetVLASize - Returns an LLVM value that corresponds to the size in bytes
|
|
|
|
// of a variable length array type.
|
|
|
|
llvm::Value *GetVLASize(const VariableArrayType *);
|
|
|
|
|
2007-06-02 12:16:21 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
2007-06-14 04:44:40 +08:00
|
|
|
// Declaration Emission
|
2007-06-02 12:16:21 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-06-09 09:20:56 +08:00
|
|
|
void EmitDecl(const Decl &D);
|
2008-04-16 06:42:06 +08:00
|
|
|
void EmitBlockVarDecl(const VarDecl &D);
|
|
|
|
void EmitLocalBlockVarDecl(const VarDecl &D);
|
|
|
|
void EmitStaticBlockVarDecl(const VarDecl &D);
|
2008-08-16 11:19:19 +08:00
|
|
|
|
|
|
|
/// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
|
|
|
|
void EmitParmDecl(const VarDecl &D, llvm::Value *Arg);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-05-30 07:50:05 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Statement Emission
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
|
2008-11-12 16:21:33 +08:00
|
|
|
void EmitStopPoint(const Stmt *S);
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitStmt - Emit the code for the statement \arg S. It is legal to call
|
|
|
|
/// this function even if there is no current insertion point.
|
|
|
|
///
|
|
|
|
/// This function may clear the current insertion point; callers should use
|
|
|
|
/// EnsureInsertPoint if they wish to subsequently generate code without first
|
|
|
|
/// calling EmitBlock, EmitBranch, or EmitStmt.
|
2007-05-30 07:50:05 +08:00
|
|
|
void EmitStmt(const Stmt *S);
|
2008-11-12 07:11:34 +08:00
|
|
|
|
2008-11-12 16:21:33 +08:00
|
|
|
/// EmitSimpleStmt - Try to emit a "simple" statement which does not
|
2009-02-09 07:14:22 +08:00
|
|
|
/// necessarily require an insertion point or debug information; typically
|
|
|
|
/// because the statement amounts to a jump or a container of other
|
|
|
|
/// statements.
|
2008-11-12 16:21:33 +08:00
|
|
|
///
|
|
|
|
/// \return True if the statement was handled.
|
|
|
|
bool EmitSimpleStmt(const Stmt *S);
|
|
|
|
|
2007-09-01 06:49:20 +08:00
|
|
|
RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
|
|
|
|
llvm::Value *AggLoc = 0, bool isAggVol = false);
|
2008-11-12 07:11:34 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitLabel - Emit the block for the given label. It is legal to call this
|
|
|
|
/// function even if there is no current insertion point.
|
2008-07-27 04:23:23 +08:00
|
|
|
void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt.
|
2008-11-12 07:11:34 +08:00
|
|
|
|
2007-05-30 08:13:02 +08:00
|
|
|
void EmitLabelStmt(const LabelStmt &S);
|
|
|
|
void EmitGotoStmt(const GotoStmt &S);
|
2008-08-05 00:51:22 +08:00
|
|
|
void EmitIndirectGotoStmt(const IndirectGotoStmt &S);
|
2007-05-31 05:03:58 +08:00
|
|
|
void EmitIfStmt(const IfStmt &S);
|
2007-06-05 11:59:43 +08:00
|
|
|
void EmitWhileStmt(const WhileStmt &S);
|
2007-06-06 04:53:16 +08:00
|
|
|
void EmitDoStmt(const DoStmt &S);
|
|
|
|
void EmitForStmt(const ForStmt &S);
|
2007-06-02 11:19:07 +08:00
|
|
|
void EmitReturnStmt(const ReturnStmt &S);
|
2007-06-09 09:20:56 +08:00
|
|
|
void EmitDeclStmt(const DeclStmt &S);
|
2008-11-12 16:21:33 +08:00
|
|
|
void EmitBreakStmt(const BreakStmt &S);
|
|
|
|
void EmitContinueStmt(const ContinueStmt &S);
|
2007-10-05 07:45:31 +08:00
|
|
|
void EmitSwitchStmt(const SwitchStmt &S);
|
|
|
|
void EmitDefaultStmt(const DefaultStmt &S);
|
|
|
|
void EmitCaseStmt(const CaseStmt &S);
|
2007-10-09 04:57:48 +08:00
|
|
|
void EmitCaseStmtRange(const CaseStmt &S);
|
2008-02-06 00:35:33 +08:00
|
|
|
void EmitAsmStmt(const AsmStmt &S);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2008-08-31 03:51:14 +08:00
|
|
|
void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S);
|
2008-09-09 18:04:29 +08:00
|
|
|
void EmitObjCAtTryStmt(const ObjCAtTryStmt &S);
|
|
|
|
void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S);
|
2008-11-16 05:26:17 +08:00
|
|
|
void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-06-02 13:24:33 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// LValue Expression Emission
|
|
|
|
//===--------------------------------------------------------------------===//
|
2007-06-06 04:53:16 +08:00
|
|
|
|
2009-02-05 15:09:07 +08:00
|
|
|
/// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
|
|
|
|
RValue GetUndefRValue(QualType Ty);
|
|
|
|
|
2009-01-10 00:50:52 +08:00
|
|
|
/// EmitUnsupportedRValue - Emit a dummy r-value using the type of E
|
|
|
|
/// and issue an ErrorUnsupported style diagnostic (using the
|
|
|
|
/// provided Name).
|
|
|
|
RValue EmitUnsupportedRValue(const Expr *E,
|
|
|
|
const char *Name);
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue
|
|
|
|
/// an ErrorUnsupported style diagnostic (using the provided Name).
|
2008-08-26 04:45:57 +08:00
|
|
|
LValue EmitUnsupportedLValue(const Expr *E,
|
|
|
|
const char *Name);
|
|
|
|
|
2007-06-06 04:53:16 +08:00
|
|
|
/// EmitLValue - Emit code to compute a designator that specifies the location
|
|
|
|
/// of the expression.
|
|
|
|
///
|
|
|
|
/// This can return one of two things: a simple address or a bitfield
|
|
|
|
/// reference. In either case, the LLVM Value* in the LValue structure is
|
|
|
|
/// guaranteed to be an LLVM pointer type.
|
|
|
|
///
|
|
|
|
/// If this returns a bitfield reference, nothing about the pointee type of
|
|
|
|
/// the LLVM value is known: For example, it may not be a pointer to an
|
|
|
|
/// integer.
|
|
|
|
///
|
|
|
|
/// If this returns a normal address, and if the lvalue's C type is fixed
|
|
|
|
/// size, this method guarantees that the returned pointer type will point to
|
|
|
|
/// an LLVM type of the same size of the lvalue's type. If the lvalue has a
|
|
|
|
/// variable length type, this is not possible.
|
|
|
|
///
|
2007-06-02 13:24:33 +08:00
|
|
|
LValue EmitLValue(const Expr *E);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-06-06 04:53:16 +08:00
|
|
|
/// EmitLoadOfLValue - Given an expression that represents a value lvalue,
|
|
|
|
/// this method emits the address of the lvalue, then loads the result as an
|
|
|
|
/// rvalue, returning the rvalue.
|
2007-06-30 00:31:29 +08:00
|
|
|
RValue EmitLoadOfLValue(LValue V, QualType LVType);
|
2008-04-19 07:10:10 +08:00
|
|
|
RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType);
|
2008-01-23 04:17:04 +08:00
|
|
|
RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType);
|
2008-08-29 16:11:39 +08:00
|
|
|
RValue EmitLoadOfPropertyRefLValue(LValue LV, QualType ExprType);
|
2008-11-23 06:30:21 +08:00
|
|
|
RValue EmitLoadOfKVCRefLValue(LValue LV, QualType ExprType);
|
2007-06-30 00:31:29 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-06-06 04:53:16 +08:00
|
|
|
/// EmitStoreThroughLValue - Store the specified rvalue into the specified
|
|
|
|
/// lvalue, where both are guaranteed to the have the same type, and that type
|
|
|
|
/// is 'Ty'.
|
|
|
|
void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
|
2008-04-19 07:10:10 +08:00
|
|
|
void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst,
|
|
|
|
QualType Ty);
|
2008-08-29 16:11:39 +08:00
|
|
|
void EmitStoreThroughPropertyRefLValue(RValue Src, LValue Dst, QualType Ty);
|
2008-11-23 06:30:21 +08:00
|
|
|
void EmitStoreThroughKVCRefLValue(RValue Src, LValue Dst, QualType Ty);
|
2008-11-19 17:36:46 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitStoreThroughLValue - Store Src into Dst with same constraints as
|
|
|
|
/// EmitStoreThroughLValue.
|
2008-11-19 17:36:46 +08:00
|
|
|
///
|
2009-02-09 07:14:22 +08:00
|
|
|
/// \param Result [out] - If non-null, this will be set to a Value* for the
|
|
|
|
/// bit-field contents after the store, appropriate for use as the result of
|
|
|
|
/// an assignment to the bit-field.
|
2008-11-19 17:36:46 +08:00
|
|
|
void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty,
|
|
|
|
llvm::Value **Result=0);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-12-29 13:02:41 +08:00
|
|
|
// Note: only availabe for agg return types
|
2008-09-04 11:20:13 +08:00
|
|
|
LValue EmitBinaryOperatorLValue(const BinaryOperator *E);
|
|
|
|
// Note: only availabe for agg return types
|
2007-12-29 13:02:41 +08:00
|
|
|
LValue EmitCallExprLValue(const CallExpr *E);
|
2007-06-02 13:24:33 +08:00
|
|
|
LValue EmitDeclRefLValue(const DeclRefExpr *E);
|
2007-06-06 12:54:52 +08:00
|
|
|
LValue EmitStringLiteralLValue(const StringLiteral *E);
|
2008-10-18 05:58:32 +08:00
|
|
|
LValue EmitPredefinedFunctionName(unsigned Type);
|
2008-08-10 09:53:14 +08:00
|
|
|
LValue EmitPredefinedLValue(const PredefinedExpr *E);
|
2007-06-06 04:53:16 +08:00
|
|
|
LValue EmitUnaryOpLValue(const UnaryOperator *E);
|
2007-06-09 07:31:14 +08:00
|
|
|
LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
|
2008-04-19 07:10:10 +08:00
|
|
|
LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
|
2007-10-23 10:10:49 +08:00
|
|
|
LValue EmitMemberExpr(const MemberExpr *E);
|
2008-05-14 07:18:27 +08:00
|
|
|
LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
|
2008-02-09 16:50:58 +08:00
|
|
|
|
2008-09-24 12:00:38 +08:00
|
|
|
llvm::Value *EmitIvarOffset(ObjCInterfaceDecl *Interface,
|
|
|
|
const ObjCIvarDecl *Ivar);
|
2008-02-09 16:50:58 +08:00
|
|
|
LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field,
|
2008-06-14 07:01:12 +08:00
|
|
|
bool isUnion, unsigned CVRQualifiers);
|
2009-02-03 08:09:52 +08:00
|
|
|
LValue EmitLValueForIvar(QualType ObjectTy,
|
|
|
|
llvm::Value* Base, const ObjCIvarDecl *Ivar,
|
2008-12-16 04:35:07 +08:00
|
|
|
const FieldDecl *Field,
|
2008-09-24 12:00:38 +08:00
|
|
|
unsigned CVRQualifiers);
|
|
|
|
|
2008-12-16 04:35:07 +08:00
|
|
|
LValue EmitLValueForBitfield(llvm::Value* Base, FieldDecl* Field,
|
2009-02-04 03:03:09 +08:00
|
|
|
unsigned CVRQualifiers);
|
2008-12-16 04:35:07 +08:00
|
|
|
|
2008-09-10 10:36:38 +08:00
|
|
|
LValue EmitCXXConditionDeclLValue(const CXXConditionDeclExpr *E);
|
|
|
|
|
2008-08-23 18:51:21 +08:00
|
|
|
LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E);
|
2008-03-31 07:03:07 +08:00
|
|
|
LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
|
2008-08-29 16:11:39 +08:00
|
|
|
LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E);
|
2008-11-23 06:30:21 +08:00
|
|
|
LValue EmitObjCKVCRefLValue(const ObjCKVCRefExpr *E);
|
2008-11-04 22:56:14 +08:00
|
|
|
LValue EmitObjCSuperExpr(const ObjCSuperExpr *E);
|
2008-08-23 18:51:21 +08:00
|
|
|
|
2007-05-31 01:57:17 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
2007-08-11 08:04:45 +08:00
|
|
|
// Scalar Expression Emission
|
2007-05-31 01:57:17 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitCall - Generate a call of the given function, expecting the given
|
|
|
|
/// result type, and using the given argument list which specifies both the
|
|
|
|
/// LLVM arguments and the types they were derived from.
|
2009-02-03 06:03:45 +08:00
|
|
|
RValue EmitCall(const CGFunctionInfo &FnInfo,
|
|
|
|
llvm::Value *Callee,
|
2008-08-30 11:02:31 +08:00
|
|
|
const CallArgList &Args);
|
|
|
|
|
2007-06-16 05:34:29 +08:00
|
|
|
RValue EmitCallExpr(const CallExpr *E);
|
This patch is motivated by numerous strict-aliasing warnings when compiling
clang as a Release build.
The big change is that all AST nodes (subclasses of Stmt) whose children are
Expr* store their children as Stmt* or arrays of Stmt*. This is to remove
strict-aliasing warnings when using StmtIterator. None of the interfaces of any
of the classes have changed (except those with arg_iterators, see below), as the
accessor methods introduce the needed casts (via cast<>). While this extra
casting may seem cumbersome, it actually adds some important sanity checks
throughout the codebase, as clients using StmtIterator can potentially overwrite
children that are expected to be Expr* with Stmt* (that aren't Expr*). The casts
provide extra sanity checks that are operational in debug builds to catch
invariant violations such as these.
For classes that have arg_iterators (e.g., CallExpr), the definition of
arg_iterator has been replaced. Instead of it being Expr**, it is an actual
class (called ExprIterator) that wraps a Stmt**, and provides the necessary
operators for iteration. The nice thing about this class is that it also uses
cast<> to type-checking, which introduces extra sanity checks throughout the
codebase that are useful for debugging.
A few of the CodeGen functions that use arg_iterator (especially from
OverloadExpr) have been modified to take begin and end iterators instead of a
base Expr** and the number of arguments. This matches more with the abstraction
of iteration. This still needs to be cleaned up a little bit, as clients expect
that ExprIterator is a RandomAccessIterator (which we may or may not wish to
allow for efficiency of representation).
This is a fairly large patch. It passes the tests (except CodeGen/bitfield.c,
which was already broken) on both a Debug and Release build, but it should
obviously be reviewed.
llvm-svn: 52378
2008-06-17 10:43:46 +08:00
|
|
|
|
|
|
|
RValue EmitCallExpr(Expr *FnExpr, CallExpr::const_arg_iterator ArgBeg,
|
|
|
|
CallExpr::const_arg_iterator ArgEnd);
|
|
|
|
|
2008-01-30 09:32:06 +08:00
|
|
|
RValue EmitCallExpr(llvm::Value *Callee, QualType FnType,
|
This patch is motivated by numerous strict-aliasing warnings when compiling
clang as a Release build.
The big change is that all AST nodes (subclasses of Stmt) whose children are
Expr* store their children as Stmt* or arrays of Stmt*. This is to remove
strict-aliasing warnings when using StmtIterator. None of the interfaces of any
of the classes have changed (except those with arg_iterators, see below), as the
accessor methods introduce the needed casts (via cast<>). While this extra
casting may seem cumbersome, it actually adds some important sanity checks
throughout the codebase, as clients using StmtIterator can potentially overwrite
children that are expected to be Expr* with Stmt* (that aren't Expr*). The casts
provide extra sanity checks that are operational in debug builds to catch
invariant violations such as these.
For classes that have arg_iterators (e.g., CallExpr), the definition of
arg_iterator has been replaced. Instead of it being Expr**, it is an actual
class (called ExprIterator) that wraps a Stmt**, and provides the necessary
operators for iteration. The nice thing about this class is that it also uses
cast<> to type-checking, which introduces extra sanity checks throughout the
codebase that are useful for debugging.
A few of the CodeGen functions that use arg_iterator (especially from
OverloadExpr) have been modified to take begin and end iterators instead of a
base Expr** and the number of arguments. This matches more with the abstraction
of iteration. This still needs to be cleaned up a little bit, as clients expect
that ExprIterator is a RandomAccessIterator (which we may or may not wish to
allow for efficiency of representation).
This is a fairly large patch. It passes the tests (except CodeGen/bitfield.c,
which was already broken) on both a Debug and Release build, but it should
obviously be reviewed.
llvm-svn: 52378
2008-06-17 10:43:46 +08:00
|
|
|
CallExpr::const_arg_iterator ArgBeg,
|
|
|
|
CallExpr::const_arg_iterator ArgEnd);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-08-27 06:58:05 +08:00
|
|
|
RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
|
2007-06-06 04:53:16 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call
|
|
|
|
/// is unhandled by the current target.
|
2008-10-10 08:24:54 +08:00
|
|
|
llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
|
|
|
|
|
2007-12-10 07:17:02 +08:00
|
|
|
llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
|
|
|
|
llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-12-11 03:35:18 +08:00
|
|
|
llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...);
|
2007-12-30 10:59:45 +08:00
|
|
|
llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals,
|
|
|
|
bool isSplat = false);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2008-08-20 08:28:19 +08:00
|
|
|
llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E);
|
2007-08-24 13:35:26 +08:00
|
|
|
llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
|
2008-06-25 01:04:18 +08:00
|
|
|
llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E);
|
2008-08-23 11:46:30 +08:00
|
|
|
RValue EmitObjCMessageExpr(const ObjCMessageExpr *E);
|
2008-11-23 02:39:36 +08:00
|
|
|
RValue EmitObjCPropertyGet(const Expr *E);
|
2008-11-23 06:30:21 +08:00
|
|
|
void EmitObjCPropertySet(const Expr *E, RValue Src);
|
2008-06-25 01:04:18 +08:00
|
|
|
|
|
|
|
|
2007-08-11 08:04:45 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
2007-08-27 07:13:56 +08:00
|
|
|
// Expression Emission
|
2007-08-11 08:04:45 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
2007-08-27 07:13:56 +08:00
|
|
|
|
|
|
|
// Expressions are broken into three classes: scalar, complex, aggregate.
|
2009-02-09 07:14:22 +08:00
|
|
|
|
|
|
|
/// EmitScalarExpr - Emit the computation of the specified expression of LLVM
|
|
|
|
/// scalar type, returning the result.
|
2007-08-24 13:35:26 +08:00
|
|
|
llvm::Value *EmitScalarExpr(const Expr *E);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-08-26 14:48:56 +08:00
|
|
|
/// EmitScalarConversion - Emit a conversion from the specified type to the
|
|
|
|
/// specified destination type, both of which are LLVM scalar types.
|
|
|
|
llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
|
|
|
|
QualType DstTy);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-08-27 00:34:22 +08:00
|
|
|
/// EmitComplexToScalarConversion - Emit a conversion from the specified
|
2009-02-09 07:14:22 +08:00
|
|
|
/// complex type to the specified destination type, where the destination type
|
|
|
|
/// is an LLVM scalar type.
|
2007-08-27 00:34:22 +08:00
|
|
|
llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
|
|
|
|
QualType DstTy);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
|
|
|
|
2007-08-11 08:04:45 +08:00
|
|
|
/// EmitAggExpr - Emit the computation of the specified expression of
|
|
|
|
/// aggregate type. The result is computed into DestPtr. Note that if
|
|
|
|
/// DestPtr is null, the value of the aggregate expression is not needed.
|
|
|
|
void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-08-21 13:54:00 +08:00
|
|
|
/// EmitComplexExpr - Emit the computation of the specified expression of
|
2007-08-24 07:43:33 +08:00
|
|
|
/// complex type, returning the result.
|
2007-08-22 00:57:55 +08:00
|
|
|
ComplexPairTy EmitComplexExpr(const Expr *E);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-08-24 07:43:33 +08:00
|
|
|
/// EmitComplexExprIntoAddr - Emit the computation of the specified expression
|
|
|
|
/// of complex type, storing into the specified Value*.
|
2007-08-27 00:22:13 +08:00
|
|
|
void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
|
|
|
|
bool DestIsVolatile);
|
2008-08-30 13:35:15 +08:00
|
|
|
|
|
|
|
/// StoreComplexToAddr - Store a complex number into the specified address.
|
|
|
|
void StoreComplexToAddr(ComplexPairTy V, llvm::Value *DestAddr,
|
|
|
|
bool DestIsVolatile);
|
2007-09-01 06:49:20 +08:00
|
|
|
/// LoadComplexFromAddr - Load a complex number from the specified address.
|
|
|
|
ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
|
2008-05-08 13:58:21 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// GenerateStaticBlockVarDecl - return the the static declaration of local
|
|
|
|
/// variable.
|
2009-02-04 02:07:49 +08:00
|
|
|
llvm::GlobalValue * GenerateStaticBlockVarDecl(const VarDecl &D,
|
|
|
|
bool NoInit,
|
|
|
|
const char *Separator,
|
|
|
|
llvm::GlobalValue
|
|
|
|
::LinkageTypes Linkage);
|
2008-08-05 00:51:22 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
// GenerateStaticCXXBlockVarDecl - return the static declaration of a local
|
|
|
|
// variable. Performs initialization of the variable if necessary.
|
2008-08-23 00:00:37 +08:00
|
|
|
llvm::GlobalValue *GenerateStaticCXXBlockVarDecl(const VarDecl &D);
|
|
|
|
|
2008-08-05 00:51:22 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Internal Helpers
|
|
|
|
//===--------------------------------------------------------------------===//
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2008-11-11 15:41:27 +08:00
|
|
|
/// ContainsLabel - Return true if the statement contains a label in it. If
|
|
|
|
/// this statement is not executed normally, it not containing a label means
|
|
|
|
/// that we can just remove the code.
|
|
|
|
static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2008-11-12 18:12:14 +08:00
|
|
|
/// ConstantFoldsToSimpleInteger - If the specified expression does not fold
|
2008-11-12 16:04:58 +08:00
|
|
|
/// to a constant, or if it does but contains a label, return 0. If it
|
|
|
|
/// constant folds to 'true' and does not contain a label, return 1, if it
|
|
|
|
/// constant folds to 'false' and does not contain a label, return -1.
|
|
|
|
int ConstantFoldsToSimpleInteger(const Expr *Cond);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2008-11-12 16:04:58 +08:00
|
|
|
/// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an
|
|
|
|
/// if statement) to the specified blocks. Based on the condition, this might
|
|
|
|
/// try to simplify the codegen of the conditional based on the branch.
|
Make emission of 'if' conditions much more sophisticated when we
have a condition that is an &&/||. Before we used to compile things like this:
int test() {
if (x && y) foo(); else bar();
}
into:
%0 = load i32* @x ; <i32> [#uses=1]
%1 = icmp ne i32 %0, 0 ; <i1> [#uses=1]
br i1 %1, label %land_rhs, label %land_cont
land_rhs: ; preds = %entry
%2 = load i32* @y ; <i32> [#uses=1]
%3 = icmp ne i32 %2, 0 ; <i1> [#uses=1]
br label %land_cont
land_cont: ; preds = %land_rhs, %entry
%4 = phi i1 [ false, %entry ], [ %3, %land_rhs ] ; <i1> [#uses=1]
br i1 %4, label %ifthen, label %ifelse
ifthen: ; preds = %land_cont
%call = call i32 (...)* @foo() ; <i32> [#uses=0]
br label %ifend
ifelse: ; preds = %land_cont
%call1 = call i32 (...)* @bar() ; <i32> [#uses=0]
br label %ifend
ifend: ; preds = %ifelse, %ifthen
Now we turn it into the much more svelte code:
%0 = load i32* @x ; <i32> [#uses=1]
%1 = icmp ne i32 %0, 0 ; <i1> [#uses=1]
br i1 %1, label %land_lhs_true, label %ifelse
land_lhs_true: ; preds = %entry
%2 = load i32* @y ; <i32> [#uses=1]
%3 = icmp ne i32 %2, 0 ; <i1> [#uses=1]
br i1 %3, label %ifthen, label %ifelse
ifthen: ; preds = %land_lhs_true
%call = call i32 (...)* @foo() ; <i32> [#uses=0]
br label %ifend
ifelse: ; preds = %land_lhs_true, %entry
%call1 = call i32 (...)* @bar() ; <i32> [#uses=0]
br label %ifend
ifend: ; preds = %ifelse, %ifthen
Note the lack of a phi node.
This shrinks the -O0 .ll file for 176.gcc/expr.c from 43176 to 40267 lines.
llvm-svn: 59111
2008-11-12 15:46:33 +08:00
|
|
|
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock,
|
2008-11-12 18:12:14 +08:00
|
|
|
llvm::BasicBlock *FalseBlock);
|
2008-11-12 16:04:58 +08:00
|
|
|
private:
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2008-08-05 00:51:22 +08:00
|
|
|
/// EmitIndirectSwitches - Emit code for all of the switch
|
|
|
|
/// instructions in IndirectSwitches.
|
|
|
|
void EmitIndirectSwitches();
|
2008-09-17 08:51:38 +08:00
|
|
|
|
2008-09-24 12:00:38 +08:00
|
|
|
void EmitReturnOfRValue(RValue RV, QualType Ty);
|
|
|
|
|
2008-09-17 08:51:38 +08:00
|
|
|
/// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty
|
|
|
|
/// from function arguments into \arg Dst. See ABIArgInfo::Expand.
|
|
|
|
///
|
|
|
|
/// \param AI - The first function argument of the expansion.
|
|
|
|
/// \return The argument following the last expanded function
|
|
|
|
/// argument.
|
2009-02-09 07:14:22 +08:00
|
|
|
llvm::Function::arg_iterator
|
2008-09-17 08:51:38 +08:00
|
|
|
ExpandTypeFromArgs(QualType Ty, LValue Dst,
|
|
|
|
llvm::Function::arg_iterator AI);
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg
|
|
|
|
/// Ty, into individual arguments on the provided vector \arg Args. See
|
|
|
|
/// ABIArgInfo::Expand.
|
|
|
|
void ExpandTypeToArgs(QualType Ty, RValue Src,
|
2008-09-17 08:51:38 +08:00
|
|
|
llvm::SmallVector<llvm::Value*, 16> &Args);
|
2009-01-12 03:40:10 +08:00
|
|
|
|
|
|
|
llvm::Value* EmitAsmInput(const AsmStmt &S, TargetInfo::ConstraintInfo Info,
|
|
|
|
const Expr *InputExpr, std::string &ConstraintStr);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2009-02-08 07:50:39 +08:00
|
|
|
/// EmitCleanupBlock - emits a single cleanup block.
|
|
|
|
void EmitCleanupBlock();
|
|
|
|
|
2009-02-08 08:50:42 +08:00
|
|
|
/// AddBranchFixup - adds a branch instruction to the list of fixups for the
|
|
|
|
/// current cleanup scope.
|
|
|
|
void AddBranchFixup(llvm::BranchInst *BI);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
};
|
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|