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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2007-05-28 09:07:47 +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"
|
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;
|
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;
|
2007-11-02 03:11:01 +08:00
|
|
|
class CGRecordLayout;
|
2008-11-01 09:53:16 +08:00
|
|
|
|
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;
|
2007-08-27 07:13:56 +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;
|
2007-06-02 11:19:07 +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;
|
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;
|
|
|
|
/// ReturnValue - The temporary alloca to hold the return value. This
|
|
|
|
/// is null iff the function has no return value.
|
|
|
|
llvm::Instruction *ReturnValue;
|
|
|
|
|
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:
|
|
|
|
// FIXME: The following should be private once EH code is moved out
|
|
|
|
// of NeXT runtime.
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
struct ObjCEHEntry {
|
2008-09-30 09:06:03 +08:00
|
|
|
ObjCEHEntry(llvm::BasicBlock *fb, llvm::BasicBlock *fne,
|
|
|
|
llvm::SwitchInst *fs, llvm::Value *dc)
|
|
|
|
: FinallyBlock(fb), FinallyNoExit(fne), FinallySwitch(fs),
|
|
|
|
DestCode(dc), Exception(0) {}
|
2008-09-28 09:03:14 +08:00
|
|
|
|
2008-09-30 09:06:03 +08:00
|
|
|
/// Entry point to the finally block.
|
|
|
|
llvm::BasicBlock *FinallyBlock;
|
|
|
|
|
|
|
|
/// Entry point to the finally block which skips execution of the
|
|
|
|
/// try_exit runtime function.
|
|
|
|
llvm::BasicBlock *FinallyNoExit;
|
|
|
|
|
|
|
|
/// Switch instruction which runs at the end of the finally block
|
|
|
|
/// to forward jumps through the finally block.
|
|
|
|
llvm::SwitchInst *FinallySwitch;
|
|
|
|
|
|
|
|
/// Variable holding the code for the destination of a jump
|
|
|
|
/// through the @finally block.
|
|
|
|
llvm::Value *DestCode;
|
|
|
|
|
|
|
|
/// The exception object being handled, during IR generation for a
|
|
|
|
/// @catch block.
|
|
|
|
llvm::Value *Exception;
|
2008-09-28 09:03:14 +08:00
|
|
|
};
|
2008-09-30 09:06:03 +08:00
|
|
|
|
|
|
|
typedef llvm::SmallVector<ObjCEHEntry*, 8> ObjCEHStackType;
|
|
|
|
ObjCEHStackType ObjCEHStack;
|
|
|
|
|
|
|
|
/// EmitJumpThroughFinally - Emit a branch from the current insert
|
|
|
|
/// point through the finally handling code for \arg Entry and then
|
2008-11-12 07:11:34 +08:00
|
|
|
/// 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
|
|
|
///
|
|
|
|
/// \param ExecuteTryExit - When true, the try_exit runtime function
|
|
|
|
/// should be called prior to executing the finally code.
|
|
|
|
void EmitJumpThroughFinally(ObjCEHEntry *Entry, llvm::BasicBlock *Dest,
|
|
|
|
bool ExecuteTryExit=true);
|
2007-06-03 06:49:07 +08:00
|
|
|
|
2007-08-24 13:35:26 +08:00
|
|
|
private:
|
2008-08-05 00:51: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().
|
|
|
|
std::map<const LabelStmt*, unsigned> LabelIDs;
|
|
|
|
|
|
|
|
/// IndirectSwitches - Record the list of switches for indirect
|
|
|
|
/// gotos. Emission of the actual switching code needs to be delayed
|
|
|
|
/// until all AddrLabelExprs have been seen.
|
|
|
|
std::vector<llvm::SwitchInst*> IndirectSwitches;
|
|
|
|
|
2007-06-02 12:16:21 +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;
|
2007-07-17 05:28:45 +08:00
|
|
|
|
|
|
|
// BreakContinueStack - This keeps track of where break and continue
|
|
|
|
// statements should jump to.
|
|
|
|
struct BreakContinue {
|
|
|
|
BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
|
|
|
|
: BreakBlock(bb), ContinueBlock(cb) {}
|
|
|
|
|
|
|
|
llvm::BasicBlock *BreakBlock;
|
|
|
|
llvm::BasicBlock *ContinueBlock;
|
|
|
|
};
|
|
|
|
llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
|
2008-09-28 09:03:14 +08:00
|
|
|
|
2007-10-10 01:08:50 +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;
|
|
|
|
|
2007-10-10 01:08:50 +08:00
|
|
|
/// CaseRangeBlock - This block holds if condition check for last case
|
|
|
|
/// statement range in current switch instruction.
|
2007-10-09 04:57:48 +08:00
|
|
|
llvm::BasicBlock *CaseRangeBlock;
|
|
|
|
|
2007-05-28 09:07:47 +08:00
|
|
|
public:
|
2007-05-30 07:17:50 +08:00
|
|
|
CodeGenFunction(CodeGenModule &cgm);
|
2007-05-24 14:29:05 +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
|
|
|
|
|
|
|
void StartObjCMethod(const ObjCMethodDecl *MD);
|
|
|
|
|
|
|
|
/// 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
|
|
|
|
|
|
|
/// 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);
|
2008-09-10 07:14:03 +08:00
|
|
|
void StartFunction(const Decl *D, QualType RetTy,
|
|
|
|
llvm::Function *Fn,
|
2008-10-19 02:22:23 +08:00
|
|
|
const FunctionArgList &Args,
|
|
|
|
SourceLocation StartLoc);
|
2008-11-12 07:11:34 +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
|
|
|
|
|
|
|
/// 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.
|
|
|
|
void EmitFunctionProlog(llvm::Function *Fn, QualType RetTy,
|
|
|
|
const FunctionArgList &Args);
|
|
|
|
|
|
|
|
/// EmitFunctionEpilog - Emit the target specific LLVM code to
|
|
|
|
/// return the given temporary.
|
|
|
|
void EmitFunctionEpilog(QualType RetTy,
|
|
|
|
llvm::Value *ReturnValue);
|
|
|
|
|
2007-06-23 03:05:19 +08:00
|
|
|
const llvm::Type *ConvertType(QualType T);
|
2008-04-04 12:07:35 +08:00
|
|
|
|
2008-08-16 11:19:19 +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();
|
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.
|
|
|
|
llvm::BasicBlock *createBasicBlock(const char *Name="",
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2008-11-12 07:11:34 +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
|
|
|
///
|
|
|
|
/// 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.
|
|
|
|
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false);
|
2008-11-11 12:34:23 +08:00
|
|
|
|
2008-11-11 17:41:28 +08:00
|
|
|
/// EmitBranch - Emit a branch to the specified basic block from the
|
|
|
|
/// current insert block, taking care to avoid creation of branches
|
2008-11-12 07:11:34 +08:00
|
|
|
/// 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
|
|
|
///
|
|
|
|
/// 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);
|
|
|
|
|
2008-11-12 07:11:34 +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 {
|
|
|
|
return Builder.GetInsertBlock() != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
void EnsureInsertPoint() {
|
|
|
|
if (!HaveInsertPoint())
|
|
|
|
EmitBlock(createBasicBlock());
|
|
|
|
}
|
2007-12-02 09:43:38 +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
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// CreateTempAlloca - This creates a alloca and inserts it into the entry
|
|
|
|
/// block.
|
|
|
|
llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
|
|
|
|
const char *Name = "tmp");
|
|
|
|
|
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.
|
|
|
|
RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
|
|
|
|
bool isAggLocVolatile = false);
|
2007-09-29 05:49:18 +08:00
|
|
|
|
2008-09-09 09:06:48 +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,
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
2008-08-31 03:51:14 +08:00
|
|
|
/// EmitMemSetToZero - Generate code to memset a value of the given type to 0;
|
|
|
|
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
|
|
|
|
// instruction in LLVM instead once it works well enough.
|
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty);
|
2008-08-31 03:51:14 +08:00
|
|
|
|
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
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
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);
|
2007-06-02 12:53:11 +08:00
|
|
|
|
2007-05-30 07:50:05 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Statement Emission
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2008-11-12 16:21:33 +08:00
|
|
|
/// EmitStopPoint - Emit a debug stoppoint if we are emitting debug
|
|
|
|
/// info.
|
|
|
|
void EmitStopPoint(const Stmt *S);
|
|
|
|
|
2008-11-12 07:11:34 +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
|
|
|
|
/// necessarily require an insertion point or debug information;
|
|
|
|
/// typically because the statement amounts to a jump or a container
|
|
|
|
/// of other statements.
|
|
|
|
///
|
|
|
|
/// \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
|
|
|
|
|
|
|
/// 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);
|
|
|
|
|
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);
|
2008-08-31 03:51:14 +08:00
|
|
|
|
2007-06-02 13:24:33 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// LValue Expression Emission
|
|
|
|
//===--------------------------------------------------------------------===//
|
2007-06-06 04:53:16 +08:00
|
|
|
|
2008-08-26 04:45:57 +08:00
|
|
|
/// EmitUnsupportedLValue - Emit a dummy l-value using the type of E
|
|
|
|
/// and issue an ErrorUnsupported style diagnostic (using the
|
|
|
|
/// provided Name).
|
|
|
|
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);
|
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
|
|
|
|
2007-08-04 00:18:34 +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
|
|
|
|
|
|
|
/// EmitStoreThroughLValue - Store Src into Dst with same
|
|
|
|
/// constraints as EmitStoreThroughLValue.
|
|
|
|
///
|
|
|
|
/// \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.
|
|
|
|
void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty,
|
|
|
|
llvm::Value **Result=0);
|
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);
|
2008-09-24 12:00:38 +08:00
|
|
|
LValue EmitLValueForIvar(llvm::Value* Base, const ObjCIvarDecl *Ivar,
|
|
|
|
unsigned CVRQualifiers);
|
|
|
|
|
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
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2008-08-30 13:35:15 +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.
|
2008-08-30 11:02:31 +08:00
|
|
|
RValue EmitCall(llvm::Value *Callee,
|
|
|
|
QualType ResultType,
|
|
|
|
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);
|
|
|
|
|
2007-08-27 06:58:05 +08:00
|
|
|
RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
|
2007-06-06 04:53:16 +08:00
|
|
|
|
2008-10-10 08:24:54 +08:00
|
|
|
/// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0
|
|
|
|
/// if the call is unhandled by the current target.
|
|
|
|
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);
|
|
|
|
|
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);
|
2007-12-16 05:23:30 +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.
|
2007-08-11 08:04:45 +08:00
|
|
|
|
2007-08-24 13:35:26 +08:00
|
|
|
/// EmitScalarExpr - Emit the computation of the specified expression of
|
|
|
|
/// LLVM scalar type, returning the result.
|
|
|
|
llvm::Value *EmitScalarExpr(const Expr *E);
|
|
|
|
|
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);
|
|
|
|
|
2007-08-27 00:34:22 +08:00
|
|
|
/// EmitComplexToScalarConversion - Emit a conversion from the specified
|
|
|
|
/// complex type to the specified destination type, where the destination
|
|
|
|
/// type is an LLVM scalar type.
|
|
|
|
llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
|
|
|
|
QualType DstTy);
|
|
|
|
|
2007-08-26 14:48:56 +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);
|
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);
|
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
|
|
|
|
|
|
|
/// GenerateStaticBlockVarDecl - return the the static
|
|
|
|
/// declaration of local variable.
|
|
|
|
llvm::GlobalValue *GenerateStaticBlockVarDecl(const VarDecl &D,
|
|
|
|
bool NoInit,
|
|
|
|
const char *Separator);
|
2008-08-05 00:51:22 +08:00
|
|
|
|
2008-08-23 00:00:37 +08:00
|
|
|
// GenerateStaticBlockVarDecl - return the static declaration of
|
|
|
|
// a local variable. Performs initialization of the variable if necessary.
|
|
|
|
llvm::GlobalValue *GenerateStaticCXXBlockVarDecl(const VarDecl &D);
|
|
|
|
|
2008-08-05 00:51:22 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Internal Helpers
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
/// 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:
|
2008-11-11 15:41:27 +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.
|
|
|
|
llvm::Function::arg_iterator
|
|
|
|
ExpandTypeFromArgs(QualType Ty, LValue Dst,
|
|
|
|
llvm::Function::arg_iterator AI);
|
|
|
|
|
|
|
|
/// 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,
|
|
|
|
llvm::SmallVector<llvm::Value*, 16> &Args);
|
2007-05-24 14:29:05 +08:00
|
|
|
};
|
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|