Skip to content

Commit fd62658

Browse files
committed
get methods and functions to have proper debug info
Signed-off-by: Jade Abraham <[email protected]>
1 parent 40eb47a commit fd62658

File tree

12 files changed

+246
-153
lines changed

12 files changed

+246
-153
lines changed

compiler/AST/astutil.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,7 @@ static FunctionType* flattenRefsForFunctionTypes(FunctionType* ft) {
16041604

16051605
newFormals.push_back({ qt2.getQual(), qt2.type(),
16061606
formal.intent(),
1607-
formal.name() });
1607+
formal.name(), formal.flags() });
16081608
changed = changed || qt1 != qt2;
16091609
}
16101610

@@ -1772,7 +1772,7 @@ computeNewSymbolType(std::unordered_map<Type*, Type*>& alreadyAdjusted,
17721772
preserveRefLevels,
17731773
f->type());
17741774
if (newT != f->type()) {
1775-
newFormals.push_back({ f->qual(), newT, f->intent(), f->name() });
1775+
newFormals.push_back({ f->qual(), newT, f->intent(), f->name(), f->flags() });
17761776
anyChanged = true;
17771777
} else {
17781778
newFormals.push_back(*f);

compiler/AST/symbol.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,6 +2149,8 @@ const char* astr_initCopy = NULL;
21492149
const char* astr_coerceCopy = NULL;
21502150
const char* astr_coerceMove = NULL;
21512151
const char* astr_autoDestroy = NULL;
2152+
const char* astr__ln = NULL;
2153+
const char* astr__fn = NULL;
21522154

21532155
void initAstrConsts() {
21542156
astrSassign = astr("=");
@@ -2196,6 +2198,9 @@ void initAstrConsts() {
21962198
astr_coerceMove = astr("chpl__coerceMove");
21972199

21982200
astr_autoDestroy = astr("chpl__autoDestroy");
2201+
2202+
astr__ln = astr("_ln");
2203+
astr__fn = astr("_fn");
21992204
}
22002205

22012206
bool isAstrOpName(const char* name) {

compiler/AST/type.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ FunctionType::Linkage FunctionType::determineLinkage(FnSymbol* fn) {
990990
static FormalVec collectFormals(FnSymbol* fn) {
991991
FormalVec ret;
992992
for_formals(f, fn) {
993-
FunctionType::Formal info = { f->qual, f->type, f->intent, f->name };
993+
FunctionType::Formal info = { f->qual, f->type, f->intent, f->name, f->flags };
994994
ret.push_back(std::move(info));
995995
}
996996
return ret;
@@ -1047,14 +1047,14 @@ FunctionType* FunctionType::getAsExtern() const {
10471047

10481048
FunctionType::Formal FunctionType::constructErrorHandlingFormal() {
10491049
auto t = getDecoratedClass(dtError, ClassTypeDecorator::UNMANAGED_NILABLE);
1050-
return { QUAL_REF, t, INTENT_REF, "error_out" };
1050+
return { QUAL_REF, t, INTENT_REF, "error_out", 0 };
10511051
}
10521052

10531053
std::array<FunctionType::Formal, 2>
10541054
FunctionType::constructLineFileInfoFormals() {
10551055
std::array<Formal, 2> ret = {{
1056-
Formal(QUAL_CONST_VAL, dtInt[INT_SIZE_DEFAULT], INTENT_CONST_IN, "_ln"),
1057-
Formal(QUAL_CONST_VAL, dtInt[INT_SIZE_32], INTENT_CONST_IN, "_fn")
1056+
Formal(QUAL_CONST_VAL, dtInt[INT_SIZE_DEFAULT], INTENT_CONST_IN, astr__ln, 0),
1057+
Formal(QUAL_CONST_VAL, dtInt[INT_SIZE_32], INTENT_CONST_IN, astr__fn, 0),
10581058
}};
10591059

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

1196-
return { qual, type, intent, name };
1196+
return { qual, type, intent, name, f.flags() };
11971197
}
11981198

11991199
static void
@@ -1300,7 +1300,7 @@ FunctionType* FunctionType::getWithWidenedComponents() const {
13001300
auto qt1 = f->qualType();
13011301
auto qt2 = widenType(qt1);
13021302

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

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

@@ -1620,6 +1620,13 @@ bool FunctionType::Formal::isRef() const {
16201620
return qualType().isRef();
16211621
}
16221622

1623+
bool FunctionType::Formal::isRetArg() const {
1624+
return flags_[FLAG_RETARG];
1625+
}
1626+
FlagSet FunctionType::Formal::flags() const {
1627+
return flags_;
1628+
}
1629+
16231630
bool FunctionType::Formal::isNamed() const {
16241631
return name_ && 0 != strcmp(name_, "") && 0 != strcmp(name_, "_");
16251632
}

compiler/codegen/cg-symbol.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,6 +2309,15 @@ codegenFunctionTypeLLVMImpl(
23092309
auto valType = formalInfo->type()->getValType()->codegen().type;
23102310
int64_t sz = getTypeSizeInBytes(layout, valType);
23112311
b.addDereferenceableAttr(sz);
2312+
// TODO: we should be marking retArg as sret, but can't
2313+
// because retArg must be either the first or second arg
2314+
// this will require more investigation
2315+
// if (formalInfo->isRetArg() &&
2316+
// isAggregateType(formalInfo->type()) &&
2317+
// llvm::isa<llvm::StructType>(valType)) {
2318+
// auto ptrType = formalInfo->type()->codegen().type;
2319+
// llvmAttachStructRetAttr(b, ptrType);
2320+
// }
23122321
}
23132322
if (argInfo->isExtend()) {
23142323
if (argInfo->isSignExt()) {
@@ -2351,6 +2360,15 @@ codegenFunctionTypeLLVMImpl(
23512360
auto valType = formalInfo->type()->getValType()->codegen().type;
23522361
int64_t sz = getTypeSizeInBytes(layout, valType);
23532362
b.addDereferenceableAttr(sz);
2363+
// TODO: we should be marking retArg as sret, but can't
2364+
// because retArg must be either the first or second arg
2365+
// this will require more investigation
2366+
// if (formalInfo->isRetArg() &&
2367+
// isAggregateType(formalInfo->type()) &&
2368+
// llvm::isa<llvm::StructType>(valType)) {
2369+
// auto ptrType = formalInfo->type()->codegen().type;
2370+
// llvmAttachStructRetAttr(b, ptrType);
2371+
// }
23542372
llvmAddAttr(ctx, outAttrs, argTys.size(), b);
23552373
}
23562374
}

compiler/codegen/codegen.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3229,20 +3229,14 @@ static void codegenPartTwo() {
32293229
if (fDebugSymbols) {
32303230
debugInfo = new DebugData(/*optimized*/false);
32313231
}
3232-
if(debugInfo) {
3232+
if (debugInfo) {
32333233
// every module gets its own compile unit
32343234
forv_Vec(ModuleSymbol, currentModule, allModules) {
32353235
// 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)
32363236
// and no compile flags, since I can't figure out how to get that either.
3237-
const char *current_dir = "./";
3238-
const char *empty_string = "";
3239-
debugInfo->createCompileUnit(currentModule,
3240-
currentModule->astloc.filename(), current_dir, empty_string
3241-
);
3237+
debugInfo->createCompileUnit(currentModule, currentModule->fname(), "./", "");
32423238
}
3243-
debugInfo->createCompileUnit(rootModule,
3244-
rootModule->astloc.filename(), "./", ""
3245-
);
3239+
debugInfo->createCompileUnit(rootModule, rootModule->fname(), "./", "");
32463240
}
32473241

32483242
// When doing codegen for programs that have GPU kernels we fork the

compiler/include/flags.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ enum Flag {
5959
FLAG_FIRST = FLAG_UNKNOWN + 1, // index of the first flag
6060
FLAG_LAST = NUM_FLAGS - 1 // index of the last flag
6161
};
62+
typedef std::bitset<NUM_FLAGS> FlagSet;
6263

6364
// only meaningful flags are allowed
6465
#define CHECK_FLAG(FLAG) \

compiler/include/llvmDebug.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ class DebugData {
4545
DebugData(bool optimized): optimized(optimized) {}
4646
void finalize();
4747
void createCompileUnit(ModuleSymbol* modSym,
48-
const char *file, const char *directory,
49-
const char *flags);
48+
const char* file,
49+
const char* directory,
50+
const char* flags);
5051

5152
bool shouldAddDebugInfoFor(Symbol* sym);
5253

53-
llvm::DIType* getType(Type *type);
54-
llvm::DIFile* getFile(ModuleSymbol* modSym, const char *file);
54+
llvm::DIType* getType(Type* type);
55+
llvm::DIFile* getFile(llvm::DIBuilder* DIB, const char* file);
5556
llvm::DINamespace* getModuleScope(ModuleSymbol* modSym);
5657

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

6465
private:
6566
llvm::DIType* constructType(Type* type);
66-
llvm::DIFile* constructFile(ModuleSymbol* modSym, const char *file);
67+
llvm::DIFile* constructFile(llvm::DIBuilder* DIB, const char* file);
6768
llvm::DINamespace* constructModuleScope(ModuleSymbol* modSym);
6869
llvm::DISubprogram* constructFunction(FnSymbol* function);
6970
llvm::DIGlobalVariableExpression* constructGlobalVariable(VarSymbol* gVarSym);

compiler/include/symbol.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ class Stmt;
6060
class SymExpr;
6161
struct InterfaceReps;
6262

63-
typedef std::bitset<NUM_FLAGS> FlagSet;
64-
6563
// for task intents and forall intents
6664
ArgSymbol* tiMarkForForallIntent(ShadowVarSymbol* svar);
6765

@@ -881,6 +879,8 @@ extern const char* astr_coerceCopy;
881879
extern const char* astr_coerceCopy;
882880
extern const char* astr_coerceMove;
883881
extern const char* astr_autoDestroy;
882+
extern const char* astr__fn;
883+
extern const char* astr__ln;
884884

885885
bool isAstrOpName(const char* name);
886886

compiler/include/type.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "alist.h"
2727
#include "genret.h"
2828
#include "intents.h"
29+
#include "flags.h"
2930

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

@@ -459,8 +460,10 @@ class FunctionType final : public Type {
459460
Type* type_;
460461
IntentTag intent_ = INTENT_BLANK;
461462
const char* name_ = nullptr;
463+
FlagSet flags_ = 0;
462464
public:
463-
Formal(Qualifier qual, Type* type, IntentTag intent, const char* name);
465+
Formal(Qualifier qual, Type* type, IntentTag intent,
466+
const char* name, FlagSet flags);
464467
bool operator==(const Formal& other) const;
465468
size_t hash() const;
466469
bool isGeneric() const;
@@ -471,6 +474,8 @@ class FunctionType final : public Type {
471474
QualifiedType qualType() const;
472475
bool isNamed() const;
473476
bool isRef() const;
477+
FlagSet flags() const;
478+
bool isRetArg() const;
474479
};
475480

476481
using Formals = std::vector<Formal>;

0 commit comments

Comments
 (0)