[cfe-commits] r43284 - in /cfe/trunk/CodeGen: CodeGenFunction.cpp CodeGenFunction.h CodeGenTypes.cpp CodeGenTypes.h
Devang Patel
dpatel at apple.com
Tue Oct 23 17:56:23 PDT 2007
Author: dpatel
Date: Tue Oct 23 19:56:23 2007
New Revision: 43284
URL: http://llvm.org/viewvc/llvm-project?rev=43284&view=rev
Log:
Constify methods and reuse RecordOrganizer object.
Modified:
cfe/trunk/CodeGen/CodeGenFunction.cpp
cfe/trunk/CodeGen/CodeGenFunction.h
cfe/trunk/CodeGen/CodeGenTypes.cpp
cfe/trunk/CodeGen/CodeGenTypes.h
Modified: cfe/trunk/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenFunction.cpp?rev=43284&r1=43283&r2=43284&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenFunction.cpp Tue Oct 23 19:56:23 2007
@@ -127,7 +127,7 @@
}
/// getRecordLayoutInfo - Return record layout info.
-RecordLayoutInfo *CodeGenFunction::getRecordLayoutInfo(CodeGenTypes &CGT,
+const RecordLayoutInfo *CodeGenFunction::getRecordLayoutInfo(CodeGenTypes &CGT,
QualType RTy) {
assert (isa<RecordType>(RTy)
&& "Unexpected type. RecordType expected here.");
Modified: cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenFunction.h?rev=43284&r1=43283&r2=43284&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/CodeGen/CodeGenFunction.h Tue Oct 23 19:56:23 2007
@@ -299,7 +299,7 @@
void StartBlock(const char *N);
/// getRecordLayoutInfo - Return record layout info.
- RecordLayoutInfo *getRecordLayoutInfo(CodeGenTypes &CGT, QualType RTy);
+ const RecordLayoutInfo *getRecordLayoutInfo(CodeGenTypes &CGT, QualType RTy);
//===--------------------------------------------------------------------===//
// Declaration Emission
//===--------------------------------------------------------------------===//
Modified: cfe/trunk/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenTypes.cpp?rev=43284&r1=43283&r2=43284&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenTypes.cpp Tue Oct 23 19:56:23 2007
@@ -182,13 +182,13 @@
RecordTypesToResolve[RD] = OpaqueTy;
// Layout fields.
- RecordOrganizer *RO = new RecordOrganizer();
+ RecordOrganizer RO;
for (unsigned i = 0, e = RD->getNumMembers(); i != e; ++i)
- RO->addField(RD->getMember(i));
- RO->layoutFields(*this);
+ RO.addField(RD->getMember(i));
+ RO.layoutFields(*this);
// Get llvm::StructType.
- RecordLayoutInfo *RLI = new RecordLayoutInfo(RO);
+ RecordLayoutInfo *RLI = new RecordLayoutInfo(&RO);
ResultType = RLI->getLLVMType();
RecordLayouts[ResultType] = RLI;
@@ -199,7 +199,7 @@
&& "Expected RecordDecl in RecordTypesToResolve");
RecordTypesToResolve.erase(OpaqueI);
- delete RO;
+ RO.clear();
} else if (TD->getKind() == Decl::Union) {
const RecordDecl *RD = cast<const RecordDecl>(TD);
// Just use the largest element of the union, breaking ties with the
@@ -260,13 +260,14 @@
return I->second;
}
- /// addFieldInfo - Assign field number to field FD.
+/// addFieldInfo - Assign field number to field FD.
void CodeGenTypes::addFieldInfo(const FieldDecl *FD, unsigned No) {
FieldInfo[FD] = No;
}
/// getRecordLayoutInfo - Return record layout info for the given llvm::Type.
-RecordLayoutInfo *CodeGenTypes::getRecordLayoutInfo(const llvm::Type* Ty) {
+const RecordLayoutInfo *
+CodeGenTypes::getRecordLayoutInfo(const llvm::Type* Ty) const {
llvm::DenseMap<const llvm::Type*, RecordLayoutInfo *>::iterator I
= RecordLayouts.find(Ty);
assert (I != RecordLayouts.end()
@@ -315,3 +316,9 @@
}
STy = llvm::StructType::get(Fields);
}
+
+/// Clear private data so that this object can be reused.
+void RecordOrganizer::clear() {
+ STy = NULL;
+ FieldDecls.clear();
+}
Modified: cfe/trunk/CodeGen/CodeGenTypes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenTypes.h?rev=43284&r1=43283&r2=43284&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenTypes.h (original)
+++ cfe/trunk/CodeGen/CodeGenTypes.h Tue Oct 23 19:56:23 2007
@@ -58,10 +58,12 @@
/// getLLVMType - Return associated llvm struct type. This may be NULL
/// if fields are not laid out.
- llvm::Type *getLLVMType() {
+ llvm::Type *getLLVMType() const {
return STy;
}
+ /// Clear private data so that this object can be reused.
+ void clear();
private:
llvm::Type *STy;
llvm::SmallVector<const FieldDecl *, 8> FieldDecls;
@@ -75,7 +77,7 @@
RecordLayoutInfo(RecordOrganizer *RO);
/// getLLVMType - Return llvm type associated with this record.
- llvm::Type *getLLVMType() {
+ llvm::Type *getLLVMType() const {
return STy;
}
@@ -117,7 +119,7 @@
void DecodeArgumentTypes(const FunctionTypeProto &FTP,
std::vector<const llvm::Type*> &ArgTys);
- RecordLayoutInfo *getRecordLayoutInfo(const llvm::Type*);
+ const RecordLayoutInfo *getRecordLayoutInfo(const llvm::Type*) const;
/// getLLVMFieldNo - Return llvm::StructType element number
/// that corresponds to the field FD.
More information about the cfe-commits
mailing list