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"
|
2008-04-13 15:32:11 +08:00
|
|
|
#include "llvm/Support/IRBuilder.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"
|
|
|
|
#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
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace llvm {
|
|
|
|
class Module;
|
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;
|
2007-05-24 14:29:05 +08:00
|
|
|
class FunctionDecl;
|
2008-03-31 07:03:07 +08:00
|
|
|
class ObjCMethodDecl;
|
2007-06-16 08:16:26 +08:00
|
|
|
class TargetInfo;
|
|
|
|
class FunctionTypeProto;
|
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;
|
2007-06-02 13:24:33 +08:00
|
|
|
|
2007-06-06 04:53:16 +08:00
|
|
|
/// RValue - This trivial value class is used to represent the result of an
|
2007-09-01 06:49:20 +08:00
|
|
|
/// expression that is evaluated. It can be one of three things: either a
|
|
|
|
/// simple LLVM SSA value, a pair of SSA values for complex numbers, or the
|
|
|
|
/// address of an aggregate value in memory.
|
2007-06-06 04:53:16 +08:00
|
|
|
class RValue {
|
2007-09-01 06:49:20 +08:00
|
|
|
llvm::Value *V1, *V2;
|
2007-06-02 08:16:28 +08:00
|
|
|
// TODO: Encode this into the low bit of pointer for more efficient
|
|
|
|
// return-by-value.
|
2007-09-01 06:49:20 +08:00
|
|
|
enum { Scalar, Complex, Aggregate } Flavor;
|
2007-06-23 02:48:09 +08:00
|
|
|
|
|
|
|
// FIXME: Aggregate rvalues need to retain information about whether they are
|
|
|
|
// volatile or not.
|
2007-05-31 05:03:58 +08:00
|
|
|
public:
|
|
|
|
|
2007-09-01 06:49:20 +08:00
|
|
|
bool isScalar() const { return Flavor == Scalar; }
|
|
|
|
bool isComplex() const { return Flavor == Complex; }
|
|
|
|
bool isAggregate() const { return Flavor == Aggregate; }
|
2007-05-31 05:03:58 +08:00
|
|
|
|
2007-09-01 06:49:20 +08:00
|
|
|
/// getScalar() - Return the Value* of this scalar value.
|
|
|
|
llvm::Value *getScalarVal() const {
|
|
|
|
assert(isScalar() && "Not a scalar!");
|
|
|
|
return V1;
|
2007-05-31 05:03:58 +08:00
|
|
|
}
|
|
|
|
|
2007-09-01 06:49:20 +08:00
|
|
|
/// getComplexVal - Return the real/imag components of this complex value.
|
|
|
|
///
|
|
|
|
std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
|
|
|
|
return std::pair<llvm::Value *, llvm::Value *>(V1, V2);
|
|
|
|
}
|
|
|
|
|
2007-06-23 02:48:09 +08:00
|
|
|
/// getAggregateAddr() - Return the Value* of the address of the aggregate.
|
|
|
|
llvm::Value *getAggregateAddr() const {
|
2007-05-31 05:03:58 +08:00
|
|
|
assert(isAggregate() && "Not an aggregate!");
|
2007-09-01 06:49:20 +08:00
|
|
|
return V1;
|
2007-05-31 05:03:58 +08:00
|
|
|
}
|
2007-05-31 01:57:17 +08:00
|
|
|
|
2007-06-16 07:05:46 +08:00
|
|
|
static RValue get(llvm::Value *V) {
|
2007-06-06 04:53:16 +08:00
|
|
|
RValue ER;
|
2007-09-01 06:49:20 +08:00
|
|
|
ER.V1 = V;
|
|
|
|
ER.Flavor = Scalar;
|
|
|
|
return ER;
|
|
|
|
}
|
|
|
|
static RValue getComplex(llvm::Value *V1, llvm::Value *V2) {
|
|
|
|
RValue ER;
|
|
|
|
ER.V1 = V1;
|
|
|
|
ER.V2 = V2;
|
|
|
|
ER.Flavor = Complex;
|
|
|
|
return ER;
|
|
|
|
}
|
|
|
|
static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) {
|
|
|
|
RValue ER;
|
|
|
|
ER.V1 = C.first;
|
|
|
|
ER.V2 = C.second;
|
|
|
|
ER.Flavor = Complex;
|
2007-05-31 01:57:17 +08:00
|
|
|
return ER;
|
|
|
|
}
|
2007-06-16 07:05:46 +08:00
|
|
|
static RValue getAggregate(llvm::Value *V) {
|
2007-06-06 04:53:16 +08:00
|
|
|
RValue ER;
|
2007-09-01 06:49:20 +08:00
|
|
|
ER.V1 = V;
|
|
|
|
ER.Flavor = Aggregate;
|
2007-05-31 01:57:17 +08:00
|
|
|
return ER;
|
|
|
|
}
|
|
|
|
};
|
2007-06-02 13:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
/// LValue - This represents an lvalue references. Because C/C++ allow
|
|
|
|
/// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a
|
|
|
|
/// bitrange.
|
|
|
|
class LValue {
|
2008-06-14 07:01:12 +08:00
|
|
|
// FIXME: alignment?
|
2007-07-11 05:17:59 +08:00
|
|
|
|
|
|
|
enum {
|
2007-08-03 07:37:31 +08:00
|
|
|
Simple, // This is a normal l-value, use getAddress().
|
|
|
|
VectorElt, // This is a vector element l-value (V[i]), use getVector*
|
|
|
|
BitField, // This is a bitfield l-value, use getBitfield*.
|
2008-04-19 07:10:10 +08:00
|
|
|
ExtVectorElt // This is an extended vector subset, use getExtVectorComp
|
2007-07-11 05:17:59 +08:00
|
|
|
} LVType;
|
|
|
|
|
2007-06-02 13:24:33 +08:00
|
|
|
llvm::Value *V;
|
2007-07-11 05:17:59 +08:00
|
|
|
|
|
|
|
union {
|
2008-05-09 14:41:27 +08:00
|
|
|
// Index into a vector subscript: V[i]
|
|
|
|
llvm::Value *VectorIdx;
|
|
|
|
|
|
|
|
// ExtVector element subset: V.xyx
|
|
|
|
llvm::Constant *VectorElts;
|
|
|
|
|
2008-07-26 04:15:41 +08:00
|
|
|
// BitField start bit and size
|
2008-01-23 04:17:04 +08:00
|
|
|
struct {
|
|
|
|
unsigned short StartBit;
|
|
|
|
unsigned short Size;
|
|
|
|
bool IsSigned;
|
2008-07-26 04:15:41 +08:00
|
|
|
} BitfieldData;
|
2007-07-11 05:17:59 +08:00
|
|
|
};
|
2008-06-14 07:01:12 +08:00
|
|
|
|
|
|
|
bool Volatile:1;
|
|
|
|
// FIXME: set but never used, what effect should it have?
|
|
|
|
bool Restrict:1;
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void SetQualifiers(unsigned Qualifiers, LValue& R) {
|
|
|
|
R.Volatile = (Qualifiers&QualType::Volatile)!=0;
|
|
|
|
R.Restrict = (Qualifiers&QualType::Restrict)!=0;
|
|
|
|
}
|
|
|
|
|
2007-06-02 13:24:33 +08:00
|
|
|
public:
|
2007-07-11 05:17:59 +08:00
|
|
|
bool isSimple() const { return LVType == Simple; }
|
|
|
|
bool isVectorElt() const { return LVType == VectorElt; }
|
|
|
|
bool isBitfield() const { return LVType == BitField; }
|
2008-04-19 07:10:10 +08:00
|
|
|
bool isExtVectorElt() const { return LVType == ExtVectorElt; }
|
2007-06-02 13:24:33 +08:00
|
|
|
|
2008-06-14 07:01:12 +08:00
|
|
|
bool isVolatileQualified() const { return Volatile; }
|
|
|
|
bool isRestrictQualified() const { return Restrict; }
|
|
|
|
|
2007-07-11 05:17:59 +08:00
|
|
|
// simple lvalue
|
|
|
|
llvm::Value *getAddress() const { assert(isSimple()); return V; }
|
|
|
|
// vector elt lvalue
|
|
|
|
llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
|
|
|
|
llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
|
2008-04-19 07:10:10 +08:00
|
|
|
// extended vector elements.
|
|
|
|
llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; }
|
2008-05-09 14:41:27 +08:00
|
|
|
llvm::Constant *getExtVectorElts() const {
|
2008-04-19 07:10:10 +08:00
|
|
|
assert(isExtVectorElt());
|
2007-08-04 01:31:20 +08:00
|
|
|
return VectorElts;
|
2007-08-03 07:37:31 +08:00
|
|
|
}
|
2008-01-23 04:17:04 +08:00
|
|
|
// bitfield lvalue
|
|
|
|
llvm::Value *getBitfieldAddr() const { assert(isBitfield()); return V; }
|
|
|
|
unsigned short getBitfieldStartBit() const {
|
|
|
|
assert(isBitfield());
|
|
|
|
return BitfieldData.StartBit;
|
|
|
|
}
|
|
|
|
unsigned short getBitfieldSize() const {
|
|
|
|
assert(isBitfield());
|
|
|
|
return BitfieldData.Size;
|
|
|
|
}
|
|
|
|
bool isBitfieldSigned() const {
|
|
|
|
assert(isBitfield());
|
|
|
|
return BitfieldData.IsSigned;
|
|
|
|
}
|
|
|
|
|
2008-06-14 07:01:12 +08:00
|
|
|
static LValue MakeAddr(llvm::Value *V, unsigned Qualifiers) {
|
2007-06-02 13:24:33 +08:00
|
|
|
LValue R;
|
2007-07-11 05:17:59 +08:00
|
|
|
R.LVType = Simple;
|
2007-06-02 13:24:33 +08:00
|
|
|
R.V = V;
|
2008-06-14 07:01:12 +08:00
|
|
|
SetQualifiers(Qualifiers,R);
|
2007-06-02 13:24:33 +08:00
|
|
|
return R;
|
|
|
|
}
|
2007-07-11 05:17:59 +08:00
|
|
|
|
2008-06-14 07:01:12 +08:00
|
|
|
static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx,
|
|
|
|
unsigned Qualifiers) {
|
2007-07-11 05:17:59 +08:00
|
|
|
LValue R;
|
|
|
|
R.LVType = VectorElt;
|
|
|
|
R.V = Vec;
|
|
|
|
R.VectorIdx = Idx;
|
2008-06-14 07:01:12 +08:00
|
|
|
SetQualifiers(Qualifiers,R);
|
2007-07-11 05:17:59 +08:00
|
|
|
return R;
|
|
|
|
}
|
|
|
|
|
2008-06-14 07:01:12 +08:00
|
|
|
static LValue MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts,
|
|
|
|
unsigned Qualifiers) {
|
2007-08-03 07:37:31 +08:00
|
|
|
LValue R;
|
2008-04-19 07:10:10 +08:00
|
|
|
R.LVType = ExtVectorElt;
|
2007-08-03 07:37:31 +08:00
|
|
|
R.V = Vec;
|
2008-05-09 14:41:27 +08:00
|
|
|
R.VectorElts = Elts;
|
2008-06-14 07:01:12 +08:00
|
|
|
SetQualifiers(Qualifiers,R);
|
2007-08-03 07:37:31 +08:00
|
|
|
return R;
|
|
|
|
}
|
2008-01-23 04:17:04 +08:00
|
|
|
|
|
|
|
static LValue MakeBitfield(llvm::Value *V, unsigned short StartBit,
|
2008-06-14 07:01:12 +08:00
|
|
|
unsigned short Size, bool IsSigned,
|
|
|
|
unsigned Qualifiers) {
|
2008-01-23 04:17:04 +08:00
|
|
|
LValue R;
|
|
|
|
R.LVType = BitField;
|
|
|
|
R.V = V;
|
|
|
|
R.BitfieldData.StartBit = StartBit;
|
|
|
|
R.BitfieldData.Size = Size;
|
|
|
|
R.BitfieldData.IsSigned = IsSigned;
|
2008-06-14 07:01:12 +08:00
|
|
|
SetQualifiers(Qualifiers,R);
|
2008-01-23 04:17:04 +08:00
|
|
|
return R;
|
|
|
|
}
|
2007-06-02 13:24:33 +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-04-13 15:32:11 +08:00
|
|
|
llvm::IRBuilder 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;
|
|
|
|
|
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;
|
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;
|
|
|
|
|
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-07-30 07:18:29 +08:00
|
|
|
void GenerateCode(const FunctionDecl *FD,
|
|
|
|
llvm::Function *Fn);
|
2008-06-18 02:05:57 +08:00
|
|
|
void GenerateFunction(const Stmt *Body);
|
2007-05-30 07:50:05 +08:00
|
|
|
|
2007-06-23 03:05:19 +08:00
|
|
|
const llvm::Type *ConvertType(QualType T);
|
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);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
2007-06-16 07:05:46 +08:00
|
|
|
void EmitBlock(llvm::BasicBlock *BB);
|
2007-12-02 09:43:38 +08:00
|
|
|
|
|
|
|
/// WarnUnsupported - Print out a warning that codegen doesn't support the
|
|
|
|
/// specified stmt yet.
|
2007-12-02 09:49:16 +08:00
|
|
|
void WarnUnsupported(const Stmt *S, const char *Type);
|
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
|
|
|
|
|
|
|
/// isDummyBlock - Return true if BB is an empty basic block
|
|
|
|
/// with no predecessors.
|
|
|
|
static bool isDummyBlock(const llvm::BasicBlock *BB);
|
|
|
|
|
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
|
|
|
|
|
|
|
/// 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);
|
|
|
|
|
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);
|
2007-06-02 12:16:21 +08:00
|
|
|
void EmitEnumConstantDecl(const EnumConstantDecl &D);
|
2008-04-16 06:42:06 +08:00
|
|
|
void EmitBlockVarDecl(const VarDecl &D);
|
|
|
|
void EmitLocalBlockVarDecl(const VarDecl &D);
|
|
|
|
void EmitStaticBlockVarDecl(const VarDecl &D);
|
2007-06-14 04:44:40 +08:00
|
|
|
void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg);
|
2007-06-02 12:53:11 +08:00
|
|
|
|
2007-05-30 07:50:05 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Statement Emission
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void EmitStmt(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-07-27 04:23:23 +08:00
|
|
|
void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt.
|
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);
|
2007-07-17 05:28:45 +08:00
|
|
|
void EmitBreakStmt();
|
|
|
|
void EmitContinueStmt();
|
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);
|
|
|
|
|
2007-06-02 13:24:33 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// LValue Expression Emission
|
|
|
|
//===--------------------------------------------------------------------===//
|
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);
|
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-01-23 06:36:45 +08:00
|
|
|
void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty);
|
2007-12-29 13:02:41 +08:00
|
|
|
|
|
|
|
// Note: only availabe for agg return types
|
|
|
|
LValue EmitCallExprLValue(const CallExpr *E);
|
2007-06-06 04:53:16 +08:00
|
|
|
|
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);
|
2007-07-21 13:21:51 +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
|
|
|
|
|
|
|
LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field,
|
2008-06-14 07:01:12 +08:00
|
|
|
bool isUnion, unsigned CVRQualifiers);
|
2008-03-31 07:03:07 +08:00
|
|
|
|
|
|
|
LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
|
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
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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);
|
|
|
|
llvm::Value *EmitObjCMessageExpr(const ObjCMessageExpr *E);
|
|
|
|
|
|
|
|
|
2007-08-22 01:43:55 +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);
|
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
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Internal Helpers
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// EmitIndirectSwitches - Emit code for all of the switch
|
|
|
|
/// instructions in IndirectSwitches.
|
|
|
|
void EmitIndirectSwitches();
|
2007-05-24 14:29:05 +08:00
|
|
|
};
|
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|