Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/AST/astutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ static FunctionType* flattenRefsForFunctionTypes(FunctionType* ft) {

newFormals.push_back({ qt2.getQual(), qt2.type(),
formal.intent(),
formal.name() });
formal.name(), formal.flags() });
changed = changed || qt1 != qt2;
}

Expand Down Expand Up @@ -1772,7 +1772,7 @@ computeNewSymbolType(std::unordered_map<Type*, Type*>& alreadyAdjusted,
preserveRefLevels,
f->type());
if (newT != f->type()) {
newFormals.push_back({ f->qual(), newT, f->intent(), f->name() });
newFormals.push_back({ f->qual(), newT, f->intent(), f->name(), f->flags() });
anyChanged = true;
} else {
newFormals.push_back(*f);
Expand Down
5 changes: 5 additions & 0 deletions compiler/AST/symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2149,6 +2149,8 @@ const char* astr_initCopy = NULL;
const char* astr_coerceCopy = NULL;
const char* astr_coerceMove = NULL;
const char* astr_autoDestroy = NULL;
const char* astr__ln = NULL;
const char* astr__fn = NULL;

void initAstrConsts() {
astrSassign = astr("=");
Expand Down Expand Up @@ -2196,6 +2198,9 @@ void initAstrConsts() {
astr_coerceMove = astr("chpl__coerceMove");

astr_autoDestroy = astr("chpl__autoDestroy");

astr__ln = astr("_ln");
astr__fn = astr("_fn");
}

bool isAstrOpName(const char* name) {
Expand Down
23 changes: 15 additions & 8 deletions compiler/AST/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ FunctionType::Linkage FunctionType::determineLinkage(FnSymbol* fn) {
static FormalVec collectFormals(FnSymbol* fn) {
FormalVec ret;
for_formals(f, fn) {
FunctionType::Formal info = { f->qual, f->type, f->intent, f->name };
FunctionType::Formal info = { f->qual, f->type, f->intent, f->name, f->flags };
ret.push_back(std::move(info));
}
return ret;
Expand Down Expand Up @@ -1047,14 +1047,14 @@ FunctionType* FunctionType::getAsExtern() const {

FunctionType::Formal FunctionType::constructErrorHandlingFormal() {
auto t = getDecoratedClass(dtError, ClassTypeDecorator::UNMANAGED_NILABLE);
return { QUAL_REF, t, INTENT_REF, "error_out" };
return { QUAL_REF, t, INTENT_REF, "error_out", 0 };
}

std::array<FunctionType::Formal, 2>
FunctionType::constructLineFileInfoFormals() {
std::array<Formal, 2> ret = {{
Formal(QUAL_CONST_VAL, dtInt[INT_SIZE_DEFAULT], INTENT_CONST_IN, "_ln"),
Formal(QUAL_CONST_VAL, dtInt[INT_SIZE_32], INTENT_CONST_IN, "_fn")
Formal(QUAL_CONST_VAL, dtInt[INT_SIZE_DEFAULT], INTENT_CONST_IN, astr__ln, 0),
Formal(QUAL_CONST_VAL, dtInt[INT_SIZE_32], INTENT_CONST_IN, astr__fn, 0),
}};

return ret;
Expand Down Expand Up @@ -1193,7 +1193,7 @@ functionTypeStreamlineFormal(const FunctionType::Formal& f) {
auto type = functionTypeStreamlineType(qual, f.type());
const char* name = "";

return { qual, type, intent, name };
return { qual, type, intent, name, f.flags() };
}

static void
Expand Down Expand Up @@ -1300,7 +1300,7 @@ FunctionType* FunctionType::getWithWidenedComponents() const {
auto qt1 = f->qualType();
auto qt2 = widenType(qt1);

Formal newFormal = { qt2.getQual(), qt2.type(), f->intent(), f->name() };
Formal newFormal = { qt2.getQual(), qt2.type(), f->intent(), f->name(), f->flags() };
newFormals.push_back(std::move(newFormal));
change = change || qt1 != qt2;
}
Expand Down Expand Up @@ -1570,8 +1570,8 @@ size_t FunctionType::hash() const {
}

FunctionType::Formal::Formal(Qualifier qual, Type* type, IntentTag intent,
const char* name)
: qual_(qual), type_(type), intent_(intent) {
const char* name, FlagSet flags)
: qual_(qual), type_(type), intent_(intent), name_(nullptr), flags_(flags) {
name_ = (name && 0 != strcmp(name, "")) ? astr(name) : astr("_");
}

Expand Down Expand Up @@ -1620,6 +1620,13 @@ bool FunctionType::Formal::isRef() const {
return qualType().isRef();
}

bool FunctionType::Formal::isRetArg() const {
return flags_[FLAG_RETARG];
}
FlagSet FunctionType::Formal::flags() const {
return flags_;
}

bool FunctionType::Formal::isNamed() const {
return name_ && 0 != strcmp(name_, "") && 0 != strcmp(name_, "_");
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/codegen/cg-expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2930,7 +2930,7 @@ static GenRet codegenCallExprInner(GenRet function,
}
}

if (CGI == nullptr && fnType != nullptr &&
if (CGI == nullptr && fnType != nullptr &&
fnType->getReturnType()->isVoidTy() &&
fnType->getNumParams() >= 1 &&
func && func->hasStructRetAttr())
Expand Down
5 changes: 4 additions & 1 deletion compiler/codegen/cg-stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ void codegenStmt(Expr* stmt) {
info->cStatements.push_back(idCommentTemp(stmt));
} else {
#ifdef HAVE_LLVM
if (debugInfo && stmt->linenum() > 0) {
if (debugInfo &&
stmt->linenum() > 0 &&
(!stmt->parentSymbol ||
debugInfo->shouldAddDebugInfoFor(stmt->parentSymbol))) {
// Adjust the current line number, but leave the scope alone.
llvm::MDNode* scope;

Expand Down
18 changes: 17 additions & 1 deletion compiler/codegen/cg-symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2309,6 +2309,14 @@ codegenFunctionTypeLLVMImpl(
auto valType = formalInfo->type()->getValType()->codegen().type;
int64_t sz = getTypeSizeInBytes(layout, valType);
b.addDereferenceableAttr(sz);
// TODO: we should be marking retArg as sret, but can't
// because retArg must be either the first or second arg
// this will require more investigation
// if (formalInfo->isRetArg() &&
// llvm::isa<llvm::StructType>(valType)) {
// auto ptrType = formalInfo->type()->codegen().type;
// llvmAttachStructRetAttr(b, ptrType);
// }
}
if (argInfo->isExtend()) {
if (argInfo->isSignExt()) {
Expand Down Expand Up @@ -2351,6 +2359,14 @@ codegenFunctionTypeLLVMImpl(
auto valType = formalInfo->type()->getValType()->codegen().type;
int64_t sz = getTypeSizeInBytes(layout, valType);
b.addDereferenceableAttr(sz);
// TODO: we should be marking retArg as sret, but can't
// because retArg must be either the first or second arg
// this will require more investigation
// if (formalInfo->isRetArg() &&
// llvm::isa<llvm::StructType>(valType)) {
// auto ptrType = formalInfo->type()->codegen().type;
// llvmAttachStructRetAttr(b, ptrType);
// }
llvmAddAttr(ctx, outAttrs, argTys.size(), b);
}
}
Expand Down Expand Up @@ -2889,7 +2905,7 @@ void FnSymbol::codegenDef() {

info->lvt->addLayer();

if(debugInfo) {
if (debugInfo && debugInfo->shouldAddDebugInfoFor(this)) {
llvm::DISubprogram* dbgScope = debugInfo->getFunction(this);
info->irBuilder->SetCurrentDebugLocation(
llvm::DILocation::get(dbgScope->getContext(), linenum(), 0,
Expand Down
12 changes: 3 additions & 9 deletions compiler/codegen/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3229,20 +3229,14 @@ static void codegenPartTwo() {
if (fDebugSymbols) {
debugInfo = new DebugData(/*optimized*/false);
}
if(debugInfo) {
if (debugInfo) {
// every module gets its own compile unit
forv_Vec(ModuleSymbol, currentModule, allModules) {
// So, this is pretty quick. I'm assuming that the main module is in the current dir, no optimization (need to figure out how to get this)
// and no compile flags, since I can't figure out how to get that either.
const char *current_dir = "./";
const char *empty_string = "";
debugInfo->createCompileUnit(currentModule,
currentModule->astloc.filename(), current_dir, empty_string
);
debugInfo->createCompileUnit(currentModule, currentModule->fname(), "./", "");
}
debugInfo->createCompileUnit(rootModule,
rootModule->astloc.filename(), "./", ""
);
debugInfo->createCompileUnit(rootModule, rootModule->fname(), "./", "");
}

// When doing codegen for programs that have GPU kernels we fork the
Expand Down
1 change: 1 addition & 0 deletions compiler/include/flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ enum Flag {
FLAG_FIRST = FLAG_UNKNOWN + 1, // index of the first flag
FLAG_LAST = NUM_FLAGS - 1 // index of the last flag
};
typedef std::bitset<NUM_FLAGS> FlagSet;

// only meaningful flags are allowed
#define CHECK_FLAG(FLAG) \
Expand Down
11 changes: 6 additions & 5 deletions compiler/include/llvmDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ class DebugData {
DebugData(bool optimized): optimized(optimized) {}
void finalize();
void createCompileUnit(ModuleSymbol* modSym,
const char *file, const char *directory,
const char *flags);
const char* file,
const char* directory,
const char* flags);

bool shouldAddDebugInfoFor(Symbol* sym);

llvm::DIType* getType(Type *type);
llvm::DIFile* getFile(ModuleSymbol* modSym, const char *file);
llvm::DIType* getType(Type* type);
llvm::DIFile* getFile(llvm::DIBuilder* DIB, const char* file);
llvm::DINamespace* getModuleScope(ModuleSymbol* modSym);

llvm::DISubroutineType* getFunctionType(FnSymbol* function);
Expand All @@ -63,7 +64,7 @@ class DebugData {

private:
llvm::DIType* constructType(Type* type);
llvm::DIFile* constructFile(ModuleSymbol* modSym, const char *file);
llvm::DIFile* constructFile(llvm::DIBuilder* DIB, const char* file);
llvm::DINamespace* constructModuleScope(ModuleSymbol* modSym);
llvm::DISubprogram* constructFunction(FnSymbol* function);
llvm::DIGlobalVariableExpression* constructGlobalVariable(VarSymbol* gVarSym);
Expand Down
4 changes: 2 additions & 2 deletions compiler/include/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ class Stmt;
class SymExpr;
struct InterfaceReps;

typedef std::bitset<NUM_FLAGS> FlagSet;

// for task intents and forall intents
ArgSymbol* tiMarkForForallIntent(ShadowVarSymbol* svar);

Expand Down Expand Up @@ -881,6 +879,8 @@ extern const char* astr_coerceCopy;
extern const char* astr_coerceCopy;
extern const char* astr_coerceMove;
extern const char* astr_autoDestroy;
extern const char* astr__fn;
extern const char* astr__ln;

bool isAstrOpName(const char* name);

Expand Down
7 changes: 6 additions & 1 deletion compiler/include/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "alist.h"
#include "genret.h"
#include "intents.h"
#include "flags.h"

#include "../../frontend/lib/immediates/num.h"

Expand Down Expand Up @@ -459,8 +460,10 @@ class FunctionType final : public Type {
Type* type_;
IntentTag intent_ = INTENT_BLANK;
const char* name_ = nullptr;
FlagSet flags_ = 0;
public:
Formal(Qualifier qual, Type* type, IntentTag intent, const char* name);
Formal(Qualifier qual, Type* type, IntentTag intent,
const char* name, FlagSet flags);
bool operator==(const Formal& other) const;
size_t hash() const;
bool isGeneric() const;
Expand All @@ -471,6 +474,8 @@ class FunctionType final : public Type {
QualifiedType qualType() const;
bool isNamed() const;
bool isRef() const;
FlagSet flags() const;
bool isRetArg() const;
};

using Formals = std::vector<Formal>;
Expand Down
Loading
Loading