forked from OSchip/llvm-project
Constify methods and reuse RecordOrganizer object.
llvm-svn: 43284
This commit is contained in:
parent
790afb0444
commit
ea37aa7d64
|
@ -127,7 +127,7 @@ void CodeGenFunction::StartBlock(const char *N) {
|
|||
}
|
||||
|
||||
/// 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.");
|
||||
|
|
|
@ -299,7 +299,7 @@ public:
|
|||
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
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
|
|
@ -182,13 +182,13 @@ const llvm::Type *CodeGenTypes::ConvertType(QualType T) {
|
|||
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 @@ const llvm::Type *CodeGenTypes::ConvertType(QualType T) {
|
|||
&& "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 @@ unsigned CodeGenTypes::getLLVMFieldNo(const FieldDecl *FD) {
|
|||
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 @@ void RecordOrganizer::layoutFields(CodeGenTypes &CGT) {
|
|||
}
|
||||
STy = llvm::StructType::get(Fields);
|
||||
}
|
||||
|
||||
/// Clear private data so that this object can be reused.
|
||||
void RecordOrganizer::clear() {
|
||||
STy = NULL;
|
||||
FieldDecls.clear();
|
||||
}
|
||||
|
|
|
@ -58,10 +58,12 @@ namespace CodeGen {
|
|||
|
||||
/// 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 @@ namespace CodeGen {
|
|||
RecordLayoutInfo(RecordOrganizer *RO);
|
||||
|
||||
/// getLLVMType - Return llvm type associated with this record.
|
||||
llvm::Type *getLLVMType() {
|
||||
llvm::Type *getLLVMType() const {
|
||||
return STy;
|
||||
}
|
||||
|
||||
|
@ -117,7 +119,7 @@ public:
|
|||
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.
|
||||
|
|
Loading…
Reference in New Issue