[cfe-commits] r94926 - in /cfe/trunk: include/clang/AST/Stmt.h lib/AST/Stmt.cpp lib/Sema/SemaStmt.cpp
Anders Carlsson
andersca at mac.com
Sat Jan 30 15:19:41 PST 2010
Author: andersca
Date: Sat Jan 30 17:19:41 2010
New Revision: 94926
URL: http://llvm.org/viewvc/llvm-project?rev=94926&view=rev
Log:
Remove the SmallVectors from AsmStmt. Fixes PR6105.
Modified:
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/lib/AST/Stmt.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=94926&r1=94925&r2=94926&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Sat Jan 30 17:19:41 2010
@@ -1120,21 +1120,27 @@
unsigned NumOutputs;
unsigned NumInputs;
+ unsigned NumClobbers;
- llvm::SmallVector<IdentifierInfo *, 4> Names;
- llvm::SmallVector<StringLiteral*, 4> Constraints;
- llvm::SmallVector<Stmt*, 4> Exprs;
-
- llvm::SmallVector<StringLiteral*, 4> Clobbers;
+ // FIXME: If we wanted to, we could allocate all of these in one big array.
+ IdentifierInfo **Names;
+ StringLiteral **Constraints;
+ Stmt **Exprs;
+ StringLiteral **Clobbers;
+
+protected:
+ virtual void DoDestroy(ASTContext &Ctx);
+
public:
- AsmStmt(SourceLocation asmloc, bool issimple, bool isvolatile, bool msasm,
- unsigned numoutputs, unsigned numinputs,
+ AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, bool isvolatile,
+ bool msasm, unsigned numoutputs, unsigned numinputs,
IdentifierInfo **names, StringLiteral **constraints,
Expr **exprs, StringLiteral *asmstr, unsigned numclobbers,
StringLiteral **clobbers, SourceLocation rparenloc);
/// \brief Build an empty inline-assembly statement.
- explicit AsmStmt(EmptyShell Empty) : Stmt(AsmStmtClass, Empty) { }
+ explicit AsmStmt(EmptyShell Empty) : Stmt(AsmStmtClass, Empty),
+ Names(0), Constraints(0), Exprs(0), Clobbers(0) { }
SourceLocation getAsmLoc() const { return AsmLoc; }
void setAsmLoc(SourceLocation L) { AsmLoc = L; }
@@ -1296,7 +1302,7 @@
/// This returns -1 if the operand name is invalid.
int getNamedOperand(llvm::StringRef SymbolicName) const;
- unsigned getNumClobbers() const { return Clobbers.size(); }
+ unsigned getNumClobbers() const { return NumClobbers; }
StringLiteral *getClobber(unsigned i) { return Clobbers[i]; }
const StringLiteral *getClobber(unsigned i) const { return Clobbers[i]; }
@@ -1313,19 +1319,19 @@
typedef ConstExprIterator const_inputs_iterator;
inputs_iterator begin_inputs() {
- return Exprs.data() + NumOutputs;
+ return &Exprs[0] + NumOutputs;
}
inputs_iterator end_inputs() {
- return Exprs.data() + NumOutputs + NumInputs;
+ return &Exprs[0] + NumOutputs + NumInputs;
}
const_inputs_iterator begin_inputs() const {
- return Exprs.data() + NumOutputs;
+ return &Exprs[0] + NumOutputs;
}
const_inputs_iterator end_inputs() const {
- return Exprs.data() + NumOutputs + NumInputs;
+ return &Exprs[0] + NumOutputs + NumInputs;
}
// Output expr iterators.
@@ -1334,17 +1340,17 @@
typedef ConstExprIterator const_outputs_iterator;
outputs_iterator begin_outputs() {
- return Exprs.data();
+ return &Exprs[0];
}
outputs_iterator end_outputs() {
- return Exprs.data() + NumOutputs;
+ return &Exprs[0] + NumOutputs;
}
const_outputs_iterator begin_outputs() const {
- return Exprs.data();
+ return &Exprs[0];
}
const_outputs_iterator end_outputs() const {
- return Exprs.data() + NumOutputs;
+ return &Exprs[0] + NumOutputs;
}
// Child iterators
Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=94926&r1=94925&r2=94926&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Sat Jan 30 17:19:41 2010
@@ -167,16 +167,25 @@
unsigned NumClobbers) {
this->NumOutputs = NumOutputs;
this->NumInputs = NumInputs;
- this->Names.clear();
- this->Names.insert(this->Names.end(), Names, Names + NumOutputs + NumInputs);
- this->Constraints.clear();
- this->Constraints.insert(this->Constraints.end(),
- Constraints, Constraints + NumOutputs + NumInputs);
- this->Exprs.clear();
- this->Exprs.insert(this->Exprs.end(), Exprs, Exprs + NumOutputs + NumInputs);
+ this->NumClobbers = NumClobbers;
+
+ unsigned NumExprs = NumOutputs + NumInputs;
+
+ C.Deallocate(this->Names);
+ this->Names = new (C) IdentifierInfo*[NumExprs];
+ std::copy(Names, Names + NumExprs, this->Names);
+
+ C.Deallocate(this->Exprs);
+ this->Exprs = new (C) Stmt*[NumExprs];
+ std::copy(Exprs, Exprs + NumExprs, this->Exprs);
+
+ C.Deallocate(this->Constraints);
+ this->Constraints = new (C) StringLiteral*[NumExprs];
+ std::copy(Constraints, Constraints + NumExprs, this->Constraints);
- this->Clobbers.clear();
- this->Clobbers.insert(this->Clobbers.end(), Clobbers, Clobbers + NumClobbers);
+ C.Deallocate(this->Clobbers);
+ this->Clobbers = new (C) StringLiteral*[NumClobbers];
+ std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers);
}
/// getNamedOperand - Given a symbolic operand reference like %[foo],
@@ -333,22 +342,29 @@
// Constructors
//===----------------------------------------------------------------------===//
-AsmStmt::AsmStmt(SourceLocation asmloc, bool issimple, bool isvolatile,
- bool msasm, unsigned numoutputs, unsigned numinputs,
+AsmStmt::AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
+ bool isvolatile, bool msasm,
+ unsigned numoutputs, unsigned numinputs,
IdentifierInfo **names, StringLiteral **constraints,
Expr **exprs, StringLiteral *asmstr, unsigned numclobbers,
StringLiteral **clobbers, SourceLocation rparenloc)
: Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc), AsmStr(asmstr)
, IsSimple(issimple), IsVolatile(isvolatile), MSAsm(msasm)
- , NumOutputs(numoutputs), NumInputs(numinputs) {
- for (unsigned i = 0, e = numinputs + numoutputs; i != e; i++) {
- Names.push_back(names[i]);
- Exprs.push_back(exprs[i]);
- Constraints.push_back(constraints[i]);
- }
+ , NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) {
+
+ unsigned NumExprs = NumOutputs +NumInputs;
+
+ Names = new (C) IdentifierInfo*[NumExprs];
+ std::copy(names, names + NumExprs, Names);
+
+ Exprs = new (C) Stmt*[NumExprs];
+ std::copy(exprs, exprs + NumExprs, Exprs);
+
+ Constraints = new (C) StringLiteral*[NumExprs];
+ std::copy(constraints, constraints + NumExprs, Constraints);
- for (unsigned i = 0; i != numclobbers; i++)
- Clobbers.push_back(clobbers[i]);
+ Clobbers = new (C) StringLiteral*[NumClobbers];
+ std::copy(clobbers, clobbers + NumClobbers, Clobbers);
}
ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect,
@@ -450,6 +466,18 @@
BranchDestroy(C, this, SubExprs, END_EXPR);
}
+void AsmStmt::DoDestroy(ASTContext &C) {
+ DestroyChildren(C);
+
+ C.Deallocate(Names);
+ C.Deallocate(Constraints);
+ C.Deallocate(Exprs);
+ C.Deallocate(Clobbers);
+
+ this->~Stmt();
+ C.Deallocate((void *)this);
+}
+
//===----------------------------------------------------------------------===//
// Child Iterators for iterating over subexpressions/substatements
//===----------------------------------------------------------------------===//
@@ -563,10 +591,10 @@
// AsmStmt
Stmt::child_iterator AsmStmt::child_begin() {
- return Exprs.empty() ? 0 : &Exprs[0];
+ return NumOutputs + NumInputs == 0 ? 0 : &Exprs[0];
}
Stmt::child_iterator AsmStmt::child_end() {
- return Exprs.empty() ? 0 : &Exprs[0] + Exprs.size();
+ return NumOutputs + NumInputs == 0 ? 0 : &Exprs[0] + NumOutputs + NumInputs;
}
// ObjCAtCatchStmt
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=94926&r1=94925&r2=94926&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sat Jan 30 17:19:41 2010
@@ -1282,9 +1282,9 @@
asmString.release();
clobbers.release();
AsmStmt *NS =
- new (Context) AsmStmt(AsmLoc, IsSimple, IsVolatile, MSAsm, NumOutputs,
- NumInputs, Names, Constraints, Exprs, AsmString,
- NumClobbers, Clobbers, RParenLoc);
+ new (Context) AsmStmt(Context, AsmLoc, IsSimple, IsVolatile, MSAsm,
+ NumOutputs, NumInputs, Names, Constraints, Exprs,
+ AsmString, NumClobbers, Clobbers, RParenLoc);
// Validate the asm string, ensuring it makes sense given the operands we
// have.
llvm::SmallVector<AsmStmt::AsmStringPiece, 8> Pieces;
More information about the cfe-commits
mailing list